using 1.1v Vref on the Arduino analog to digital converter for better precision

This commit is contained in:
tth 2019-02-07 10:18:10 +01:00
parent dd4757f56c
commit acd1248fa5
4 changed files with 23 additions and 10 deletions

View File

@ -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, \

View File

@ -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;
}

View File

@ -29,9 +29,9 @@ float datas[4];
for (count=0; count<iters; count++) {
foo = getline_to(sfd, ligne, 100, 0);
//
if (verbosity > 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);

View File

@ -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<NBVAL; foo++) {
values[foo] = analogRead(A0);
delay(500);
delay(200);
}
}
/* -------------------------------------------------- */