Asked — Edited

LCD Display

DJ, I am out of Digital Ports and I want to use a LCD Display. Can I use a 12C port and if so do I need to purchase a special interface and how would I input the text since the only control available under 12C is blinkin and nothing that I can see in Script? I await your input.


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

PRO
Synthiam
#1  

You sure can use the I2C ... The script command SendI2C will allow you to output to a I2C display.

There are problems i've found with I2C displays though. They are usually poorly documented or have strange initialization commands. If you find a nice easy one, I'd love for you to share it.

#3  

I think I found a good one. I will let you know when it gets here. I do not see 12C marked on the EZ-B. Where do you plug into the board for 12C?

PRO
Synthiam
#4  

Bookmaker, which version of the EZ-B do you have? v2, v2.1 or v3?

The I2C ports on the V3 are located under the Analog ADC inputs

#5  

DJ, I am running V3 and it is just amazing what you can find if one just looks. Yup, sure enough, there it is as big as life, 12C.

#7  

DJ, I received my 12C LCD and tried the script command and I keep getting a syntex error. Can you give me an example?

PRO
Synthiam
#8  

You'll have to check your datasheet for the specific commands that it will accept. You can post a link to the datasheet and i can take a look for you.

This is how you send an I2C command:


sendi2c(0x0a, "Hello world")

Keep in mind, that it is I (as in the vowel). it is not a number one.. It's EYE TWO SEE:)

#9  

DJ, You were absolutly correct "There are problems i've found with I2C displays though. They are usually poorly documented or have strange initialization commands." I ran the code you wrote above and nothing happened. I have found the documentation but it reads like Greek to me. Any advise?

PRO
Synthiam
#10  

The code I pasted was an example of how I assumed it would work, but there are two things that are missing...

  1. You'll need to know the address. the 0x0a was just a sample

  2. It might not accept merely a string of text. You might have to send it an initialization string first

#11  

Thanks for the input DJ, I found the address. It is 0x27. I tried that and all that happened was the screen turned from a lit blue (on power up) to a blank (no power). Any idea how to find out what the initialization string might be?

#12  

DJ, This is what I found. Makes no sense to me but it may to you. Can you translate?

///Arduino Sample Code ///www.DFRobot.com ///Last modified on 17th September 2010

#include #include

LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() { lcd.init(); // initialize the lcd

// Print a message to the LCD. lcd.backlight(); //lcd.setCursor(0, 1); lcd.print("Hello, world!"); }

void loop() { // when characters arrive over the serial port... if (Serial.available()) { // wait a bit for the entire message to arrive delay(100); // clear the screen lcd.clear(); // read all the available characters while (Serial.available() > 0) { // display each character to the LCD lcd.write(Serial.read()); }

PRO
Synthiam
#13  

You know, i'm entirely unsure what that mess is. I'll have to probe the Arduino library to see what they're doing. Does your LCD have a serial interface also? You can use that instead maybe.... Now that ARC supports more than one EZ-B Board:) You have lots of free I/O!

I2C is great if your hardware is documented. Doesn't look like that I2C LCD is documented very well

#14  

DJ, I found an add that has alot of documentation. Can you please take a look and see if maybe there is a solution at hand?

E Bay add

Many thanks in advance.

PRO
Synthiam
#15  

try


 sendI2C(0x50, 0x80, "Hello world")

also, make sure the interface is indeed I2C and not SPI. The pins should be marked as:

  • SDA
  • +5
  • GND
  • SCL
PRO
Synthiam
#16  

Ah after fustrating searches... Look at this link: Proper Datasheet

Your device address is 0x27 it seems. Now I still don't know what command is sent to write a string.. you can try this first


sendI2C(0x27, "Hello World")

PRO
Synthiam
#17  

I also just read that the default address could be 0x4C ... Geez this LCD is not documented well

so maybe this will work..


sendI2C(0x4C, "Hello World")

PS.. I'd cycle the LCD power before trying different commands. Each command might get to the LCD but do something that makes the next command not work.

#18  

Thanks a bunch DJ, I am at work now but I will try it when I get home. It is definitely i2C. I did try the sendI2C(0x27, "Hello World") but all that happened was the screen went dead. Thanks for all your time!

PRO
Synthiam
#19  

Wait!!! It responded with 0x27? That might be it!! See if it goes dead with 0x4C also...

Does it normally go dead? Or only that time?

Chinese stuff like this is never documented well

#20  

Actually that is the one and only responce I have gotten.

PRO
Synthiam
#21  

Okay then we're on the right track for address ID i think

#22  

Hello, I just got home and tried everything you mentioned. The only one that did anything was the sendI2C(0x27, "Hello world") which blanked the screen.

PRO
Synthiam
#23  

Okay, that's a start. Now we need to find out how to send commands.

How about


SendI2C(0x27, 0x80, "Hello World")

PRO
Synthiam
#24  

For reference:


// commands (these are sent either alone or as an identifier
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80

// flags for display entry mode (LCD_ENTRYMODESET)
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

// flags for display on/off control (LCD_DISPLAYCONTROL)
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00

// flags for display/cursor shift (LCD_CURSORSHIFT)
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00

// flags for function set (LCD_FUNCTIONSET)
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

// flags for backlight control (LCD_DISPLAYCONTROL)
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

PRO
Synthiam
#25  

So looks like you can do this for initialization....


sendI2C(0x27, 0x20, 0x10) # put in 8 bit mode
sendI2C(0x27, 0x20, 0x08) # configure for 2 line display
sendI2C(0x27, 0x01) # clear display
sendI2C(0x27, 0x02) # return home (not sure if this is needed)

I'm not sure, but looks like you need to put it in some Enable mode to begin writing after you initialize


sendI2C(0x27, 0x10) # enable high
sendI2C(0x27, "Hello World")
sendI2C(0x27, 0xEF) # enable low

#26  

Ah, ha I will give it a try as soon as I get home. Are you sure that last line of code (0xEF) is correct? All the others are numbers???

PRO
Synthiam
#27  

All numbers that have a 0x in front of them are called Hexidecimal

0xEF is a number. It is hexidecimal. It is another way to count, but it is base 16. Normal counting is Base 10 and it is called Decimal (for 10:))

Hexidecimal counts like this: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 2A 2B 2C 2D 2E 2F ....

So the least significant digit (the digit on the right) increases from 0 to F before the next digit increases. You can count to 255 with Hex by having only two digits. Decimal 255 is FF Hex

Hex 0xEF is 239 in decimal

You could write that same peice of code without the 0x and specify decimal instead...


sendI2C(39, 239)

Look at this link: http://www.cdrummond.qc.ca/cegep/informat/Professeurs/Alain/files/ascii.htm

#28  

Thanks for the ASCII lesson. I tried the code above and the screen blinked. Without the last line of code the screen went blank. What now?

PRO
Synthiam
#29  

Keep trying:)

