Quick reference
-
Make video smaller
Just make it smaller (scale determines the width of the video in pixels)ffmpeg -i input_video_large.mp4 -vf scale=400:-2 -vcodec libx264 -crf 20 output_video_small.mp4
Remove the audio too:ffmpeg -i input_video_large.mp4 -vf scale=400:-2 -vcodec libx264 -an -crf 20 output_video_small.mp4
-
Convert PCB traces from svg to png
Take an svg image of your foreground copper traces and produce a png image for your foreground traces and generate a png image for your edge. You can use this script: http://logical.ai/make/trace-png.sh, whose source is shown below. It uses ImageMagick.#!/bin/bash # This file is trace-png.sh FOREGROUND_SVG=$1 FOREGROUND_PNG="$FOREGROUND_SVG-traces.png" FOREGROUND_TMP="$FOREGROUND_SVG.tmp.png" BACKGROUND_PNG="$FOREGROUND_SVG-edges.png" CMD="convert -density 1000 -borderColor white -border 5%x5% $FOREGROUND_SVG $FOREGROUND_TMP" eval $CMD CMD="convert $FOREGROUND_TMP -negate $FOREGROUND_PNG && rm $FOREGROUND_TMP" eval $CMD CMD="convert -density 1000 $FOREGROUND_SVG -threshold 100% -alpha off -negate -borderColor black -border 5%x5% $BACKGROUND_PNG" eval $CMD
Usage:trace-png my-pcb-board-fcu.svg
-
Check whether your board/programmer are plugged into the computer properly.
On linux-like machines, you can run:lsusb
which will list all of the devices plugged into the computer. In the usual setup, one will be Future Technology Devices International (FTDI) corresponding to your board, and another will be e.g. USBTiny or Avrisp II (your programmer).
Pro tip: if you put watch before a command, it will run that command periodically every 2 seconds (read the man page for options.) In this case, you can have a terminal showing you in real time what's currently plugged in.watch lsusb
-
Check that your board is functional
The program avrdude is what the typical Makefiles are using under the hood to send programs to your board. You can use it to get basic information about your board and/or see if your board is functional. Run, for example, a command like:avrdude -p t44 -c avrisp2
If your board, the programmer, and the computer are all connected properly with all cables oriented the right way and no problems with your circuitry and with the command above tailored to reflect your specific devices (see below), this command will tell you about your board. (If the command fails, this means that something is wrong with one of these aspects of your setup.)
Here, the -p flag indicates what kind of microcontroller is on your board, for example t44 indicates the ATTiny44, t45 indicates the ATTiny45, etc. The -c flag indicates what you're using to program your board — don't forget to change this! The light blue box programmers that live in lab are avrisp2. In contrast, the programmers that we make ourselves are usbtiny.
If you have a brand-new device and you're not sure what command to use for it, just replace the processor (t44) or programmer (avrisp2) with a question mark to see a list of available options that avrdude supports. For example, during group project week, I needed to look up an appropriate XMEGA chip (-p x256a3u) and a new type of Atmel ICE programmer (-c atmelice_pdi). -
Diagnose rc=-1 errors (when your board won't program)
(Courtesy of bzy) To diagnose rc=-1 errors, you can check the following:- Your board is plugged in
- Your microcontroller (attiny, etc.) is oriented correctly. (Each one has a nearly invisible dot indicating the "upper left" of the chip.)
- The programming cable is oriented correctly (A Brian-pattern FabTiny will light up bright red if connected correctly, and dim red if connected incorrectly. An avrisp2 ("blue box") programmer will flash red if connected incorrectly)
- There are no shorts between power and/or data lines. (Use a multimeter to check that everything that should be connected is connected, and nothing that shouldn't be connected, like VCC and ground, is accidentally connected.)
- There is no unintended solder joining pins or traces (Use visual inspection, assisted by multimeter. You can get rid of solder joins by piling on additional solder then using solder braid. You can also sometimes just sever the connection with the tip of a solder iron because of surface tension.)
- If your board has a clock (e.g. crystal/resonator/...), make sure that the clock works. If the board has a clock, make sure you use a programmer to set the fuses to use the external clock. If the board doesn't have a clock, never set the fuses to use external clock.
- Your data signals are not swapped: In your design file, ensure that the MOSI pin on your microcontroller goes to MOSI on the 6 pin connector and MISO goes to MISO.
- The programmer works. (Does it talk to a known-good board? if FabTiny, did you make rstdisbl?).
- The computer is in good condition. (Try a different computer.)
-
Converse with a PCB board over serial
For when you have a PCB board connected to a computer via serial and you're trying to complete the echo-hello-world assignment. You need a program that will allow the board to send data to you and for you to be able to send data to it. The echo world program on the board will take any data you type to it and and send it right back.
One option is to run Neil's term.py script:python term.py /dev/ttyUSB0 9600
A second option: if you install picocom, you can call it from a terminal:picocom -b 9600 /dev/ttyUSB0
! To exit picocom, hit Ctrl-A, Ctrl-X (or the reverse; I forget? todo.) The -b flag indicates the baud rate (the number of symbols per second being communicated.) This has to match whatever the program on your board says. In the default echo-hello-world example, it's 9600 as shown above. The path /dev/ttyUSB0 is wherever your board is mounted on your operating system. This kind of name is typical for Linux systems, but your own system may differ.
If using Nodejs is somehow convenient, a third option is to use Nodejs, which I figured out how to do during interfaces week. Import the fab libraries into KiCad
The purpose of this process is to ensure that you can look up and use, in KiCad, the specific circuit elements (etc.) that are in the fab inventory. You only have to do this once, when you first install KiCad. First, download the KiCad directory from here: https://gitlab.cba.mit.edu/pub/libraries (or consult the electronics design page if this link is out of date). That directory contains both fab.lib and fab.pretty, which we need to install. Confusingly, you must import these two separate things in separate places/programs: (1) Open EESchema (the green-on-white schematic view). Go to Preferences > Manage Symbol Libraries. (This menu item may be in a different place on Macs relative to Linux.) You'll see a list of "symbol libraries" (which contain information about the logical layout of circuit elements---how many pins they have, what they're called, how they're numbered, etc.) Add the fab library by clicking "Browse libraries" and finding the file fab.lib. Set its nickname to fab if it isn't. Click OK.
(2) Go to Pcbnew (the red-on-black layout view). Go to Preferences > Manage Footprint libraries. You'll see a list of footprint libraries, which contain information about the physical shape of circuit elements and the physical location of their connections. Add the fab footprint library by clicking Browse Libraries and finding fab.pretty. Nickname it fab and click OK.Pick a resistor for various components
You can use between 500Ω - 1kΩ resistors for limiting the current to LEDs. Slight difference based on frequency of color— blue needs less resistance.
You can use 499Ω limiting resistor for red LEDs, 1kΩ resistor for green, 100Ω for blue, 330Ω for infrared. Slight difference based on color.
Use 10kΩ resistor for buttons.Pick an appropriate ATMega
ATMega48/88/168/328 fab:ATMEGA88-THIN ATMega8u2/16u2/32u2 fab:ATMEGA16U2-TQ Some things some microcontrollers can do
Various microcontrollers have some of the following built-in: high-frequency oscillators, pull-up resistors, pulse-controlled modulation (pcm), multiple timers and counters, asynchronous interrupts, analog-digital conversion (adc), usb compatibility. (To be expanded)
Weekly assignments
Key: 💯 indicates especially successful weeks and/or weeks that I expect will be useful for others.1 | Project prototyping |
I imagine building an artifical skylight using mirrors and optical effects to create a physically-accurate illusion of an infinitely distant sun in a blue sky. (Note: This project prototyping page is deprecated. I eventually go with a different idea.) |
2 | Computer controlled design | I cut a star key sticker out of vinyl and use a laser cutter to make tinkertoy-like toothed polygons out of cardboard. Success level: learned how to use equipment. |
3 | Electronics production | I mill my first PCB, learning how to solder and "stuff" (add electrical components to) boards. |
4 | 3D scanning and printing | Using OpenSCAD (CAD software), I design a three-dimensional celtic knot that envelops an icosahedron. I 3D print it and it turns out great! I also 3D scan various shapes, the best of which turns out to be my wallet. |
5 | Electronics design 💯 | Using the KiCad software, I design my own circuit. Success level: Exceeded weekly expectations. It eventually worked well enough to program, and I took a decent amount of notes. |
6 | Computer-controlled machining | Using OpenSCAD (CAD software), I design a parametric shelving unit. The code lets you choose the number of shelves and also packs the pieces densely to reduce the number of cuts. Success level: The design is robust, but the shapes were the wrong dimension to print. |
7 | Embedded programming 💯 | Using KiCad, I modify the hello-world board to have an LED. I
learn how to write programs in C which control the signals on the
pins of the microcontroller. I learn all about PCM (pulse-controlled
modulation) which lets you control the brightness of an LED by
switching it on and off faster than humans can see.
|
8 | Molding and casting 💯 |
I attempt to make a pumpkinoid shape for Halloween. I design it in OpenScad and prepare to mill it out of the provided machineable wax. The project goes badly through several iterations of trial and error. Eventually, I change tack and instead make a flat triforce shape which is easier to mill. Success level: Learn from my many, many mistakes. I took notes. |
9 | Input devices |
I attempt to make a step-response input combined with a speaker output. I do not succeed, but I learn some things. |
A | Output devices |
I make my own speaker and learn how to use the hardware PCM (pulse-controlled modulation) on the ATTiny44 to generate sound. The speaker was very quiet, but it did work. I learned about using MOSFETs to protect microcontrollers from devices (like speakers and motors) that draw large, board-frying amounts of current. I learn how to make a four-pin connector. From the ashes of the week before. I documented many mistakes. |
B | Group project |
As a group, we all build a milling machine (like the Roland) starting from some motors, parametric design files, and code for networking / running motors. I'm on the electronics team, and nothing works for days and days until finally it does, it all comes together, and it only takes a week. |
C | Interfaces and applications 💯 |
I learn how to use Nodejs and web sockets to toggle an LED light on a pcb board by clicking a button on a local html page. In this report, I provide all of my code and some detailed documentation. |
D | Networking and communications |
I successfully establish contact with an infrared camera over TWI (I2C). (Its eight-bit address is 0xB0.) First I use an attiny45 and bitbanging with Neil's predesigned circuit, then I design a board with an atmega328p and use built-in TWI registers. |
E | Wildcard—Embroidery |
I learn to use a computer-controlled embroidery machine. I use a proprietary hand-holding software suite to generate a pattern from a raster image. I experiment with color gradients, which are otherwise difficult to do by hand. I explore, but do not finish, generating embroidery patterns in code. |
F | Final project 💯 |
I make a device which tracks your head position to control the camera position in a virtual 3D scene. The effect is that your flat computer monitor behaves like a window into a virtual world. The project uses a wearable pair of LEDs and an infrared camera; the camera communicates over I2C to a board, which communicates over serial to a computer. The computer communicates over web sockets to a webpage rendered in threejs. Software written in Nodejs/javascript. Bonus: my progress notes. |