AlexIII / t-rex-duino

Clone of T-rex game from Chrome browser rewritten for Arduino
MIT License
81 stars 12 forks source link

OLED initialization using I2C failes sometimes #2

Open nebomuk opened 2 years ago

nebomuk commented 2 years ago

Used hardware: SSD1306 based OLED display and Arduino Nano. Display is connected via I2C.

Sometimes, the OLED display stays black after starting the t-rex-duino app. I could not identify the specific reason in the source code for this but I found the following workaround:

When initializing the display with another SSD1306 library before the custom I2C code of the t-rex-duino app is executed, the display works properly. For example when putting

Adafruit_SSD1306 display = Adafruit_SSD1306(...); display.begin();

in the first lines of the setup(); function, the OLED display always turns on.

Is it possible that there's some kind of initialization bytes missing in the custom I2C SSD1306 code of the t-rex-duino app?

AlexIII commented 2 years ago

Hi! Thanks for your comment. Yes, it is possible that the initialization procedure is incomplete. There's a few different 'flavors' of 1306 controllers and they slightly differ from one another. Universal libraries such as Adafruit account for that. I only tasted the code with a single display I have on hands. I'll try to look into the Adafruit library, but without having the exact same display to experiment on, it is unlikely I can guess what exact init command is missing.

rtek1000 commented 8 months ago

In order to use SH1106/SSD1306 you will need to add two 470 ohm resistors to the display board. You can add these resistors right on top of 10k resistors that already present (or replace them).

Hi @AlexIII , Where was this information obtained? This value of 470 ohms seems to be very low.

AlexIII commented 8 months ago

@rtek1000 What do you mean "very low"? It's perfectly safe and necessary in this case, since the i2c bus is significantly overclocked.

rtek1000 commented 8 months ago

@rtek1000 What do you mean "very low"? It's perfectly safe and necessary in this case, since the i2c bus is significantly overclocked.

Ok, there is a calculator that might be useful:

(3.3V, 400pF, HS (1.7MHz/3.4MHz): Pull up resistor range 0.967 KOhm < Rp < 0.472 KOhm; Rp can be replaced by external current source pull-ups to meet the rise time requirements)

Link: https://atman-iot.com/blog/i2c-pull-up-calculator/

Note: There are interesting resources about this in the footer too.