Hi,
Using image "ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',19)" we can increase the font size but when we have to refresh data we had to paint the entire image. Is there way to increase the font size when we just use OLED.text(x,y,"text",fill)
Thanks and Regards
Sarang
Adafruit PiOLED - 128x32 Monochrome OLED HOW TO INCREASE FON
Moderators: adafruit_support_bill, adafruit
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
- stirucherai
- Posts: 26
- Joined: Sun Sep 26, 2021 11:44 am
- stirucherai
- Posts: 26
- Joined: Sun Sep 26, 2021 11:44 am
Re: Adafruit PiOLED - 128x32 Monochrome OLED HOW TO INCREASE
Solved it -- it is all working
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit PiOLED - 128x32 Monochrome OLED HOW TO INCREASE
What was your solution?
- stirucherai
- Posts: 26
- Joined: Sun Sep 26, 2021 11:44 am
Re: Adafruit PiOLED - 128x32 Monochrome OLED HOW TO INCREASE
1. Had two fonts declared.
2. draw.rectangle((0, 0, width, height), outline=0, fill=0) had this statement for every refresh of data
Attached the full code which is used for display -- now it works perfectly. Now got 2.23 inch PIOLED 128*32 (same size as this mini) and the same code works perfectly (just that we need to change 1306 to 1305 - 3 places)
from board import SCL, SDA
import busio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
i2c = busio.I2C(SCL, SDA)
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
disp.fill(0)
disp.show()
width = disp.width
height = disp.height
image = Image.new("1", (width, height))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, width, height), outline=0, fill=0)
fontB = ImageFont.truetype('/opt/vc/src/hello_pi/hello_font/Vera.ttf',19)
fontS = ImageFont.truetype('/opt/vc/src/hello_pi/hello_font/Vera.ttf',11)
def displayData(soc, voltage, current):
draw.rectangle((0, 0, width, height), outline=0, fill=0)
draw.text(( 0, 6), str("{:6.2f}".format(soc)) +"%", font=fontB, fill=255)
draw.text((75, 0), str("{:8.2f}".format(voltage)) + "V" , font=fontS, fill=255)
draw.text((75,16), str("{:8.2f}".format(current)) + "A" , font=fontS, fill=255)
disp.image(image)
disp.show()
~
2. draw.rectangle((0, 0, width, height), outline=0, fill=0) had this statement for every refresh of data
Attached the full code which is used for display -- now it works perfectly. Now got 2.23 inch PIOLED 128*32 (same size as this mini) and the same code works perfectly (just that we need to change 1306 to 1305 - 3 places)
from board import SCL, SDA
import busio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
i2c = busio.I2C(SCL, SDA)
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
disp.fill(0)
disp.show()
width = disp.width
height = disp.height
image = Image.new("1", (width, height))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, width, height), outline=0, fill=0)
fontB = ImageFont.truetype('/opt/vc/src/hello_pi/hello_font/Vera.ttf',19)
fontS = ImageFont.truetype('/opt/vc/src/hello_pi/hello_font/Vera.ttf',11)
def displayData(soc, voltage, current):
draw.rectangle((0, 0, width, height), outline=0, fill=0)
draw.text(( 0, 6), str("{:6.2f}".format(soc)) +"%", font=fontB, fill=255)
draw.text((75, 0), str("{:8.2f}".format(voltage)) + "V" , font=fontS, fill=255)
draw.text((75,16), str("{:8.2f}".format(current)) + "A" , font=fontS, fill=255)
disp.image(image)
disp.show()
~
- stirucherai
- Posts: 26
- Joined: Sun Sep 26, 2021 11:44 am
Re: Adafruit PiOLED - 128x32 Monochrome OLED HOW TO INCREASE
Attached photo - for both mini PiOLED and 2.23inch PiOLED
- Attachments
-
- piOLED.jpg (432.46 KiB) Viewed 95 times
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit PiOLED - 128x32 Monochrome OLED HOW TO INCREASE
That Vera font looks good. Thank you so much for sharing the code and pictures. I'm sure this will help others.
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/