Showering the Members of M5 with Love and Care
Last semester, I spent some time getting a receipt printer to print user-defined inputs. To do this, I used a MAX233 chip, to convert from TTL logic levels up to the RS-232 logic levels (-15v to 15v). This chip uses a charge-pump technology to boost the 5v from the raspberry pi’s BUS pin, to the usable communication levels. This is pretty much all that’s needed to convert serial messages into something the receipt printer would accept.
An example of a Charge Pump Circuit, by Circuits DIY.
For the first saturday makerday, which coincidentally fell on Valentines day, I decided it would be fun to rewrite the project in MicroPython, to quickly develop a compliment machine!
An example of the receipts printed during Saturday Makerday
I quickly copied my circuit over to a second breadboard, as to simplify the circuit. After that, I got programming.
The first challenge was getting the correct time. To do this, I swapped my Pico for the Pico W, which includes a Wi-Fi module, that can request the time information from the online NTP servers. To connect to the internet, I used the M5 IOT internet, which can let micro-controllers connect to the internet. Once I got the time, I had to subtract the timezone difference from UTC time, which involved converting the requested time information into seconds, then subtracting 7 hours from that value, then converting back into a date object.
The time and compliment displayed
One issue I faced with this design, is that the Pico would quickly fill up the internal buffers of the printer, leading to dropped characters. To fix this quickly, I added sleep commands every 3-4 lines of my code. The proper way to do this would be to wait for the received message on the received pin.
import random
import time
import machine
import network
import ntptime
from machine import UART, Pin
button = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_UP)
wifi = network.WLAN(network.STA_IF) # station mode
wifi.active(True)
wifi.connect("UMASS-MPSK", "...")
print("about to connect")
while not wifi.isconnected():
pass
print("Wifi Connected!")
while True:
try:
ntptime.settime()
break
except:
print("Failed to get time...")
print("synced time")
uart = UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=Pin(4), rx=Pin(5))
time.sleep(1)
# Initialize printer once
uart.write(b"\x1b@")
compliments = [
...
]
while True:
while button.value():
pass
print("printing...")
months = [
...
]
weekdays = [
...
]
corrected_time = time.time() - 5 * 3600
year, month, day, hour, minute, seconds, weekday, _ = time.localtime(corrected_time)
formatted_time = f"{weekdays[weekday]}, {day} {months[month - 1]} {year} | {hour}:{minute}:{seconds}"
rand_compliment = compliments[random.randint(0, len(compliments) - 1)]
uart.write(b"\x1br\x00")
uart.write(formatted_time.encode())
uart.write(b"\r\n")
uart.write(b"\x1br\x01")
uart.write(rand_compliment.encode())
time.sleep(0.25)
uart.write(b"\r\n")
# uart.write(str(counter))
uart.write(b"\x1br\x00")
uart.write(b"\r\n")
uart.write(b"#####################################\r\n")
uart.write(b"############## ################\r\n")
uart.write(b"## ##### ## ###\r\n")
time.sleep(0.25)
uart.write(b"### ### #### ####\r\n")
uart.write(b"### # +### ############\r\n")
uart.write(b"#### ## ############\r\n")
time.sleep(0.25)
uart.write(b"#### . ## ####\r\n")
uart.write(b"#### # #% ## #### ###\r\n")
uart.write(b"#### ## ## ######### ##\r\n")
time.sleep(0.25)
uart.write(b"#### ## ## ######### ##\r\n")
uart.write(b"#### ## ## ######### ##\r\n")
uart.write(b"#### ## ### ######### ##\r\n")
time.sleep(0.25)
uart.write(b"##### ######## # #### ###\r\n")
uart.write(b"##### ######## # #### ###\r\n")
uart.write(b"#### ##### #####\r\n")
time.sleep(0.25)
uart.write(b"#########################. -#########\r\n")
uart.write(b"#####################################\r\n")
uart.write(b"\r\n")
uart.write(b"We hope you stop by M5 another time <3")
uart.write(b"\r\n" * 12)
time.sleep(1)