Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: ++Help change this I2c Lcd library for arduino 1.0++ on: January 30, 2013, 08:09:32 am
OK.I change my Library and it still have the same error

Code:
#include "LCDI2C4Bit.h"
#include "Wire.h"

extern "C" {
  #include <stdio.h>  //not needed yet
  #include <string.h> //needed for strlen()
  #include <inttypes.h>
  #include "Arduino.h"  //all things wiring / arduino
}

//command bytes for LCD
#define CMD_CLR 0x01
#define CMD_RIGHT 0x1C
#define CMD_LEFT 0x18
#define CMD_HOME 0x02

//stuff the library user might call---------------------------------

//constructor.  num_lines must be 1 or 2, currently.

byte dataPlusMask = 0; // TODO!!!

LCDI2C4Bit::LCDI2C4Bit( int devI2CAddress, int num_lines, int lcdwidth) {
  myNumLines = num_lines;
  myWidth = lcdwidth;
  myAddress = devI2CAddress;
}

void SetMCPReg( byte deviceAddr, byte reg, byte val ) {
  Wire.beginTransmission(deviceAddr);
  Wire.write(reg);
  Wire.write(val);
  Wire.endTransmission();
}

void SendToLCD( byte deviceAddr, byte data ) {
  data |= dataPlusMask;
  SetMCPReg(deviceAddr,0x0A,data);
  data ^= 0x80; // E
  delayMicroseconds(1);
  SetMCPReg(deviceAddr,0x0A,data);
  data ^= 0x80; // E
  delayMicroseconds(1);
  SetMCPReg(deviceAddr,0x0A,data);
  delay(1);

}

void WriteLCD( byte deviceAddr, byte bdata ) {
  SendToLCD(deviceAddr,bdata >> 4);
  SendToLCD(deviceAddr,bdata & 0x0F);
}

void LCDI2C4Bit::init( void ) {
  dataPlusMask = 0; // initial: 0
  SetMCPReg(myAddress,0x05,0x0C); // set CONFREG (0x05) to 0
  SetMCPReg(myAddress,0x00,0x00); // set IOREG (0x00) to 0
  //
  delay(50);
  SendToLCD(myAddress,0x03);
  delay(5);
  SendToLCD(myAddress,0x03);
  delayMicroseconds(100);
  SendToLCD(myAddress,0x03);
  delay(5);
  SendToLCD(myAddress,0x02);
  WriteLCD(myAddress,0x28);
  WriteLCD(myAddress,0x08);
  WriteLCD(myAddress,0x0C); // turn on, cursor off, no blinking
  delayMicroseconds(60);
  WriteLCD(myAddress,0x01); // clear display
  delay(3);
}

void LCDI2C4Bit::backLight( bool turnOn ) {
  dataPlusMask |= 0x40; // Lights mask
  if (!turnOn) dataPlusMask ^= 0x40;
  SetMCPReg(myAddress,0x0A,dataPlusMask);
}


void LCDI2C4Bit::print( int value ) {
  dataPlusMask |= 0x10; // RS
  WriteLCD(myAddress,(byte)value);
  dataPlusMask ^= 0x10; // RS
}

void LCDI2C4Bit::printIn( char value[] ) {
  for ( char *p = value; *p != 0; p++ )
    print(*p);
}

void LCDI2C4Bit::clear() {
  commandWrite(CMD_CLR);
}

void LCDI2C4Bit::cursorTo(int line_num, int x) {
  commandWrite(CMD_HOME);
  int targetPos = x + line_num * myWidth;
  for ( int i = 0; i < targetPos; i++)
    commandWrite(0x14);
}

void LCDI2C4Bit::commandWrite( int command ) {
  // RS - leave low
  WriteLCD(myAddress,command);
  delay(1);
}
2  Using Arduino / Programming Questions / Re: ++Help change this I2c Lcd library for arduino 1.0++ on: January 30, 2013, 07:31:32 am
C++ source file
Code:
#include "LCDI2C4Bit.h"
#include "Wire.h"

extern "C" {
  #include <stdio.h>  //not needed yet
  #include <string.h> //needed for strlen()
  #include <inttypes.h>
  #include "Arduino.h"  //all things wiring / arduino
}

//command bytes for LCD
#define CMD_CLR 0x01
#define CMD_RIGHT 0x1C
#define CMD_LEFT 0x18
#define CMD_HOME 0x02

//stuff the library user might call---------------------------------

//constructor.  num_lines must be 1 or 2, currently.

byte dataPlusMask = 0; // TODO!!!

LCDI2C4Bit::LCDI2C4Bit( int devI2CAddress, int num_lines, int lcdwidth) {
  myNumLines = num_lines;
  myWidth = lcdwidth;
  myAddress = devI2CAddress;
}

void SetMCPReg( byte deviceAddr, byte reg, byte val ) {
  Wire.beginTransmission(deviceAddr);
  Wire.write(reg);
  Wire.write(val);
  Wire.endTransmission();
}

void SendToLCD( byte deviceAddr, byte data ) {
  data |= dataPlusMask;
  SetMCPReg(deviceAddr,0x0A,data);
  data ^= 0x80; // E
  delayMicroseconds(1);
  SetMCPReg(deviceAddr,0x0A,data);
  data ^= 0x80; // E
  delayMicroseconds(1);
  SetMCPReg(deviceAddr,0x0A,data);
  delay(1);

}

void WriteLCDByte( byte deviceAddr, byte bdata ) {
  SendToLCD(deviceAddr,bdata >> 4);
  SendToLCD(deviceAddr,bdata & 0x0F);
}

