Tuesday, October 28, 2014

Tone/DTMF detector library for Arduino

Was playing with some cheap radios and decided that the keypad DTMF tones could be used for remote control.
I had some old source that detected touch tones using a AVR microcontroller and decided to convert it for Arduino.

This resulted in a library that detect audio tones played into any Arduino pin.
The audio is first clipped to a 1-bit signal (played loudly into a digital pin) then sampled at 10kHz.
256 1-bit samples (25.6mS) can then be analyzed for the content of one or more audio tones.
The analyzer uses a crude 1-bit DFT but works surprisingly well at detecting multible tones such as DTMF or guitar plucks.
The result can be presented as either a DTMF symbol or approximate signal strength for any frequency analyzed (up to 5kHz).

Here is the library for now (will move to github).

Magnetic levitation

Some students wanted to build a toothbrush holder that floated a toothbrush in mid air to avoid contamination.
I build a prototype to see if it was possible to implement the control system in software.

This project allow a small permanent magnet to be levitated by a electro magnet.
Since static passive magnetic levitation is not possible a HALL effect sensor
 is used to constantly regulate the magnetic field.
To achieve stability a software based PID controller is used.
5 potentiometers is used to control the PID parameters.
This is the Arduino code for the project

Minimalistic APRS transponder

After working on a High altitude Balloon project I got interested in APRS.
APRS is basically a radio amateur driven network that among other things lets you broadcast your position worldwide on VHF radio.
For out project we used this APRS transponder to keep track of the balloon.
Mostly for the challenge I decided to build a really small and inexpensive APRS tracker you wouldn't be too sad to loose.

I used a FS6377 integrated clock synthesizer as the VHF transmitter. This chip is I2C programmable and is able to generate 144.8MHz (or 144.39MHz for US) from a 20MHz crystal.
The FS6377 does not have a modulation input but I was able to modulate the crystal oscillator using a simple variable capacitance diode.
I chose the ATTINY85 microcontroller form Atmel because it is cheap and available in a really small package.
The BELL202 modem signal needed for APRS is synthesized inside the ATTINY85 microcontroller and output as a PWM signal.
The frequency of the modem tones need to be very precise and since the internal clock is not very accurate I chose to generate a 10MHz clock frequency externally. It is possible to tune the internal clock in software to gain an extra I/O pin but I didn't need it here.

The transponder really show potential to miniaturized. The transmit power is around 30mW enough for long range if transmitting in line of sight.

The project is heavily inspired by the Trackduino project.

Here is the source code for the project as an AtmelStudo project

Monday, May 12, 2014

A bit more wheelchair stuff

Figured out some more details about the actuator data format.
Also a short video from FabLabRuc of me driving the wheelchair using a HCD controller.

Sunday, May 11, 2014

Hacking electric wheelchair drive

While building some robots for a museum we came up with the idea of using an electric wheelchair as the base for the robot.
Not wanting to replace the electronics we gave it a shot to try to use the existing motor driver and control it from an Arduino. On inspection it turned out to be a very common Penny and Giles Pilot plus drive.
Very little technical information is available about the interface between the joystick- and motor unit of this system. So we started reverse engineering. Here is what we have found so far.

By opening up the joystick and probing connections inside we found that the joystick movement are communicated as serial data @19200BAUD, 8 databits and even parity. Apart from the driving data the joystick unit also emit an additional, and completely different, data stream for controlling various lights and actuators on the chair.
The physical connection is using a propitiatory 6 way connector.

I turns out that the joystick sends drive data packets with checksum roughly every 10mS. Immediately after the data line changes direction and the motor controller returns a packet of data, again with checksum.
Simultaneously but not in sync another data signal is sent to control lights and actuators.

The data format seem to be completely non-standard but relatively simple to encode.

Probably for safety reasons the system does not tolerate any signals being missing or corrupted without shutting down so a fair bit of probing and fiddling went in to eliminating the joystick and replacing it with an arduino.
Here is a rough cut first Arduino sketch that allowed us to drive the wheelchair motors actuators and lights.
Quick shaky video of it running.

We plan to turn out a easy-to-use Arduino library for controlling the PG Pilot Plus soon.

Saturday, April 26, 2014

