Sending Output Data to LCD Effects Value of Input Signal

I have enountered a problem which may indicate a hardware/firmware problem with the Ardunio or Electronic Brick. I don't know how to get this post to the people who should evaluate it.

Situation: A simple sketch to read the input from the Electronic Brick temperature sensor, convert it to Degrees C and output to serial monitor and/or LCD board. Listings of sketches for serial monitor only and serial monitor + LCD follow.

==============================================================
Serial Monitor Only

// Project Seven - temperature
//

int a;
int del=1000; // duration between temperature readings
float temperature;
int B=3975;
float resistance;

void setup()
{
Serial.begin(9600);
}

void loop()
{
a=analogRead(1);
resistance=(float)(1023-a)*10000/a;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
delay(del);
Serial.print(a);
Serial.print(" ");

Serial.println(temperature);
}

=======================================================================
Serial Monitor Plus LCD

// From http://www.seeedstudio.com/wiki/Project_Seven_-_Temperature
//
// Project Seven - temperature
//
//
// temperature is in Deg C
int a;
int del=1000; // duration between temperature readings
float temperature;
int B=3975;
float resistance;
float degF ;

#include <LiquidCrystal.h>

#include<LiquidCrystal.h>
// Liquid/crystal display with:
// rs on pin 10
// rw on pin 11
// enable on pin 12
// d4, d5, d6, d7 on pins 13, 14, 15, 16
LiquidCrystal lcd(10,11,12,13,14,15,16);

void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);

}

// Project Seven - temperature
//

void loop()
{
a=analogRead(1);

resistance=(float)(1023-a)*10000/a;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
degF = (9/5)*temperature + 32 ;
delay(del);

Serial.print(a);
Serial.print(" ");
Serial.println(temperature);

lcd.clear();
lcd.setCursor(0,0);
lcd.print(temperature);
lcd.setCursor(6,0);
lcd.print("C");
lcd.setCursor(9,0);
lcd.print(degF);
lcd.setCursor(15,0);
lcd.print("F");
lcd.setCursor(0,1);
lcd.print(a);
lcd.setCursor(5,1);
lcd.print("a");

}

With trhe serial monitor only, the value of "a" (temp sensor input) is about 500 and Deg C is about 24. With output to the LCD, the value of "A" is about 122 with Deg C about -14.0. When I comment-out all coding related to the LCD in the second sketch, the value of "a" is much closer to the 500 value in the serial monitor only sketch. With all LCD related lines commented-out, the two sketches are virtually identical.

Will someone look at this and confirm/deny a hardware/firmware problem? Also, can someone try it with a Grove shield and temp sensor?

Thanks for your help. This is a real head scratcher!

My suspicion is that this is a hardware issue - can you provide more information on how things are wired up.

Incidentally there is a code tag, use the '#' button, this will list code sections properly

// like this

What Arduino-board are you using?

James and MarkT,

Thanks for the prompt responses.

Wiring: Temp. sensor to A1 and LCD to Bus2 on Electronic Brick chassis.
Ardunio Board: UNO, version R3.

To see if problem is related to source of power, I tested with both USB only and USB plus external DC source. No change.

I am tempted to order a Grove Starter Kit so see if that makes a difference. Also, the Electronic Brick was purchased from Trossen Robotics. I may send them my code as ask that they run the sketches on a different Brick and UNO so see if the problem is unique to me.

Thanks for your help.
Ken Russell

california-ken:

// d4, d5, d6, d7 on pins 13, 14, 15, 16

LiquidCrystal lcd(10,11,12,13,14,15,16);

Why are you using pins 14, 15, and 16?

california-ken:
Wiring: Temp. sensor to A1 and LCD to Bus2 on Electronic Brick chassis.
Ardunio Board: UNO, version R3.

Digital Pins 14,15, and 16 on an Uno are Analog 0, 1, and 2.

I'm confused how you have your LCD wired, but you are clearly trying to use pins A0/D14, A1/D15, and A2/D16 two different ways in the code.

James,

You hit it on the head.

I lifted the LCD code from the Electronic Brick Cookbook, Vol I.

The Brick chassis schematic in the Cookbook shows bus #2 pins 2 - 5 as D10 - D13. Now I'm really confused. I a new kid at Ardunio and I thought all "D" pins were digital and all "A" pins were analog.

I changed the temp sensor input to port A5 and all is well!!!

Looks like I need to do more homework on Ardunio/Brick pin assignments.

Thanks a bunch.

Ken Russell

Analog inputs can be used as digital inputs / outputs. By default they are analog input, but you can use pinMode/DigitalRead/DigitalWrite to use them as digital inputs.

See the note at the bottom of the page here:
http://arduino.cc/en/Reference/DigitalRead