Test Equipment Class

This weekend at NYC Resistor, I took the test equipment class taught by Trammel Hudson. It was a great class on how to use two very common tools for debugging issues with electronics.

The first half of the class covered how to use an oscilloscope. We used the DSO Nano v3 by Seeed Studios. This pocket-sized oscilloscope is powerful despite its small size. We first discussed how to measure signals and then moved on to more complex topics, such as using the triggering functions and figuring out baud rates based on the oscilloscope readings. The small size is a major plus, as it will fit nicely in my hack box. It’s a big step up from the giant analog oscilloscope that my grandfather used back in the day.

IMG_8373

The second half of the class covered how to use a multimeter. This is a must-have for anyone who likes to tinker with microcontrollers as I do. We covered how to measure AC and DC voltage, resistance and amperage, as well as continuity testing. Even though I already knew how to use one, this was a great refresher.

Resistance is futile... or approximately 220 ohms.
Resistance is futile… or approximately 220 ohms.

Of course, no class is complete without sticking something into the electric socket!

IMG_8377

The best part of the class was that we got to keep the tools! I can’t wait to break things so I can use my new tools to fix them!

Arduino and Sensors

I’ve been busy putting the finishing touches on a class I am teaching at NYC Resistor called Arduino and Sensors. The purpose of this class is to teach people how to use common sensors with Arduino so they can build awesome interactive projects. The class features the Adafruit Sensor Pack 900, as this pack contains a nice selection of common sensors. I’ve written some sample code for each of the sensors in the pack. We will discuss both digital signal and analog signal sensors.

Sensors!

Digital signal sensors are the simplest to use. They simply return a 1 or a 0 based on the reading of the sensor (just like a switch, it’s on or off). Therefore, reading the state of one of these sensors is as simple as hooking the output of the sensor to a digital pin on the Arduino (pins 2-13 on the Uno) and calling digitalRead() on that pin. Here is a simple example – an IR sensor:

IMG_6848

Analog signal sensors are more complex. These sensors return a voltage on an analog pin somewhere from 0 volts to the max voltage of the microcontroller (with the Uno, it’s 5 volts). In order to read an analog sensor value, the sensor output needs to be connected to an analog pin on the Arduino (pins A0-A5 on the Uno). In the code, calling analogRead() on the analog pin will give you the sensor reading. The Arduino automatically converts the voltage on the analog pin to an integer between 0 (no power) and 1023 (full power). Generally, the reading can be mapped back to some meaningful value. For example, here is a simple analog sensor – a temperature sensor:

IMG_6832

According to the datasheet, this sensor returns 0 volts at -50 degrees Celsius and 1.75 volts at 125 degrees Celsius. It has a scale of 10 millivolts per degree Celsius. To get the raw voltage reading, we take our reading value, divide it by 1024 (to get the percentage of the full voltage) and then multiply that by 5 (since the microcontroller is supplying 5 volts). To scale the voltage to the range, we can simply multiply the voltage by 100 (according to our scale factor, 1/100 volt is 1 degree Celsius) and then subtract 50 (since zero volts is -50 degrees Celsius).

Of course, many sensors are more complex than just reading a simple pin. We’ll discuss a number of different scenarios and how to handle them. Did you ever wonder what the AREF pin is for? It’s the analog voltage reference pin and we will be discussing how to use it. We’re also going to use potentiometers to tune the sensitivity of some of the sensors.

The class is already almost sold out! If all goes well, I will hopefully teach it again soon!

General Class Amateur Radio

I upgraded my ham radio license to a general class license today! Yay!

IMG_6784

The test was harder than the technician class test as the material was a bit more technical. I used KB6NU’s No-Nonsense General-Class License Study Guide for the material and eHam.net practice exams. This strategy seemed to work well for me and I will probably do the same thing if I decide to upgrade to the extra class license.

Why upgrade to the general class? The general class gives you more privileges across the amateur radio spectrum. In particular, a large chunk of high frequency bands are only available to general class and above. This is important if you want to talk to people across the world.

My path into amateur radio was a strange one. After my grandfather’s death, my uncle mentioned that amateur call signs were inheritable. Since both of my uncles were already licensed and no one else seemed to be interested, I decided to get my license. After passing my technician class test, I applied to the FCC for a vanity call sign, requesting my grandfather’s old call sign. Coincidentally, the FCC assigned my grandfather’s call sign to me on what would have been his 85th birthday!

