From ecd19e582e485aa40ededc6c3737576891aef026 Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Thu, 2 Feb 2023 12:54:10 -0800 Subject: [PATCH] Update nano_c_mk1.ino --- nano_c_mk1/nano_c_mk1.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nano_c_mk1/nano_c_mk1.ino b/nano_c_mk1/nano_c_mk1.ino index 58950b8..8eb7c5c 100644 --- a/nano_c_mk1/nano_c_mk1.ino +++ b/nano_c_mk1/nano_c_mk1.ino @@ -4,6 +4,7 @@ #define ADS_MAX 4 // # of analog input pins of an ADS1115 #define VOLTAGE_RANGE 6.144f // ADS1115 default gain (+/- 6.144V). Change this number smaller will reduced its actual magnutude, and vice versa #define CONST_I2C 32768 // a constant value +#define ADC1_ADDR 0x48 // Address (identifyer) for the first ADS1115 chip. We might gonna have up to four of those connected in one I2C line #ifndef IRAM_ATTR #define IRAM_ATTR #endif @@ -29,9 +30,9 @@ volatile bool new_data = false; // "ready" flag for the ADS1115 /**************************************************************************/ void readData() { // we only wanna grab/set data if the ADS is ready to - if (new_data) { // for some reason it treat the last index to the zeroths and everything else off by 1 + if (new_data) { // TODO: for some reason some board get the channel index off // save the value - adcReadings[channel == 0 ? ADS_MAX - 1 : channel - 1] = adc.getLastConversionResults(); // the lambda inside [] to set index to its correct position + adcReadings[channel] = adc.getLastConversionResults(); channel = (channel + 1) % ADS_MAX; // request next channel #. Cycle back to zero if the number is larger than ADS_MAX (maybe must multiple of 2) adc.startADCReading(MUX_BY_CHANNEL[channel], true); new_data = false; // toggle back the flag @@ -43,9 +44,8 @@ void IRAM_ATTR NewDataReadyISR() { // interrupt to make it read data } void setup() { - Wire.begin(); Serial.begin(19200); - adc.begin(); + adc.begin(ADC1_ADDR, &Wire); // initialize one ADS1115 on approprate address pinMode(READY_PIN, INPUT); // "Ready" when on falling signal edge (negedge) attachInterrupt(digitalPinToInterrupt(READY_PIN), NewDataReadyISR, FALLING);