I don’t have a microphone in my setup, mine is all Breakout Garden stuff.
It was a bit of work splitting it up into three separate screens. There is code in the all-in-one-mini example that I know what it does, I just have no idea how it does it.
This is my code for the 3 display setup.
#!/usr/bin/env python3
import os
import sys
import time
import colorsys
import logging
import ST7735
import RPi.GPIO as GPIO
from sys import exit
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from subprocess import PIPE, Popen
from fonts.ttf import RobotoMedium as UserFont
from bme280 import BME280
def Shutdown(channel):
os.system("sudo shutdown now -P")
time.sleep(30)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(24, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
logging.basicConfig(
format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
logging.info("""Displays readings from BME280 sensor
Press Ctrl+C to exit!
""")
bme280 = BME280()
disp0 = ST7735.ST7735(
port=1,
cs=0,
dc=19,
# backlight=5,
rotation=90,
spi_speed_hz=10000000
)
disp1 = ST7735.ST7735(
port=1,
cs=1,
dc=19,
# backlight=6,
rotation=90,
spi_speed_hz=10000000
)
disp2 = ST7735.ST7735(
port=1,
cs=2,
dc=19,
# backlight=13,
rotation=90,
spi_speed_hz=10000000
)
WIDTH = 160
HEIGHT = 80
disp0.begin()
WIDTH0 = disp0.width
HEIGHT0 = disp0.height
disp1.begin()
WIDTH1 = disp1.width
HEIGHT1 = disp1.height
disp2.begin()
WIDTH2 = disp2.width
HEIGHT2 = disp2.height
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
draw = ImageDraw.Draw(img)
path = os.path.dirname(os.path.realpath(__file__))
font_size = 20
font = ImageFont.truetype(UserFont, font_size)
message = ""
top_pos = 25
def display_text0(variable, data, unit):
values[variable] = values[variable][1:] + [data]
vmin = min(values[variable])
vmax = max(values[variable])
colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
message = "{}:{:.0f}{}".format(variable[:11],data,unit)
logging.info(message)
draw.rectangle((0, 0, WIDTH0, HEIGHT0), (255, 255, 255))
for i in range(len(colours)):
colour = (1.0 - colours[i]) * 0.6
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
draw.rectangle((i, top_pos, i + 1, HEIGHT0), (r, g, b))
line_y = HEIGHT0 - (top_pos + (colours[i] * (HEIGHT0 - top_pos))) + top_pos
draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
draw.text((0, 0), message, font=font, fill=(0, 0, 0))
disp0.display(img)
def display_text1(variable, data, unit):
values[variable] = values[variable][1:] + [data]
vmin = min(values[variable])
vmax = max(values[variable])
colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
message = "{}:{:.0f}{}".format(variable[:11],data,unit)
logging.info(message)
draw.rectangle((0, 0, WIDTH1, HEIGHT1), (255, 255, 255))
for i in range(len(colours)):
colour = (1.0 - colours[i]) * 0.6
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
draw.rectangle((i, top_pos, i + 1, HEIGHT1), (r, g, b))
line_y = HEIGHT1 - (top_pos + (colours[i] * (HEIGHT1 - top_pos))) + top_pos
draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
draw.text((0, 0), message, font=font, fill=(0, 0, 0))
disp1.display(img)
def display_text2(variable, data, unit):
values[variable] = values[variable][1:] + [data]
vmin = min(values[variable])
vmax = max(values[variable])
colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
message = "{}:{:.0f}{}".format(variable[:11],data,unit)
logging.info(message)
draw.rectangle((0, 0, WIDTH2, HEIGHT2), (255, 255, 255))
for i in range(len(colours)):
colour = (1.0 - colours[i]) * 0.6
g, r, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
draw.rectangle((i, top_pos, i + 1, HEIGHT2), (r, g, b))
line_y = HEIGHT2 - (top_pos + (colours[i] * (HEIGHT2 - top_pos))) + top_pos
draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
draw.text((0, 0), message, font=font, fill=(0, 0, 0))
disp2.display(img)
last_page = 0
variables = ["Temperature",
"Humidity",
"Pressure"]
values = {}
for v in variables:
values[v] = [1] * WIDTH
mode = 0
F = 0
D = 0
while True:
if F < 161:
F = F + 1
elif F >= 161:
time.sleep(5)
D = D + 1
if mode == 0:
mode %= len(variables)
last_page = time.time()
unit = "C"
data = bme280.get_temperature()
display_text0(variables[mode], data, unit)
mode = 1
if mode == 1:
mode %= len(variables)
last_page = time.time()
unit = "%"
data = bme280.get_humidity()
display_text1(variables[mode], data, unit)
if D == 0:
mode = 2
elif D > 0 and D < 9:
mode = 0
elif D == 9:
mode = 2
D = 0
if mode == 2:
mode %= len(variables)
last_page = time.time()
unit = "mb"
data = bme280.get_pressure()
display_text2(variables[mode], data, unit)
mode = 0