Go Down

Topic: ATMEGA 1284p and I2C LCD Woes (Read 2488 times) previous topic - next topic


Hi everyone

I am trying to integrate a 20x4 LCD into a project running on a bigger MCU

Basically simple LCD4bit->PCF8574A->SDA/SCL_with_4.7KPullups->MCU   circuit

Hardware (external to micro) not the issue:  If I connect SCL/SDA and GND to a ATmega328p with same sketch uploaded, I2C works, and my LCD works too
Running the I2CScanner.pde sketch (from Playground) - it detects my PCF8574 on 0-x38 just fine and dandy from a 328p

Software also works - as two different scenarios has same symptoms:
1.  I2C Scanner:  On ATMega328p : finds the I2C Device -  On ATmega1284P : Does not find any I2C Devices
2.  LiquidCrystal_I2C  -  On ATMega328p - no issue, change Board to 1284 (Gen7 with Marlin cores on Arduino 1.0.3) - upload (i.e. no changes to code: I2C pins are coded in cores so no need to define, and I2C Address/pinout stays the same - same sketch goes to both boards) and darn, display does not even initialise

Now since the I2C Scanner sketch does not even detect any I2C devices on the 1284p it would not find a device to initialise at the address either (despite we knowing it is correct address)

Now about 2 months ago when I started developing this, I was using a ATmega644P (had on hand) and that was working with same (though slightly older) codebase (Arduino 1.0.0 with Gen 7 2.0 Cores).   Then later in the project switched to 1284p.  Now the actual project's code is of no importance, as I am simply testing with the LiquidCrystal_I2C sketch:

SO the question started arising, I2C in some way disabled on the 1284p?  Looked at Engbedded's Fuse Calc and cannot see any fuses related to I2C/TWI (only SPI - which is enabled for my SD)

Someone mentioned PPR - a way to turn of LCD in code - but doubt strongly thats the case as it worked on the 644p...

Any ideas?

Code: [Select]

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

#define I2C_ADDR    0x38  // Define I2C Address where the PCF8574A is
#define En_pin  6
#define Rw_pin  5
#define Rs_pin  4
#define D4_pin  3
#define D5_pin  2
#define D6_pin  1
#define D7_pin  0

int n = 1;

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

void setup()
  pinMode(13, OUTPUT);
  lcd.home();                   // go home

lcd.print("I2C tester"); 
  lcd.setCursor ( 0, 1 );        // go to the 2nd line
  lcd.print("F Malpartida library");
  lcd.setCursor ( 0, 2 );        // go to the third line
  lcd.print("Test By OpenHardware");
  lcd.setCursor ( 0, 3 );        // go to the fourth line
  lcd.print(".co.za ");}

void loop()
  lcd.setCursor(14,3);        // go col 14 of line 3
  digitalWrite(13, HIGH);
  digitalWrite(13, LOW);


My setup works when I use A0 for SCL and A1 for SDA.  The documentation for the ship says A4 and A5.  Could that be your problem?

Also, my backpack works at address 0x20. 


The 1284p has dedicated I2C pins on physical pins 22=SCL and 23=SDA

This is what I am using, and the 644 is in same place so still does not indicate what is different why 1284 does not work



I'm using the ATMEGA 328 and its documentation says that SDA and SCL are at PC4 and PC5, but I found the signals at PC0 (Analog 0) and PC1(Analog 1).  Your documentation has them at PC0 and PC1.  I was able to find my signals by attaching LEDs and resistors to those pins.  The sketch "i2c_scanner" sends out a continuous signal. 



Jan 20, 2013, 07:15 pm Last Edit: Jan 20, 2013, 07:45 pm by tack Reason: 1
What pin mappings are you using.

On the Uno I have I2C at A4/Pin 27 (SDA) and A5/Pin 28 (SCL)

On the 1284P I use the Bobuino pin mapping and I have I2C at D22/Pin 22 (SCL) and D23/Pin 23 (SDA)

My I2C LCD/Keypads, via 3 different backpacks and a breadboarded 8574, work fine.

