From ed850dea77cede98584a49c1614a15eecd208b5e Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Wed, 1 Feb 2023 01:54:27 -0800 Subject: [PATCH] update firmware + cleanup a bit --- .idea/deployment.xml | 14 +++++ ESP32Driver.py | 1 + ReadRaw/ReadRaw.ino | 26 --------- SeeDatResistance.iml | 12 ---- __pycache__/read_arduino.cpython-39.pyc | Bin 1576 -> 0 bytes __pycache__/serial_plot.cpython-39.pyc | Bin 1681 -> 0 bytes __pycache__/serial_plotter.cpython-39.pyc | Bin 2954 -> 0 bytes __pycache__/ui.cpython-39.pyc | Bin 4514 -> 0 bytes nano_c_mk1/nano_c_mk1.ino | 64 +++++++++++++++++----- 9 files changed, 64 insertions(+), 53 deletions(-) create mode 100644 .idea/deployment.xml delete mode 100644 ReadRaw/ReadRaw.ino delete mode 100644 SeeDatResistance.iml delete mode 100644 __pycache__/read_arduino.cpython-39.pyc delete mode 100644 __pycache__/serial_plot.cpython-39.pyc delete mode 100644 __pycache__/serial_plotter.cpython-39.pyc delete mode 100644 __pycache__/ui.cpython-39.pyc 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 d00f49cfb86e41009d8d47169f212737f1ece2cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1576 zcmYim$!;4rl;kWLjV0N!9j|G^qV>T*ZKQD#6h=`rXaWQ+;uI0O4FU+XNZF%|NtLAJ zSQuUE_Lv}_ARPOj+h zFwM?{7242&R->GQLS@jZ0WHKx6zLVjk9M(3z?-o7nK-%%LDKc&|Gz~bpa|$oSf<2~ zFrFZbrq~ircyLK(c!EpJ!%Z|HfFrmb!(-X9wSH38O2nIQ$Rq(P^)j;Qt7wMxTf4wpm-uH~Cey|Yy~FzT_z$3) zGc;}SMetg;L4OhATq^4`4D>C&^oDR`(_aaAO~KkStd%k?qZ#41wh>=mg=qQmHkvF{ zJE7kxgK`1(RyNQonl$+8bQSh)myPL~U5C>RyD{AapIiL)49^1a+q6;Htnwgb%-8rj zU*sEa!bz)aO}EP?-&_YT7y)-@hA{db{q#13diLMz-?jI8tMbal67UVDiE(w4WTcpTB5#o;~`( zrQi8npLokzoSWy~TB6~3R&m7Fu3e3pxpnWpZ^Wn z?qU}D;)At$f9ME2=-7jr2Z;y%J!?PXvJ{4i)v73j&gwq9jvqWQnV9VqFi&7k0cAvy zMY;o-!aQTv;ofgZKLGuIKYo1p@+7yX!{e8JbnUgPR@;NNn-3%Nva-sqhuHq$!i8SY z0A=$K0Ky?&!U_B>_&rWYf>Y8Wzy&ELxJB;9cku@K5cZbfOe0*w`V-LHOnq;3N)=|`Co_KmksO{4F7z54(sw-Y#;SB~fCFzL`Rq*bVIe;E RooRf`VbH)EKFA;>{{gM{!kPd8 diff --git a/__pycache__/serial_plot.cpython-39.pyc b/__pycache__/serial_plot.cpython-39.pyc deleted file mode 100644 index 4e2bc115d96594da3b04b50029a370543adcd8dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1681 zcmYjR&2Jk;6rZpCa_o?nK$Cz_4@h8WqY4Qjp{k-%Kp>$U8mWa(*YE8{jYbW@Gx+)6_5irQ zt?>HegYX3`l>y<1;}rF9Nbr)UJr+7E-VNRA+zY*G_d|d5cEtr@AcC^S$pT~a1Z6u6 ziM8Pm7};0&Wqkqr_b4Ox5T~3yLt%sC1Jrb0LQJ%8oG0HsjN^_KE*}RN4;F=`{s5v; zi8bMvlL>?wBTWl%wv8ruZaKD%<}U2cHsbC(XbiR>c_4xPoWzLxzvDU9taNz5g9SMx zV=_lEnme!TipJuFdV`NJyC=YI-F+FWh(G*X~lup^ynYvw%ukrdbf6TOZ z?1Rr>feOYO7X*r0-yb!U&^pOtwR^1c%wTEiN@OaRt$r@GGTvE|9V8=R94^vmnEV4( znxLDcqLoEG(PW0T(}6HqT}Lnat%b*!F~F`YRjEr{)=t$OBidP3!6O=b?*xhG6M1`Eci zJ&nyuP^BTzW59Nw2jl49I5| zgHXGWIh)`K-a}7696K{~?9H5l6@d8+Tgrjwck+%f& zc9R&Vlc%{fP8zjE3djkio7m7a?=){3Uy6vQNd_RQewt{|TO^}?Uu4|Se%?1uH_an$ zoF&$*pXOlIPjyJ+P84p(Lbp;8gL&&H%6KYNtBRxy<4FfhM@c_)mlnqTF@nK?qZ2Vy z#_7u>1J8*TJ=F{h)+WfrIry^)v5Mj(4B!%|6ig;Q4!u#MK^>q4waAzq+~m>+aH=B%938BlRUd^XZsT%2>aN@HN1`)UMHKtG0^y! z;2rWVz6oy)Zvd_T=erwVwS`AJ)}0n|_dXyKrRu@%m0N&|bq86eSu?EqVi_R94a)%} zxe3wa4iMw3LEAb}@+~WR%ljg1doy&OBk5W*+D&5lzIAfPl8-F;z><%F z7;lwT0|fOR5CnPGp^`e(<&zD$WEPKhK`S^#A|> diff --git a/__pycache__/serial_plotter.cpython-39.pyc b/__pycache__/serial_plotter.cpython-39.pyc deleted file mode 100644 index f7c36a8747193fab6a658b74efd9ab2f8cab8586..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2954 zcmZ`*OK%*<5$>MX&OW%LXhsqxK^Yri;*DiOi4H*oL5LE8aSWI+Oax8_GzPQV&E>3S zXI4GEd@PnHIzSMBfD`0q8`#Y)*ZiEm<`N!*+;WM(>Lulsj117#UDc1OuB!fO(v_74 z!}s&Q{JUFkG4@YlmOmHFFVLzJ5Wxh`*^tGI)7Z&*?AYFoUE6y@KMw4io7aY69A2%f z$8|g3h#R(V#!cI|;+E}K;uY!6+QOT2&VJ2=FM`jR2+o~&RXBUBQ@ezA*5M`;sg^n$ z%3UxkJL97FtjLC`&dS30pZ@Myzu%*k%ipUT>_946%msthTsU8G;R^3_54JBj((1*Y z^ugD@azrTV;Df8#hG>GT2@ZQ&W@S&REX_a8ORc3MYXT+pSQS0Kq};*SNBb38^$!ru zW?WnC=gyo@S>kGM$_B1*H`zJyzU914hH+rW{w6$em-t$riQ3<2RjBKO2JC}{qH*Ew zJCHTeTG-JXtiY4t2CH+2vy67GS$adSL+YRN=j^k4XI!-UIBT#r$k(mz7N9ku0=f$}Zh7 zo>lJUWh#tUj&N3ZZI^L#u(gFzm1)2pQ6AG-iqhKzy)rLVW!zD&v1{BNA#Pxy(75SI z6$ibvI7+LyIUMCluPh4L)25Xy+tHx3+tcZARG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qTJ!w{jLDGT>vFYNdySKM>y#U{-Q=s%Zlhet zRd5<~w{=r+nW!_3>CHe2r-ox-VCzKaf`*W4&{KvpKrAF=FRN|af-vFeYg=o(5jZS3 zldF_Bt7^X1Xw0aJ=+pCs!>3UvML@9eAEh@z@*mRNpgbQMYN6pKBZird#+rtW_;D zSl+a)lWmJod}E_hdZTXc)?RPdim<~wr9ye5Tq@!*&#~R|=2in=t~blBuq>mYxBWznuOiN{c7_(1tq*2>(V}i09t&}zzIM#ur&w8H~oFMdAb*O=p z1*^4ZL1MT`K4n1F#TnpIr-mQ3c)r7!WxB~d<{v(uS$?LwNnR<`y$*BZB~ycN1L7fV zz88qjp>?9RoC7xr8m}~?1FIaH^X5kxswl(p0yUXU7t(MoP-EYXx1p4p3@7%4+%n`3 zq=b;cNhp`<0qitR90yYep4@XhcCe>5t(Mw`B7-jl-V_ckC`S%XdsRZU+U)O=eHSXh zFAs{}y*tp^VQ25%F4f4RIyD{3e&pRG8eBupyN@@^i_DBe?TM2Un$q+DS1lC zC|BfZ<+6h0419mBor2ln8@U;|qD(6pkj^L%pc z2c|^dYwp3&O{glNhN}J*29EfDg4`VsY>1UA-1$&uO}Il<)lI8v%OV|v_cN;chmK}= zDdje)~{N!}$)NYEo5XT{an|$HfUE}}c LaJY9#IT`;Sm$=Vt 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 + } }