I2C LCD not working properly with standalone ATMega328

Hey everyone!
I have a 16x2 LCD with I2C (PCF8574) in my project which works 100% fine when setup on a breadboard (with the ATMega328 on the Arduino UNO), but when set on a PCB I made with the same ATMega328 (without the Arduino interface) it only shows white squares on the top row and the second row is empty.

I’ve seen many posts regarding this issue but I found no solution. This is the data I believe to be talkpoints:

  • The cables used are 10cm long breadboard jumper wires
  • SCL, SDA, VCC and GND connections from the ATmega328 to the LCD are OK (no mixed connections)
  • I tried with and without 4.7kOhm resistors from SCL to VCC, and from SDA to VCC (like attached below) and got the same null result with both setups
  • I have a LM7805 with decoupling capacitors that feeds the IC (power source is a switching 12V 5A), and it indeed recieves 5V… but I noticed the voltage goes up on the LCD’s VCC and GND pins! It starts at 5V and after a couple seconds rises up to 6.3v!! So does the current, it starts at 25.4mA which is normal for this display, but then rises up to 33mA! I am absolutely baffled as to why this might happen…
  • I also tried a resistor in series with VCC with values from 100 to 1k ohms, just cause… nothing happened though

According to the PCF8574’s datasheet, it should work with 2,5v as with 7v, so my conclusion is that while there might be something funky going on with the supply it should still work, right?!

I’m attaching only the LCD’s connections to the ATMega328 due to failure to comprehend how EasyEDA works lack of time. Will upload any extra information you might need, just ask!

Thanks to everyone in advance!

LCDconnection.png

You did put a crystal on your PCB, didn't you? :roll_eyes:

You should first make sure that your standalone ATMega328 can successfully run some simple programs that do not involve I2C etc.

I would start by blinking an LED.

Don.

Paul__B:
You did put a crystal on your PCB, didn’t you? :roll_eyes:

Yes! The crystal and the 22pF capacitors.

floresta:
You should first make sure that your standalone ATMega328 can successfully run some simple programs that do not involve I2C etc.

I would start by blinking an LED.

Don.

I have to admit I didn’t try that with this particular IC. I have another one which came with the Arduino Uno, and I did try it with that one. I programmed the Blink sketch, put it in the breadboard with the crystal and the capacitors along with the 10k resistor to the reset and everything worked fine.

There’s a slight confusion in my mind regarding this chip I’m using now, I don’t remember if this one was or was not bootloaded (the other one I used came with the Arduino so I assumed it is bootloaded)… but it does work fine on the Arduino Uno, and I thought uploading a sketch then using the same chip as standalone would do OK.

There’s something that’s bugging me and I think maybe it has something to do with this I2C problem… I attached below the same schematic (now done properly) with the addition of the reset configuration for the IC. I set up a 10k resistor from pin 1 to VCC and a momentary pushbutton from pin 1 to GND. When checked for continuity with the multimeter the button’s doing fine at closing pin 1 to GND, but when the IC’s powered up I see absolutely no flicker on the LCD (or on the indicating LED of a relay I’m also using) when the button is pressed or even held down for some time. I thought maybe there is something wrong with the reset and might cause the IC to never fully initialize, I don’t really know what to think anymore lol

Schematic_LCD-Reset-Connections-Forum_Sheet-1_20190801125520.png

Schematic_LCD-Reset-Connections-Forum_Sheet-1_20190801125520.png
Need to detail how the relay module comes into this and I think we need some pictures of this magic PCB.

Program a "blink" to operate the relay module.

Ok here’s the full schematic and pictures of the PCB!

I’m only begging in electronics as you might be able to tell by the schematic heh
So far everything worked as intended on the breadboard.

I’ll get around the relay test tomorrow

UPDATE!
I moved my IC to a breadboard with only the crystal, capacitors, reset resistor and LCD, fed it 5V from USB and the LCD displayed the same white squares on the top row and blank on the bottom one. Hence I thought the chip might be the issue, so I grabbed my Arduino Uno (withouth IC) and hooked it like so:
Reset -> Pin 1
Rx ----> Pin 2
Tx ----> Pin 3
And tried re-uploading the code, no to avail. I connected an LED with resistor to pin 19 (digital 13), uploaded the Blink sketch andd.. nothing.
The Arduino IDE displays "Done Uploading" and I see the Arduino's Rx and Tx lights go crazy.

Maybe the chip isn't bootloaded? As I mentioned earlier I had this confusion, I really wasn't sure lol
The chip and the code work FINE when on the Arduino UNO, the problem is when making it standalone.

If it is in fact not bootloaded, is there a way to bootload it with the Arduino Uno WITHOUT another chip on it? All the tutorials and examples I've seen require an IC on the board apart from the one you want to bootload, and I just finished confirming my other IC is fried, so I only have 1..

Thanks to all!

As best I know, if the Arduino IDE displays "Done Uploading", it has successfully performed an upload to the chip you have connected (wherever it is) and clearly that chip has a bootloader in place in order for that to occur.

Your problem remains cryptic. :roll_eyes:

So there's absolutely no other explanation regarding a chip that works on the Arduino board but not when off of it?

UPDATE!!
The LED with which I tested the ATMega standalone was dead, replaced it and the blink sketch works FINE with the ATMega328 standalone!! So it's not the chip that's the problem :smiley:

MAJOR UPDATE!

For the first time in weeks I got a proper reading from the LCD!!!

It was really a lucky find, since I wasn't even trying lol

I was running an I2C Scanner (Nick Gammon's), like I did many many times before (with the LCD not beign found), but this time I tried to move the SCL's cable closer to the MCU (in my breadboard, they're a few holes apart) and accidentally touched the MCU's pin with the cable's tip.. voila! The I2C scanner found a device on 0x3F, which was my LCD's address in the first place!
So I ran my code but this time I waited until the code was uploaded, then took the SCL's wire out of the breadboard and touched the MCU's pin with it, and it worked!

I'm not sure if this is more comforting than baffling 'cause I have not the slightest sign of an idea as to what the :heart::heart::heart::heart::heart::heart::heart: hell is going on.

To keep in mind, like I said in my original post, the LCD and MCU used to be on a PCB with solder in between the MCU and the wires going to the LCD, and it still wouldn't work. So I wouldn't consider the breadboard's connections to be the problem.

R2eno:
So I wouldn't consider the breadboard's connections to be the problem.

We would. :roll_eyes:

Yup. The breadboard was the problem in the end.
Bare with a noob man out of all the rows in the breadboard literally only this one was somehow broken.

The LCD works in the breadboard now, but not on the PCB. I moved it back to it, and checked the soldering and cables for continuity with a multimeter, and that's all well and good but the LCD still won't work on the PCB.

You could install the hd44780 library (available in the library manager) and run the included I2CexpDIAG sketch and have it report any issues it sees.
--- bill

Sorry for the late reply, I left the proyect for a while to clear my mind off it.

Got back to it recently, moved only the MCU and LCD to a new smaller PCB with crystal, 22pF caps, and 0.1uF caps on VCC and GND, now the LCD's working as intended.

Conclusion: there was someting fuzzy on the previous PCB. To date I still don't know what, I've checked the connections with a multimiter to no end.

Thanks to everyone for baring with the noob, much appreciated :slight_smile: