Update nano_c_mk1.ino
This commit is contained in:
parent
ed850dea77
commit
ecd19e582e
|
@ -4,6 +4,7 @@
|
||||||
#define ADS_MAX 4 // # of analog input pins of an ADS1115
|
#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 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 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
|
#ifndef IRAM_ATTR
|
||||||
#define IRAM_ATTR
|
#define IRAM_ATTR
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,9 +30,9 @@ volatile bool new_data = false; // "ready" flag for the ADS1115
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void readData() {
|
void readData() {
|
||||||
// we only wanna grab/set data if the ADS is ready to
|
// 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
|
// 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)
|
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);
|
adc.startADCReading(MUX_BY_CHANNEL[channel], true);
|
||||||
new_data = false; // toggle back the flag
|
new_data = false; // toggle back the flag
|
||||||
|
@ -43,9 +44,8 @@ void IRAM_ATTR NewDataReadyISR() { // interrupt to make it read data
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Wire.begin();
|
|
||||||
Serial.begin(19200);
|
Serial.begin(19200);
|
||||||
adc.begin();
|
adc.begin(ADC1_ADDR, &Wire); // initialize one ADS1115 on approprate address
|
||||||
pinMode(READY_PIN, INPUT);
|
pinMode(READY_PIN, INPUT);
|
||||||
// "Ready" when on falling signal edge (negedge)
|
// "Ready" when on falling signal edge (negedge)
|
||||||
attachInterrupt(digitalPinToInterrupt(READY_PIN), NewDataReadyISR, FALLING);
|
attachInterrupt(digitalPinToInterrupt(READY_PIN), NewDataReadyISR, FALLING);
|
||||||
|
|
Loading…
Reference in New Issue