Week 9, Input Devices¶
(Not here yet)
Assignment¶
Group assigment¶
- Probe an input device(s)’s analog levels and digital signals
- Document your work on the group work page and reflect on your individual page what you learned
Individual assignment¶
- Measure something: add a sensor to a microcontroller board that you have designed and read it.
Checklist¶
from Nueval
- Linked to the group assignment page
- Documented what you learned from the interfacing an input device to your microcontroller
- Documented your design and fabrication process
- Explain the programming processes you used
- Included original design files and source code
- Included a ‘hero shot’ of your board
Individual work¶
Making board¶
Programming ESP32¶
pip install esptool
brew install thonny
#
# step_response.py
#
# ESP32S3 XIAO touch
# Albert Vernon Smith 3/25/25
#
# Based on hello.touch.S3.py
# https://academy.cba.mit.edu/classes/input_devices/step/ESP32S3/hello.touch.S3.py
# From Neil Gershenfeld 7/25/24
#
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose, but must
# acknowledge this project. Copyright is retained and
# must be preserved. The work is provided as is; no
# warranty is provided, and users accept all liability.
#
# install MicroPython
# https://micropython.org/download/RPI_PICO/
#
import time
import machine
eps = 0.01 # smoothing filter fraction
loop = 500 # smoothing filter iterations
# The original code had hard coded pins
# Use a class which allow for flexibility
class Pad:
# Initialize the pad, largely by specifying the pin
# Also track the distance between the pad and ground
# Also track the size of the page
def __init__(self, pin, dist = 1, length = 20, height = 5):
self.pin = machine.Pin(pin)
self.dist = dist
self.area = length * height
self.rmin = 1e6
self.rfilt = 0
self.t = machine.TouchPad(self.pin)
def getRmin(self):
return self.rmin
def getRfilt(self):
return self.rfilt
def setRmin(self, num):
self.rmin = num
def setRfilt(self, num):
self.rfilt = num
def updateRfilt(self):
r = self.t.read()
rmin = self.getRmin()
if (r < rmin):
rmin = r
self.setRmin(rmin)
rfilt = self.getRfilt()
rfilt = (1-eps)*rfilt+eps*(r-rmin)
self.setRfilt(rfilt)
sizepins = [1,3,5,6,4]
pins = sizepins
#distpins = [8,7,9,2]
#pins = distpins
pads = []
for p in pins:
pads.append(Pad(p))
while True:
for i in range(loop):
for pad in pads:
pad.updateRfilt()
rfilts = [str(p.getRfilt()) for p in pads]
print(",".join(rfilts))