IIC trouble (Solved)

I will preface this with the fact that I am relatively new to Arduino but I have some prior experience with coding and solder less prototyping. I bought an Arduino mega 2560 as well as jumper wires and a 20x4 LCD screen to go with it. The screen has a IIC adapter soldered onto it. Every time I try to get the screen to print anything it will go black, flicker, or have a weird grainy effect. I used multiple different codes to try to get it to work with the aforementioned results still happening. This is the link to the screen on amazon if I should have bought a different one -

I also have my own crude code attached if there is anything wrong with it.

screen_test.ino (234 Bytes)

The I2C pins on a Mega are pin 20 (SDA) and pin 21 (SCL). Is that how your display is connected?

It is often very helpful if you post photos of the wiring of your display. Show the solder joints on the connection between the backpack and LCD.

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

Install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

I will not download code. If you want help on the forum, post the code on the forum. Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

I installed the library and got the screen working. I really appreciate the ridiculously fast and concise answer to my question.

Here is my awful code if you still wanted to see it-

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(1,1);
  lcd.print("hello");
}

void loop() 
{
  
}

groundFungus:
I will not download code.

Why?
You can configure the browser (at least I can with Firefox on linux) to bring up the attachment in the desired favorite code editor.
So for me, I just click on the attachment and it is up in my favorite code editor where I can see syntax highlighting, as well as do other code like things.
IMO, it is easier and more handy than having to use copy and paste to get the code into a code editor when the code is placed in the post vs as an attachment.

--- bill

Why

Because, to put the code into the IDE from an attachment, I have to create a folder on my machine that I later have to remember to delete. Or put the code into an editor then copy and paste into the IDE. I use the IDE to verify (assuming that I have or can get the libraries) the code or use autoformat (which my editor will not do).

Posting in code tags makes it equally easy for me to put code into my IDE and for you to put code into your editor. Also there are members that use devices that will not directly open an ino file. Posting in code tags makes it easy for them to see the code.

groundFungus:
Posting in code tags makes it equally easy for me to put code into my IDE and for you to put code into your editor. Also there are members that use devices that will not directly open an ino file. Posting in code tags makes it easy for them to see the code.

Yes, a reduction to lowest common capability, to make it equally as painful for everyone.
But I get it. The majority of people don't have proper development systems, tools, or their browsers set up in way to use better tools.

Pasting code in a Code Window means that readers can view it on PC, Tablet, phone, ...

From a PC point of view, downloading an attached File is easy.

David.

groundFungus:
Because, to put the code into the IDE from an attachment, I have to create a folder on my machine that I later have to remember to delete. Or put the code into an editor then copy and paste into the IDE. I use the IDE to verify (assuming that I have or can get the libraries) the code or use autoformat (which my editor will not do).

Pretty much my point against attaching “.ino” files.

The IDE when set up normally (default), will be invoked if I click on a “.ino” attachment which means that all my current sketches will suddenly appear as well as the “new” project and (default) will want to save the new project.

This is frankly, a nuisance as I have to then deal with those windows; I don’t want to close them as I had each one open for a particular reason.

And of course if I am browsing - like Mike - on a tablet, the attachments are again, impractical.

We are going off topic, particularly in a "solved" thread.
One last comment from me about attachments.
IMO, the attachment vs inlining is primary a forum s/w issue.
The forum s/w should be smart enough to also inline attached code at the bottom of the post when it "sees" it if the number of lines is below some threshold. Same for photos. This could offer a single consistent way to post code & images that offers the best of all worlds.
I also don't think users should be bashed for using attachments over inlining their code.
Me, while I would prefer attachments, particularly when the size is over just a few lines, I can deal just fine with inlining, so I never bash users for doing it either way.

#7 of the sticky that users are often directed to when using code attachments doesn't say "Post inline unless you can't" and then post #8 talks about using attachments.
But neither says that it is preferred to use inline code vs attachments whenever possible.
Yes #8 says "If your code is too long to fit into a post..." but nowhere does it say that inlining is preferred over attachments.
So I think forum "regulars" should be much gentler on users that use attachments for their code.
Now those that inline their code without code tags, well those need a bit of feedback to push them to properly post their inline code.

--- bill