June 3, 2014

Programmable Servo Controller

This is an update on my earlier Remote key-switch operation post. These things have become rather useful around the lab! In addition to the original key-switch operation, they've been put to use running optical shutters for pump lasers, turning deposition shields inside vacuum chambers, etc. Basically, any time we have a mechanical device we want to be in one of two positions, we use a servo and this board.

The only problem is the inconvenience of programming the limits on the servo. Each application has different desired positions for 'on' and 'off' logic level, and we were having to break out the AVR Programmer each time... So here's the fix. This version has user-programmable limits!
After first turning the device on, apply one logic level (low, say) then press the 'Learn' button. While holding the Learn button, adjust the servo position with the 'Adjust' potentiometer. When the servo is in the desired 'low' position, release the 'Learn' button and the ATtiny45 will store that position in EEPROM. Then apply high logic level, and use the 'Learn' button to teach the microcontroller where the servo should go for high input. Releasing the 'Learn' button stores the high position in EEPROM. From then on, even after power cycling, the device will remember where it needs to go for high and for low input. You can re-program it any time, as often as you like. (Well, up to the limit of EEPROM write cycles for the ATtiny45, which is about 10,000 or so.)

The LEDs indicate power, logic state, and whether the servo is currently 'active'. That last one deserves some more explanation... Servos twitch. They jitter. They are not mechanically (or electrically) quiet. This is an annoyance sometimes, and a serious disadvantage if you need to mount the servo on an optics table. So the other feature to this device is that it turns the servo power off when it's not moving the servo. This may be a disadvantage if you have an application for which the holding force is not negligible, but it's acceptable for our applications. There's a switch in the code so that you can leave the servo power on continuously if you wish.

Another improvement to the previous circuit is that the PWM signal on this version drives a transistor buffer which drives the servo, rather than driving the servo directly with PWM. This allows the circuit to control much larger servos reliably.

It's still limited to 5V supply. The obvious next version would be to add a voltage regulator for the microcontroller, and drive the servo with whatever supply voltage you wanted... but we haven't needed that increase in servo power yet, so haven't bothered.

Here are the EAGLE files and the ATtiny45 code.

September 19, 2013

The "BAD DOG! NO!" alarm

We have a dog. He's a good dog, and very sweet, although a 70-pound golden retriever who thinks he's a lapdog can be a challenge.
One of the current challenges is that he's decided that it's ok to cruise the countertop for goodies while we're off at work and school. We need some negative reinforcement...

Here's just the thing.
The sensor (on the left of the box) is a Passive Infrared (PIR) sensor. I do not know the origin of this particular unit, it's been rattling around my parts-bin for a few years; but similar units are about $10 at Adafruit.com. It puts out a logic high any time it detects motion. That PIR signal is connected to the RESET pin of a 555 timer chip, which is wired to generate a 2.5kHz square wave. The 555 output goes to the piezo buzzer on the right of the box. A switch and power-on LED complete the electronics.

Net result: loud annoying beep any time the sensor detects a dog in the area. We're now working on sensitizing the dog to the noise: every time it goes off we all yell "NO! BAD DOG!" so he starts associating that particular beep with "NO!" Next, we'll put it on the countertop, aligned so that it trips whenever he puts his nose over the edge.

Will it work? I don't know. It'll probably work better than nothing, which is what else we have.

If you're curious, the box was made in Google Sketchup and printed in ABS on a Solidoodle. The box holds all the parts and the circuit board, with a 9V battery to run things. I could really get used to this whole 3D printing thing: custom hardware like this is very cool.

August 30, 2013

Why should the army have all the good drones?

This hack is long overdue. It's been at least two years since I started thinking about how (and whether) to do it, and it's finally coming together. Earlier this month, I finally pulled the trigger on eBay and got a FatShark FPV video system.

The FatShark is a combined video-receiver and video-goggles system. It includes a small video camera and 5.8GHz radio transmitter; the video plays through the goggles. The camera is mounted on a servo-controlled 2-axis gimbal, and a 2-axis gyroscopic/magnetic sensor on the goggles transmits a 433MHz signal to a receiver which controls the gimbal. Net result: A videocamera small enough to mount on an RC plane, that not only shows you the view from the cockpit but tracks your head motion and moves the camera accordingly. Control of the plane is achieved through the regular 2.4GHz RC transmitter/receiver: the FatShark video is a separate system operating on a completely different set of frequencies.

I needed a good way of mounting the camera on the plane. Needed a good plane, too... well, a not-so-good plane, actually; something slow and forgiving and not "special" in any way to either my son or myself. Most of our planes are hand-crafted balsa constructions that take a month to build and involve some emotional cost if they crash, and I figure this thing will crash. We have a "Sky Surfer" that someone gave us, and it fits the bill perfectly: slow, solid foam construction, underpowered (by our standards) and boooring. Someone gave it to us; we use it for teaching other people how to fly RC. It's an absolute pig of a plane, but I think that's probably what we need here. It's also a pusher-prop plane, so there's no obstruction of the front view.