The_synth Arduino library got an upgrade

A while ago I released a Arduino synthesizer library. A new and improved version is now available github:


I was asked to play a small concert at my friends PhD defense using an Arduino running this library.

Listen to the result here:


The music was sequenced using Ableton Live and sent to the Arduino via. MIDI @ 31250 BAUD serial data. The output from the Arduino was a 8 bit PWM signal that was subsequently lowpass filtered using a simple LC filter.
Part of the low pass filtered audio signal was sent back through a echo effect processor (inside Ableton) to add a bit of flavor and make it tolerable to regular people :)

Monday, February 24, 2014

Easy to use Arduino wireless library

When working on the HCD project it came apparent that the small radio chips used could be used for general purpose wireless communication.
The BK2421 based radio turns out to be compatible with a lot of other devices like the RFM70  or the nRF24L01 from Sparkfun.
I have made a simple to use library for Arduino that uses the HCD or similar radio for simple character driven communication.
In addition to communicating between Arduinos it can be used to connect to the HCD or similar handsets so they may be used for controlling your own stuff.
See the library examples for basic functionality.

Check out the Arduino library.

Friday, January 10, 2014

Fun with thermopile generator

Got a bag of Peltier cooling elements (thanks Dan) and experimented with using them as thermoelectric generators. These devices will generate an electric current when subjected to a temperature difference.
When placed on a hot oven they will generate about 1,8V and 650mA for a few seconds and then fade out due to heat conducting through the element and cancelling out the temperature difference.
I found a really fancy heat sink from an old server. By placing the heat sink on top of the element I was able to sustain generation for a much longer time.
Even the heat sink eventually gets hot causing the power output to decrease. Sitting on top of the oven in a column of warm air it is not able to dissipate heat well.
I found that blowing cold(er) air from the surroundings onto the heat sink increased the efficiency dramatically.
As a small cooling fan I used a motor/prop assembly from one of the HCD's, powered directly from the Peltier element. This allows sustained power generation.
Just for fun I connected a color changing LED (Thanks Jim), powered by modified Joule Thief circuit:

Video of the thing going.

Update: Picked up the cold generator and held it in my hand. After a few seconds the fan started just from the heat of my hand!

Sunday, December 1, 2013

More cheap drones on the horizon

I have noticed that these have started to show up in the maker community stores. This is exciting since A-I own a couple and B-they are compatible with the hardware I use for the HCD.
I actually started work on the radio interface for the HCD using one of these.
I find them less easy to fly and they have less load capacity but they have a cool flip feature that let's the quad do a flip just by sending a command.
If these takes on I plan to expand the HCD library (NOTE: not currently compatible with this model) to control these too..

Friday, November 22, 2013

Data visualizer for drone tracker

I needed a way to visualize the spatial data from the drone tracking software. I wrote a OpenFrameworks program to do this. Click here or on image to see it in action.

Did a hover test

Here is a video of the test

Monday, November 18, 2013

Tangible paramter tuning thingy

When tuning PID parameters for the HCD flight controller I pretty much spend 2 evenings waiting for the program to recompile.
I would change some parameter a tiny bit, recompile, get the HCD in the air to evaluate and then repeat the process over and over.
At some point I realized that tuning the parameters in mid-air would be much more efficient.
For this i made this simple controller:
It's simply 6 faders hooked up to an Arduino. It transmits the 6 fader values to the flight controller software where they are scaled to the appropriate range and fed into the feedback controller in real time.

Saturday, November 16, 2013

The loop has been closed

After a lot of crashing and swearing in the lair closed-loop control of the HCDs has now been achieved!!
The rough control parameters has been established so autonomous take off, flight and landing can be continously reproduced.
Now I need to fine tune the flight controller software and package everything nicely into something others can use too.


Friday, November 15, 2013

Fly by wire

Hooked a HCD handset up to an Arduino to send raw joystick values to my tracking software.
The tracking software then sent the joystick commands via. another Arduino with a BK2421 radio to a HCD.
This tells me that my tracking software is able to control a Quadcopter (for now with a little help from a pilot).
Next step is to create a control-loop that will enable me to fly one or more Quadrotors under complete software control.
Here is a video of one of the first tests.

Tracking flying quadcopter