KA3USO, the first.
KA3USO, the first.

Interestingly enough, the FCC restricts transferal of cancelled call signs for two years except under two conditions. The first case is that a close family member wants to inherit a call sign. The second case is if a club wants to hold a call sign in memoriam of a former member. It makes me wonder how many call signs are transferred this way.

Blinky Box

This was a gift for my two year old nephew. Since he is a fan of lights and buttons, I wanted to make something blinky for him to enjoy. The concept was simple: make a clear box with buttons and lights that would change color and pattern based on the buttons that were pressed.

Blinky Box

First, I had to find a clear acrylic box large enough for some LEDs, switches, buttons and a microcontroller. I found this great polycarbonate box from Hammond Manufacturing that seemed to be the right size. Next, I needed to find some buttons that could take a beating. Fortunately, Adafruit sells some translucent arcade buttons in bright colors. The lighting was a no-brainer as I am a huge fan of Adafruit’s addressable LED strips. I also found a glowy on/off switch for the power. Somewhere along the way, I thought it would be a cool idea to add a rotary knob so that he could select different blinking patterns.

The next step was to assemble the pieces and wire everything together. The polycarbonate box was harder to work with than I had hoped. The polycarbonate would discolor if I used the laser cutter, so I found myself drilling all of the holes with a rotary tool. I then added the buttons, knob and on/off switch.

Assembly

Once all of the bits were together, I had to add a microcontroller to control the button states and light transitions. I decided to go with the Teensy 3 as it was what I had on hand (and I had yet to work with one). Also, Teensy 3 allows all digital pins to be interrupted (as opposed to four on the Teensy 2), which would simplify reading the button state. The other great reason for selecting the Teensy is that it already has an Encoder library, which makes reading the knob state simple.

The code was easy. Interrupts on the arcade buttons would change a variable representing the color. The interrupt for the black button would kick off a rainbow display routine. In the main loop, I polled for changes in the rotary encoder state and transitioned the lights accordingly. When I was finished, there were five main light colors (white, red, yellow, green and blue), one rainbow routine and six possible blink patterns (always on, fade on/off, blink on/off, chasing light, random twinkling lights and alternating lights).

IMG_6082

I saved the hardest part for last: power. I wanted something that my nephew couldn’t disturb, so anything outside of the box was out of the question. Regular batteries would require opening the box to change, so I thought something rechargeable would work better. I decided to go with a Lithium Ion battery. Unfortunately, these are generally around 3.7 volts and the LED strips require 5 volts. This meant that I needed to find a way to recharge the battery from the outside and find a way to step up the voltage. Fortunately, SparkFun sells a power cell board that does both. Yay!

Power Supply

I added a power jack to the box and used an old 5 volt AC adapter to supply the charging power. I then connected the power cell board and the battery using this handy tutorial. Fortunately, the charging of the battery seemed to work! Unfortunately, the power cell board only provides 600 milliamps at 5 volts, which is not enough power to run a full meter of the LED strip. Sadly, I had to cut the strip in half. It was still impressive even with just one loop of lights! To make the battery last even longer, I also implemented some of the suggestions for conserving power with the Teensy.

The best part about this toy is that it is fully programmable. As he gets older, I can program new features or games into it. Perhaps one day, I can even teach him to program it himself! 🙂

Here is a short video of the assembled box

 

Raspbian

While working on another project, I set up my Raspberry Pi (revision B) with Raspbian. Although it was a bit time consuming, it was not difficult at all. Instead of using the default desktop environment (LXDE),  I decided to try out Raspian Mate as it’s a fork of the well-loved GNOME 2 desktop environment.

Raspbian

I was happy to see that GNOME 2 was still alive and well. I used to run Ubuntu on my home computers, but abandoned it when they switched over to GNOME 3 and Unity. The lack of features in GNOME 3, the clunky Unity interface and the poor device support in Ubuntu pushed me over the edge. I sold out to Macintosh and happily resigned myself to never having to look at xorg.conf ever again.

Raspberry Pi

It surprises me how far computers have come already in my lifetime. As a little girl, I remember playing with my grandfather’s Color Computer 2. It seemed remarkable at the time and I never expected computing to progress as rapidly as it has. For some perspective, the CoCo2 cost $240 in 1983 and had 16KB of RAM and an 8 bit processor at 1 MHz. Twenty years later, the Raspberry Pi costs $35 and has 512 MB of RAM and a 32 bit processor at 700 MHz. It will be interesting to see what the next twenty years brings.

