From 96dc63afe12bfa624c12bd6d3ecf144efe147ed3 Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Tue, 31 Jan 2023 22:45:45 -0800 Subject: [PATCH] Update nano_c_mk1.ino --- nano_c_mk1/nano_c_mk1.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nano_c_mk1/nano_c_mk1.ino b/nano_c_mk1/nano_c_mk1.ino index b68a966..7726053 100644 --- a/nano_c_mk1/nano_c_mk1.ino +++ b/nano_c_mk1/nano_c_mk1.ino @@ -2,13 +2,13 @@ #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 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 unsigned long currTime; // non-blocking timer Adafruit_ADS1115 adc; int i; // loop iterators -float adcReadings[ADS_MAX]; +float adcReadings[ADS_MAX]; // buffer to hold all values read from an adc void setup() { Wire.begin(); @@ -18,12 +18,13 @@ void setup() { } void loop() { - // TODO: The current reading is too slow for even the arduino's own ide's grapher cannot parse the data in time + // TODO: The current reading is too slow beacuse `readADC_SingleEnded` is a blocking function. Not ideal on real-application. if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay for (i = 0; i < ADS_MAX; i++) { - adcReadings[i] = adc.readADC_SingleEnded(i) * VOLTAGE_RANGE / CONST_I2C; + adcReadings[i] = adc.readADC_SingleEnded(i) * VOLTAGE_RANGE / CONST_I2C; // this part can just read the adc. The conversion part could done in the Python code for flexibility } Serial.print("["); + // two seperate for loops for read adc and serial write to make it seems less laggy. again, this is completly wrong and need to replace it to something more non-blocking for (i = 0; i < ADS_MAX; i++) { Serial.print(adcReadings[i]); if (i != ADS_MAX - 1) {