0

Refresh display on button press
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Refresh display on button press

by sebastienperth on Wed Apr 07, 2021 2:33 pm

Hello. I am working on a simulated glucometer.
I am using a feather M0 express, with a 2.9" grayscale e-ink display.
I 3d printed a housing for the feather and display that holds the display vertically. There are 3 buttons that can be pushed on the right side, while the reset button of the display is accessible through the bottom of the housing by inserting a glucose testing strip in a small slot, which guides it directly on the reset button.
I want to set the value displayed on the screen by using the side buttons. Then the screen goes blank after 60 seconds.
Then when the student goes through the motions of taking a blood sample, and inserts the test strip in the bottom, the screen refreshes with the last set value.

This chunk of code displays a value from a tuple (I figured it would be easier to use this way, allowing a quicker cycle through a decent range of values, with HIGH, and LOW at either end of the tuple). It also assigns the buttons to variables.
Code: Select all | TOGGLE FULL SIZE
import time
import busio
import board
import displayio
import adafruit_il0373
import terminalio
from adafruit_display_text import label
from digitalio import DigitalInOut, Direction, Pull


# This pinout works on a Feather M4 and may need to be altered for other boards.
# spi = busio.SPI(board.SCK, board.MOSI)  # Uses SCK and MOSI
spi = board.SPI()
epd_cs = board.D9
epd_dc = board.D10
epd_reset = board.D5
epd_busy = board.D6

btnA = DigitalInOut(board.D11)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP

btnB = DigitalInOut(board.D12)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP

btnC = DigitalInOut(board.D13)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP


# testing a block of text as a variable 0 - 8
mytuple = ("LOW", "1.2", "2.4", "3.6", "4.8", "5.5", "6.3", "7.0", "HIGH")
x = 7
y = 9
z = 0

displayio.release_displays()
display_bus = displayio.FourWire(board.SPI(), command=epd_dc,
                                 chip_select=epd_cs, reset=epd_reset,
                                baudrate=1000000)
# time.sleep(1)
display = adafruit_il0373.IL0373(
    display_bus,
    width=128,
    height=296,
    rotation=180,
    black_bits_inverted=False,
    color_bits_inverted=False,
    grayscale=True,
    refresh_time=1,
    seconds_per_frame=5
)

g = displayio.Group()


# Draw simple text using the built-in font into a displayio group
text_group = displayio.Group(max_size=10, scale=4, x=30, y=70)
text = mytuple[x]
text_area = label.Label(terminalio.FONT, text=text)
text_group.append(text_area)  # Add this text to the text group
g.append(text_group)

text_group2 = displayio.Group(max_size=10, scale=2, x=30, y=110)
text2 = "mmol/L"
text_area2 = label.Label(terminalio.FONT, text=text2)
text_group2.append(text_area2)  # Add this text to the text group
g.append(text_group2)

display.show(g)
display.refresh()

print("Insert test strip")
time.sleep(60)

Seperatly, I have another chunk of code that does cycle through the tuple, serving up the results through the serial reader.
Code: Select all | TOGGLE FULL SIZE
while True:
    if not btnA.value:
        x += 1
        print(mytuple[x])
        if x >= 8:
            x = 0
    elif not btnB.value:
        # code that makes the screen refresh when this button is pressed
      print("refreshed")
    elif not btnC.value:
        x -= 1
        print(mytuple[x])
        if x <= 0:
            x = 8
    # else:
        # print("BTN is up")
        pass
    time.sleep(0.2) # simple debouncer


I just haven't been able to find a way to combine these chunks in a way that refreshes the display after changing the value. I understand e-ink shouldn't be refreshed too quickly, so I would be fine with pressing "up" or "down" a few times, and then pressing the middle button to refresh the display to confirm I have the right value set.
gluc display.jpg
Sim glucometer
gluc display.jpg (24.01 KiB) Viewed 42 times

sebastienperth
 
Posts: 5
Joined: Fri Jan 15, 2021 4:21 pm

Re: Refresh display on button press

by mikeysklar on Thu Apr 08, 2021 6:31 pm

Your Sim Glucometer is rad!

As someone who checks their blood glucose each day I can appreciate a DIY setup. What are you using for the actual glucose reader and strips?

Since your code is working in terms of initial display, button presses and serial output why not create some methods (functions) for that setup the text_area / text_group and call display.show(). Those methods can be embedded as method calls in your button logic code.

mikeysklar
 
Posts: 3882
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.