The cockpit of the plane is removable, and I now have access to a 3D printer; so I used Google Sketchup to design and print a replacement cockpit that can hold the radio gear. The cockpit just drops in where the stock cockpit came out; no modification to the plane is required. The pan servo on the video gimbal screws into the front slot on the cockpit, with clearance for wiring and for slightly larger servos as well. The angled slot at the back is designed to hold the video transmitter: the antennas are nicely exposed, and there's plenty of airflow onto the transmitter which otherwise gets quite hot. The pan/tilt receiver is stuck to the bottom of the cockpit with doublestick tape.

The original cockpit is held in place by the front tab you can see on the print, and by a magnet that grips a 1-square-cm metal plate on the top-back surface of the cockpit. I designed this replacement cockpit with a recess to mount that plate, but I'm a bit leery of having things come loose in negative-g maneuvers so I strapped the cockpit down with a couple rubber bands just in case.

Now if we just had some good flying weather... Maybe tomorrow! This will be a new experience for me: I've been flying RC planes since high school, but never from "inside the plane!"

Files for this project are available at Thingiverse.

August 4, 2013

3D printing for lab parts...

I reached a fascinating technological milestone this weekend.

I needed some small plastic brackets to hold a sensor for a new experimental apparatus I'm building for the fall semester's Advanced Lab course. So I designed them, in 3D, on my laptop. This took about 30 minutes. When that was done, I went to my lab and printed them, which took another 30 minutes.

Printed. Parts. Real parts. Physical objects. From "Light bulb!" to "Here are the custom parts you just designed" in an hour. SO COOOL!!!

This is a GOOD time to be a nerd.

Technical details: parts designed in Google Sketchup, printed in ABS on a Solidoodle 2. This blog post should in no way be construed as an endorsement of Solidoodle, where the company policy appears to be to ship replacement parts on a schedule that would make glaciers wonder about the hold-up, and whose printer is currently printing using a jury-rigged extruder heater element that would make MacGyver shudder.

June 1, 2013

Radioactive isotope decay simulation

My students need to learn LabVIEW —I know, it's proprietary software, and expensive, but until a viable open-source equivalent comes along we're stuck with it— and one of the exercises I have them do is to make a program to analyze radioactive decay. This gives them experience in using counters, plotting data in real time, curve fitting, etc.

The problem arises when I have a dozen students and not so many good sources and detectors. During the students' development of their LabVIEW program, they need multiple re-starts on the measurement. The program NEVER works right the first time, and if you're using neutron-activated indium as a source it's hard to "reset" it when you realize that your block diagram isn't wired right.

I have a dozen Arduinos, though, and I've programmed them to behave as if they were radioactive sources. This way the students can try their program, fix their program, push the reset button on the Arduino and try the program again.

Here's the code. I use pin 13 as an output since the LED allows students to see that it's working, even when their program isn't. The plot shown at the top of this page is actual data from the Arduino, as collected via a student LabVIEW program and plotted in Python. There's a step in the data at about 80 seconds —not sure if that's the Arduino or LabVIEW— but it works well enough for the job.

Once the students are confident that their program works, then I bring out the real sources: neutron-activated indium, neutron-activated silver, and a "cesium-barium cow".

May 12, 2013

"Ayrduino" Single-Sided Arduino Clone

I'm teaching "Electronics for Scientists" this semester, and I wanted to allow each student to have their own Arduino to play with for microcontroller lab exercises and possibly use for their final projects. The Arduino is not very expensive at roughly $30 per, but they add up quickly when you have a whole class of students needing one each. I'd been buying enough electronics equipment over the course of the semester that my department chair was showing an involuntary tic any time I knocked on his office door... So I built my own. They are a stripped-down variant of the Duemilanove.

  • Standard Arduino form-factor and mount-points.
  • Accepts standard Arduino shields.
  • Single-sided board, easy to make with toner-transfer method. 
  • 16MHz ATmega328.
  • No SMT parts.
  • On-board 5V regulation.
  • Screw-terminal power-in connector, rather than barrel jack.
  • Pin-13 LED.
  • Lacks on-board USB-Serial conversion, so programming requires an FTDI cable.
  • No 3.3V regulator.
  • This is as detailed a board as I ever want to make using toner-transfer.  
  • No TX/RX LEDs.
  • No ISP connector.
  • Three component-side jumpers. Couldn't quite get all traces on the back side!
None of these down-sides are significant for this application. The requirement of FTDI cable is inconvenient, sometimes, but I have 3-4 of them in the lab and students share them without too much squabbling.

My grader, Lena, did most of the drilling and soldering work. She's graduating next week, and I'll miss her, but the graduate program in Nuclear Engineering at University of New Mexico is going to be thrilled.

If you want to make your own single-sided Arduino variant, and this set of pros/cons is acceptable to you, here are the EAGLE files. One of the smart-asses in the electronics class immediately dubbed it the "Ayrduino"...

Note: the Arduino design, on which this is based, is licensed under the Creative Commons Attribution-ShareAlike 2.5 license; so this is available under that same license as well.