Ill post something soon as I can think of anything else... hmm

#30  

Hello DJ, Love V13. Does the read I2C help any to find out how to print with my LCD?

PRO
Synthiam
#31  

Having no datasheet on that lcd isn't making this easy. Have you tried anything since then? Just keep poking at it. We know that the screen clears when we send any data to 0x27 .. So we have to assume the LCD address is 0x27.

Try sending more data to 0x27 and see what you get. Try different things like


sendI2C(0x27, "Hello World")

and other things like..


sendI2C(0x27, 0x01, "hello world")

and try incrementing 0x01 by 1 .. try 0x02, 0x03, 0x04... etc

#32  

Thanks DJ, I will give that a try.

PRO
Synthiam
#33  

Let's hope v13 makes it a bit easier for you by using the script console.

PS, i ordered one. So i'll be able to help you when i get it

#34  

As usual you always go above and beyond. WAY ABOVE AND BEYOND. It is more of a chalange now than a practacality since I have an additonal 20 digital ports to work with I could simply order a serial LCD but like I said it is more of a chalange at this point.

PRO
Synthiam
#35  

LOL, we'll figure it out:)

#36  

Well, I tried a bunch to noavail.

PRO
Synthiam
#37  

Does the screen still go blank with the anything send to the address 0x27?

#38  

DJ, sendI2C(0x27, "Hello World") Blanks the screen.

I get a lit screen with the curser flashing in position one when I send: sendI2C(0x27, 0x20, 0x10) # put in 8 bit mode sendI2C(0x27, 0x20, 0x08) # configure for 2 line display sendI2C(0x27, 0x01) # clear display

PRO
Synthiam
#39  

Well that's good news!

After those commands, try sending something like

sendI2C(0x27, 0x80, "Hello World")

#40  

No such luck. May be we should wait until you get yours. Don't need taking everyones time up.

#41  

DJ, I downloaded the new version and firmware. Tried sending I2Cwrite(0x27,"test") and it blacked out the EZ-B. NEXT?

PRO
Synthiam
#42  

You need to i2cStart() first. The i2c command structure has changed to support more devices, including debugging your device.

In order to "talk" to a slave from the master (Ez-b), a Ttart sequences is one of two special sequences defined by the i2c bus. The other sequences is the Stop sequence. So a master must send a Start or a Stop. The master in our case is the EZ-B. The EZ-B plays the roll of a master on the i2c network. Your LCD device would be the slave.

So in your case, you would now need to do this...


i2cStart()
i2cWrite(0x4E, "test")
i2cStop()

But that's not going to do much. I doubt it would even blank the screen. This is because the first bit (also called the least significant bit or LSB) is set to a 1. What? Ha, let me tell you...

So how I originally implemented the i2c was for simple devices like stepper motor controls, blinkm and one of the lcd's i have. Lately there have been people using different i2c devices that require special care. That means I had to dramatically change the i2c command structure. We have an ez-robot member, for example that is building a flying drone and needs to talk to a specific g sensor.

What's this about bits? It's an i2c thing... Here's how it works. So the address of i2c devices or functions are really 7 bit, and the 8th bit is used for the direction (kinda). So let's say your LCD address is 0x27. Well that's 00100111 in binary IF it was an 8 bit number. But because the address is 7 bit and we use the 8th bit to determine the communication direction (Read/Write), we need to shift the bits over by 1.

So you always need your first bit to be a 0 when writing. That means your address is actually 0x4E and not 0x27. Because you have to shift the bits over of 0x27. When you shift bits from left to the right, you multiple the number by 2.

0x27 = 0010 0111 0x4E = 0100 1110

See how the last bit is now a 0 with the 0x4E? That means "write to the device".

Read more here www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html

#43  

Well, it made the screen go blank. Guess I have some studying to do!!!

#44  

DJ, Did you receive your LCD yet? If so any progress on getting something to print? Buster wants to know. Gosh, it has only been a week. It seemed like alot longer. Anyway, after our Etiquette lesson I am feeling realy stupid. Please disregard my impatients. I will just wait.

PRO
Synthiam
#45  

No, sadly i have not received it yet

#46  

I was tinkering with the blinkM I just got and wanted to try things out. I noticed when making a script that the 'auto complete' doesnt have "sendI2C". Theres the I2CWrite and SendSerial. There are a few references to SendI2C as examples under the script help on the right side. Im new to this so am I missing something?

#47  

DJ, Did you ever figure out how to get the LCD to work? Mine is still blank.