Hello,
1) When I switch back and forth between the two examples on AdaFruit, I must remove power each time. If I don't all I get is a black screen or a flash of the previous python3 mimiPiTFT program and then a black screen. I guess this is because the miniPiTFT is not fully reset when changing programs. Is there a way to fully reset the screen without having to pull power?
2) In both of the examples the BAUDRATE is set to 64000000, one has a note saying the max is 24000000. What should I believe?
Thanks for your help,
Bruce
miniPiTFT 1.14" 240x135 partial blank
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: miniPiTFT 1.14" 240x135 partial blank
The MiniPiTFT does not have a reset pin.
In your setup are you using the user Python code or have you also tried the kernel driver?
Modern Pi's should easily support the faster 64 MHz versus the old default value of 24 MHz.
In your setup are you using the user Python code or have you also tried the kernel driver?
Modern Pi's should easily support the faster 64 MHz versus the old default value of 24 MHz.
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Mike,
I loaded the kernel driver and it worked, but I wanted the control Python gives.
The two programs I tried to switch between are both python3 programs (below).
I downloaded them from the AdaFruit leaning page and made small changes to make them work on my Raspberry Pi Zero.
I will move both/all to 64MHz.
Thanks,
Bruce
I loaded the kernel driver and it worked, but I wanted the control Python gives.
The two programs I tried to switch between are both python3 programs (below).
I downloaded them from the AdaFruit leaning page and made small changes to make them work on my Raspberry Pi Zero.
I will move both/all to 64MHz.
Thanks,
Bruce
Code: Select all
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import digitalio
import board
import time
from adafruit_rgb_display.rgb import color565
from adafruit_rgb_display import st7789
# Configuration for CS and DC pins for Raspberry Pi
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None
BAUDRATE = 24000000 # The pi can be very fast! was 64_000_000
# Create the ST7789 display:
display = st7789.ST7789(
board.SPI(),
cs=cs_pin,
dc=dc_pin,
rst=reset_pin,
baudrate=BAUDRATE,
width=135,
height=240,
x_offset=53,
y_offset=40,
)
backlight = digitalio.DigitalInOut(board.D22)
backlight.switch_to_output()
backlight.value = False
buttonA = digitalio.DigitalInOut(board.D23)
buttonB = digitalio.DigitalInOut(board.D24)
buttonA.switch_to_input()
buttonB.switch_to_input()
# Main loop:
while True:
if buttonA.value and buttonB.value: # No Button Pushed
backlight.value = False # turn off backlight
else: # Any Button Pushed
backlight.value = True # turn on backlight
if buttonB.value and not buttonA.value: # just button A pressed D23
display.fill(color565(255, 0, 0)) # red
if buttonA.value and not buttonB.value: # just button B pressed D24
display.fill(color565(0, 0, 255)) # blue
if not buttonA.value and not buttonB.value: # Both buttons pushed D23 + D24
display.fill(color565(0, 255, 0)) # green
time.sleep(0.1)
Code: Select all
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# -*- coding: utf-8 -*-
import time
import board
import digitalio
import subprocess
from PIL import Image, ImageDraw, ImageFont
from adafruit_rgb_display import st7789
# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None
# Config for display baudrate (default max is 24mhz):
BAUDRATE = 64_000_000
# Setup SPI bus using hardware SPI:
spi = board.SPI()
# Create the ST7789 display:
disp = st7789.ST7789(
spi,
cs = cs_pin,
dc = dc_pin,
rst = reset_pin,
baudrate = BAUDRATE,
width = 135,
height = 240,
x_offset = 53,
y_offset = 40,
)
# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new("RGB", (width, height))
rotation = 90
DayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Beerday"]
sec = None
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
disp.image(image, rotation)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height - padding
# Move left to right keeping track of the current x position for drawing shapes.
x = 0
# Alternatively load a TTF font. Make sure the .ttf font file is in the
# same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
font24 = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24)
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 18)
font12 = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 12)
# Turn on the backlight Setup Buttons
backlight = digitalio.DigitalInOut(board.D22)
backlight.switch_to_output()
backlight.value = not False
buttonD23 = digitalio.DigitalInOut(board.D23)
buttonD24 = digitalio.DigitalInOut(board.D24)
buttonD23.switch_to_input()
buttonD24.switch_to_input()
while True:
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0)
# Shell scripts for system monitoring from here:
# https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
cmd = "hostname -I | cut -d' ' -f1"
IP = "IP: " + subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = 'df -h | awk \'$NF=="/"{printf "Disk: %d/%d GB %s", $3,$2,$5}\''
Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
cpu_temp = tempFile.read()
tempFile.close()
cpu_temp = float(cpu_temp) / 1000
cmd = ("CPU Temp: %.1fC %.1fF" % (cpu_temp, cpu_temp*1.8+32))
#cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}'" # pylint: disable=line-too-long
#Temp = subprocess.check_output(cmd, shell=True).decode("utf-8")
Temp = cmd
y = top
draw.text((x, y), IP, font=font, fill="#FFFFFF") # White
y += font.getsize(IP)[1]
draw.text((x, y), CPU, font=font, fill="#FFFF00") # Yellow
y += font.getsize(CPU)[1]
draw.text((x, y), MemUsage, font=font, fill="#00FF00") # Green
y += font.getsize(MemUsage)[1]
draw.text((x, y), Disk, font=font, fill="#0000FF") # Blue
y += font.getsize(Disk)[1]
if cpu_temp <= 50.0:
draw.text((x, y), Temp, font=font, fill="#FF00FF") # Magenta
else:
draw.text((x, y), Temp, font=font, fill="#FF0000") # Red
y += font.getsize(Temp)[1]
now = time.localtime()
while (sec == now.tm_sec): now = time.localtime()
sec = now.tm_sec
year = now.tm_year
month = now.tm_mon
mday = now.tm_mday
yday = now.tm_yday
hours = now.tm_hour
minutes = now.tm_min
seconds = now.tm_sec
isdst = now.tm_isdst
wday =(now.tm_wday+1)%7
if isdst: ET = 'EDT'
else: ET = 'EST'
Date = ("{}/{}/{} {}:{:02}:{:02} {}".format(month, mday, year, hours, minutes, seconds, ET))
draw.text((x, y), Date, font=font, fill="#00FFFF") # Cyan
y += font.getsize(Date)[1]
Disk2 = DayOfWeek[wday][0:3] + '. - (c)AdaFruit 2022'
draw.text((x, y), Disk2, font=font, fill="#FFFFFF") # White
# Display image.
disp.image(image, rotation)
#time.sleep(0.1)
#backlight.value = not backlight.value
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Mike,
Found it! I had to reinstall blinka, rgb library, and spidev.
Thank you for your help,
Bruce
Found it! I had to reinstall blinka, rgb library, and spidev.
Thank you for your help,
Bruce
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Mike,
How I found it:
The program was running with python3 code.py.
Wanted to put it on rc.local.
Would not run from rc.local as /usr/bin/python3 /home/pi/code.py.
I spent a long time trying variations.
Then I tried /usr/bin/python3 /home/pi/code.py at the local prompt and got a ...rgb... not found.
Went looking for that error and saw where reloading blinka may fix it, and it did.
Still confused why b]python3 code.py[/b] was good at the local prompt but /usr/bin/python3 /home/pi/code.py was not.
Bruce
How I found it:
The program was running with python3 code.py.
Wanted to put it on rc.local.
Would not run from rc.local as /usr/bin/python3 /home/pi/code.py.
I spent a long time trying variations.
Then I tried /usr/bin/python3 /home/pi/code.py at the local prompt and got a ...rgb... not found.
Went looking for that error and saw where reloading blinka may fix it, and it did.
Still confused why b]python3 code.py[/b] was good at the local prompt but /usr/bin/python3 /home/pi/code.py was not.
Bruce
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Good job resolving the issues you came across.
Can you return the output from these commands. It might be relevant about where python3 is being pulled from.
It would probably be best to show this both for the user the command is running as (maybe “pi” in your case) and as “root” in terms of the /etc/rc.local running.
Can you return the output from these commands. It might be relevant about where python3 is being pulled from.
Code: Select all
which python3
whereis python3
echo $PATH
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Mike,
Here is what I found without, then with admin rights.Whitespace added by me.
Bruce
Here is what I found without, then with admin rights.
Code: Select all
login as: pi
[email protected]'s password:
Linux raspberrypi-162 5.10.103+ #1529 Tue Mar 8 12:19:18 GMT 2022 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Sep 12 18:43:55 2022
pi@raspberrypi-162:~ $ which python3
/usr/bin/python3
pi@raspberrypi-162:~ $ whereis python3
python3: /usr/bin/python3.7 /usr/bin/python3.7m-config /usr/bin/python3 /usr/bin/python3.7m /usr/bin/python3.7-config /usr/lib/python3.7 /usr/lib/python3 /etc/python3.7 /etc/python3 /usr/local/lib/python3.7 /usr/include/python3.7 /usr/include/python3.7m /usr/share/python3 /usr/share/man/man1/python3.1.gz
pi@raspberrypi-162:~ $ echo $PATH
/home/pi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
pi@raspberrypi-162:~ $
pi@raspberrypi-162:~ $
pi@raspberrypi-162:~ $ sudo -i
root@raspberrypi-162:~# which python3
/usr/bin/python3
root@raspberrypi-162:~# whereis python3
python3: /usr/bin/python3.7 /usr/bin/python3.7m-config /usr/bin/python3 /usr/bin/python3.7m /usr/bin/python3.7-config /usr/lib/python3.7 /usr/lib/python3 /etc/python3.7 /etc/python3 /usr/local/lib/python3.7 /usr/include/python3.7 /usr/include/python3.7m /usr/share/python3 /usr/share/man/man1/python3.1.gz
root@raspberrypi-162:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@raspberrypi-162:~#
root@raspberrypi-162:~#
root@raspberrypi-162:~#
Bruce
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Alright, I don't think there is anything there in terms of path to resolve.
How did you install the libraries RGB / spidev / blinka? Was it system wide with sudo or just as user pi or some other way?
How did you install the libraries RGB / spidev / blinka? Was it system wide with sudo or just as user pi or some other way?
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Mike,
I used these scripts from the AF pages I then installed via the AF pagesI don't see any install residue in the /root directory, so I assume it was all installed from the /pi directory.
I do not remember how I installed blinka. It is working so this is not a critical issue. It is just annoying because we don't know the why!
I may make a copy of the SD card and try updating the RPi OS. I am using an old version because there may have been a compatibility issue.
Bruce
I used these scripts from the AF pages
Code: Select all
pip3 install adafruit-circuitpython-rgb-display
pip3 install --upgrade --force-reinstall spidev
Code: Select all
sudo apt-get install fonts-dejavu
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
I do not remember how I installed blinka. It is working so this is not a critical issue. It is just annoying because we don't know the why!
I may make a copy of the SD card and try updating the RPi OS. I am using an old version because there may have been a compatibility issue.
Bruce
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Updating to a current Pi OS might help.
Since you know you want to run both as user 'pi' and system startup as root for /etc/rc.local you should be using sudo in front of the pip3 installs so they are system side and not just user specific.
Since you know you want to run both as user 'pi' and system startup as root for /etc/rc.local you should be using sudo in front of the pip3 installs so they are system side and not just user specific.
Code: Select all
sudo pip3 install adafruit-circuitpython-rgb-display
sudo pip3 install --upgrade --force-reinstall spidev
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: miniPiTFT 1.14" 240x135 partial blank
Mike,
Thanks for the education. They are not shown that way in the tutorial.
Bruce
Thanks for the education. They are not shown that way in the tutorial.
Bruce
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: miniPiTFT 1.14" 240x135 partial blank
It is a subtle difference installing system wide as root versus just as user pi. I think the guides are reasonable to try and do things as the default user. It only becomes an issue when you want to do system-wide stuff. Please let us know if an update and use of sudo resolves the full path usage weirdness you had been seeing.
Please be positive and constructive with your questions and comments.