uploaded I2C test firmware

This commit is contained in:
Eric Yu 2023-01-31 01:22:12 -08:00 committed by GitHub
parent 48da0c3be2
commit 6394e2c073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

32
nano_c_mk1/nano_c_mk1.ino Normal file
View File

@ -0,0 +1,32 @@
#include <Adafruit_ADS1X15.h>
#define WAIT_TIME 1000UL // default wait time each value read
#define ADS_MAX 4 // # of analog input pins of an ADS1115
#define VOLTAGE_RANGE 6.144f // ADS1115 default gain (+/- 6.144V)
#define CONST_I2C 32768 // a constant value
unsigned long currTime; // non-blocking timer
Adafruit_ADS1115 adc;
int i; // loop iterators
void setup() {
Wire.begin();
Serial.begin(19200);
adc.begin();
currTime = millis();
}
void loop() {
// TODO: The current reading is too slow for even the arduino's own ide's grapher cannot parse the data in time
if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay
Serial.print("[");
for (i = 0; i < ADS_MAX; i++) {
Serial.print(adc.readADC_SingleEnded(i) * VOLTAGE_RANGE / CONST_I2C); // a raw to voltage conversion based from the library's method
if (i != ADS_MAX - 1) {
Serial.print(", ");
}
}
Serial.println("]");
currTime = millis();
}
}