Understanding Monochrome OLED Breakouts & STEMMA QT

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gallaugher
 
Posts: 267
Joined: Tue Aug 14, 2018 12:42 pm

Understanding Monochrome OLED Breakouts & STEMMA QT

Post by gallaugher »

Hi,
I've added I2C to an Arduino Nano RP2040 Connect & have gotten an Adafruit Gator touch to work, added a non-STEMMA Neopixel strand - that lights up, and now I'm daisy chaining a Monochrome 0.91" 128x32 I2C OLED Display - STEMMA QT / Qwiic PRODUCT ID: 4440
to the Gator.
Sample code from this page works:
https://learn.adafruit.com/monochrome-o ... thon-usage
and "Hello World" prints, but I'm not sure of next steps.

If I try to write more text, say use the code below, it seems the old text is overwritten by new text, so anything beyond "H" (used in both text phrases, "Hello World" and "Hi Buddy" has pixels from both words written.

I then thought since inner_sprite was already created, I could just put a:

splash.append(inner_sprite)

in between the two blocks of code where I draw a label like this:
# Draw a label
text = "Hi, Buddy!"
text_area = label.Label(
terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=HEIGHT // 2 - 1
)
splash.append(text_area)

However, I get an error that this layer is already in a group.
If I repeat all the code that creates and appends the inner sprite, then I get the desired effect - screen blanks, and I only see the second phrase:
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000 # Black
inner_sprite = displayio.TileGrid(
inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)

Do I need to do this - clear the screen or at least the area over any old text each time I want to enter new text, and do I have to completely recreate the TileGrid as above, then splash.append that recreated tile grid, or is there an easier way.

Am I over-complicating things for basic text use? For example, if I want to simply, regularly update the three lines of text in the display, is there a way to purge what's on the display with a simpler command, then start writing out my text?

Thanks for helping me understand how to best use this display in CircuitPython!
J

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Understanding Monochrome OLED Breakouts & STEMMA QT

Post by dastels »

You can change the text of a label to a new value by setting it's text property. That should do it for you.

Dave

User avatar
gallaugher
 
Posts: 267
Joined: Tue Aug 14, 2018 12:42 pm

Re: Understanding Monochrome OLED Breakouts & STEMMA QT

Post by gallaugher »

Worked great, as you can see :)
And I concur with the Nano RP2040
dastels_is_awesome.png
dastels_is_awesome.png (952.05 KiB) Viewed 85 times

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Understanding Monochrome OLED Breakouts & STEMMA QT

Post by dastels »

Haha! Good stuff. Have fun.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”