diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..fe4108e --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ESP32Driver.py b/ESP32Driver.py index 6660082..1533907 100644 --- a/ESP32Driver.py +++ b/ESP32Driver.py @@ -13,3 +13,4 @@ with ZipFile('ESP32driver', 'r') as zipObj: zipObj.extractall(os.path.join(os.path.expanduser("~"), "Downloads", "ESP32driver")) # TODO: after extract the file, run the .inf file in it to actually install the driver # 11/5/22 --> Created bash script with same name to run files and control destination folder. MUST RUN AS AN ADMINISTRATOR +# TODO: integrate the bash script into the python script so ppl don't have to run/have seperate files in their device \ No newline at end of file diff --git a/ReadRaw/ReadRaw.ino b/ReadRaw/ReadRaw.ino deleted file mode 100644 index 79fc70d..0000000 --- a/ReadRaw/ReadRaw.ino +++ /dev/null @@ -1,26 +0,0 @@ -#define WAIT_TIME 1000UL - -int pins[] = {A0, A1, A2, A3, A4, A5}; -int i; -unsigned long currTime; // non-blocking timer - -void setup() { - Serial.begin(9600); - currTime = millis(); -} - -void loop() { - if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay - // Serial.println(); - Serial.print("["); - for (i = 0; i < sizeof(pins)/2; i++) { - Serial.print(analogRead(pins[i])); - if (i != sizeof(pins)/2 - 1) { - Serial.print(", "); - } - } - Serial.println("]"); - currTime = millis(); - } - -} \ No newline at end of file diff --git a/SeeDatResistance.iml b/SeeDatResistance.iml deleted file mode 100644 index 597619a..0000000 --- a/SeeDatResistance.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/__pycache__/read_arduino.cpython-39.pyc b/__pycache__/read_arduino.cpython-39.pyc deleted file mode 100644 index d00f49c..0000000 Binary files a/__pycache__/read_arduino.cpython-39.pyc and /dev/null differ diff --git a/__pycache__/serial_plot.cpython-39.pyc b/__pycache__/serial_plot.cpython-39.pyc deleted file mode 100644 index 4e2bc11..0000000 Binary files a/__pycache__/serial_plot.cpython-39.pyc and /dev/null differ diff --git a/__pycache__/serial_plotter.cpython-39.pyc b/__pycache__/serial_plotter.cpython-39.pyc deleted file mode 100644 index f7c36a8..0000000 Binary files a/__pycache__/serial_plotter.cpython-39.pyc and /dev/null differ diff --git a/__pycache__/ui.cpython-39.pyc b/__pycache__/ui.cpython-39.pyc deleted file mode 100644 index acac223..0000000 Binary files a/__pycache__/ui.cpython-39.pyc and /dev/null differ diff --git a/nano_c_mk1/nano_c_mk1.ino b/nano_c_mk1/nano_c_mk1.ino index 7726053..58950b8 100644 --- a/nano_c_mk1/nano_c_mk1.ino +++ b/nano_c_mk1/nano_c_mk1.ino @@ -1,37 +1,71 @@ -#include // https://github.com/adafruit/Adafruit_ADS1X15 +#include // https://github.com/adafruit/Adafruit_ADS1X15, with partially its "continuous" example code integrated in ths #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). Change this number smaller will reduced its actual magnutude, and vice versa #define CONST_I2C 32768 // a constant value +#ifndef IRAM_ATTR +#define IRAM_ATTR +#endif -unsigned long currTime; // non-blocking timer Adafruit_ADS1115 adc; -int i; // loop iterators +unsigned long currTime; // non-blocking timer +int channel = 0; // mux selector for which channel (AIN0-AIN3) to read the analog value from. See ADS1115 datasheet for details float adcReadings[ADS_MAX]; // buffer to hold all values read from an adc +constexpr int READY_PIN = 3; // pin # that connects the "ALRT" pin of the ADS1115 to the board +volatile bool new_data = false; // "ready" flag for the ADS1115 + +/**************************************************************************/ +/*! + @brief parse data from the ADS1115 and record to the buffer array + + Upon data recieved, call getLastConversionResults() once to record the + value into the adcReadings array. Increment/cycle back the channel mux + selector and call startADCReading() to read the next channel. set back + the new_data flag back to false + + @acknowladgement https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_continuous_4_channel/ADS_continuous_4_channel.ino +*/ +/**************************************************************************/ +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 + // save the value + adcReadings[channel == 0 ? ADS_MAX - 1 : channel - 1] = adc.getLastConversionResults(); // the lambda inside [] to set index to its correct position + 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 + } +} + +void IRAM_ATTR NewDataReadyISR() { // interrupt to make it read data + new_data = true; +} void setup() { Wire.begin(); Serial.begin(19200); adc.begin(); - currTime = millis(); + pinMode(READY_PIN, INPUT); + // "Ready" when on falling signal edge (negedge) + attachInterrupt(digitalPinToInterrupt(READY_PIN), NewDataReadyISR, FALLING); + adc.startADCReading(MUX_BY_CHANNEL[channel], true); // read once + currTime = millis(); // record the current time } void loop() { - // 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; // this part can just read the adc. The conversion part could done in the Python code for flexibility - } + readData(); // always read data from the ads1115 + if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay, giving ADC and everything else enough time to update + // print the array, as we don't have internal method for it. 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) { + for (int i = 0; i < ADS_MAX; i++) + { + Serial.print(adcReadings[i] * VOLTAGE_RANGE / CONST_I2C); + if (i != ADS_MAX - 1) { // fence-post the array print Serial.print(", "); } } Serial.println("]"); - currTime = millis(); - } + currTime = millis(); // reset the current time + } }