TheDiY
Published © MIT

EnviroGo - A Portable Environmental Monitoring Platform

EnviroGo is a compact, portable environmental monitoring project designed to help students, makers, and engineers learn real environment dat

IntermediateProtip4 hours157

Things used in this project

Story

Read more

Code

Code Circuit Python

Python
Circuit Python
import time
import board
import busio
import displayio
import terminalio
from adafruit_st7735r import ST7735R
from adafruit_display_text import label
from adafruit_display_shapes.roundrect import RoundRect
import fourwire
import digitalio

# ---------------- DISPLAY SETUP ----------------
displayio.release_displays()

spi = busio.SPI(clock=board.GP2, MOSI=board.GP3)
tft_cs = board.GP5
tft_dc = board.GP4
tft_rst = board.GP22

display_bus = fourwire.FourWire(
    spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst
)

tft_bl  = board.GP14
led = digitalio.DigitalInOut(tft_bl)
led.direction = digitalio.Direction.OUTPUT
led.value=True

display = ST7735R(
    display_bus,
    width=160,
    height=80,
    rotation=90,
    rowstart=1, colstart=26,
    bgr=True
)

main = displayio.Group()
display.root_group = main

# ---------------- BACKGROUND ----------------
bg = displayio.Bitmap(160, 80, 1)
bg_palette = displayio.Palette(1)
bg_palette[0] = 0x0A0A0A
main.append(displayio.TileGrid(bg, pixel_shader=bg_palette))

# Title
title = label.Label(
    terminalio.FONT,
    text="LIVE TEMP",
    color=0xFFFFFF,
    x=48,
    y=8
)
main.append(title)

# Card
card = RoundRect(
    6, 14, 148, 60, 10,
    fill=0x1C1C1C,
    outline=0x00E5FF,
    stroke=2
)
main.append(card)

# Temperature text
temp_label = label.Label(
    terminalio.FONT,
    text="--.- C",
    scale=2,
    color=0x00E5FF,
    x=12,
    y=30
)
main.append(temp_label)

# ---------------- GRAPH BITMAP ----------------
GRAPH_W = 136
GRAPH_H = 26
GRAPH_X = 12
GRAPH_Y = 42

TEMP_MIN = 20
TEMP_MAX = 35

graph_bitmap = displayio.Bitmap(GRAPH_W, GRAPH_H, 2)
graph_palette = displayio.Palette(2)
graph_palette[0] = 0x1C1C1C  # background
graph_palette[1] = 0x00FF00  # graph line

graph = displayio.TileGrid(
    graph_bitmap,
    pixel_shader=graph_palette,
    x=GRAPH_X,
    y=GRAPH_Y
)
main.append(graph)

# ---------------- GRAPH FUNCTIONS ----------------
def temp_to_y(temp):
    # Clamp temperature
    temp = max(TEMP_MIN, min(TEMP_MAX, temp))
    # Map temperature to bitmap Y so higher temp = higher pixel
    return int((temp - TEMP_MIN) * (GRAPH_H - 1) / (TEMP_MAX - TEMP_MIN))


# ---------------- MAIN LOOP ----------------
temperature = 25.0

while True:
    # Simulated temperature (replace with real sensor)
    temperature += 0.2
    if temperature > 34:
        temperature = 25

    temp_label.text = f"{temperature:.1f} C"

    '''
    # Scroll graph left
    for x in range(GRAPH_W - 1):
        for y in range(GRAPH_H):
            graph_bitmap[x, y] = graph_bitmap[x + 1, y]

    # Clear last column
    for y in range(GRAPH_H):
        graph_bitmap[GRAPH_W - 1, y] = 0

    # Draw new temperature point
    y = temp_to_y(temperature)
    graph_bitmap[GRAPH_W - 1, y] = 1
    '''
    # Scroll graph right
    for x in range(GRAPH_W - 1, 0, -1):
        for y in range(GRAPH_H):
            graph_bitmap[x, y] = graph_bitmap[x - 1, y]

    # Clear first column
    for y in range(GRAPH_H):
        graph_bitmap[0, y] = 0

    # Draw new temperature point at left
    y = temp_to_y(temperature)
    graph_bitmap[0, y] = 1
    time.sleep(0.5)

Credits

TheDiY
1 project • 0 followers
I’m a hardware and embedded systems enthusiast with a passion for ethical hacking, IoT, and hands-on learning. I design open-source projects

Comments