element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Forum Live Update of OLED module in Python
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 504 subscribers
  • Views 1253 views
  • Users 0 members are here
Related

Live Update of OLED module in Python

vandia
vandia over 8 years ago

I know this is probably a beginner/no-brainer question about a command I just don't know, but:

 

I'm using the PIL(Python Image Library) to write to an OLED via I2C for a project.

I can write to it alright, but when I create a loop, it writes the new message OVER the old message, causing the 2 to overlap the 1, and so on.

How can I remove either the selected line, or just one character, to replace with an updating number?

 

Note, the i increment is just a placeholder for other numeric data, where I just really need to update what's after "Num" with replacing it, not creating a 1/2/3 overlapped abomination. I just, with my still learning python, figured rewriting the line several numbers will be updated on, would be the easiest remedy.

 

My Code

def numbers():

    for i in range(int(11)):

        print(i)

 

 

  draw.text((0, top-8)," Num:"+str(i),  font=ImageFont.truetype("fonts/arial.otf", 17), fill=255)

  disp.image(image)

  disp.display()

 

 

  time.sleep(2)

 

I know this is outside typical e14 posts, but since it's an I2C(IoT) module that can work for BeagleBone, Raspberry Pi, and the Edison (anything that can run Python on I2C), but  I felt it appropriate to ask here how to make it work (compared to some unnamed sites where asking a noob programming question gets you ostracized).

  • Sign in to reply
  • Cancel
  • vandia
    vandia over 8 years ago

    I spent more time playing with it and ideas to get it to work. I tried calling disp.clear ( where disp = SSD1306.SSD1306_128_64() )  within the loop, but no luck.

     

    An article on the Arduino forums HERE explained a typical way of doing it, that's not actually exclusive to Python.

    In short, it was to write over the old test you're wanting to replace with the background color... which is monochrome for most OLEDs. So, Fill=0 vs Fill=255 in Python. If you call to write over the old OLED message with the same exact one but in the former color, and do so before the next cycle (message change), it will remove what it just put.

     

    I've still yet to figure out how to properly make .clear() work on this model, but here is the correction to the code I had, in case anyone else may need:

     

    def numbers():

      for i in range(int(11)):

       print(i)

      draw.text((0, top-8)," Core:"+str(i),  font=font, fill=255)

      # Display image.

      disp.image(image)

      disp.display()

      time.sleep(2)

      #remove old image before next cycle

      draw.text((0, top-8)," Core:"+str(i),  font=font, fill=0)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • RogueGesus
    RogueGesus 2 months ago in reply to vandia

    8 years late but this helped me. Thank you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube