loading

Welcome to my attempt at an first Instructable. I'm making this because I bought a cheap crappy I2C LCD for Arduino off of eBay and spent several hours trying to hook it up. As expected the horrible instructions didn't do anything for me and I had to figure it out on my own. I didn't find anyone on the internets who seemed to be having the same stupid problems I was so I figured I would make this to save some other people some time. What you see above (probably. Wherever the photos are.) is my little project which, when I actually get the sensors, will be a little battery testing unit that I will use to check how much power some batteries at my lab are actually holding after the time we have been using them.

Declaimer: I am NOT going to explain to you how to program an Arduino. I am NOT going to explain how this display works or how to plug it in. Everyone and their grandmother has made an Instructable for that. Go read their stuff and come back. If you don't know what is going on. It's alright. I didn't either. But I did know how it worked and how to plug it up so please make sure you know those things first.

If you left, Welcome back. If not, then I trust you kind of know what's going on. None of this is going to be super hard so don't worry about it. Just follow along and you'll be fine.

Step 1: Software Setup.

The first thing we're going to do is make sure we're on the same page in terms of code. To write my program I used F Malpartida's LiquidCrystal_I2C library. You can find the page I found it on here: https://arduino-info.wikispaces.com/LCD-Blue-I2C
or you can find the actual library here: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
Either way I uploaded it just so there isn't any confusion. I'm using version 1.2.1.

First we're going to add it our IDE by going to Sketch>Import Library...>Add Library...

This will give you a file browser. Navigate to the zipped library you downloaded.

Once you download it you should have an option at the bottom that says LiquidCrystal. Click it.
At this point I feel like I should let you know I already included the test program I used. If you are lazy like me then just use that. If not then keep going.

This will give you a bunch of imports. We're only interested in the LiquidCrystal_I2C.h one. Remove the others.

Now add an import for Wire.h to your code right above the import. I can't actually write them out because they look like HTML to the stupid text editor and it deletes them.

Next we're going to add variables for the pins we're going to need to control the display.

#define I2C_ADDR 0x27

#define BACKLIGHT_PIN 3

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

These are going to hold the values of the SOFTWARE pins that are attached to the actual physical pins that they are named.

Next we're going to make an instance of the LiquidCrystal_I2C class.


LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

This is going to allow us to control the LCD once we correctly mark the pin variables we just made.

Now, under void setup() we're going to add our setup commands.

Serial.begin(9600); //this opens the serial connection that we are going to connect to later.

lcd.begin(16,2); // initialize the lcd

Finally we're going to put some code into void loop() to allow us to switch on and off each of the pins and tell us which is being changed so we can keep track.

if(Serial.available()) //this if is checking to see if someone connected to our open serial connection.

{

for(int i = 0; i < 16;i++) //this for loop is going through our list of ports and changing toggling each

{

Serial.print("Setting pin: ");

Serial.print(i);

Serial.println(" low");

lcd.setBacklightPin(i, NEGATIVE);

delay(2000);

Serial.print("Setting pin: ");

Serial.print(i);

Serial.println(" high");

lcd.setBacklightPin(i, POSITIVE);

delay(2000);

}

}

This code will wait for a serial connection and then begin testing toggling each pin on and off and announcing which is being changed so you can check them. Next step we'll check them. In order for the program to start you have to send something to the Arduino. I just pressed the space key and hit enter. That triggered the Arduino and started the program.

Step 2: Physically Probing the Pins.

This is the annoyingly slow part. Now you need to grab your trusty volt meter and begin testing each pin one at a time. If your LCD is like mine, you can ignore the D0-D3 pins as they aren't even used by the LCD. If your LCD isn't like mine then figure it out yourself. I checked them all because I'm OCD like that. 0-3 didn't actually work so I wasted my time but now I know that.

Basically what you do is probe the Vss pin and a pin of your choice and wait till the voltage spikes. That will tell you that the pin is being pulled high and if you look at the Serial Monitor then you'll know what software pin it is. At that point you should correctly mark the pin in your program variable that we made earlier or even write it on the back in fine point Sharpie. That's what I'm doing right now because I just thought of it, and you should too. That way you don't forget or lose the program and have to do this over again.

I hope this helped you figure out your stuff and get it working. I spent about 7 hours on this stupid LCD until I realized I could do this, and I've spent about 3 writing this for you silly people. If you have any questions let me know, but we aware that if you ask how to plug it up or what I2C is I will send you a link to someone else's Instructable. I'm only writing this for debugging. Not actually connecting the LCD or knowing how it works. Thanks for reading and I hope you enjoyed.

<p>This is great! I often buy cheap chinese knock off parts. Often times it's funner to figure out the darn thing than whatever project I'm building! Thanks for sharing and welcome to the community! </p>

About This Instructable

1,567views

11favorites

License:

More by Superfish1000:Arduino Voltage Sensor 0-25V Arduino I2C display PIN debugging 
Add instructable to: