uploaded I2C test firmware
This commit is contained in:
parent
48da0c3be2
commit
6394e2c073
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue