ADS1115 analog gain signal module - how to run it with espruino? #835
Replies: 82 comments
-
Posted at 2015-08-20 by @gfwilliams Sure, I think your first port of call would be to try and replace the readRegister/writeRegister commands that were in arduino:
In Espruino I reckon they should look like this:
That might actually print the conversion value... But for a fully working ADC you'll need to look at readADC_SingleEnded and copy what that's doing. It does use a delay there, so I'd be tempted to use a callback to return the values instead, as it means Espruino can get on with other stuff in the mean time:
Maybe define a 'config' variable instead of all the #defines as well,
hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-20 by bigplik Thank you for your effort, I am beginner with espruino and python, so don't understand much of your code, a bit better doing that with C, I mean it is more easy to me how to place the parts of the code and implement libraries, here for now it is a bit of cosmos to me Is there any tutorial to show how to implement new modules, libraries, and place code properly in Web IDE? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-20 by @gfwilliams There's this one? For now, I would copy and paste this into the right-hand side of the Web IDE:
Change I2C1.setup pins to whatever you're using, and then see what happens... It might be that it works, but I haven't been able to test it. When it is working properly, it's easy enough to convert it into a module - just remove the few 'testing' lines at the end and add |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-21 by bigplik will check it at the evening, no errors in WEB IDE ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-22 by bigplik I've got that error when wanted to upload it into board
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-22 by DrAzzy I2C1.setup({ scl : ..., sda: ...} ); Did you fill in which I2C pins you have it connected to there? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-23 by bigplik Yes I did try to choose both pins from both ports (I2C1 and I2C2) from my maple leaflabs,
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-23 by LawrenceGrif Have you tried pull resistors on the ic2 scl & sda to to vdd? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-24 by @gfwilliams It's a bug in the code I posted - as I don't have anything here to test with. Same with |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-25 by bigplik code works ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-25 by @gfwilliams Have you tried calling the following code again:
The first argument is a value between 0 and 3 (for each input). As with other things in Espruino, the code works with a callback (so Espruino can do other things while it's waiting for the ADC). For setting the gain, use the following code, but with the
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-25 by bigplik thank you Gordon, it is working ;) play with Espruino is much easier than C and PIC modules I see ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-25 by @gfwilliams I'm not sure what to suggest. This is just like Maybe you want to read 4 values every second and write them to the console, you could do:
Basically you call the function and it returns almost immediately. However it calls the function you supply at some point later on. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-25 by @gfwilliams I have also just put the ADS1X15 module onto the website, so you no longer need all the code I posted. You just need:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-25 by bigplik thank you for a lot of your work Gordon, now it would be much much easier for others ;) Do you know how to set print or console.log function to show float value like from analogRead but only to show 3 places after .dot ? eg. (1.234V) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-17 by @gfwilliams You can use an older version of firmware using 'advanced flasher' but I'd advise you just use a more recent firmware that'll have this (and other things!) fixed. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-17 by bigplik I still use 1v81 , now used this code
and ADS shows me only one channel value, I've connected 3 voltage sources into it,
I checked 3 other ADS, they are working on arduino, but here I get only one value, also I am not sure about gain settings, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-23 by bigplik any updates about new version of espruino software? or ads1115 error fix? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-24 by @gfwilliams Anything from the git builds from the last few weeks should have this fixed, so you can just use the instructions under I'll do a 1v82 release today though. I think it's stable enough now. What do you mean by the ads1115 error fix? The |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-24 by bigplik I didn't get readings of all sensors I connected, just first one, but I connected 3 of them, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-25 by @gfwilliams Have you tried with the new 1v82 release? That should have |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-27 by bigplik thank you Gordon, it is working now, espruino is reading all channels and gain is working as well, do you know the way how to create new var value which will get readings from this ADS function?
I have to do plenty of mathematical operations with my variable on few channels, it would be much simpler to use eg. var inputOne instead of this function above, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-27 by @allObjects Just place all your processing into the anoymous funtion - either inline defined - or outside defined. For inline/anonymous, it would look - for channel 0 - like this:
A 'better' way would be to define upfront functions for the different - channel specific - haendling which include: receiving, processing, and printing. This allows to re-use the handlers for more than just one channel, if needed.
The 'main' flow of your application will include something like that - logically:
I said logically, because a next Other postings cover the sequencing of (dependent) callbacks (see squence controller - lines 20..30. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-27 by @allObjects Just place all your processing into the anoymous funtion - either inline defined - or outside defined. For inline/anonymous, it would look - for channel 0 - like this:
A 'better' way would be to define upfront functions for the different - channel specific - haendling which include: receiving, processing, and printing. This allows to re-use the handlers for more than just one channel, if needed.
The 'main' flow of your application will include something like that - logically:
I said logically, because a next Other postings cover the sequencing of (dependent) callbacks (see squence controller - lines 20..30). When all channels have to be read with the same frequency at about the same time, a sequence controller does just fine. If the channels have to be read whit a different frequency, it becomes a bit more complex: the sequenc controller has to be extended to handle time dependent evnt list, and the addition of an even has to insert the future event taking into acount when in the future it has to happen, how long it takes to complete. Complexity increases with handling efficiently dependent AND independent events, because independent events can overlap (something can be done between the initiation and the callback of the event in order to be efficient: either just some initiation(s) or complete independent event(s), all depending on the times involved. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-01 by bigplik thank you, got my code construction and can deal with my data ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-03 by bigplik is it possible to make for loop with some delay? I want to make an average sum for first few readings from ADS but for loop without delay between following readings pico return only 0 value, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-07 by @gfwilliams @bigplik you can't use a You need to use callbacks, so that you issue the next reading only after you got the last one. For instance:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-07 by @allObjects ...and for the processing you have to apply the 'delay pattern' to 'wait until all readings happened'. Therefore, add something like this after line 7 in code above (note the curly bracket added to the end of line 6):
Mean may not be the right thing to do because there may be values outside expected confidence interval. This solves only the ten first readings for channel 0... What about the other channels... and then the subsequent readings at intervals of... With all this nesting of callbacks, you end up in callback hell. Most sophisticated solution are Promises... and these aren't the easiest thing to grasp either. For a first 'cut' to get all four channels read 10 times and after that every 30 seconds, see next post. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-07 by @allObjects The code below reads ten times channel 0..3 one ofter the the other, and after that, all channels one right after the other every 30 seconds. To understand the idea behind the implementation: the array's size is used to determine if 10 reads or 1 read has to be done. After all channels have been read ten times, the array is resized to 1, and the code branches into the interval logic.
Some refactoring will make the code leaner (with less repetition of ads.getADC(... invocation... etc.) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-14 by bigplik I am afraid it's to hard for me at the moment, don't understand well this array construction |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-20 by bigplik
Hi, I would like to use ADS1115 module with espruino, it is working by I2C, under arduino is nice library
https://github.com/adafruit/Adafruit_ADS1X15 ,
I was trying this library to work with stm32 maple leaflabs R3+ and it was working with it well.
I wonder how to use this module with espruino?
Any chance you could help me to solve it?
Beta Was this translation helpful? Give feedback.
All reactions