Hello everyone!
I have a LCD with the LCD03 adapter on it which works fine with the old LCDi2cR library with IDE0.23
The I2C controller is a PIC16F819.
I tryed to make the LCD03 working with the new LiquidCrystal (malpartida) library for IDE1.0 but I failed.
The setup is correct, because with the first IDE/lib is ok. The I2C address I use here is 0x63.
This is an example of working code with IDE0.23
#define VERSION "0.1"
#include <Wire.h>
#include <inttypes.h>
#include <LCDi2cR.h>
LCDi2cR lcd = LCDi2cR(4,20,0x63,0);
uint8_t rows = 4;
uint8_t cols = 20;
int tmp102Address = 0x48;
float analogPin = 0;
float hum;
float RH;
float maxvoltage;
void setup() {
lcd.on();
lcd.clear();
lcd.init(); // Init the display, clears the display
}
void loop()
{
float celsius = getTemperature();
hum = analogRead(analogPin);
maxvoltage = (3.27-(0.006706*celsius)) ; // The max voltage value drops down 0.006705882 for each degree C over 0C. The voltage at 0C is 3.27 (corrected for zero precent voltage)
RH = ((((hum/1023)*5)-0.8)/maxvoltage)*100;
lcd.setCursor(0,0);
lcd.print("Temp.: ");
lcd.setCursor(0,7);
lcd.print(celsius);
lcd.print("C");
lcd.setCursor(1,0);
lcd.print("Hum. : ");
lcd.setCursor(1,7);
lcd.print(RH);
lcd.print("%");
delay(500);
//lcdtest_basic();
}
float getTemperature(){
Wire.requestFrom(tmp102Address,2);
byte MSB = Wire.receive();
byte LSB = Wire.receive();
//it's a 12bit int, using two's compliment for negative
int TemperatureSum = ((MSB << 8) | LSB) >> 4;
float celsius = TemperatureSum*0.0625;
return celsius;
}
while this is not working on IDE1.0
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x63,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.print("Hello, world!");
}
void loop()
{
}
The LCD stays in its initial splash screen (LCD03 revision 8 I2C mode @ 0xC6) and doesn't do anything.
Of course, I tryed to adapt the old library for the new IDE, but I got too many errors I cannot handle, as I'm not really expert in C.
Do you need any other info in order to help me? Thx!
/* LCDi2cR Library for the LCD display from robot-electronics.co.uk
Version 0.1 4/2/2009
Arduino Library maintained by Dale Wentz dale@wentztech.com
For the latest version see
*/
#include "LCDi2cR.h"
#include <Wire.h>
#include <inttypes.h>
#include "WConstants.h" //all things wiring / arduino
#define _LCDEXPANDED // If defined turn on advanced functions
// Global Vars
uint8_t g_num_lines = 4;
uint8_t g_num_col = 20;
int g_i2caddress = 0x63;
uint8_t g_display = 0;
int g_cmdDelay = 0;
int g_charDelay = 0;
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] LCDi2c Class
// []
// [] num_lines = 1-4
// [] num_col = 1-80
// [] i2c_address = 7 bit address of the device
// [] display = Not used at this time
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
LCDi2cR::LCDi2cR(uint8_t num_lines,uint8_t num_col,uint8_t i2c_address,uint8_t display){
g_num_lines = num_lines;
g_num_col = num_col;
g_i2caddress = i2c_address;
g_display = display;
//if (g_num_lines < 1 || g_num_lines > 4)
//g_num_lines = 2;
//if (g_num_col < 1 || g_num_col > 40)
//g_num_col = 16;
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] initiatize lcd after a short pause
// []
// [] Init the i2c buss
// [] Put the display in some kind of known mode
// [] Put the cursor at 0,0
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::init () {
Wire.begin();
on();
clear();
blink_off();
cursor_off();
home();
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Over ride the default delays used to send commands to the display
// []
// [] The default values are set by the library
// [] this allows the programer to take into account code delays
// [] and speed things up.
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::setDelay (int cmdDelay,int charDelay) {
g_cmdDelay = cmdDelay;
g_charDelay = charDelay;
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Send a command to the display.
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::command(uint8_t value) {
Wire.beginTransmission(g_i2caddress);
Wire.send(0x00);
Wire.send(value);
Wire.endTransmission();
//delay(g_charDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Send a command to the display.
// []
// [] This is also used by the print, and println
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::write(uint8_t value) {
// This display maps custom characters from 128-135 Dec, most displays map them to 0-7 so lets remap them for compatibility
if ( value < 8)
value = value + 128;
Wire.beginTransmission(g_i2caddress);
command(value);
Wire.endTransmission();
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Clear the display, and put cursor at 0,0
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::clear(){
command(0x0C);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Home to custor to 0,0
// []
// [] Do not disturb data on the displayClear the display
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::home(){
command(0x01);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Turn on the display
// []
// [] Depending on the display, might just turn backlighting on
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::on(){
command(0x13);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Turn off the display
// []
// [] Depending on the display, might just turn backlighting off
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::off(){
command(0x14);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Turn on the underline cursor
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::cursor_on(){
command(0x05);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Turn off the underline cursor
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::cursor_off(){
command(0x04);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Turn on the blinking block cursor
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::blink_on(){
command(0x06);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Turn off the blinking block cursor
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::blink_off(){
command(0x04);
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Position the cursor to position line,column
// []
// [] line is 0 - Max Display lines
// [] column 0 - Max Display Width
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::setCursor(uint8_t Line, uint8_t Col){
Line++; // This display starts counting at 1, so this brings it in line with the class definitions
Col++;
Wire.beginTransmission(g_i2caddress);
Wire.send(0x0);
Wire.send(0x03);
Wire.send(Line);
Wire.send(Col);
Wire.endTransmission();
delay(g_cmdDelay);
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Extended Functions
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
#ifdef _LCDEXPANDED
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Adust the brightness of the backlight
// []
// [] For this display we only have on and off, so
// [] 0 will turn it off
// [] any other value will turn it on
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::backlight(uint8_t value){
if (value == 0){
command(0x14);
}else{
command(0x3);
}
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Return the status of the display
// []
// [] For this display returns the number of free bytes
// [] in the FIFO (Returns 0-64)
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
int LCDi2cR::status(){
int DisplayStatus = 0;
// Connect to device and request byte
Wire.beginTransmission(g_i2caddress);
Wire.requestFrom(g_i2caddress, 1);
if (Wire.available()) {
DisplayStatus = Wire.receive();
}
return DisplayStatus;
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Read data from keypad
// []
// []
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
uint8_t LCDi2cR::keypad (){
uint8_t reg0 = 0;
uint8_t reg1 = 0;
uint8_t reg2 = 0;
Wire.beginTransmission(g_i2caddress);
Wire.requestFrom(g_i2caddress, 3); // Read 3 bytes
reg0 = Wire.receive(); // FIFO, just ignore
reg1 = Wire.receive(); // Keypad state Low byte
reg2 = Wire.receive(); // Keypad state High byte
Wire.endTransmission();
if (reg1 & 1) return 1;
if (reg1 & 2) return 2;
if (reg1 & 4) return 3;
if (reg1 & 8) return 5;
if (reg1 & 16) return 6;
if (reg1 & 32) return 7;
if (reg1 & 64) return 9;
if (reg1 & 128) return 10;
if (reg2 & 1) return 11;
if (reg2 & 2) return 13;
if (reg2 & 4) return 14;
if (reg2 & 8) return 15;
return 0;
}
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
// []
// [] Load data for a custom character
// []
// [] Char = custom character number 0-7
// [] Row is array of chars containing bytes 0-7
// []
// []
// [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void LCDi2cR::load_custom_character(unsigned char char_num, unsigned char *rows)
{
Wire.beginTransmission(g_i2caddress);
Wire.send(0x00);
Wire.send(0x1B);
Wire.send(char_num+128);
for (uint8_t i = 0; i < 8; i++)
Wire.send(rows[i]+128);
Wire.endTransmission();
}
#endif
Not as simple as I had hoped it would be but in trying to find the original library/site I came across this one http://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/ that is a more modern extension of the original library your using. I don't have an I2C LCD but installing the above library and making a couple of changes to you code it compiles okay. Does this work for you?