Made some tracking software to track the HCD's. Click here or on picture for video.
The tracker is made using Kinect and OpenFrameworks. I use the Kinects color video image to track orientations and the depth camera for altitude.

The tracker locks on to colored tags made from pink post-it notes and use their position to select which part of the depth information is relevant.
It's all very experimental at the moment but seems promising.
The aim is to autonomously fly one or more HCD's in formation.

Tuesday, November 12, 2013

Controlling toy quadcopter(s) with Arduino

The last couple of days I have done some more work on the small toy quadcopters (now dubbed HCD for Hamster Cage Drone). The goal was to hack the communication so that they could be controlled using computer vision software. Basically the poor mans version of this (don't bother you have already seen it).

UPDATE: I have made a Arduino library for controlling this particular Quadrotor (may work with similar products). You will need to build this simple hardware (discribed on this page) to use the library. All parts (apart from Arduino) may be found inside the remote controller that comes with the quadcopter.

The first thing I did was to take the remote control handset apart to see what kind of radio system was used.
 Inside was pretty much what you'd expect. A couple of cheap paper PCB's with not a lot on them.

The radio communication is handled by a small discrete radio module. After a lot of internet digging it turned out that the module was based on the BK2421 2.4GHz tranceiver IC. This also seem to be the choice for a lot of cheap RC toys coming out now.

With a datasheet for this chip and an oscilloscope it was simple enough to figure out the pin configuration for the SPI communication between the radio module and the handset.

Using an ArduinoUNO to eavesdrop on this comunication I was able to figure out the initialization and thereby the mode of communication. Here is a annotated list of the initialization sequence.

Without going into detail about the low level communication the following happen when the handset and
Quadcopter are turned on:
1) Handset broadcast it's unique network address or ID.
2) Quadcopter receives the broadcast it acknowledges this and start listening to data from that ID.
3) Upon acknowledge the handset then start transmitting flying data packet every 20 mS.

Multible Quadcopters can be controlled simultaneously by assigning them different addresses.
The passing of ID is done on one fixed radio channel and flying data is sent on one of about 12 random radio channels. The quadrotors seem to auto scan the radio channels until they find data.

Flying data is transmitted as 8 byte packets in following format:
Byte 0 = throttle 0-255
Byte 1 =Yaw 0-255
Byte 2 =Yaw_trim 0-128
Byte 3 = Pitch 0-255
Byte 4 = Roll 0-255
Byte 5 = Pitch_trim 0-128
Byte 6 = Roll_trim 0-128
Byte 7 = Fly/run 0=fly, 16=run (toggle button on handset)

Next I created a base station that would connect to the quadrotors. I happened to have some RFM-70 modules that contain the same BK2421 chip. Not reading the datasheet properly I initially thought that this module required 3.3V logic and hence all the resistors. They are not needed since the BK2421 has 5V tolerant data pins.

NOTE: CE goes to pin 8 (missing on drawing)

I eventually ended up with a much simpler set-up using just the module salvaged from the handset and an Arduino.
To enable future experimentation I have written a Arduino library for connecting to one or more of these quadcopters.
The library should work on any ATMEGA88 to ATMEGA328P based Arduino boards.
If you want to have a go yourself you may get the HCD's here or here among other places. These are just random hits on google, you may get them elsewhere.

Less crappy video here.

Please share if you find other toys that may be hacked using similar methods.
Happy hacking.

Wednesday, November 6, 2013

Fun with cheap toy quadcopters

Got a whole bunch of these from an art festival I was involved in.

I have now started using them for all kinds of fun projects.
The first experiment was to remove the cage. Without the cage the little quads are really stable and capable of carrying a lot of weight.
Obviously i HAD to add a small wirerless camera. Here is the first result:

I am also hacking the communication protocol so that they may be controlled from a computer but more about that in later posts.

Monday, August 26, 2013

DIY active anti corrosion system

