TonyGo

Enlarged TEXT on SSD1306

Jul 5th, 2026
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | Software | 0 0
  1. # Enlarged Text demo on SSD1306 OLED display
  2. # Tony Goodhew (Tonygo2) 5 July 2026
  3. # Method:
  4. #  Draws normal characters in 'scratch area'
  5. #  at bottom of screen. Then enlarges it
  6. #  at the required position. Small text is then
  7. #  removed. Avoid bottom 8 lines of screen until
  8. #  the end of screen drawing.
  9.  
  10. from machine import Pin,I2C
  11. from ssd1306 import SSD1306_I2C
  12.  
  13. i2c = I2C(sda=0,scl=1)
  14.  
  15. #Set up OLED display
  16. WIDTH  = 128          # oled display width
  17. HEIGHT = 64
  18. oled = SSD1306_I2C(WIDTH,HEIGHT,i2c)
  19. oled.fill(0)
  20. oled.show()
  21.  
  22. # Procedure to draw enlarged text on SSD1306
  23. # using the built-in font
  24. def xtext(string,xx,yy,size):
  25.     ln = len(string)
  26.     oled.text(string,0,56,1) # Normal size string
  27.     for yq in range(8):
  28.         for xq in range(ln*8):
  29.             px = oled.pixel(0+xq,56+yq) # Get pixel value
  30.             if px == 1:
  31.                 oled.rect(xx+xq*size,yy+yq*size,size,size,1,1)
  32.     oled.rect(0,56,ln*8,8,0,1) # Clear temp text area
  33.    
  34. xtext("Tony",17,7,3)
  35. xtext("0123456",8,40,2)
  36. oled.rect(0,0,128,64,1)
  37. oled.show()
  38.  
Advertisement
Add Comment
Please, Sign In to add comment