Show Posts
Pages: [1]
1  Using Arduino / Displays / Re: (ANSWERED) Move cursor to second row through I2C I/O expander on: June 10, 2012, 12:28:17 pm
I was thinking the same about reversing things after having that trouble. I will just go with the standard pin configuration from now on with this project to avoid future confusion.

#define interLeng B00111111

If you look at the datasheet for the HD44780 on page 24, table 6 there is a part called function set which is what I'm using to set the LCD into 2 row mode.

essentially B00111111
data bus     76543210

db5 is used to say your using the function set
db4 tells the LCD I'm sending in 8-bit
db3 tells the LCD how many lines
db2 says what size font
and the last 2 seem to be unused

so B00111100 would essential be the same I think, I have yet to test however

2  Using Arduino / Displays / Re: (ANSWERED) Move cursor to second row through I2C I/O expander on: June 10, 2012, 12:01:59 pm
I completely forgot to mention that I reversed the pin out from the I/O expander to the LCD because when I solder it together it will end up saving me a lot of time and effort. thats why the commands look wrong to you.

This is what I came up with to set the LCD to use 2 rows. and it seems to be working.(though IIRC the last two make no difference what state their in
Code:
#define interLeng B00111111

now I just use
Code:
#define line2Curs B11000000

and the cursor jumps to the second row :]

I'm not used to using hex so all these codes are troublesome for me to interpret, but I seem to be getting better the more I use it! Thanks for the info as well floresta, I'm sure it will be invaluable in the future.
3  Using Arduino / Displays / Re: Move cursor to second row through I2C I/O expander on: June 10, 2012, 02:19:48 am
Seems like I must have deeper problems then, the cursor still is int showing up in the second row with 0xC0. Just disappearing as usual.. I will dig through the data sheet again and see if I find anything of use.

After a little bit of playing with it, I noticed that the cursor seems to be looping back to the home position when writing to the end of the row (since I cant see, I'm guessing it is reaching the end and looping). Any thoughts on if this may be a result of my initialization process, or putting it in this mode somehow?

I found my error, I didn't realize that I had to set the interface to a 2 row display. After doing so everything is working flawlessly. Regardless thanks for the help floresta.
4  Using Arduino / Displays / (ANSWERED) Move cursor to second row through I2C I/O expander on: June 09, 2012, 06:35:53 pm
I tried searching but couldn't find an answer other than things I have tried so I hope someone on here can help.

Currently with my project I am learning about I2C and LCD's so I'm displaying info on a HD44780 based 16x2 LCD through a MCP23017 16-bit I/O expander. Up until now things have been rocky but Ive been able to get through the initial hurdles and can command and write to the display. The problem is I cant seem to get my cursor to set to the second row first column. On the web I've found multiple references to 0x40 being the magical number to get to line two as the HD44780 is made to control a 40x4 LCD, however I dont seem to be having any luck getting it to move the cursor to the second row... So any Ideas?

for reference here is my code: (albeit messy with different data types and such, binary seems to be working best for testing so far)
Code:
#include "Wire.h"

//define commands
#define initalize B00001100
#define clearHome B00000001
#define blinkCurs B00001111
#define line1Curs B10000000
#define line2Curs B11000000


/////////////////////////////////////////////////////////////////
//                           Setup                             //
/////////////////////////////////////////////////////////////////
void setup()
{
  beginI2C(); 
  beginLCD();
}

/////////////////////////////////////////////////////////////////
//                           Loop                              //
/////////////////////////////////////////////////////////////////
void loop()
{
  for(int i; i<16; i++)
  {
    writeLCD(B00110000);// "0"
    delay(500);
    commandLCD(0x40);//WTF!?! should be row 2 column 1!
    delay(500);
    writeLCD(B00110000);// "0"
    delay(500);
    commandLCD(B10000000);
  } 
  commandLCD(B00000001);//clear LCD and home cursor
}

/////////////////////////////////////////////////////////////////
//                        Functions                            //
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void beginI2C()
{
  Wire.begin(); // wake up I2C bus

  // setup addressing style
  Wire.beginTransmission(0x20);
  Wire.write(0x12);
  Wire.write(0x20); // use table 1.4 addressing
  Wire.endTransmission();

  // set I/O pins to outputs
  Wire.beginTransmission(0x20);
  Wire.write(0x00); // IODIRA register
  Wire.write(0x00); // set all of bank A to outputs
  Wire.write(0x00); // set all of bank B to outputs
  Wire.endTransmission();
}

/////////////////////////////////////////////////////////////////
void beginLCD()
{
  delay(50); 
  commandLCD(initalize);//init first attempt
  commandLCD(initalize);//init second attempt
  commandLCD(initalize);//init final attempt
  commandLCD(clearHome);//clear LCD and home cursor
  commandLCD(blinkCurs);//display blinking cursor
}

//////////////////////////////////////////////////////////////////
void commandLCD(byte data)
{
  Wire.beginTransmission(0x20);
  Wire.write(0x12); // A register
  Wire.write(data); // Bank A
  Wire.write(B00000001); // Bank B
  Wire.endTransmission();
 
  Wire.beginTransmission(0x20);
  Wire.write(0x12); // A register
  Wire.write(data); // Bank A
  Wire.write(B00000000); // Bank B
  Wire.endTransmission();
  delay(50);
}

//////////////////////////////////////////////////////////////////
void writeLCD(byte data)
{
  Wire.beginTransmission(0x20);
  Wire.write(0x12); // A register
  //     pins 76543210
  Wire.write(data); // Bank A
  Wire.write(B00000011); // Bank B
  Wire.endTransmission();
  delay(50);
 
  Wire.beginTransmission(0x20);
  Wire.write(0x12); // A register
  Wire.write(data); // Bank A
  Wire.write(B00000000); // Bank B
  Wire.endTransmission();
  delay(50);
}

and data sheets in case there needed
http://www.adafruit.com/datasheets/HD44780.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf

Pages: [1]