The biggest catch is the Wiring library requiring the I2c device to be in 7bit mode (shifted left by one) since it does an auto shift right and appends the 1 or 0 depending on if it is reading or writing to the I2c bus.
- Code: Select all
/* 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 <Wire.h>
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);
}



