Design Like a Physicist
Physics 371 (previously 398DLP), Spring 2023
3 credit hours
Face-to-face (but masked, please), Friday afternoons, 1 pm - 5 pm, in Loomis 276.
Code and design resource repository
As a security precaution, some browsers will block the download of (code) files ending in, for example, ".py". I have added a ".txt" extension to these filenames, which you should strip off after downloading.
p398dlp_arduino_demo.ino
p398dlp_simple_python_example.py.txt
Code to test some of the Fall 2021 hardware
Code to test some of the Spring 2021 hardware
- Group 1 test routines, schematic, and PCB photo
- Group 2 test routines, schematic, and PCB photo
- Group 3 test routines, schematic, and PCB photo
- Group 4 test routines, schematic and PCB photo
- Groups 1 and 4 base station test routines, schematic, and PCB photo
Dealing with Arduino libraries
Sometimes when you are developing Arduino code to talk to a new-to-you device (for example, a BME680 breakout board manufactured by Adafruit), you'll need to install a library with code specific to the new device. Doing this is REALLY EASY! Here are the steps.- 1, Go to the Adafruit site and look for the entry page into the company's BME680 material.
- 2. Find (and follow) the link to the "detailed tutorial" about the BME680.
- 3. Find (and follow) the link to the "Arduino Wiring & Test" page. (We'll be using the I2C version of wiring the BME680.
- 4. On that page find the section titled "Install Adafruit_BME680 library" and follow the directions. The directions are very clear, and even have screen shots.
A Python refresher: material from Physics 298owl
Physics 398DLP data logger and GG's sample Arduino code for various devices
- ✯ Read an electret microphone through an Adalogger ADC pin A1 and write its data to SD files, with each file holding 10,000 samples. 12-bit data are recorded at about 16 kHz; there's about a 120 millisecond gap between successive files due to the amount of time to write to SD. The program writes 20 files each time it is run.
- ✯ Here's a python program that will read the electret microphone (binary) audio file, take its Fourier transform, and make a couple of plots. (Strip off the .txt file extension to run.)
- ✯ Simple GPS code based on an Adafruit example. Start with this... Also see the GPS microtutorial, which will be available soon.
- ✯ Code to explore the behavior of the Arduino Mega 2560's millis() and micros() functions by using GPS PPS (pulse per second) signals. The code uses two different methods to interrogate the Arduino pin receiving the PPS signal: digitalRead(), which takes about 3.84 microseconds per call, and a direct reference to the appropriate I/O port via a (*myPin_port & myPin_mask) statement. The latter is much faster, executing in about 630 nanoseconds. I find that the clocks on two different (Italian) Arduinos differ by about 0.06%, which corresponds to a processor-to-processor discrepancy of about 600 microseconds per second. You'll need your GPS module to have found satellites before you run my code. The code doesn't try to talk to the GPS, and only looks at Arduino pin D43 for a PPS signal without caring about anything else that might be going on with the GPS. There are lots of comments, so this is easy to use and adapt.
- ✯ Test an Arduino that reads one or two INA219s, one with (default) I2C address of 0x40 and the other (if installed) with address 0x41.
- ✯ Here is the code I used to check the PCBs before distributing them to the fall 2020 class. The code looks at the INA219(s), BME680, microSD breakout, GPS, keypad, LCD, RTC, and microphone RMS in one-second intervals..
- ✯ Week 1 demo: reading a BME680 with an Arduino
- ✯ Set a DS3231 real time clock to local time
- ✯ GG's data logger schematic for spring 2021
- ✯ Very simple circuit with an Arduino, a BME680, and an LCD. (spring 2021, in class, week 1)
- ✯ The schematic for the fall 2020 group 3 PCB is a little different. Here it is.
- ✯ Code from the spring 2019 dust group (with some mods by GG) to read data from a PMS5003 airborne particulates sensor.
- ✯ GG's code to handle radio communications between a pair of Adafruit Feather M0s equipped with RFM95 LoRa (Long Range) radios. You'll need a pair of Radio Feathers with whip antennas of the right length. (These are 1/4 wavelength, which is 3 inches for 915 MHz.) The program asks whether a microcontroller is meant to initiate communications or to respond when it "hears" something.
- ✯ GG's proto-DAQ for an Adalogger Feather M0, of the sort used by the Drone Warriors. The code talks to a GPS module, a BME680, and an MLX90614 IR non-contact thermometer. The GPS data is written to a microSD card.
- ✯ Circuit schematic and PCB layout for the Adalogger Feather M0 version of the p398DLP data logger.
- ✯ GG's data logger schematic and PCB layout for fall 2019
- ✯ GG's data logger schematic, February 8, 2019 version
- ✯ PCB layout for February 8, 2019 version
- ✯ GG's data logger schematic, fall 2018 version
- ✯ Read GPS and BME680 data, and write them to the microSD memory
- ✯ Unit 1 blinking LED code
- ✯ Repeated microphone RMS measurements, half-second intervals
- ✯ 16 x 2 LCD code
- ✯ 4 x 3 keypad code
- ✯ MCP4725 DAC code
- ✯ ADXL326 accelerometer calibration code
- ✯ microSD card read/write (plain text) code
- ✯ 32 kHz audio recording to binary file code, now corrected for output buffer overwrite-related problem (needs keypad and LCD
- ✯ 32 kHz audio recording to binary file AND read/report the temperature read from a BME680 (Arduino code that needs keypad and LCD)
- ✯ 32 kHz audio recording to binary file AND read/report BME680 readings, with VOC gas measurement disabled. (Runs faster this way!)
- ✯ Read temperature, pressure, and humidity from a BME680, but disable the volatile organic compounds gas measurement. This runs considerably faster than a version in which the gas measurements are performed.
- ✯ Python code to read an Arduino binary audio file and (optionally) write a WAV format version. I include a short snippet of the Rolling Stones recorded by my Arduino for you to practice with. Note: if your laptop complains of memory errors, try reducing the value of max_buffers from its current (very large!) value of 50,000,000.
- ✯ Arduino code to read from the GPS breakout board and set the real time clock from the GPS clock. You may want to change the program's insistence on having you enter year, month, day information from the serial monitor.
- ✯ Much better Arduino code to set the real time clock from the GPS clock. Use this program instead of the older version, above. I think it'll synchronize your DS3231 RTC so that it is within about two milliseconds of the GPS system's clock. You will need to have connected the GPS board's PPS pin to the Arduino's D43. (That requires a wire that's about a half-inch long to be soldered onto your PCB. It's a very simple patch.) The program will wait until your GPS device sees satellites, though, so do this outdoors, or someplace where there's a decent GPS signal.
- ✯ GG's Arduino code to read various sensors, taking keypad input from the user. Available functions are these:
- ⚛noop (no operation) = ✳NOO# = ✳666#
- ⚛display Real Time Clock value = ✳RTC# = ✳782#
- ⚛display ax, ay, az = ✳ACC# = ✳222#
- ⚛display battery voltage and current = ✳BAT# = ✳228#
- ⚛measure audio power, 1 second duration = ✳AUD# = ✳283#
- ⚛display GPS information = ✳GPS# = ✳477#
- ⚛display temperature = ✳T# = ✳8#
- ⚛display pressure = ✳P# = ✳7#
- ⚛display (relative) humidity = ✳H# = ✳4#
- ⚛display VOC reading = ✳VOC# = ✳862#
- ⚛display infrared sensor temperature = ✳IR# = ✳47#
- ⚛calibrate ax, ay, az = ✳CAL# = ✳225#
- ⚛play audio tones based on keypad selection = ✳MUS# = ✳687#
- ⚛send help information to LCD = ✳000# = ✳000#
- ⚛altitude above sea level = ✳A# = ✳2#
- ⚛laser range finder distance (mm) = ✳D# = *3#
- ⚛repeat last command = ✳# = *#
- ✯ Arduino website
- ✯ Arduino programming language reference
- ✯ Arduino programming language libraries
- ✯ Arduino Mega 2560 schematic
- ✯ Atmel 2560 manual
- ✯ Our latest home-brewed EAGLE parts library: put into an external_lbrs folder, then have EAGLE open the parts you need.
- ✯ A not-as-recent EAGLE parts library: put into an external_lbrs folder, then have EAGLE open the parts you need.
- ✯ How to Install and Setup EAGLE: A tutorial on the SparkFun web site.
- ✯ Using EAGLE: Schematic.: Another tutorial from SparkFun.
- ✯ Using EAGLE: Board Layout: a tutorial on laying out a PCB once your circuit is defined. Also on the SparkFun web site.
- ✯ "Every Layer in Autodesk EAGLE and What You Need to Know About Them"
- ✯ EAGLE circuit design files for fall 2021 group 1
- ✯ EAGLE circuit design files for fall 2021 group 2
- ✯ EAGLE circuit design files for fall 2021 group 3
- ✯ EAGLE circuit design files for fall 2021 group 4
- ✯ p398DLP_UM2plus_set_nozzle.curaprofile: Cura 3.5.1 settings profile. Download and use this for a Cura slicing with a UM2+ target machine.
- ✯ Cura 3.5.1 settings I use for an Ultimaker 2+ 3D printer (a PDF file of screen shots). I find that poor adhesion of the PLA (poly lactic acid) plastic to the printer's glass build plate is the principal difficulty to be overcome. Here's what works for me: (1) Keep the glass build plate scrupulously clean, and wipe it down with 70% isopropyl alcohol (ordinary rubbing alcohol, which is a 70-30 mix of alcohol and water) before each print job. The water content is important, since there'll probably be a 100 nm thick layer of water that adsorbs to the glass surface when you wipe it down. Pure isopropanol will strip this away, and you won't have all those helpful hydrogen bonds from the water to hold the plastic to the glass. (2) Don't apply glue, masking tape, or any of the other suggested toppings you might read about (chocolate sprinkles?) to the glass. (3) Do a quick adhesion test, using this STL file, which you'll need to turn into gcode. It runs in a little less than 9 minutes on an Ultimaker 2+ with a 0.6 mm nozzle if you load the Cura 3.5.1 profile p398DLP_UM2plus_test_no_brim.curaprofile first. (4) Adjust the nozzle and build plate temperature. I find that dark colors of PLA require higher temperatures than light colors. Black, for example, works nicely with a 235°C nozzle and 65°C build plate.
- ✯ Cura 3.5.1 profile for Ultimaker 2 (not 2+)
- ✯ Cura 3.5.1 profile for adhesion tests with Ultimaker 2 (not 2+)
- ✯ Cura 3.5.1 profile for Ultimaker 2+
- ✯ Cura 3.5.1 profile for adhesion tests with Ultimaker 2+
- ✯ Breadboarding guide
- ✯ Adafruit Industries website
- ✯ CrystalFontz LCD
- ✯ Adafruit tutorial for their microSD breakout board
- ✯ DS3231 real time clock
- ✯ Bosch BME680 temperature, pressure, humidity, volatile organic compounds sensor
- ✯ GPS module data sheet
- ✯ GPS NMEA command description
- ✯ More GPS information
- ✯ Texas Instruments HDC1000 humidity and temperature sensor
- ✯ Melexis MLX 90614 IR thermometer
- ✯ Maxim microphone preamplifiers (rotating the underside potentiometer COUNTERCLOCKWISE increases the amplifier gain)
- ✯ Microchip MCP4725 12-bit digital-to-analog converter
Atmel microcontroller and Arduino Mega 2560
EAGLE schematic capture and PCB tools
3D printing; construction tips and techniques
Sensors and other hardware
A table that includes I2C addresses for some of the Physics 398DLP hardware.
...and
a link to Adafruit's list of I2C addresses for their devices.
part | description | I2C address |
---|---|---|
0.1uF capacitors | for 5V bypass | |
10kohm | sets contrast for LCD | |
16 × 2 LCD | liquid crystal display | |
22 gauge wire | for breadboarding, various colors | |
3 x 4 keypad | tap tap tap | |
AA batteries and case | power to go | |
Adapter Cable | for GPS antenna | |
Arduino Mega 2560 | microcontroller | |
Black cardboard box | for your breadboard | |
BME680 | T/P/RH/VOC | 0x76 or 0x77 |
Breadboard | for building your prototype; on loan | |
CR1220 batteries | batteries for GPS and RTC | |
digital multimeter | on loan for the semester | |
DRV2605L | haptic vibrator driver | 0x5A |
DS3231 | real time clock | 0x68 |
electret microphone | amplified microphone | analog output |
EMG electrodes | Electromyogram electrodes | |
eye protection | on loan for the semester | |
Force-sensitive resistors | Just like it says | |
GPS Antenna | External Active Antenna | |
GUVA | Analog UV sensor | analog output |
Haptic feedback | motorized vibrator | |
INA219 | voltage/current sensor | 0x40 |
L3GD20H | Triple-Axis Gyro Breakout | 0x6B |
LSM9DS1 | accelerometer/magnetometer/gyroscope | 0x1E |
MCP4725 | DAC, 12-bit, I2C | 0x62 |
MicroSD card breakout | holds microSD card | SPI |
MicroSD memory card | 8 GB SDHC | |
Mini Metal Speaker | 8 ohm 0.5W | |
MLX90614 | IR thermometer | 0x5A |
MMA8451 | ±2 g accelerometer | 0x1D |
MyoWare | EMG muscle sensor | analog output |
of/off/on/off pushbutton | battery vs. USB power | |
P164 GP2Y0A21YK0F | IR distance sensor | analog output |
PAM8302 | PWM audio amplifier | PWM analog output |
Pink plastic bag | your toy bag! | |
PM2.5 PMS5003 | airborne particulate monitor | UART RX/TX |
QS-FS01 | anemometers | analog output |
T-slot photointerrupter | counts blades | phototransistor output |
TCA9548A mux | I2C multiplexer | 0x70 |
Tiny camera | Adafruit “mini spy camera” part 3202 | MicroSD; USB |
TSL2561 | Digital Luminosity/Lux/Light sensor | jumper to 0x39 |
tweezers | on loan for the semester | |
ultimate GPS | cool navigation device | UART RX/TX |
USB cable | talk to the Arduino | |
VL53L0X | Time of Flight Distance Sensor | 0x29 |
wire stripper | on loan for the semester |