ATMega328P doesn't work with SSD1306 OLED display

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I'm having trouble getting an SSD1306 OLED 128x64 display to work with an ATMega1284P. I've tried everything I can think of but the display remains blank. The display works fine when used with the Arduino Uno R3; I can upload and run a "blink" sketch on the ATMega1284P; I've tested all the wires with a DVM for integrity; I've checked and rechecked the wiring.

 

I'm using a Windows 8 machine. I've had problems using the Uno to upload sketches to the ATMega1284P, so I've been using a USBtiny instead. I use the "Maniacbug Mighty 1284p 16 MHz using Optiboot" board in the Arduino IDE to build the hex file. I then flash the sketch on to the ATMega1284P with the USBtiny by running the following command from a command shell:

avrdude -c usbtiny -p atmega1284p -U flash:w:HelloWorld.ino.hex

 

The command appears to execute without a problem, but the display remains blank. I'm using the U8g2 library; the full code of the sketch is shown below.

 

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 22, /* data=*/ 23, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display

void setup(void) {
    u8g2.begin();
}

void loop(void) {
    u8g2.firstPage();
    do {
        u8g2.setFont(u8g2_font_ncenB14_tr);
        u8g2.drawStr(0,24,"Hello World!");
    } while ( u8g2.nextPage() );
}

I suspect that I'm incorrectly specifying the SCL and SDA pins in the constructor (pins 22 and 23 respectively) but don't know what else to try.

 

I'd appreciate any help in moving forward with this. Thank you.

This topic has a solution.

Alan

Last Edited: Tue. May 15, 2018 - 07:47 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awarren.darwin wrote:
Maniacbug Mighty 1284p 16 MHz using Optiboo

awarren.darwin wrote:
I suspect that I'm incorrectly specifying the SCL and SDA pins in the constructor

 

Searching the first I found a pinout map, SCL = D16, SDA = D17

 

from this:

 

worth a try!

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP has deliberately chosen a software I2C constructor.    It should work on any GPIO pins.     The I2C bus must have real external pullup resistors e.g. 4k7

 

The hardware constructor would use the hardware SDA, SCL pins.

 

Oliver has written the library in C.   With a C++ wrapper for the benefit of Arduino.    I would guess his driver(s) are 100% good.    If you have a problem "olikraus" is active on the Arduino.cc Displays Forum.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That worked. Thanks very much, Jim.

Alan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mark the solution - see Tip #5

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regardless of whether it uses hw or sw I2c, the constructor probably needs Arduino “PIN numbers”, and not chip PIN numbers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I marked it as solution yesterday. The button now reads 'unmark solution'. Is there something else I need to do?

Alan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope, everyone else reading this sees:

 

So it is quite obvious that #2 is the chosen solution.

 

PS forgot to say that possibly even more important is that back in the forum list there is this:

 

The green tick there says "don't beat yourself up trying to answer this as there's already an acceptable solution contained within".

 

EDIT2: Oh yeah, and this....

Last Edited: Wed. May 16, 2018 - 03:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awarren.darwin wrote:
I marked it as solution yesterday. 

Yes, I now see it as marked.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"The button now reads 'unmark solution'. Is there something else I need to do?"

I suppose you are free to change your mind and , if you realize it was a wrong solution, you are allowed to unmark it .

But, from what I read and understood, seems unlikely.... (but nice to be able to change one's mind)