I'm part of Illutron. We have our main workshop at a large steel barge and we are always worried about corrosion.
Since we could not afford to have the barge sand blasted and painted we looked into other options.
Cathodic protection is a process where you actively impress an electric current between a ships hull and some anode. The replaceable anode is then corroded in place of the ship and everybody is happy.
The Anode may be any large clump of metal submerged next to the ship, e.g. an old engine block. We use 3 meters of rail track.
A variable voltage between 0 and 1.5V and a current between 0 and 10A is required.
For this I designed a simple power supply circuit:
Mains is first converted to 12V using an efficient industrial switch mode power supply. A low frequency Buck converter (low frequency=low switching loss) then lower the voltage further under microcontroller control.
Low frequency switching require a rather large inductor. The transformer like object in the picture below is a 55mH(1) inductor (schematic says 100, not critical) for the Buck converter. If you want to build this you may use the primary of an old microwave transformer (remove secondary!!).
( 1: used to say micro-Henry it need to say mili-Henry. Thanks Fred )

The microcontroller measures the output current and voltage and displays them on a standard 2x16 chr. LCD. I used an Arduino and connected the LCD according to the Arduino LCD example.
I use the somewhat exotic BTN7970 as H-bridge driver for the Buck converter. This offer very low switching losses but could be replaced by your favorite choice of H-bridge device.
The Arduino code implements the following functions:
By pressing the switches you can adjust the voltage in small steps. Press both switches to lock the keys from unintended access, press both again to unlock.
Up-time is displayed and a clearable message appears if the unit have been power-cycled.

Does it work? 


These two mild steel plates was submerged next to the barge. The left is isolated from the hull and the right is electrically connected to it.
This picture is taken after two days.

If you attempt to use this system on your own ship/structure you need to know what you are doing. Reversing the polarity result in the ship being corroded super-fast and running too much current result in calcium build up on the hull potentially stripping off existing paint.
You need to measure the corrosion potential and adjust the voltage accordingly.

You may use the following method if you are careful:
Connect a piece of blank steel to the hull with a beefy bable. Slowly increase the voltage over several days until the steel stays blank. Clean the steel between inspections with steel wool.
Good luck.

Monday, July 22, 2013

Diy Arduino based metal detector.

UPDATE: Try using BC547 as transistor people have reported problems with 2n2222.

Me and my son decided to go treasure hunting with a metal detector that we have but we couldn't find it anywhere. Being proper makers we decided that it would be more fun to build one ourselves rather than keep trying to find it. 
Most metal detectors uses a search coil that act as part of an oscillator circuit. When metal is put in proximity of the search coil the frequency of the oscilations changes.
Many metal detectors (including the one we can't find) uses another more stable oscillator BFO (beat frequency oscillator) to act as a reference for the frequency of the search coil. Usually the frequency of the BFO is adjusted to exactly match that of the search coil oscillator when no metal is present near this.
The signals from these two oscillators are then fed to a, usually analog, circuit that create an output proportionally to the difference in frequency og the two. This may be either an audiable tone and/or some meter reading.
Another device that are really good at detecting minute frequency changes is a microcontroller. We decided to swap the BFO approach for a microcontroller and came up with following simple circuit:

The oscillator circuit feeds a around 160kHz signal to pin 5 of the Arduino. The Arduino sketch then measures the frequency of this pin very accurately. When the 'NULL SW.' button is held this frequency is stored. Any deviation from this frequency is then represented as a series of 'geiger counter' clicks on the piezo. The rate of the clicks increases as metal approaches the coil.

We tried different search coils and found that around 30 turns of wirer around a 15cm. plastic bucket worked well.

All we needed then was to tie it all to a discarded Ikea lamp and hey-presto off to the beach to find treasures.
The metal detector has excellent sensitivity and by changing the SENSITIVITY value in the Arduino sketch you are able to tune it for both small and large objects.
Here is the source code if you want to build one yourself.
Happy hunting!

Wednesday, July 3, 2013

Quick and dirty replacement of number plate lights

My car is a "recreational vehicle". It was given to me by a friend to scrap but it has turned into a project to keep it running at minimal cost.
The other night I noticed that the humber plate lights wasn't working (bulbs was blown years ago). It was late so I gave myself 10 minutes to solve the problem.
It turned out that a piece of un-etched PCB would fit directly into the bulb sockets. After a quick fr

eehand scribble with the Dremel I was able to solder a couple of LEDs and resistors to the board. After securing everything with hot-glue everything with hot glue the bulb-replacements was ready.