Go Down

Topic: SSD 1306 0.96" Oled powered from Arduino pin U8GLIB (Read 139 times) previous topic - next topic

rkflyer

Hi All

I could use some help / advice on powering one of the small SSD1306 oled 0.96" displays from an Arduino pin

Im using an ATMEGA328 and powering the small display directly from the Arduino, I've checked the current draw and its in the order of 15mA-20mA - well within the output current capabilities of the chip.

It all works fine with the Adafruit libraries and the SSD1306Ascii ones and I'm setting the pin output to high in the void setup();

However when using the U8GLIB libraries it wont work, If I power the display from a static 5v feed the libraries work just fine so its a display power issue not my use of the libraries.

So I started trying various delays after setting the pin to high thinking it was an issue of the display 'starting up' before the I2C init codes were sent - but no.

If I take the line  U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); and insert it in the void setup(); after the pin is turned on it still will not initialise. If however I put it within the main loop it does but reinitialises it every loop - but at least it proved I could make it startup.

So realising the code in U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); was executed BEFORE the void setup(); I decided to look into the library code  (Im a NOOB so this was brave - Don't shout or laugh at me)

If I put the following into the U8glib.cpp within the I2C init section, but before the prepare(), I can turn the port on for as long as I set the delay to, but as soon as the prepare() executes it turns it off again - I assume part of the init.

  DDRB |= (1<<PB0);
  PORTB ^=(1<<PB0);
  _delay_ms(250);

HOWEVER, the display now works using the U8GLIB !!

Im not fully satisfied this is a valid fix as I am wondering if the display now works down to some persistence in that the power to the pin is only off for a short while after I force it on and its reset by the prepare() then it comes back on again when I set it high in the void setup();

Ive tried following the prepare() in U8glib.cpp to U8glib.h then to U8Init in u8g.h but my knowledge has expired by this stage

Can anyone offer any thoughts or suggestions as to what is happening here and where I might look next

Ric

olikraus

I do not know what PB0 does, but you can re-init the OLED by calling u8g.begin().
This means you can place your port manipulation and the delay in setup() and call u8g.begin() after the delay.
Will this help?

Oliver

rkflyer

Oliver,

Thank you for the reply - Im struggling a little with this one, even though I've got it working with what feels like a bit of a hack, I want to understand why it works.

Ive tried the ug8.begin(); instead but it doesn't work - there is something else going on during the init of the display that appears to be happening before the void setup(); is run.

Im away working at the moment and this is my amusement when quiet, but I have a logic analyser at home and need to look at the I2C lines and understand exactly what is sent and at what point during the mega boot process.




As for the the PBO bit,  its directly manipulating the digital ports on the Mega, i.e. Im forcing the pin into an output mode and turning it on within the u8g libraries - Even though the rest of the Mega startup process appears to turn it off again this 250ms is enough for the u8g libraries to be able to init the display.

I got my information from the following link re direct port manipulation...

https://hekilledmywire.wordpress.com/2011/02/23/direct-port-manipulation-using-the-digital-ports-tutorial-part-3/


Modified to suit the two key lines are

  DDRB |= (1<<PB0);  Sets the PortB pin 0 to an output - This is digital pin 8 (PB0) on the Mega
  PORTB ^=(1<<PB0); This then turns it on

Ric



olikraus

Hi
Sure you are manipulating the port lines, but why?  What is the purpose of the manipulation?

Another point is this: Actually Arduino language is C++. The constructors (and this includes the U8glib constructor) are executed before setup. So the u8glib code is executed before setup() starts. Initially the init code was sent to the OLED during this phase, before setup(). However now u8glib tries to delay this until the first u8glib command. The current version of u8glib should not do anything to the ports lines until the first u8glib command is executed.

Not sure whether this helps...

Oliver

rkflyer

Oliver

Firstly thank you for taking to time to read me problem and try and help me, I'm new at this and really appreciate any help and clues i can glean.

Quick background to what I'm doing - I have a device that I need to put into a power down sleep mode, but one that also has an oled display.  The reason for powering the display from an Arduino pin is I can turn the display off before i put the device into an ultra low current shutdown mode (its a full reboot restart so the re-init isn't an issue)

So this is where my problem starts, I could turn on the pin conventionally via the void setup(); with a digitalWrite, however the u8glib 'constructor' as you said is run before setup - theres the catch, at the stage it runs the display is not yet powered because setup hasn't yet run the digitalWrite.

Hence i went off onto an investigation on how to turn the pin on before the u8glib init sequence ran.

What I'm struggling to understand how the library initialises the display and you might have given me a small clue - the word 'constructors' to go and investigate.

You mentioned that u8glib tries to delay this until the first u8glib command but it would appear to be running from the display config statement U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK)  - I could be totally wrong with this but its what appears to be happening..

Subsequently running the begin that you first pointed me to doesn't seem to re-init the display.

Attaching a small led to the pin to watch what happens with the line shows a short 250ms pulse from when I'm turning it on via the code in u8glib, but as soon as the timer finishes (and the prepare is executed) the line goes low until the digitalWrite in setup runs.

BUT the display works!! which is confuses the hell out of me, taking this pulse out stops it working again and is repeatable.  Like i said in the first post I'm concerned its work down to luck and persistence in the power of the oled rather correctly powering.

Once again, thank you for any clues you can give me...

Ric




olikraus

Hi

I have seen several displays running fine without power supply.They just get the power from their digital pins.

You say, that u8g.begin() does not work. Which version do you use? I just checked the code. It should work.
With u8g.begin() the init sequence is set again. Regardless what happend before, turn on your power supply (by setting the output pin) and then call u8g.begin(). This shoudl init the display, independently what happend before.

Oliver

Go Up