Wednesday, February 1, 2012

HexBot Arduino - Netduino Wireless IR Controller

I got a new IR toy, a HexBot, and wanted to create an IR controller similar to what I did with my helicopter.
I also got a new Netduino Plus board that I wanted to try!

I ran into some problems with the netduino board while trying to create a simple IR emitter, because the netduino utilizes the .NET Micro Framework, which generates managed code and hence can't do real-time to the microsecond responses to generate the IR pulses.

So I went back to the arduino board, and used the old decoding program to get the pulses.
It's quite a simpler device, with just four buttons. The IR pulses are in the arduino code attached below.

But, I wanted to use my netduino too! so I created a program (utilizing NeonMika Webserver) to load a html page that shows the possible moves, and goes back to the server on each click, to activate ports.
I first tried to get SPI working between netduino and arduino, but it didn't work right away, and since I just need 4 flags, one for each direction, I found it easier to just allocate 4 pins for the communication between the devices.
Netduino pins 1-4 to arduino 4-7. Once pin 4 is ON, the arduino code sends the forward pulse. Same for each other direction.

Attached is the code for the webserver, and the arduino!

For now you can control the HexBot with a cellphone (on the same network) by browsing to the netduino (port 8080).

I have a few ideas on what to move next. Maybe store paths and image recognition to identify obstacles?

Here is the robot walking.

And here the new remote control!

A closer look at the setup, Arduino and Netduino playing nice

Netduino Plus webpage used:

And the Arduino code to handle the netduino requests and emit IR pulses:

Wednesday, August 3, 2011

Android Live Wallpaper tutorial

Continuing my Android exploration, I found AndEngine.
It's a great tool to do graphics and the forums are very active and helpful.

Based on a few of the samples that include a multiplayer pong, I decided to go for a Pong Clone as a first approach to Android Games, and see how it works.
The basics are covered in the tutorials and examples in AndEngine forums.

I started installing the engine and examples. They worked great and was easy to read and the code is very readable.
Though as the engine is new and in constant development, it changes faster than the samples found on the web, and some tweaks have to be done to get it to compile.

Then I found the live wallpaper extension and in the forums a Template by Mimminito for AndEngine Live Wallpapers, and it seemed like a good idea to have a pong game playing itself as a wallpaper, so I moved my pong code to it.

I had some troubles at first, figuring out how to move objects around.
For example, the ball:

When the object is created, you can override the update method, and add the behaviour you want to it.
I thought this was going to solve all my problems, but when I got to the paddles, the overriden function cant access the ball position, so I went looking around for info on how to do this, and found that I can override the method
public void onUpdate(final float pSecondsElapsed)

and put my logic there.

The wallpaper looks great, very retro, and can be found on the Android Market

Here's the full code:

Thursday, July 28, 2011

Start custom Service when Android starts up

Another interesting part of the RemindMe development is considering what happens when the phone is powered up.
The Reminder service must be "woken up" for it to be useful.

The way to do this, is to create a receiver, and hook it up to the android action BOOT_COMPLETED

In the AndroidManifest.xml, declare the following receiver:

With this, every time the phone is powered up, after boot is complete, AlarmBroadcastReciever will be called, which sets up the inexactRepeatingAlarm mentioned in my previous post.

Wednesday, July 27, 2011

Android Reminder Application Development

I started working on a simple reminder application for Android.
The idea is to gain some experience in android development, and also to try to create a useful tool.

You can find the latest version here: RemindMe

I'm still working on it, I won't post the complete code here as it might change, but feel free to email me and I'll provide the latest version.

The idea of the app is to create a tool that can set up simple text reminders, independent of the actual time.
For example, to be able to say "remind me in two hours" and you don't have to configure when that is, just the delay.
It also allows for daily reminders.

The design is fairly straightforward: A SqlLite database to store the notifications, the application to create them, and the task to poll the database and alert the user.

One thing particularly interesting here is how to schedule the task to check for expired notifications.
The way to do this is to set up an AlarmManager and utilize the setRepeating() method.
But there's also a setInexactRepeating() method that allows to set the time, though the android system does not necessarily fire it at the exact moment, but might wait and group different alarms that happen around the same time, and then fire them all at once, making it more power-efficient.

