Arduino‎ > ‎Brewing Arduino‎ > ‎

LCD Graphic Shield Plus Temperature Sensor!

posted Oct 17, 2010, 8:01 AM by Haris Hashim   [ updated Mar 29, 2011, 7:46 AM ]
This shield is one of the new toy in my recent DFRobot shipment. Being a display shield, it has to be positioned top most. Otherwise, how to see the display? So there is no standard top shield connector provided. Instead, an array of 3 pin male connector can be found on top of the shield. 

Upon closer inspection, this 3 pin connector can be used to connect DFRobot sensors. This is where things get exciting. Anyway, I planned to blog about  the sensors too. Now both LCD Graphic Shield and sensor can be tested and blogged about in one article!

Please note that there are two type of sensor in DFRobot standard sensor set. Analog sensor and digital sensor. Connectors for digital sensor are on top left corner, while for analog sensor are in the bottom right corner of the shield. It is a row of three pins. The first pin are the sensor output, which can be analog or digital. The other two pins are VCC and GND. 

 
The shield on top of Uno

Connector for digital sensor

 
Connector for Analog sensor


It might not be obvious initially, but they both require different type of cable. Due to pin out configuration that switch between VCC and GND. 
  • For Analog sensor, pin 1,2 and 3 are respectively Signal (S), Ground and VCC. 
  • For Digital sensor, the pin 1,2 and 3 are respectively Signal (D), VCC and Ground. 
So a common pitfall (happen to me!) is to use digital cable with analog sensor or vice versa. Which will not work!

Here is pictures of digital and analog cable. Also picture of LM35 Linear Temperature Sensor which is an analog sensor. Hence pictured using analog cable. Click the picture for larger view.


 Left: Analog cable
Right: Digital cable

Analog sensor using analog cable.
 


Setting up the hardware part of this tutorial is as simple as:
  1. Stack the LCD Graphic Shield on top of an Arduino board. In my case I use Uno, the latest basic official Arduino board.
  2. Connect LM35 Linear Temperature Sensor to analog input 5. Make sure pin 1 is S, pin 2 is GND and pin 3 is VCC.
  3. Connect Arduino board to the PC or notebook using USB and un the Arduino development environment. Don't forget to set the appropriate COM port and board type. 
The rest is coding which we will go through in picture tutorial bellow. In the mean time, enjoy this video showing the display output. Help to visualize what is going to happen!



Picture Tutorial




Source Code

// Global area
#include "LCD4884.h"

const float MULTIPLIER = 0.48828;

// Initialization that run on 
// powerup or after reset
void setup(){
  lcd.LCD_init();
  lcd.LCD_clear();
  lcd.LCD_write_string( 8, 0, "Homebrew &", MENU_NORMAL );
  lcd.LCD_write_string( 7, 1, "Technology", MENU_NORMAL );
  lcd.LCD_write_string(14, 2, "presents", MENU_NORMAL );
  lcd.LCD_write_string(16, 3, "Graphic", MENU_NORMAL );
  lcd.LCD_write_string(13, 4, "LCD 4884", MENU_NORMAL );
  lcd.LCD_write_string(16, 5, "Shield", MENU_NORMAL );
  
  lcdBlink(3, 2000);
}

// After setup is completed this part
// of code will repeat until device off
void loop(){
  lcd.LCD_clear();
  int raw = analogRead(2);
  int temp = MULTIPLIER * (float) raw;
  char tempString[6] = "";
  sprintf(tempString,"+%d",temp);
  lcd.LCD_write_string_big(
      15, 1, tempString, MENU_NORMAL);
  lcd.LCD_write_string(
      55, 2, "C", MENU_NORMAL);
  delay(2000);
}

void lcdBlink(int count, int delayMs){
    for(int i=0; i< count; i++){
     lcd.LCD_backlight(1);
     delay(delayMs);
     lcd.LCD_backlight(0);     
     delay(delayMs);
   }
   lcd.LCD_backlight(1);
}

*NOTE* : Stay tuned for the next part. Where we will demonstrate the simple code to bounce the temperature reading around and add RTC chip and turn this temperature display to temperature display plus clock! Here is the next part!



Conversation Element


ą
Haris Hashim,
Oct 18, 2010, 8:22 PM
Comments