Notifications
Clear all

Clearing garbage characters on OLED display

23 Posts
5 Users
5 Likes
4,724 Views
(@davemorris)
Member
Joined: 3 years ago
Posts: 31
Topic starter  

So if I was to use a string to do this, as suggested, I am confused about how to generate the "new" string vs the "old" string.  Making a string with the voltage reading I understand and I have done that successfully. I get the proper voltage reading on my display using the string. I am unclear of the syntax for generating the "old" string to overwrite the value in black prior to writing the new reading to begin the cycle over again.


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

If I understand this right, the new code works. But you still need to cover up some misaligned characters? You can try:

 

//Send results to display
display.setTextColor(WHITE,BLACK);
display.setCursor(82,20);
display.setTextColor(WHITE);
display.print("         ");
display.setCursor(82,20);
display.print(" ");
display.print(String(in_voltage, 2));
delay(1000);

 

That would just print spaces there then right after it write the new value. If you see a delay you don't like in the screen, you could always make a string with the in_voltage and add a few spaces after it then print that. So far I don't think I have seen any library that allows a clear section. I would like that though!

 

Otherwise, your option would be to redraw the whole screen when updating.

 

Edit: If it is not covering it all up, try setting the color before the spaces as black then back to white before printing the new value. If that does not work then maybe redrawing might be the best option.


   
ReplyQuote
(@davemorris)
Member
Joined: 3 years ago
Posts: 31
Topic starter  
Posted by: @madmisha

@davemorris

If it was correct on the serial monitor but the screen was still garbage, then I would download the Waveshare library/example I linked above. They do things a little different in their example. Maybe it isn't compatible with the other library. It also included a font.

Everything else on the display looks perfect though.  The only issue is refreshing the numbers as the voltage reading fluctuates. When I first turn it on, the numbers at cursor position 82,20 look perfect. Lets assume my voltage I am testing is reading 10.00v.  I get a perfect 10.00 at that cursor position and everything on the display looks great.  Then I change my voltage that is being measured to, say 8.55v. At cursor position 82,20 I should be seeing 8.55. Instead I get a mish-mash of characters and it looks like it is just overwriting the new reading on top of the old.  Again, all of the rest of the display is fine.  Printing spaces prior to updating the numbers didn't change it. A complete screen refresh cleans it up but it flashes and is annoying. I need to have code that will clear the 4 spaces at 82,20 and only those characters prior to writing the new value to it. 

I can not wrap my head around how I would generate an "old string" to then write that value in black just prior to writing the "new string". I have looked through a ton of Waveshare docs as well as Adafruit library docs and have not found how to write this.  Being very new to coding isn't helping me either but I guess this is how one learns these things. 


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

@davemorris

If the spaces don't work, try drawing a black rectangle there instead. I'm sorry I didn't think of that sooner. That seems stupidly simple.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @davemorris

A complete screen refresh cleans it up but it flashes and is annoying

When I perused these posts regarding your OLED display I thought I had done something similar a while back so looked to dig out my code.  It turns out I was using an sh1106 display and the code was in micropython 😉 so probably not much help but here are my comments for what they are worth. 

Looking at my code I see that the temperature is written to the appropriate screen coordinates, but they do not get actually displayed on the screen until I do a display.show()

The python function is shown below.  When the temperature changes (or some other stuff changes) and the function is called I first blank the display, then I write to the display memory (the display.text stuff - the temp reading it the display.text(roomTemp,80,0,1) line ), and then I finally write the display memory to the screen (display.show)

def oledDisplay(roomTemp,setPoint,boilerStatus):
    global display, targetDesc
    display.fill(0)
    display.text('Room Temp:', 0, 0, 1)
    display.text(roomTemp,80,0,1)
    display.text(targetDesc, 0,20, 1)
    display.text(setPoint,80,20,1)
    display.text('Boiler:', 0,40, 1)
    display.text(boilerStatus,80,40,1)
    display.show()

So I would think that maybe your screen should be first blanked out, then you write to the screen memory, and then you do your screen refresh, and this is the way it should be done ??  From memory my screen did not appear to have an annoying flash, but of course this is a different screen than yours.  Maybe this helps, maybe not. 😎 


   
ReplyQuote
(@davemorris)
Member
Joined: 3 years ago
Posts: 31
Topic starter  
Posted by: @madmisha

@davemorris

If the spaces don't work, try drawing a black rectangle there instead. I'm sorry I didn't think of that sooner. That seems stupidly simple.

Well, I would love to try that, however as I am in my true infancy of programming drawing a stupidly simple rectangle eludes me.  🙂

I was looking at documentation for the Adafruit GFX library and didn't see anything that explained how to do that. I thought it would be another way to do it.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @davemorris

I was looking at documentation for the Adafruit GFX library and didn't see anything that explained how to do that

https://learn.adafruit.com/adafruit-gfx-graphics-library/graphics-primitives

The above link will show you how to draw boxes on you screen.  Have fun. 😎 


   
MadMisha reacted
ReplyQuote
(@davemorris)
Member
Joined: 3 years ago
Posts: 31
Topic starter  
Posted by: @byron
Posted by: @davemorris

I was looking at documentation for the Adafruit GFX library and didn't see anything that explained how to do that

https://learn.adafruit.com/adafruit-gfx-graphics-library/graphics-primitives

The above link will show you how to draw boxes on you screen.  Have fun. 😎 

Dude!! Between you posting this link (not sure how I missed it when I was searching) and MadMisha suggesting the rectangle draw, I now have success. Thank you both so much! Now to the next complication in this project...Adding two MLX90614 IR temp sensors and using them to report temps. I think through doing this voltage display exercise I am better prepared to code it.


   
LydaRA and MadMisha reacted
ReplyQuote
Page 2 / 2