Browse code

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

tth authored on 07/02/2019 09:18:10
Showing 4 changed files
... ...
@@ -7,17 +7,17 @@ TMPFILE="/tmp/dd2data"
7 7
 IMAGE="graphe.png"
8 8
 NB_READ=5000
9 9
 
10
-./t -v -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE}
10
+./t -vv -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE}
11 11
 
12 12
 gnuplot << __EOC__
13
-set term png 	size 3200,512
13
+set term png 	size 3200,640
14 14
 set output 	"${IMAGE}"
15 15
 set grid
16 16
 set title	"Temperature dans le Double Dragon 2"
17 17
 set xdata 	time
18 18
 set timefmt 	"%s"
19 19
 set format x 	"%a, %H:%M:%S"
20
-set yrange [ 5.0 : 30.0]
20
+set yrange [ 0.0 : 30.0]
21 21
 plot	"${DATAFILE}" using 1:2 title " foo" with lines, \
22 22
 	"${DATAFILE}" using 1:3 title " bar" with lines, \
23 23
 	"${DATAFILE}" using 1:4 title "quux" with lines, \
... ...
@@ -45,12 +45,18 @@ return value;
45 45
 /*
46 46
  *   this fonction is specific to the LM35 thermo-sensor
47 47
  *   connected to a ADC pin of an Arduino Mega
48
+ *
49
+ *	WARNING !
50
+ *   this function _must_ be modofied if you change the
51
+ *   Vref of the Analog to Digital converter on the
52
+ *   Arduino !
53
+ *
48 54
  */
49 55
 int values2temperature(float array[4])
50 56
 {
51 57
 int	foo;
52 58
 for (foo=0; foo<4; foo++) {
53
- 	array[foo] *= (5.0 / 1023.0 * 100.0);
59
+ 	array[foo] *= (1.1 / 1023.0 * 100.0);
54 60
 	}
55 61
 return 0;
56 62
 }
... ...
@@ -29,9 +29,9 @@ float		datas[4];
29 29
 for (count=0; count<iters; count++) {
30 30
 	foo = getline_to(sfd, ligne, 100, 0);
31 31
 	//
32
-	if (verbosity > 1) {
33
-		fprintf(stderr, "getline #%d on %d -> %d\n",
34
-					count, iters, foo);
32
+	if (verbosity) {
33
+		/* fprintf(stderr, "getline #%d on %d -> %d\n",
34
+					count, iters, foo); */
35 35
 		fprintf(stderr, "%s\n", ligne);
36 36
 		}
37 37
 	foo = parse4values(ligne, 'T', datas);
... ...
@@ -4,7 +4,7 @@
4 4
 /* -------------------------------------------------- */
5 5
 
6 6
 #define NBVAL   4
7
-#define DELAI   10000
7
+#define DELAI   12000
8 8
 
9 9
 int   values[NBVAL];
10 10
 
... ...
@@ -13,7 +13,14 @@ void setup() {
13 13
   Serial.begin(9600);
14 14
   pinMode(LED_BUILTIN, OUTPUT);
15 15
   Serial.print("\n");
16
-  delay(2000);
16
+  /* XXX */
17
+  /*  changing the voltage reference of the ADC
18
+   *  greatly increase the prcision on the limited
19
+   *  range of our temperatures.
20
+   */
21
+  analogReference(INTERNAL1V1); // Pour Arduino Mega2560
22
+  
23
+  delay(1000);
17 24
 }
18 25
 /* -------------------------------------------------- */
19 26
 void updatevalues(void)
... ...
@@ -21,7 +28,7 @@ void updatevalues(void)
21 21
   int foo;
22 22
   for (foo=0; foo<NBVAL; foo++) {
23 23
     values[foo] = analogRead(A0);
24
-    delay(500);
24
+    delay(200);
25 25
    }
26 26
 }
27 27
 /* -------------------------------------------------- */