void LCDI2C4Bit::init( void ) {
  dataPlusMask = 0; // initial: 0
  SetMCPReg(myAddress,0x05,0x0C); // set CONFREG (0x05) to 0
  SetMCPReg(myAddress,0x00,0x00); // set IOREG (0x00) to 0
  //
  delay(50);
  SendToLCD(myAddress,0x03);
  delay(5);
  SendToLCD(myAddress,0x03);
  delayMicroseconds(100);
  SendToLCD(myAddress,0x03);
  delay(5);
  SendToLCD(myAddress,0x02);
  WriteLCDByte(myAddress,0x28);
  WriteLCDByte(myAddress,0x08);
  WriteLCDByte(myAddress,0x0C); // turn on, cursor off, no blinking
  delayMicroseconds(60);
  WriteLCDByte(myAddress,0x01); // clear display
  delay(3);
}

void LCDI2C4Bit::backLight( bool turnOn ) {
  dataPlusMask |= 0x40; // Lights mask
  if (!turnOn) dataPlusMask ^= 0x40;
  SetMCPReg(myAddress,0x0A,dataPlusMask);
}


void LCDI2C4Bit::print( int value ) {
  dataPlusMask |= 0x10; // RS
  WriteLCDByte(myAddress,(byte)value);
  dataPlusMask ^= 0x10; // RS
}

void LCDI2C4Bit::printIn( char value[] ) {
  for ( char *p = value; *p != 0; p++ )
    print(*p);
}

void LCDI2C4Bit::clear() {
  commandWrite(CMD_CLR);
}

void LCDI2C4Bit::cursorTo(int line_num, int x) {
  commandWrite(CMD_HOME);
  int targetPos = x + line_num * myWidth;
  for ( int i = 0; i < targetPos; i++)
    commandWrite(0x14);
}

void LCDI2C4Bit::commandWrite( int command ) {
  // RS - leave low
  WriteLCDByte(myAddress,command);
  delay(1);
}

Header file
Code:
#ifndef LCDI2C4Bit_h
#define LCDI2C4Bit_h

#include <inttypes.h>

// IMPORTANT! Wire. must have a begin() before calling init()

class LCDI2C4Bit {
public:
  LCDI2C4Bit(int devI2CAddress, int num_lines, int lcdwidth);
  void commandWrite(int command);
  void init();
  void print(int value);
  void printIn(char value[]);
  void clear();
  void backLight( bool turnOn );

  //non-core---------------
  void cursorTo(int line_num, int x);
  //void leftScroll(int chars, int delay_time);
  //end of non-core--------

  //4bit only, therefore ideally private but may be needed by user
  //void commandWriteNibble(int nibble);

private:
  //void pulseEnablePin();
  //void pushNibble(int nibble);
  //void pushByte(int value);

  int myNumLines;
  int myWidth;
  int myAddress;
};
#endif

Sketch
Code:
#include <Wire.h>
#include <LCDI2C4Bit.h>

int ADDR = 0xA7;

/*
;Connect the following pins from MCP23008 to LCD
;
;P0 - D4
;P1 - D5
;P2 - D6
;P3 - D7
;P4 - RS
;P5 - RW (not used, set to 0 to ground for write)
;P6 - Bl (backlight switch)
;P7 - E
*/

byte x = 0;
byte data = 1;
byte c;

LCDI2C4Bit lcd = LCDI2C4Bit(ADDR,4,20);

void setup()
{
  Serial.begin(9600);
  Wire.begin(); // join i2c bus (address optional for master)
  lcd.init();
  lcd.printIn("test");
  WriteLCD(ADDR,'a');
  lcd.clear();
  WriteLCD(ADDR,'c');
  lcd.cursorTo(0,0);
  lcd.printIn("0");
  lcd.cursorTo(1,0);
  lcd.printIn("1");
  lcd.cursorTo(2,0);
  lcd.printIn("2");
  lcd.cursorTo(3,0);
  lcd.printIn("3");
}



void loop()
{
  lcd.backLight(true);
  delay(1000);
  lcd.backLight(false);
  delay(1000);
}

Error picture
3  Using Arduino / Programming Questions / ++Help change this I2c Lcd library for arduino 1.0++ on: January 29, 2013, 10:44:21 pm
Hi,there!
http://playground.arduino.cc/Code/I2CPortExpanderAndLCDs


How to change this library for Arduino 1.0
I tried change
"WConstants.h"  to "Arduino.h"

and  Change
Wire.send to Wire.write
 But it still can not compile.
So,How to do it  for Arduino 1.0?
4  Using Arduino / Displays / Re: Do you have new LCDI2C4BIT Library? on: January 27, 2013, 09:53:20 am
I didn't use pcf5874

Can this library use with my module?
How can i change my library code in my link?(in below of page
http://www.ebay.com/itm/IIC-I2C-TWI-SPI-Interface-Module-1602-2004-LCD-Arduino-SMALL-/130791077092)

P.S.I dont know what is my IC in module
5  Using Arduino / Displays / Do you have new LCDI2C4BIT Library? on: January 27, 2013, 04:20:57 am
Hey,I come from Thailand
i bought this
http://www.ebay.com/itm/IIC-I2C-TWI-SPI-Interface-Module-1602-2004-LCD-Arduino-SMALL-/130791077092
and connect with LCD 20x04.

And library in the page is too old
I try to fix something like  "Arduino.h"
and Wire.Write.

But it still doesn't work.
Pages: [1]