element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Internet of Things
  • Technologies
  • More
Internet of Things
Forum Live Update of OLED module in Python
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Internet of Things requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 1 reply
  • Subscribers 334 subscribers
  • Views 265 views
  • Users 0 members are here
Related

Live Update of OLED module in Python

vandia
vandia over 5 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).

  • Reply
  • Cancel
  • Cancel
Parents
  • vandia
    vandia over 5 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
    • Up 0 Down
    • Reply
    • Cancel
Reply
  • vandia
    vandia over 5 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
    • Up 0 Down
    • Reply
    • Cancel
Children
No Data
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube