I2C ADS1115 ADC Chip - Not all channels in data

I got a flow working great... buttons, blinky lights... GPIO... all good.

I added an ADS1115 analog to digital chip and you MUST connect the channels in a daisy-chain combination or it will fail Node Red so hard you will need to go to the directory and delete the file. (Lesson learned... backup...backup...backup.)

Anyway, I was always getting data for channel 3 (They go 0 to 3.) but never anything else, and I have a potentiometer connected to CHAN-0. I have a trigger once per second for testing, and I see all four channels updating... but only the last in the queue will ever make it to the event message. I reordered the layout in the flow to 3,2,1,0 and now I only ever see chan-0 in the event.

I thought, okay, perhaps it is just so fast that I cannot see it... so I installed some IF / THEN / ELSE filters in the JavaScript to look for the text A0-GND, A1-GND, A2-GND, and A3-GND, so if found, it returns the position in the string if not, it returns -1.

I then have it display either "Valid Data" or "No Data Found" in the matching text box.

And as I suspected... it ONLY finds data from the last position called.

Anyone know how to get past this? I mean... I could use only ONE input per chip... but that's limiting me to 3. If this can be done, then I have 12 which is plenty.

Anyone have an idea???

See attached. ~ JerryBACKUP 4-10-2020.json (34.8 KB)

Look at the output data on the ADC.

