adafruit / Adafruit_ADS1X15

Driver for TI's ADS1015: 12-bit Differential or Single-Ended ADC with PGA and Comparator
Other
289 stars 301 forks source link

added parentheses in conversionComplete request #62

Closed FahrJo closed 3 years ago

FahrJo commented 3 years ago

Without those parentheses the associativity does not fit to the expected behavior, at least in my case. I got the same known issue with the same value over all channels (#46).

caternuson commented 3 years ago

What platform are you building on?

FahrJo commented 3 years ago

I build on an ESP32 Devkit V1 with Platformio.

caternuson commented 3 years ago

It may be a PlatformIO thing? Are you sure it's bringing in the latest version of this library? I just tested this with a Feather ESP32 to see if it was something ESP32 specific and can't recreate the behavior.

Using an ADS1015 with channels 0 and 1 wired to the same voltage divider, channel 2 wired to GND, and channel 3 wired to 3.3V and running the example sketch: https://github.com/adafruit/Adafruit_ADS1X15/blob/master/examples/singleended/singleended.ino gets the expected output: Screenshot from 2021-03-30 11-37-09

Channels 0 and 1 follow each other as the voltage divider is changed and channel 2 stays at 0 and channel 3 at ~3.3V.

FahrJo commented 3 years ago

Sorry, first I have to revise my previous answer, this sketch is running on an ESP8266 NodeMCU, sorry for that mistake. And yes, it is the same sketch. My first channel is connected to an as voltage divider wired poti and the other ports are connected to GND or VDD (doesn't change the behavior). The first three channels return the expected value of the first channel and only the last channel returns the right value again.

By adding the parentheses around the bitwise operation, I get the correct value for all channels. I'm building on an MacOS system. And it currently depends on the compiler whether it prioritizes the & or the !=.

caternuson commented 3 years ago

OK, thanks for clarifying. Let's just merge it. Being more explicit with the parans won't break it for anything else.

FahrJo commented 3 years ago

Thank you😉!