Monday, January 21, 2013

ProtoCylon: Telling the Temperature

ProtoCylon: Telling the Temperature

By Bobby Neal Winters
I remember reading old documents, ages ago, about the computing model that was in three parts: Input, Process, and Output.  I thought it was kind of goofy at the time, but I was younger and smarter then.  Now that I am old and stupid I’ve gained an appreciation of how separating a project into smaller parts--even into three parts--can make doing the project a reality. (When I was younger and smarter, I never actually did anything.)
Thus is the tale of teaching my ProtoCylon to tell the temperature.  It comes in three parts and there is a part where I grow just a little bit.
The Input part I referred to in my post ProtoCylon Senses. This involved the DS18B20 digital temperature sensor.  This is a tiny thing.  It has three pins like a transistor.  Heck, for all I know, it might be a transistor.  The power goes in one side, out the other, and the center pin is connected to the Arduino board.  You can check the wiring at this tutorial.
For the Output, I used an LCD display.  This required growth for me.  I will work with the most obvious part first. This display has 16 pins.  That is a lot of pins. This is eased a bit by the fact that four of them are used for power and one is just grounded out.  This leaves eleven, though, and that is nothing to sneeze at.  This wasn’t the major growth inducer, however.  No, the big this is that I had to solder--yes, solder--those 16 pins to a set of pins that would allow me to plug it into the breadboard before I could even start to hook up the rest. (I will leave out the part where I attempted to hook it up without soldering. Not a happy time.)
After I got it soldered, I hooked it up and it didn’t work.  This is becoming a theme with me, but I am learning from this and recovering quicker each time.  The first stage is not to allow myself to be crushed by each failure.  I stop, take a deep breath, let it out, and try to figure out where I goofed.  
One useful technique is to take it apart and put it together again--slowly from scratch.  For wiring up the LCD display, I recommend the tutorial at Adafruit Learning System.
In between the Input and the Output is the Process.  The process in this case involved the use of libraries.  Libraries are specialized functions that make using hardware easier.  While there is a young turk deep inside me that would like to write my own libraries, there is an old goat who would like to actually get something done without taking it apart electron by electron.  Therefore, I happily use the libraries.
In creating this project, I actually used my creativity to merge two programs.  One of these was a “Hello, world!” program for the LCD that was an example that came with my Arduino compiler.  The other was in the book Beginning Arduino by Michael MacRoberts. I lay claim to the creativity crown because I did have to modify their code mutatis mutandis for the project to work.  The completed project follows:

This is the code:
The uses temperature sensors to take the temperature
and outputs it to an LCD display.
I fused two programs by other people and modified them.

The first was:

The LCD Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe

This example code is in the public domain.

The second was from Begining Arduino by Michael MacRoberts

// include the library code:

#define ONE_WIRE_BUS 3

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer, outsideThermometer;

void setup() {
 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 // Get the temperature sensors running.


void loop() {
 //Get the Temperatures
 //Print it on the first row, i.e. row 0
 //Print it on the second row, i.e. row 1
 lcd.setCursor(0, 1);
 //enjoy the weather for one second

void printTemperature(DeviceAddress deviceAddress){
 //Get the temperature
 float tempC=sensors.getTempC(deviceAddress);
 //print it out.
 lcd.print("TempF:  ");

No comments: