Hi Rui, I am experimenting with the Heltec LoRa 32 v2 board, and am having problem to get the OLED display to work with MicroPython.
The board worked correctly when I received it, and I could see the Heltec logo and the LoRa sender APP information on the OLED display.
After flashing the latest version of MicroPython I am trying to display same sample text on the display and I am able to make it work.
I am using the Adafruit ssd1306 library and the following code to turn the whole display on/off. There is no error reported on the REPL and the code runs correctly until I press Ctrl-C:
i2c = I2C(-1, scl=Pin(15), sda=Pin(4)) oled_width = 128 oled_height = 64 oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) oled.show() sleep(0.5) oled.fill(1) oled.show() sleep(0.5) while True: print("Works !!") The specific questions are:
- What am I doing wrong, or missing?
I have found the probable cause of the issue, which might be specific to this kind of integrated OLED displays on the Heltec Lora 32 I am using.
A special initialization of the display has to be done through the displays RST pin. This is shown in the tutorial TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE in this “Arduino code”:
pinMode(OLED_RST, OUTPUT); digitalWrite(OLED_RST, LOW); delay(20); digitalWrite(OLED_RST, HIGH);
- How can I go back and reset the board to the Factory settings where I would expect to see the original OO working on the display. I have not been able to find instructions on how to re-flash the board to factory setting.
After some more searching and consideration for a “factory image”, it became clear that to put the board back to factory setting you only have to load a sample application sketch through the “Arduino IDE” onto the board. I decided to load the “OLED_Lora_sender” from the “Examples | Heltec ESP32 Dev-Boards | LoRa” section in the Arduino IDE. Once the flashing process finishes the board is back to “Factory Setting”.
Thank you in advance…
When you press CTRL+C you interrupt the execution of the code. That’s why it stops working.
I think you can go back to the factory settings if you find the original firmware.
Thank you Sara, I am aware that Ctrl+C stops execution. What I meant to say is the display does not work while the code is executing, reason for which I press Ctrl-C.
I have not been successful in finding the “factory image” to flash it the board. I had hoped that you could point me to a location where to find it. In your “MicroPhyton Programming for the ESP32” or on one of your tutorials I remember having read that you can return to the “Arduino Enviornment”, which I understand would be through flashing an Arduino or factory image.
Yes, you can upload an Arduino code and it will overwrite the micropython firmware.
That board should be similar with the TTGO LoRa32 OLED. We wrote a tutorial about that a few days ago: https://randomnerdtutorials.com/ttgo-lora32-sx1276-arduino-ide/
Were you able to make the OLED work using micropython?
The following micropython code attempts to implement the “initialization” sequence for the display. Unfortunately it does not do anything and the display does not show anything.
d_rst = Pin(16, Pin.OUT, value=0) d_rst.value(1) sleep_ms(20) d_rst.value(0) sleep_ms(20) d_rst.value(1) sleep_ms(20) d_rst.value(0)
Thank you in advance for your suggestions
I think the OLED RST pin must be HIGH to work properly.
So, you should have:
d_rst = Pin(16, Pin.OUT) d_rst.value(0) sleep_ms(20) d_rst.value(1)
Can you try doing that?
I’ve tried controlling the OLED of my TTGO LORA board, but it didn’t work. I’m still trying to figuring that out.
UPDATE. The following code shows how to init the OLED with the TTGO LoRa board and it worked for me.
Please use the following code and see if it works for you:
from machine import Pin, I2C import ssd1306 from time import sleep # ESP32 Pin assignment i2c = I2C(-1, scl=Pin(15), sda=Pin(4),freq=400000) # ESP8266 Pin assignment #i2c = I2C(-1, scl=Pin(5), sda=Pin(4)) oled_width = 128 oled_height = 64 d_rst = Pin(16, Pin.OUT) d_rst.value(0) sleep_ms(20) d_rst.value(1) oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c, addr=0x3c) oled.text('Hello, World 1!', 0, 0) oled.text('Hello, World 2!', 0, 10) oled.text('Hello, World 3!', 0, 20) oled.show()
Hi Sara, thank you for your response and suggestion.
I tested the code on my Heltec LoRa 32 board and unfortunately it does not work.
The specific comment I have found on the Heltec Arduino code which explains the “initialization process”:
This is a simple example show the Heltec.LoRa sended data in OLED. The onboard OLED display is SSD1306 driver and I2C interface. In order to make the OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft- ware to OLED's reset pin, the low-level signal at least 5ms.
Further research showed that the new Adafruit ssd1306 library for their implementation of “CircuitPython” includes the critical initialization code for the OLED display and an optional parameter to trigger it during the object intiantiation. Following the code extract taken from the class “_SSD1306:
def poweron(self): "Reset device and turn on the display." if self.reset_pin: self.reset_pin.value = 1 time.sleep(0.001) self.reset_pin.value = 0 time.sleep(0.010) self.reset_pin.value = 1 time.sleep(0.010) self.write_cmd(SET_DISP | 0x01) self._power = True
However, although I tried to use this same exact code, I was unable to succeed. Needless to say that my display keeps refusing to show anything.
I know it is working from a Hardware perspective, because the original Arduino code works fine.
What library are you using exactly?
In the code I’ve shown you, I was using the deprecated library and it worked well: https://raw.githubusercontent.com/RuiSantosdotme/ESP-MicroPython/master/code/Others/OLED/ssd1306.py
However, I’m using a TTGO board, I don’t have an Heltec to experiment with. I don’t know if there is any other trick to make it work.
At this moment, I’m out of ideas to debug this issue :/
If you can give me any other information, maybe I can suggest other alternatives.
I am using the same library that you indicate above. However on my board the OLED display does not show anything. For the moment I have given up, and am working on other components on the board. As soon as I get the TTGO LoRa board which I have on order, I will try to find a solution. Once I get it working, I will update this post with any findings.
Thank you very much. Best Regards, Manfred
I am happy to report that after a lot of reading and searching on google, the solution turned out to be quite simple.
Basically the I2C bus pins “scl” and “sda” need to be initialized with the internal pull_up resistors enabled. For reference the specific code that now works reliable is as follows:
# Heltec LoRa 32 with OLED Display oled_width = 128 oled_height = 64 # OLED reset pin i2c_rst = Pin(16, Pin.OUT) # Initialize the OLED display i2c_rst.value(0) sleep(0.010) i2c_rst.value(1) # must be held high after initialization # Setup the I2C lines i2c_scl = Pin(15, Pin.OUT, Pin.PULL_UP) i2c_sda = Pin(4, Pin.OUT, Pin.PULL_UP) # Create the bus object i2c = I2C(scl=i2c_scl, sda=i2c_sda) # Create the display object oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) oled.fill(0) oled.text('Hello, World 1!', 0, 0) oled.text('Hello, World 2!', 0, 10) oled.text('Hello, World 3!', 0, 20) oled.text('Hello, World 4!', 0, 30) oled.show()
I hope this might help someone else to save a lot of time.
You can go ahead and close this issue as solved / answered. Thank you for your assistance.