Parts list:
  • ATmega328P-PU (1)
  • 16MHz crystal (1)
  • 22 pF cap, ceramic (2)
  • Button, momentary tactile switch (1)
  • Angled header, 6-pin male (1) 
  • 0.1µF cap, ceramic (5)
  • Red LED (1)
  • Green LED (1)
  • 1N4001 diode (1)
  • 2-position screw terminal (1)
  • 7805 regulator (1)
  • 10kΩ resistor (1)
  • 510Ω resistor (2)
  • 47µF Al. Elect. cap (2) (short ones to fit under shield boards)
  • Female headers, 8-pin (2) (optional)
  • Female headers, 6-pin (2) (optional)
  • 28-pin IC socket (1) OR 14-pin IC socket (2) (optional)
  • Three short jumper wires
  • Single-sided PC board, 0.032" 1/2oz Cu.
You can cut 11 of these from one 8x10 sheet of PC board if you do it just right.

April 30, 2013

Minecraft Ore-Block night-light

You can buy a minecraft ore-block night-light... but it's more fun to make your own, and this one is not just redstone. It cycles through the colors of redstone, emerald, lapis lazuli, iron, gold, and diamond. It also pulses slowly; just a subtle fading in and out. My son and my nephew both had birthdays this month; although they're past the age of needing nightlights they're both minecraft nuts so I decided to make these for them.

Let's start with the light. For the light source, I used a 10mm RGB LED from Adafruit. This common-anode RGB LED provides a nice bright color-space, and the diffused package mixes the light well. I first wrote a quick Arduino program to read three potentiometers and adjust the red, green, and blue levels according to those pots. The program would then send the actual RGB values back to the computer via the serial line. This allowed me to experiment with different light mixes in an effort to find the best RGB combination for each color. I could tweak each knob, see the results immediately, and when I found a combination I liked I could check the serial line to see what it was.

Here's the program, and here's what the test-rig looked like:

I eventually decided on these tuples for each type of ore:
Redstone (255,0,0)
Emerald (0,255,0)
Lapis Lazuli (0,0,255) --- those three are easy!
Iron (16,4,0) --- closest I could get to "brown" with the RGB!
Gold (255,115,0) --- maybe a bit less green?
Diamond (0,255,100) --- could've gone more blue, but this works.

These colors are hard-coded into the program, which was downloaded onto the microprocessor before soldering the microprocessor into the board. Here's the program.

Next, the electronics: I chose to use an ATtiny84 microprocessor to drive the light. The ATtiny84 has much more memory than necessary for this purpose, but I needed three separate PWM outputs to do the color mixing (so the ATtiny45 was out) and I didn't have any ATtiny44's handy. The board layout was fairly simple: I used EAGLE CAD, and here's the design:

The EAGLE files are available here. I created the board using toner-transfer and FeCl etching.

Next, it was time to make the physical ore-block. I used 1/4" clear acrylic, cut on my table saw. The sides are each 3" high by 2 7/8" wide, and the top is 2 3/4 x2 3/4. I then used a router table to cut a 1/8x1/8" shoulder-groove around each piece.
The side pieces then fit together, each overlapping the next. The top fit perfectly inside the recessed square formed by the sides. The bottom was left open for the moment, but if you're following along on visualizing how this goes together, you'll realize that there is a 2 3/4x2 3/4" recessed square hole there, too --- just the right size for the circuitboard.

Before gluing the pieces together, I sandblasted them ---both sides--- to make them better diffusers.
I then solvent-welded them together using methylene chloride. Plastic model glue would have worked nearly as well, but I work in a building with chemistry labs and fume hoods and solvent-welding acrylic works REALLY well. When finished, I had a nice translucent 3" cube of frosted acrylic, open on the bottom. I also drilled three holes near the bottom of one side of the block; holes that would later accommodate the buttons and power cord.

The outside pattern is key to making this a Minecraft block, of course! I created a single 3x3" side using a vector graphics program, then put five sides together so I could wrap them around the cube. The largest-format laser printer I have available will only print letter-sized paper, so I had to break the wrap into two pieces, like this:
The top piece wraps around three sides of the block, and the bottom folds over the top and fourth side. The extra on the sides wrap around to prevent light leakage around the edges. Here's a link to a .pdf of that design, should you want to make your own block.

To make the "stone" parts of the lamp light-proof I used 3M spray adhesive ("Super 77") to glue a print of this pattern onto a smooth piece of aluminum foil. Next, I carefully cut the pattern out using a sharp new X-Acto blade and a metal straightedge.
I then carefully creased this aluminum-foil/paper label on all fold lines, using the metal straightedge again. I sprayed the aluminum side with adhesive once more, and wrapped the label around the block.
The final assembly step was to provide a power source (salvaged 5V phone charger) and solder the power cord and buttons. I found two buttons that were nearly identical; one was momentary and the other latched. The latched button is used for power, the momentary button cycles through ore-type. The circuitboard fit (with a small amount of sanding) into the recess on the bottom of the cube: I glued it into place with RTV and added four stick-on rubber feet.

It works great, the boys think they are cool, and it's on to the next project: writing a final exam for my electronics course!