Week 09

Input devices

Goal: measure something: add a sensor to a microcontroller board that you have designed and read it. I set out to create a board with an analog microphone and read its output. Ultimately, my final project will incorporate a microphone that captures and records sound for playback.
Software Tools: Autodesk Fusion 360 (aka Autodesk Eagle), Universal Gcode Platform (Version 2.0.20) to send the gcode file to the milling machine, Quentin's online gerber to image tool, and Professor Neil's modsproject online tool to create a gcode file.
Hardware Tools: Genmitsu milling machine
Previous experience: Board design experience from week 06

This week can be broken down into three phases:
  1. Designing a board with a microphone
  2. Milling the board and soldering the components on
  3. Reading the outputs of the microphone
I was able to visualize the output of the microphone through Arduino's serial plotter.


Video of the microphone capturing sound and music in the office



Designing a board

I needed help this week. I went to two office hour sessions, watched YouTube videos, and drew inspiration from past projects. Specifically, I utilized the following resources:

Referencing the resources above, I designed a simple circuit board with the Analog SPU0414HR5H-SB-7 microphone, a resistor, three capacitors, and a Xiao RP2040 microcontroller.

I followed the process I documented in Week 06 Electronics Production to create gerber files and gcode files of the board traces and edge.

Here are the files I created for easy reference:

  1. .f3z File of my board schematic and PCB in Autodesk Fusion 360
  2. Board copper traces gerber file
  3. Board profile gerber file
  4. Board traces image file
  5. Board outline image file
  6. Board traces gcode file (.nc)
  7. Board edge gcode file (.nc)

schematic
Screenshot of the class website for week 09, input devices

schematic
Neil's board design for inspiration

schematic
RP2040 pins

schematic
RP2040 schematic. Link to RP2040 Wiki

schematic
The first schematic of my board design

board
The first PCB for my design

Milling a board

I used the Genmitsu milling machine in E15-043 with the Universal Gcode Sender software on the adjacent desktop machine. When I arrived, the software program was not open, but my trusty peers in the cba shop shared their past class website with me which included instructions for starting the program!

I followed the instructions on Vincy Xiao's Electronics Production page from 2023:

  • On the desktop, enter Ctrl + Alt + T
  • In the terminal, type cd Desktop/ugsplatform-linux/bin/
  • type ./ugsplatform
  • This should open the Universal Gcode Sender program. Then I opened my gcode file.

I followed the process I documented in Week 06 Electronics Production to mill the board. The only difference this week is that I used double-sided tape to secure a new board on the sacrificial board. I felt comfortable using the machine, zeroing the z-axis, and finishing the board. There were no issues.

If needed, this website has a good guide on how to use the "UGS platform".

These are the steps I followed to run the milling machine:

  1. Click “Open” - select my gcode file (.nc)
  2. Check if the drill is the right one (1/64” for traces, 1/32” for edge cutting)
  3. Click “macro” -> “[1] Raise Z”
  4. Setup the grounding cables, and click “macro” -> “[2] Probe and zero Z”
  5. Position the drill to the right position and set X0 and Y0
  6. Press the play button that reads “send” and start milling
  7. Turn on the vacuum cleaner and wear ear mufflers or noise-cancelling headphones
  8. Repeat the steps above for the edge of the board

milling
Using double-sided tape to secure the board

milling
Preparing for milling


Video of running the milling machine


milling
The final board

Soldering components to the board

This gets tricky! I needed to find a way to solder the tiny microphone to the board without solder paste - we don't have any in the cba shop. The microphone has 4 small pads on its underside, making it the first of its kind for me. Quentin's advice was to pre-tin the pads and then use a hot air gun, which I did.

I used the following components for my board:

  1. RP2040 microncontroller
  2. SPU0414HR5H-SB-7 link to data sheet
  3. Two 0.1 uF capacitors
  4. One 10 uF capacitor
  5. One 1,000 ohm resistor

I then patiently and deliberately soldered the components to the board with the help of flux. The soldering job is not good, but it's an improvement from week 06. I continued to watch YouTube videos on the basics of soldering, particularly for the microphone.

soldering
Microphone inventory in cba shop

soldering
Capacitor inventory in cba shop

soldering
All the components for my board

soldering
Pre-tinning the pads for the microphone


Video of trying to solder a capacitor to the board


soldering
The final, ugly board

Reading the microphone

I have limited to no experience with programming, so I started with the basics. I am still trying to learn how to record sound in audio files from the microphone. For this week, I just wanted to confirm that I setup the microphone correctly, and I could see sound outputs from the analog microphone.

First I setup Arduino with my board and Xiao RP2040 microcontroller. I followed the process I documented in Week 03 Embedded Programming so I could write and upload a program to the RP2040 board. Specifically, I did the following:

  1. Plug in RP2040 to laptop via USB-C cable
  2. All the LEDs turn on, including the large one at the base of the device which blinks and changes colors
  3. I pressed and held the “B” button, then pressed and released the “R” button. This turned off the light, and then the RP2040 appeared as an external drive with the name “RPI-RP2”
  4. In Arduino IDE, I went to the Tools menu to select the right board (screenshot below).
  5. I wrote a simple code to read the analog value from the A1 pin. A1 is GPIO27, so pin “27” Arduino also has a tutorial on how to capture sound via the onboard analog microphone on the the Nano RP2040, a different board. link to Nano RP2040 microphone basics
  6. I uploaded the simple code to the Xiao microcontroller and then opened the serial plotter to check if any data was being captured. It seems to be picking up sounds!

Here is the simple Arduino program I wrote and uploaded to the board:

  • Basic Arduino code to see microphone output in serial plotter
  • 
    void setup() {
    	// put your setup code here, to run once:
    	Serial.begin(9600);
    	
    	}
    	
    	void loop() {
    	// put your main code here, to run repeatedly:
    	//analogReference(INTERNAL);
    	int val = analogRead(27);
    	
    	Serial.println(val);
    	delay(1);
    	
    	}
    												

    As first, the serial plotter on Arduino only displayed 50 data points along the x-axis. To see a longer time scale of the audio output, I followed Anthony’s instructors to change Arduino’s plotter window setting:

    • As installed, the serial plotter for Arduino IDE 2.2 will only display fifty points at a time, insufficient for our purposes. Fortunately, as described at https://github.com/arduino/arduino-ide/issues/803#issuecomment-1338149431 at the end of https://github.com/arduino/arduino-ide/issues/803 , Arduino IDE 2.2's serial plotter is a web application written in javascript, and is easy (sort of) for you to customize and plot 500 points.
    • Find the installation folder for Arduino IDE 2.2, and navigate to the subfolder "Resources/app/lib/backend/resources/arduino-serial-plotter-webapp/static/js". Make a copy of the file main.35ae02cb.chunk.js, in case something goes wrong, and then use any text editor to open the original main.35ae02cb.chunk.js file.
    • Use the text editor's search function to find the text U=Object(o.useState)(50) in the file, then change the 50 to 500, save the file, and then quit the editor.
    • For some operating systems, it may be necessary to change the permissions for the main.35ae02cb.chunk.js file before you will be allowed to save your changes.
    • And for Mac users, you can find usually find the installation folder by searching the Application folder for Arduino IDE.app , then right clicking on it, and choosing "Show Package Contents", and opening the Contents folder.

    Arduino
    Setting up the RP2040 board on Arduino

    Arduino
    Setting up the RP2040 board on Arduino


    Video of uploading the simple program to the board and viewing the outputs on the serial plotter. I snapped my fingers and made funny sounds near the microphone.