Everything was set by initially installing the Mighty1284P Optiboot bootloader with Bobuino pin map. That's just to set fuses etc and from then on I'm uploading via a 328 chip set as ISP. Fuses are Low = 0xff, High = 0xde, Extended = 0xfd

What pins are you connecting to on the 1284P, and have you checked the order as they are the opposite way round to on 328P, with SCL on the lower pin (22) and SDA on the higher (23).


Guys, I really do not want you to take offence, but please read up about I2C before offering useless advice.  I2C is not "mapped pins" - it physical device connected to the pins as indicated.   

Please refrain from replying if you have less than 1 year of MCU experience.... I was hoping for input from someone who actually has it working with a PCF8574 and the library in question

@tack, have not tried the Boduino cores - doubtful the reprap community supports it
But glad to know you have it working on a 1284P!

My fuses are


Will check the difference on a fusecalc now...


Oscilator:   Mine:  Crystal 8+, Yours Full Swing
Boot flash size:   Mine:  512 words, Yours 1024 words
Brownout:  Mine: 4.3v, Yours 2.7v
I have CKSEL3 on, yours off
I have BOOTSZ1 on, yours off

First three definately not related - checking datasheet re CKSEL3 (Clock source)



I understand that I2C is on physical pins, but the equivalent position in Arduino digital/analog mapping IS dependent on the pin map.

If I used the mighty1284 standard map then the equivalent Arduino digital pins would NOT be D23 and D24, although the 1284P IC physical pins are obviously still 23 & 24.

You just said you were hoping from help from someone who has this working with the libraries in question. I do; a 1284P using several differently connected 8574, with both LiquidCrytal_I2C and Keypad_I2C, yet I'm offering 'useless advice'

If you don't want any input from someone with 'less than 1 years experience in MCU' then fine. The bottom line is that I2C works fine on my 1284p setup and not on yours, so go figure it out yourself without any further useless attempts from me to help.


Oct 21, 2015, 02:43 pm Last Edit: Oct 21, 2015, 04:24 pm by penjoseph
I was successful in connecting Sanguino 1284p through I2C to 16x2 LCD (JHD162A) with I2C piggyback (IIC Module)

The Arduino IDE is 1.0.6 & the compatible 'Board' selection is 'avr-developers.com pinouts 16MHz' from Jack Christensen's Mighty-1284P core update library.

Used CH340G USB adapter with DTR pin for uploading sketches through the serial port.

I2C pinouts:
Pin22 (D16) - SCL
Pin23 (D17) - SDA

-which is as per 1284p datasheet pictured above.

Initially I had a problem having the LCD characters not being displayed though the backlight on/off was working fine in the code. Later after testing the I2C LCD on an Arduino Leonardo I figured out the USB serial adapter when connected to a PC (5v USB power source) is not giving enough power for the LCD to initialize correctly. With the input power jumper set to 'external', connected a 12v DC adapter source directly to Sanguino board & it worked fine.

Slow Coach


Since you have a "Green" LCD,  you don't really need the backlight.   Or perhaps you can just reduce the current by changing the series SMD resistor on the LCD.    Or change the LED jumper on the adapter to a series resistor.

Some modules have "sensible" series resistors for their backlight LED(s).    Others just have a 0R which means that they take an unlimited massive current at 5V.



Oct 21, 2015, 03:39 pm Last Edit: Oct 21, 2015, 03:40 pm by penjoseph
True, however characters on the Yellow-Green JHD162A LCD without backlight are not visible without ambient lighting.

The LCD with I2C piggyback works fine when connected to an Arduino Leonardo with just PC USB power but not so with the CH340G USB adapter power to the Sanguino.
Slow Coach


Oct 21, 2015, 03:48 pm Last Edit: Oct 21, 2015, 03:48 pm by david_prentice
Yes,   I quite agree that you can not read it in the dark.   In the dark,   you do not need a very bright backlight.

Just experiment with different series resistors untill you get a reasonable legibility.    Then you can replace the SMD on the main LCD board.

It is the blue displays that are pretty unreadable in bright sunlight.   And completely unreadable without any backlight.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131