Saturday, 25 February 2017

arduino - Serial Enabled LCD


What sort of LCD should should i be using to go with my Arduino?


I have used the HD44780-compatible LCD in the past, but heard that the Serial Enabled LCDs make life a lot easier.



Answer



It really depends upon what you want to do with the Arduino, besides displaying information on the LCD. Like you, I used an HD44780-compatible LCD for my first project, and while it worked fine, it consumed half of my digital I/O pins, and seriously limited what I could do with my project. If you don't really need a lot of I/O, that can be fine.


On the other hand, if you want to do more than that, a serial LCD interface may make more sense. They cost twice as much, but as you can see from this example, you can daisy chain with I2C.


/* Quick example to use FunGizmos serial LCD in I2C mode
*
* Connections between LCD & Arduino
* LCD P2

* Pin1 not connected
* Pin2 not connected
* Pin3 SCL -> Analog in 5 (Arduino has internal pullup resistor)
* Pin4 SDA -> Analog in 4 (Arduino has internal pullup resistor)
* Pin5 VSS -> gnd
* Pin6 VDD -> +5V
*
* To enable I2C mode of LCD Pads of R1 must be jumpered on back of LCD
* (Between R6 & R14 right below the black IC glob)
*

*/

#include

int lcd_addr = 0x50; //default I2C hex address from datasheet
int blink;

void setup(){
delay(1000); //allow lcd to wake up.


Wire.begin(); //initialize Wire library

// Wire library expects 7-bit value for address and shifts left appending 0 or 1 for read/write
// Lets adjust our address to match what Wire is expecting (shift it right one bit)
lcd_addr = lcd_addr >> 1;

//Send lcd clear command
Wire.beginTransmission(lcd_addr);
Wire.send(0xFE); //Cmd char
Wire.send(0x51); //Home and clear

Wire.endTransmission();

Wire.beginTransmission(lcd_addr);
Wire.send(0xFE); //Cmd char
Wire.send(0x70); //Display LCD firmware version
Wire.endTransmission();

delay(2000);

//Send lcd clear command

Wire.beginTransmission(lcd_addr);
Wire.send(0xFE); //Cmd char
Wire.send(0x51); //Home and clear
Wire.endTransmission();

Wire.beginTransmission(lcd_addr);
Wire.send("Hi I'm using I2C");
Wire.endTransmission();

Wire.beginTransmission(lcd_addr);

Wire.send(0xFE); //Cmd char
Wire.send(0x45); //Set Cursor pos
Wire.send(0x40); //Line 2
Wire.endTransmission();

Wire.beginTransmission(lcd_addr);
Wire.send("FunGizmos.com");
Wire.endTransmission();

}




void loop(){

Wire.beginTransmission(lcd_addr);
Wire.send(0xFE); //Cmd char
Wire.send(0x45); //Set Cursor pos
Wire.send(0x40+15); //Line 2 last char
Wire.endTransmission();


Wire.beginTransmission(lcd_addr);
if(blink)
Wire.send('*');
else
Wire.send(' ');
Wire.endTransmission();
blink = !blink;

delay(500);

}

No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...