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

Add volts and other tweaks #61

Closed caternuson closed 3 years ago

caternuson commented 3 years ago

The main thing here is providing a new function to convert counts to volts. Example updated to show usage. Not sure what's less clunky? This PR, which requires making two calls (one to read, one to convert) OR adding new "volts" versions of existing raw ADC read functions, like readADC_SingeEnded_Volts or some such. Could also be a parameter maybe? readADC_SingleEnded(uint8_t channel, bool volts=False);

Another minor but (possibly) significant tweak is changing the return type of readADC_SingleEnded from uint16_t to int16_t. The use of uint16_t has been the source of lots of confusion and issue generation. It worked fine, not really an issue, but technically, all the register values are signed: image even if generating a negative value is not possible for the current arrangement. Using int16_t also works, and I'm not seeing any reason not to just use that.

ladyada commented 3 years ago

im ok with it!

caternuson commented 3 years ago

okie doke