3 * Demonstrate use of the Gertboard A to D converter to make
4 * a simple thermometer using the LM35.
6 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
7 ***********************************************************************
8 * This file is part of wiringPi:
9 * https://projects.drogon.net/raspberry-pi/wiringpi/
11 * wiringPi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * wiringPi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************
29 #include <gertboard.h>
37 printf ("Gertboard demo: Simple Thermemeter\n") ;
38 printf ("==================================\n") ;
40 // Always initialise wiringPi. Use wiringPiSys() if you don't need
41 // (or want) to run as root
45 // Initialise the Gertboard analog hardware at pin 100
47 gertboardAnalogSetup (100) ;
50 printf ("| Channel 0 | Channel 1 | Temperature 1 | Temperature 2 |\n") ;
55 // Read the 2 channels:
57 x1 = analogRead (100) ;
58 x2 = analogRead (101) ;
60 // Convert to a voltage:
62 v1 = (double)x1 / 1023.0 * 3.3 ;
63 v2 = (double)x2 / 1023.0 * 3.3 ;
67 printf ("| %6.3f | %6.3f |", v1, v2) ;
69 // Print Temperature of both channels by converting the LM35 reading
70 // to a temperature. Fortunately these are easy: 0.01 volts per C.
72 printf (" %4.1f | %4.1f |\r", v1 * 100.0, v2 * 100.0) ;