Shop OBEX P1 Docs P2 Docs Learn Events
OLED Display flicker or blanking? — Parallax Forums

OLED Display flicker or blanking?

Hello all, new to the Propeller and programming as well. I have put together a small SPIN program to read some potentiometers, I want to send the raw pot reading to a small OLED display with the SSD1306 chip. I am using this OBJ: SSD1306_Driver_Plus v 1.3. In my SPIN code the "pot" reading is in a loop. When I send it to the display (I am sending 1 line of text and the value reading) it blinks or blanks, but I can see the value change as I turn the pot. I have tried changing the timing of the loop but it doesn't seem like it changes. Is there a way to stop the blinking/blanking or am I doing something wrong in the code??

Comments

  • ElectrodudeElectrodude Posts: 1,638
    edited 2024-06-08 04:19

    Can you post your code, or at least tell us more about you're using the OLED display?

  • moseisleymoseisley Posts: 10
    edited 2024-06-10 10:15

    Thanks for responding! On further playing with I notice when I initiate the OLED code everything slows down even output to the PST, it updates when the OLED blinks as does motor movement, when the OLED code is commented out it seems to run and update smoothly. Using the .96 128x64 ssd1306 OLED display in I2C mode. I have paired down the code and posted it below, also attached a video file of the oled behavior.

  • JonnyMacJonnyMac Posts: 8,974

    You really should post an archive so that all of the files are in one place -- don't make people search for libraries they may not have.

  • As per JonnyMac's suggestion I have added a zip with all relevant files to previous comment!

  • evanhevanh Posts: 15,338

    Init() is a big routine doing a rather lot of setting up. You probably don't want to be calling that upon every print. What happens when that's commented out?

    PUB OLEDdisplay
    
    '        OLED.Init
            OLED.Tx(CLS)
            OLED.Str(String("POT READ: "))
            OLED.Dec(potValue)
    
  • evanhevanh Posts: 15,338

    Also, and I haven't tested any of this myself, you've got a bad indentation on the main loop. The waitcnt() is short. That might exclude it from the loop. Here, I've added one space to fix the indentation:

       REPEAT
            potValue := mcp3208.read(F_POT_CHANNEL, mcp3208#SE)                         ' Read focus potentiometer value
            angle := MapFocusPotValueToAngle     'MapPotValueToAngle '(potValue)
            DisplayStatus '*** Debug Msgs
            OLEDdisplay
            waitcnt(clkfreq / 40 + cnt)
    
  • evanh, thanks for the reply, I have tried the comment out of init, and I indented the waitcnt() no difference.

  • evanhevanh Posts: 15,338

    Maybe give it longer. Use /4 instead of /40: waitcnt(clkfreq / 4 + cnt)

  • evanhevanh Posts: 15,338
    edited 2024-06-10 11:01

    Hmm, looking at the object file it seems that that CLS character triggers a rather large screen erase sequence. It'll be spending a lot of time doing that. Here's a much shorter routine that hopefully will allow you to overwrite the text on screen instead of repeatedly erasing.

    You'll need to add this to the SSD1306_Driver_Plus.spin source file and then make use of it with a OLED.Home in place of OLED.Tx(CLS)

    PUB Home
    ''Moves cursor to top left of OLED Screen
       Start     
       Write($78)     'Address with Write Bit             
       Horizontal_Addressing
       Stop                                   
       return                                  
    
  • In addition to what @evanh suggested, you can also write blank spaces to a line (or part of a line) to clear the content, rather than clearing the entire display. Often times you'll find that blanking a line is less flickery than clearing he whole display and re-writing all the content.

  • Thank you for the replies again!

    evanh I did try the waitcnt() adjustment earlier but no change, but you suggestion and code snippet did do the trick!! Thank you, I have attached a video of the result. I do however have a couple questions, how would I move it to another line on the display, I don't see any location commands in that driver, also how would I clear the line as I am getting leftover characters from the reading, like when I turn the pot to 0 I see some value still there? VonSzarvas I did try that but evanh has come up with a very simple solution thank you!

  • SavageCircuitsSavageCircuits Posts: 233
    edited 2024-06-10 15:27

    I know I'm a little late, but the OLED driver I use on Arduino has a HOME command, in addition to CLS. For testing, I would have used something like this:

    PUB OLEDdisplay
    
            OLED.Home
            OLED.Str(String("POT READ: "))
            OLED.Dec(potValue)
            OLED.Str(String("     "))
    
    

    The Home command doesn't erase anything, but the " " null spaces at the end erase extra characters on the line.

  • @SavageCircuits said:
    I know I'm a little late, but the OLED driver I use on Arduino has a HOME command, in addition to CLS. For testing, I would have used something like this:

    PUB OLEDdisplay
    
            OLED.Home
            OLED.Str(String("POT READ: "))
            OLED.Dec(potValue)
            OLED.Str(String("     "))
    
    

    The Home command doesn't erase anything, but the " " null spaces at the end erase extra characters on the line.

    This worked for the clearing thanks, I tried this but didn't put it in the right place! Thank you!

    I tried to upload a video file but it wont let me !!??

  • @moseisley said:
    This worked for the clearing thanks, I tried this but didn't put it in the right place! Thank you!
    I tried to upload a video file but it wont let me !!??

    It may exceed the upload file size. I usually post videos on my YouTube channel and embed or link them.

  • yep size limit, here is what I get now, just need to figure positioning out now!

  • @moseisley said:
    yep size limit, here is what I get now, just need to figure positioning out now!

    Yeah, looking at the object, it doesn't seem to support character positioning. You'd have to build the screen using HOME and CR.

  • @SavageCircuits said:

    @moseisley said:
    yep size limit, here is what I get now, just need to figure positioning out now!

    Yeah, looking at the object, it doesn't seem to support character positioning. You'd have to build the screen using HOME and CR.

    Looks that way, darn!!

  • evanhevanh Posts: 15,338
    edited 2024-06-10 23:14

    It will be possible with better knowledge of the hardware. My posted routine isn't exactly doing a home either. I just copied the first part of the clear screen routine - which I presume is setting the hardware into a character line mode. Which just happens to also reset the cursor's position.

    There looks to be a few supported modes by the hardware, including bitmap graphics.

  • @evanh said:
    It will be possible with better knowledge of the hardware. My posted routine isn't exactly doing a home either. I just copied the first part of the clear screen routine - which I presume is setting the hardware into a character line mode. Which just happens to also reset the cursor's position.
    There looks to be a few supported modes by the hardware, including bitmap graphics.

    I don't have the time to port it from C, but the Arduino SSD1306 library I use has CLS, HOME, cursor position, different fonts existing on the same screen, circles, lines, etc.

    Seems like in C it wouldn't be too hard to port, but again, no time here. I'm trying to move within 2 months.

  • Thank you, I have at least something that works, I would have no idea how to port or implement the function as I am still trying to learn this stuff, and ALL of this really helps!! I appreciate the time from this group!! I will keep plugging along and read as much as I can to try and figure it out.

  • Good luck! Just for reference, this is the SSD1306 display I am using and below is a photo from a project showing the graphics and text on the display.

    https://savagecircuits.com/arduino-blaster/

    Very soon I will have a video of it in action, since the display is quite animated. Below is the code that draws the display in the photo.

    void loop() {
      //Fire button check loop
      u8g3.firstPage(); 
      do {
        int a = random(1, 22);
        int b = random(1, 22);
        int c = random(1, 22);
        int d = random(1, 22);
        int e = random(70, 90);
    
        //Draw Scope
        u8g3.drawCircle(64, 32, 25);//Outer Ring
        u8g3.drawCircle(64, 32, 4);//Inner ring
        u8g3.drawLine(52, 32, 32, 32);//left hash
        u8g3.drawLine(76, 32, 96, 32);//right hash
        u8g3.drawLine(64, 44, 64, 64);//bottom hash
        u8g3.drawLine(64, 1, 64, 20);//top hash
    
        //u8g3.setFont(u8g2_font_tom_thumb_4x6_tf);
        u8g3.setFont(u8g2_font_pressstart2p_8u);
        u8g3.setCursor (86, 10);
        u8g3.print("TI-23");
        u8g3.setCursor(102, 50);
        u8g3.print("RNG");
        u8g3.setCursor(102, 62);
        u8g3.print(e);
        u8g3.setCursor(1, 50);
        u8g3.print("MODE");
        u8g3.setCursor(1, 62);
        if (count2 == 1)
          u8g3.print("KILL");
        else
          u8g3.print("STUN");
    
        //Top Left Bars
        u8g3.drawBox(1, 1, a, 2);//bar 1
        u8g3.drawBox(1, 6, b, 2);//bar 2
        u8g3.drawBox(1, 11, c, 2);//bar 3
        u8g3.drawBox(1, 16, d, 3);//bar 4
        delay(50);
      } while ( u8g3.nextPage() );
    
    
  • Savage looks very slick!! Also very nice website!! I think I figured out the 1306 driver I am using, you have to use "page" to get line by line, then I used spaces to position on the line see attached pic. Also here is the code snippet for the pic:

  • Very cool! It was the nomenclature that got me. When I used to write software back in the DOS days, pages were like separate cached screens. I did not equate "pages" in that driver to "lines". I'm glad you figured it out. If text is all you need, that should get you where you need to go.

Sign In or Register to comment.