Microcontrollers!

IMG_6193

Looking through some of my electronics stuff, I realized that I ten different kinds of microcontrollers! That’s not bad at all, considering that I only discovered my love of them last summer. There are five flavors of Arduino: Uno, Uno Ethernet, MEGA, MEGA ADK and Due. There are three flavors of Teensy: Teensy 2.0, Teensy++ 2.0 and Teensy 3.0. There are also two wearables: Lilypad Arduino and Adafruit Flora. So many microcontrollers, so little time!

Motion-Sensitive Paper Lantern

Back in February, I made a motion-sensitive lantern for the Lunar New Year. The idea was simple: have a lantern that appeared to be mostly plain but would reveal a design when a person moved closer to it.

Lantern from far away

The easiest form to use was a round paper lantern. I started with a 14″ white paper lantern and some markers. I then attempted to draw some snakes on it, as 2013 is the year of the snake. As I am not an artist, let’s pretend that these squiggles look like snakes.

Lantern up close

The next part was to add some lighting. The lighting needed to change color. I decided to go with LED strips from Adafruit, as I could wrap them in the center of the lantern and have fairly uniform lighting. I had some left over pieces from a previous project and this seemed like the perfect occasion to use them.

Next, the lighting needed to respond to motion. There were a couple of sensors that would have allowed me to detect motion, but I decided on a passive infrared (PIR) sensor. Interestingly, these sensors work by detecting rapid changes in infrared radiation (including those given off by body heat).

PIR Sensor

The code for this was very straightforward. The PIR sensor sends a high signal on its output pin whenever motion is detected. Therefore, it’s as simple as polling the output pin with digitalRead() and transitioning the lights based on changes in the output pin state.

Finally, I had to find a lightweight power source. I found an Energizer power pack, which was the perfect power supply for Teensy. It even came with a mini USB adapter, which meant that I could plug it directly into the Teensy without having to solder anything. Here is the final internal assembly of the lamp!

The final assembly

And here is the lamp, fully assembled and running!

Dance Dance Revolution Keyboard

Over the weekend, I turned a Dance Dance Revolution dance pad into a keyboard input device. The pad will be used as part of a larger project at the NYC Resistor 2013 Interactive Show. Here is how I did it.

The pad itself is one of those metal arcade style Dance Dance Revolution pads. The only output was a 15 pin D-Sub connector, much like a VGA cable.

Dance Pad
The dance pad connector

Fortunately for me, a fellow Resistor already went through the arduous task of figuring out the pinout for this particular pad. A little further research based on the pinout revealed that this particular model was a TX-1000. The full pinout can be found here.

The next task was to wire the connector to a microcontroller and try to read input from the board. I decided to go with a Teensy as it already has a library that supports keyboard output. In order to have the Teensy be recognized as a HID by a computer, you have to change the USB type. This can be done by changing Tools -> USB Type to “Keyboard + Mouse + Joystick”.

Now I needed to write some code to read the input from the dance pad and convert it to keyboard output. First, I had to define the input pins in the setup function of the Teensy code. This was done with pinMode using pullup resistors.

pinMode(leftPin, INPUT_PULLUP);   // Left arrow

The next step was to read the input from the control pad and send the corresponding keyboard character when a pad was pressed. Fortunately, Teensy offers a Bounce library which makes debouncing switches easy. First you declare a Bounce object on your input pin.

Bounce leftButton = Bounce(leftPin, 400);

Next, poll the pin in the loop() method for state changes. Once a state change is detected, send the corresponding keyboard key.

if (leftButton.update()) {
    if (leftButton.fallingEdge()) {
         Keyboard.set_key1(KEY_LEFT);
    }
}

Once everything was wired up and the Teensy code was running, everything seemed to work… except the right arrow. Unfortunately, this meant that it was time to take the pad apart!

Underneath a panel

The wires

After a bit of investigating and a few false starts, I found that the wires were easily accessible under the up arrow. Thankfully, the wires for each button were a different color so it was easy to determine which wires to test. Testing with a multimeter showed that the right signal wire in the cable was not working. After running a new signal wire for the right pad (and soldering everything else I cut), everything worked as expected! I then used a solderable D-Sub connector and enclosure from RadioShack to make a connector for the pad.

The completed connector

I could then hook the dance pad connector to my homemade connector and then a mini USB to USB cable from the Teensy to my computer. There is nothing more satisfying than navigating your computer by dancing!