• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ssd1306.py

Q&A Forum › Category: ESP32 › ssd1306.py
0 Vote Up Vote Down
self.raymond asked 5 years ago

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 

9 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
self.raymond answered 5 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
self.raymond answered 5 years ago

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()

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
self.raymond answered 5 years ago

Thank You let me try that out.. Thanks for getting to me with a quick answer
 

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Then, let me know what you think.

0 Vote Up Vote Down
self.raymond answered 5 years ago

That was awesome work great.  Had to insert the address of the oled but that will work.  Thanks so much for the help

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Great!
I’ll close this question.
If you need further help, you just need to open a new question.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.