I would like to be able to scroll the display from one screen to another in a loop. So the first screen displays something for like 5 sec and goes blank and another screen pops up for 5 seconds and repeat over and over. Can you help with that?? Thanks
Hi Ray.
I don’t know the right way to do that. So, I’ll suggest what I think can be the easiest way to achieve that.
Create two different functions, for example displayScreen1() and displayScreen2().
Inside the first function add the necessary lines to display what you want on the first screen. To the same thing for the other function.
Then, inside your loop (while True) call your functions one after the other with some delay in between.
Or do you have any idea in mind?
Regards,
Sara
Thank You Sara. I was thinking about that but I was not able to just turn off one function. I was thinking I was reading from 1 pin… would it be okto toggle between high and low where high reads the function and turns the pin on for like 5 sec and turns the pin off. Can that be done. I will work on the other way for sure Thanks big
Hi Ray.
I’m sorry, but I don’t understand your question.
You want to turn off the screen is that it?
To turn off the screen, you can use the following commands:
oled.fill(0)
oled.show()
If you reformulate your question, maybe I can help you better.
Regards,
Sara
Let me start off with the first part. My first function is oled screen 1. The second function will be oled screen 2 and so on. I am looking to have the 1306 to display the first function for 5 seconds and go blank and display the 2nd function for 5 sec and so on. I do not want to scroll the text… I want to scroll the whole screen from one function to another function. Can that be done and how. Thank you for your time.
Start your code here
from machine import Pin, I2C
import ssd1306
from time import sleep
import dht
# ESP32 Pin assignment
i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
address = 60
sensor = dht.DHT11(Pin(5))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c, address)
def oled_screen1():
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
temp_f = temp * (9 / 5) + 32.0
# print(‘Temperature: %3.1f C’ %temp)
print(‘Temperature: %3.1f F’ %temp_f)
print(‘Humidity: %3.1f %%’ %hum)
oled.text(‘{:^16s}’.format(‘Temp:’), 0, 0)
oled.text(‘{:^16s}’.format(str(temp_f) + ‘%’), 0, 16)
oled.text(‘{:^16s}’.format(‘Humidity:’), 0, 32)
oled.text(‘{:^16s}’.format(str(hum) + ‘%’), 0, 48)
oled.show()
except:
pass
oled_screen1()
Hi Ray.
I create a simple script that changes between screens: https://pastebin.com/YHRd7dCu
I’ve create two functions:
display_screen(screen)
the screen is a list of lists that contains the coordinates and text to display on each row. It’s easier to understand how it works if you take a look at the example.
and the following function
transition_screen(speed)
The speed is a number (divisor of 128), that allows you to change the speed of the transition.
Test the example I’ve sent you and see if it does what you want.
Then, replace with your sensor readings.
I hope this helps.
Regards,
Sara
That was awesome work great. Had to insert the address of the oled but that will work. Thanks so much for the help