HTMAA 25
home about me final projectThis week’s task was to create a microcontroller board with an input device. As will be seen, I largely took this as an opportunity to create a first version of the electronics I will need for my final project.
Using an oscilloscope, we measured the signals produced by a microphone as well as a phototransistor. (todo: link)
I wanted to use the input devices and output devices weeks to essentially create a first draft of the entire electronics of my final project - the peashooter. This meant that at minimum it should incorporate:
After consulting with Anthony, I was handed the VL53L1X Time-of-Flight Distance Sensor, the JYCRS390H 12V DC Motor, and the PZ22GR9120R DC Gearmotor.
The 12V motors also meant that I needed a 12V power supply to the board separate from the 5V USB line from my laptop.
Additionally, I wanted to include the following:
My first general sketch looked something like:
// insert picture
Again another consultation with Anthony and some online sources, I made the following refinements:
This resulted in the following sketch:
// insert picture
And the following Fusion schematic:
// insert screenshot
My first PCB layout was the following:
Which seemed neat and well laid-out, until I realized that ground was not connected. Most importantly, the source of two of my transistors did not contact ground. Since the motor current would be going through those points, I didn’t want to just put on a 0-ohm resistor.
After trying out a few other board layouts, e.g. the following (where I also updated the barrel jack to a component that we actually had)
I decided that laying out three motors nicely would be topologically impossible with a single-layer PCB and decided to abandon the extra motor. This led to the final layout of:
Using the Bantam Tools Othermill, the PCB was cut from single-sided FR1. The total milling time was less than 10 minutes.
Since I was using the pads under the microcontroller that I could not access with a traditional soldering iron, I knew I needed to reflow solder the microcontroller. Unfortunately, after trying and failing to do this for a decent amount of time, I was running out of time and decided to go for a much less elegant method of simply sticking wires where they needed to go:
// insert picture
Here, a thin wire was soldered to the Vin pad at the back of the microcontroller, then the entire back was covered with kapton tape and the microcontroller was traditionally soldered to the relevant pad. Since the back was no longer entirely flat, extra care was taken on this step.
The wire sticking out from underneath the back was then soldered to the original Vin trace. Instead of repeating the same thing for the ground pad from under the microcontroller, I wired ground over from an adjacent area.
The rest of the components went on uneventfully. Here is the final result:
// insert picture
#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
void setup()
{
while (!Serial) {}
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1);
}
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(50000);
sensor.startContinuous(50);
}
void loop()
{
Serial.print(sensor.read());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
#include <Wire.h>
#include <VL53L1X.h>
#define RED 17
#define GREEN 16
#define BLUE 25 // from XIAO RP2040
VL53L1X sensor;
void setup()
{
pinMode(RED, OUTPUT); digitalWrite(RED, HIGH);
pinMode(GREEN, OUTPUT); digitalWrite(GREEN, HIGH);
pinMode(BLUE, OUTPUT); digitalWrite(BLUE, HIGH); // high = off
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
sensor.setTimeout(500);
if (!sensor.init())
{
digitalWrite(RED, LOW);
while (1);
}
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(15000);
sensor.startContinuous(15);
}
void loop()
{
int dist = sensor.read();
if (dist < 300) {
digitalWrite(BLUE, LOW); // on
} else {
digitalWrite(BLUE, HIGH); // off
}
}
// insert picture/video
designed 1”x1” boards
designed holders that can pass a ping pong ball through (exact measurements kinda arbitrary ngl)
printed holder + milled parts
realized oops I forgot to break out the 3.3V pin for my phototransistor
extra pin inserted
Testing code:
#define IRLED 26
#define PHOTOTRANSISTOR 27
void setup() {
pinMode(IRLED, OUTPUT);
pinMode(PHOTOTRANSISTOR, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(PHOTOTRANSISTOR));
digitalWrite(IRLED, HIGH);
delay(200);
Serial.println(analogRead(PHOTOTRANSISTOR));
digitalWrite(IRLED, LOW);
delay(200);
}
with 10kOhm resistor on phototransistor, 100 ohm resistor on diode: no difference. got 11/12 readings every tick
bumped to 100kOhm - small differences between on and and not (e.g. 20 vs 30), not enough that I’d trust it in different lighting
bumpted to 1MOhm - now on/off distance is beyond random fluctuation error! (see graph) but discovered that my ping pong ball is slightly translucent in IR
(ping pong ball, hand, ping pong ball)
(ping pong ball, hand, piece of paper, rolling ping pong ball)
not much difference
whatever, still enough for my purposes
This is definitely a draft 1 board, but everything works! Will probably use this to test things for now and then create a board with better layout (and all the correct pins, soldering etc.) for actual final creation.
Plan for next week: Add motors and actually code it up to respond the way it should for all its inputs.