From acd1248fa5b84ea4c34a668a96b41302996726d5 Mon Sep 17 00:00:00 2001 From: tth Date: Thu, 7 Feb 2019 10:18:10 +0100 Subject: [PATCH] using 1.1v Vref on the Arduino analog to digital converter for better precision --- serial/essai.sh | 6 +++--- serial/funcs.c | 8 +++++++- serial/t.c | 6 +++--- simulator/rdtemp/rdtemp.ino | 13 ++++++++++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/serial/essai.sh b/serial/essai.sh index e0014fc..9f9f773 100755 --- a/serial/essai.sh +++ b/serial/essai.sh @@ -7,17 +7,17 @@ TMPFILE="/tmp/dd2data" IMAGE="graphe.png" NB_READ=5000 -./t -v -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE} +./t -vv -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE} gnuplot << __EOC__ -set term png size 3200,512 +set term png size 3200,640 set output "${IMAGE}" set grid set title "Temperature dans le Double Dragon 2" set xdata time set timefmt "%s" set format x "%a, %H:%M:%S" -set yrange [ 5.0 : 30.0] +set yrange [ 0.0 : 30.0] plot "${DATAFILE}" using 1:2 title " foo" with lines, \ "${DATAFILE}" using 1:3 title " bar" with lines, \ "${DATAFILE}" using 1:4 title "quux" with lines, \ diff --git a/serial/funcs.c b/serial/funcs.c index cfd1808..d670534 100644 --- a/serial/funcs.c +++ b/serial/funcs.c @@ -45,12 +45,18 @@ return value; /* * this fonction is specific to the LM35 thermo-sensor * connected to a ADC pin of an Arduino Mega + * + * WARNING ! + * this function _must_ be modofied if you change the + * Vref of the Analog to Digital converter on the + * Arduino ! + * */ int values2temperature(float array[4]) { int foo; for (foo=0; foo<4; foo++) { - array[foo] *= (5.0 / 1023.0 * 100.0); + array[foo] *= (1.1 / 1023.0 * 100.0); } return 0; } diff --git a/serial/t.c b/serial/t.c index 4f4b2e3..02a73c9 100644 --- a/serial/t.c +++ b/serial/t.c @@ -29,9 +29,9 @@ float datas[4]; for (count=0; count 1) { - fprintf(stderr, "getline #%d on %d -> %d\n", - count, iters, foo); + if (verbosity) { + /* fprintf(stderr, "getline #%d on %d -> %d\n", + count, iters, foo); */ fprintf(stderr, "%s\n", ligne); } foo = parse4values(ligne, 'T', datas); diff --git a/simulator/rdtemp/rdtemp.ino b/simulator/rdtemp/rdtemp.ino index fb0125c..9f2610c 100644 --- a/simulator/rdtemp/rdtemp.ino +++ b/simulator/rdtemp/rdtemp.ino @@ -4,7 +4,7 @@ /* -------------------------------------------------- */ #define NBVAL 4 -#define DELAI 10000 +#define DELAI 12000 int values[NBVAL]; @@ -13,7 +13,14 @@ void setup() { Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); Serial.print("\n"); - delay(2000); + /* XXX */ + /* changing the voltage reference of the ADC + * greatly increase the prcision on the limited + * range of our temperatures. + */ + analogReference(INTERNAL1V1); // Pour Arduino Mega2560 + + delay(1000); } /* -------------------------------------------------- */ void updatevalues(void) @@ -21,7 +28,7 @@ void updatevalues(void) int foo; for (foo=0; foo