errrr - surely you can tap the result from each of those ADC nodes as they go past ?
(maybe use a join node to collect all 4 readings ?

Even better... David Burrows (the guy that created the module
node-red-contrib-anolog-to-digital-converter-raspberry-pi

Jumped on SLACK and we beat on it for about an hour or more. It resulted in update 4.22 and 4.23 which fixed a few issues.
(We found the thingie that crashes Node Red too!)

Then... we (he) got creative with post processing the data in the stream... wait until you see this flow... and I jumped in with the JavaScript and parsed each sub-stream.

It wasn't the quick fix we both thought it was. But hey... it is working JUST FINE now so I'll have to create some custom graphic displays for it and give it a full test.

I'm making SURE this one is backed up!!!
DISP 4 CHAN ADC plus Buttons Primary 2020-04-10 flows.json (42.5 KB)
~ Jerry

2 Likes

I did notice one odd thing that I cannot explain... it sends out the four A/D channels as:
2.212345678 ADC-A
0.545686776 ADC-B
0.555699726 ADC-C
0.514765869 ADC-D
So all I have to do is identify the channel name, then pull the attached voltage. I only have one potentiometer connected now, and it is reading about 2v. The other channels are like 0.5 or so. Yet every now and then... I see the data for channel A pop up on channel D.

So weird... because this is my JavaScript to capture and send to the appropriate text box for viewing...

        function wsMessage(event) 
        {
            MESSAGE.value   = event.data ;
            if ( MESSAGE.value.match(/ADC-A/g)  == "ADC-A" ) {chan0.value = parseFloat(event.data); }  
            if ( MESSAGE.value.match(/ADC-B/g)  == "ADC-B" ) {chan1.value = parseFloat(event.data); }  
            if ( MESSAGE.value.match(/ADC-C/g)  == "ADC-C" ) {chan2.value = parseFloat(event.data); }  
            if ( MESSAGE.value.match(/ADC-D/g)  == "ADC-D" ) {chan3.value = parseFloat(event.data); }  
        }

Pretty simple... look for the tag, pull the voltage and stick it in a box. I have no clue how it can possibly mistake ADC-A for ADC-D. So strange... happens like once every 30-40 times.

Computers... they will drive you insane. (Short drive for me.)

~Jerry

Hi Jerry,
Have you thought about using a slave to sample your analog values??

A number of people on the forum use Wemos D1 Minis (ESP8266-based microcontrollers) to capture and control things (rather than using a Raspberry Pi).

Personally I use Wemos D1 Minis flashed with ESP Easy firmware. You can then plug in all sorts of interface devices and pick-up device drivers built in to ESP Easy. Tasmota offers similar features.

One key point, as far as I'm concerned is, a Wemos is inexpensive, so if you destroyed it - it's only GBP 2 down the drain rather than GBP 30 or more for a RPi.

Dynamic David

Just wondering,,,
You say event.data is a string, typically like "2.212345678 ADC-A"
Would it not be safer to first create an array to pick the voltage level value from?
Like:
chan0.value = parseFloat(event.data.split(' ')[0]);

DynamicDave -
That is a very good idea. Actually I can directly program Atmel AVR chips in BASCOM which is a version of BASIC. (Don't laugh!) I have been using that compiler for about 22 years now, it makes the same HEX files that you would see on an Arduino only the bootstrap loader is not required so I can program chips right out of the container.

Since there is a set of SERIAL modules, it would not be hard for me to have the Raspberry Pi do the fancy graphics and just send a signal of what the pin status is, then get direction as to how to handle it.

Right now I'm learning how to handle the following...
GPIO OUTPUT - Check.
GPIO INPUT - Check
A/D INPUT - Pretty much yeah.
12C Output to 16-Bit I/O extenders - On the list.
Serial In/Out - On the list.
HTML - Check
JavaScript - Pretty much... haven't used it in awhile... kinda rusty.

Krambriw - Let me give that a try. I don't think it will work... the current code should be near bulletproof... but hey let me see. I was using search(), then includes(), and now match(). I may as well look at new tools for the data extraction too!

Thanks,
Jerry

Addendum... I tried the code but it immediately locked up JavaScript. After evaluating more closely, it is attempting to pull an array from a single item. You see, the way I have it set up with David's help is that each stage is delayed by 200uS so that it sends out the data one at a time. Another reason I couldn't understand the intermittent data issue. I even slowed the delays down to 1 per second with the trigger once per 5 seconds. I could clearly see ADC-A but yet it fell into the ADC-D box. It's odd. I'll have to tinker with filter modification, timing, etc. Right now... I'm getting a solid data flow... it just breaks down to parsing it differently, or modifying the tags in the "STRING" module.

methinks there may be a lot of extra conversions going on here - what is the full msg that comes out of one of the ADC nodes ? Does it have other properties as well as the payload ? I'm sure you would be better trying to send a json like string across your websocket which would much easier to parse at the other end.

The nodes are laid out like this...

Here is an actual message after processing...
2.2515687124240853 ADC-A
The HTML page looks like this...
image

You can see that channel-A has just sent data and was properly parsed.

I am as of yet unfamiliar with json... I'll start reading about it.

Thanks,
Jerry

can you add another debug node (or copy /paste the existing one) and attach to the output of one of the ADC nodes and show us what that returns ?

Do you mean node-red kept crashing when it started the flows so you couldn't edit the flows file? If so then possibly starting it with the --safe option would have saved the situation.

1 Like

It crashed so hard that the Raspberry Pi booted, attempted autoload of Node Red, crashed, rebooted, attempted autoload ot of Node red, Crashed....

I ended up hitting control keys fast enough that I got it to lock up, and deleted the files, then power cycled it and it restarted normally. I mean... if you are gonna break it... break it good. Right?

David found an error in the node and updated it to version 4.22 then later in the evening found another issue and updated it to version 4.23. It has been very stable since.

I have that Raspberry Pi set to auto-boot Node red, then auto-boot chrome and jump to the_lab:1880/DISP because I want it to run very similar to if it was in a remote location.

I probably should rethink that strategy...

This sheds more light on it... my JavaScript is functioning... it is something odd in the filter... or because there is nothing connected to the ADC other pins the output is actually glitched.

image

Notice the Channel Loggers... the A,B,C,D is correct... but logger D reports a voltage... I'll have to put load resistors on the other channels and try it. The plot thickens!

Update: Well, I added resistors and the other channels read 0.0v. Running for 4 hours and I have not seen any errors. (Yeay). I also added .toFixed( ) into the code to limit it to 6 decimal places... trying out the command... and it looks really pretty now.

if ( MESSAGE.value.match(/ADC-D/g) == "ADC-D" ) {chan3.value = parseFloat(event.data).toFixed(6); }

So I'm definitely archiving this code to grab snippets for future projects.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.