Week 9, Input Devices¶
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
Group work¶
See the group page
Individual work¶
For my input device testing, I am investigating the use of step response for input. As a principle, I want to test the effects of different pad size on input. I also plan to test the effects of distance between the pad and ground for the step response. My design will be set up to work with an ESP32 microprocessor as well as an SAMD21.
Making board¶
I am designing my board in KiCad, and the schematic design is quite simple for the step response. I am setting it it to use all the available pins for input. The schematic doesn’t capture the different pad parameters.
Board schematic
For board design an important first step is setting the design rules. When eventually setting the traces on the board, it is important to have the traces set to be appropriate width which work with our Roland MX-20.
In house, our recommendation is to have a minimium width of 0.4mm, though I set these at 0.45mm to start.
Setting board design rules
The board design is relatively simple.
On the left side of the board, the pad sizes are varied in length with a constant height. All those pads are 5mm in height, while the lengths vary from 20mm to 15mm (each decreasing 1mm in length).
On the right side of the board, the pad sizes are constant (20mm x 5mm), while increasing the distance from 1mm to 2.5mm, each distance increasing by 0.5mm.
For some reason, KiCad wouldn’t let me connect the large surrounding ground pad to the pin. This problem was be fixed in Inkscape.
Stepper response board design
The board design was exported as an SVG, using the same process from Week 8 (Electronics Design). This was imported into InkScape, and the disconnected ground was fixed by adding a line connecting the ground pin to pad.
For the milling, the trace PNG was imported to the web server running the MX-20 mill. I told the process was Roland milling, and then calculated the traces. The traces look good, and it is time to mill
Board trace paths
Similarly, I imported the PNG for the board edge, and set a command to do board tracing.
Board cutting path
The board traces were very rough, likely due to an aging bit. The traces were very rough, and I sanded the board with wet sandpaper. (Roughness is evident in the final board picture).
Sanding the rough board
To prepare for use of the board, pins were soldered to the microprocessors (ESP32 and SAMD21), and pin connectors were soldered to the board.
Finished board with microprocessors
The KiCad design files for the board can be downloaded.
Programming ESP32¶
With a finished board, it is time to turn to programming the board and examining step response. To start, I will work with the ESP32 and program it with MicroPython. Previously I had used VSCode to interface with an RP2040 and MicroPython. However, for this project I will be working with Thonny. Therefore, I needed to get that set up.
Working on a Mac, it was relatively easy to get Thonny running. For a long time I have worked with Homebrew, which is a application manager for Mac. It allows for consistent installation and update of software, notably for open source projects. My primary Python installation is via Homebrew (and consequently the Python package manager, pip
).
To get thonny working for esp, I needed to install esptool
and thonny
which I did with the following commands.
pip install esptool
brew install thonny
The ESP32 needs to have MicroPython installed, which I could easily flash via Thonny. I connected the microprocessor to my computer via USB-C, and then flashed MicroPython via Thonny. I did have to chose the right flavor for the specific microprocessor (ESP-S3).
Installing Micropython
I then tested the step response with MicroPython code (see below). With the code running, I put my finger over the different sized pads. With Thonny, adding the plotter view allows the output to be seen visually. In the screen shot, the shell shows the textual output with comma separated values for each pad. The plotter shows the different qualitative response. The colors (bottom right) are ordered with the size of the pads in decreasing size. As seen in this, the larger pad had stronger steps response.
Step response visualized
When writing the code for this, I started with example code from the class page. The example code had hard coded pins. Because I was repeating the same logic for each pin, it made more sense to modify the code with each pin as a class in Python. The code below allows for testing the size varying pads. To test the varying distance there currently is a set of pin numbers which are commented out in the code.
#
# 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))
Programming SAMD21¶
I also got similar tests working with the SAMD21 processor. For that, I worked with the Arduino IDE, again installed with Homebrew (brew install arduino-ide
). A critical extra need is the Adafruit Freetouch library, which is installed via the IDE library manager.
The code used was that from the course page. This version tested the distance varying pins. (The pins could be modified to test the size varying pads.)
Installing the library
Compiling and uploading the sketch got it running. In the screen shot, the varying response can be seen visualized in the serial plotter from the Arduino IDE. For the smaller gaps, the response is stronger.
Varying response on SAMD21 for varying step response pad distance
Conclusion¶
I was very satisfied to get robust step response, and ability to see variation by pad size and pad distance. For further work, it could be good to fully quantify the differences. In the context of a week, I didn’t have time to get to that fuller analysis.