This is how the wake up alarm is set up for the Reminder:

What this does is set up a timer to check for expired reminders every 30 seconds, but not necessarily exactly in 30 seconds, more likely when android wakes up and has some task to perform.

The app is free in the market, and i'm open to suggestions on how to improve it!

Friday, May 6, 2011

Arduino helicopter infrared controller


Some time ago I got the S107 helicopter as a birthday present, and as I found myself with some free time, I got an Arduino board with the intent of flying it with my computer.

Helicopter being tracked with webcam and speed adjusted
My experience has always been on the software side, so this is my first try  utilizing hardware and micro controllers.

While waiting for the Uno, I started reading the basics and found this amazing tutorial on how Infrared works, and code samples on reading and emitting infrared signals.

The code in that tutorial was extremely helpful in getting me started, and understanding the basics of Infrared communications.

Arduino Uno and IR emitter and receiver circuit
Delivery day and I get my arduino, (for some reason I ordered two usb cables instead of two IR leds, guess I didn't double check the order)

Following the first steps, I installed the software, and then tested out the board with the begginer examples it provides.
Later on, I built the ladyala emitter and receiver circuit, and its ready for work!

The schematics are identical to the ones here, but on an Uno board instead of the duemilanove version, but it shouldn't be a problem.

Before getting into the helicopter remote, I tried it with  my audio remote control, which has only 3 buttons and seems simpler.
After decoding the pulse, I played around to make a program that graphics the pulses.

As the Arduino runs in the board, the communication is done through the serial port.
To communicate with it while it’s running, it’s done through the same serial port used to upload data to it.

Utilizing Processing language ( the program to graphic the pulse is quite simple.

Here’s a picture of the three button’s pulses (on, vol up, vol down), done with the Processing language.

On to the helicopter!
This is a little bit trickier, because once you’re flying the helicopter it’s a continuos stream of data from the remote to the helicopter, instead of a single burst of data.
We’ll need to figure out how it transmits the data to the helicopter, that is, which protocol it uses.

Reading a bit more into IR protocols, I found a thread that depicted usual protocol pulses here.

There is a Header followed by “bits”. Each bit is a pair of on/off IR pulse. The 0 is a short on, short off, and the 1 is a short on, longer off.

With the decoding program loaded into the board, the output for the helicopter is the following:

(off / on)
-10072 – 1930
1880 - 330
250 - 370
230 - 350
590 - 320
640 - 330
640 - 370
210 – 370

So, the header is a 2000 ms on, 2000ms off, the 0 a 300/300 pair and the 1 a 300/600 pair pulse.

The separation between headers is between 32 pairs, so I assume the helicopter uses a 32bit pulse.
Modifying the receiver program to adapt to this format, and make it easier to figure out the protocol, the output now shows H for header, 0 and 1, in a 32 bit string:


The next step is the most tedious:
Detecting the changes when only one movement is done, to figure out which bits do what.
I recorded hundreds of combinations, and did a little program to eliminate the repeated ones.

The outcome:

Byte 1: Yaw
Byte 2: Pitch
Byte 3: Throttle
Byte 4: Yaw correction from Remote.

They all use the last 7 bits of the byte.
Throttle goes from 0 to 126, while pitch and yaw start centered in 63.

With all this info, it’s time to create a processing program to test this, a program to transmit pulses with the decoded format.
Then some buttons to handle the increases and decreases, and off it goes!

The emitter program in the arduino to keep sending the same pulse, and the processing program to just notify the changes in the bits, instead of always telling the board what pulse to send, for timing purposes
(It uses a simple way of just sending one ascii character, and both programs know which bit it’s referring to)

It works! But the IR Led seems to be quite underpowered compared to the one in the remote control, so the range is about one meter, then the helicopter drops dead.

One final test is to have the computer do some flying on its own.
As a proof of concept, with the jMyron library for Processing to handle video input, I want to make the program have the helicopter hover at a steady position.

Utilizing the input from the webcam, it adjusts the speed until the helicopter is in the middle of the screen.
If it goes too high, it lowers the speed. If it gets too low or is stopped, it slowly increases the upwards speed.
It works!

Any ideas on what to move on to next?

Arduino Source Code: