Samstag, 7. Januar 2012

RC remote control Pong

Hi everyone!

This time, I'm back with a project in which two RC remote controls are used to move the paddles in Pong. Watch me lose it against my brother here ;)
But now how does it work?
Let's start by looking at the RC controls: For each channel a pulse with a width of 0.7 up to 2 milliseconds is issued from the remote control. A pulse shorter than 1.5 ms would turn a servo left, one greater 1.5 would turn it right. You can read about this in some more detail here.
The analogue RC receivers' signal output lines are connected directly to digital inputs (ports 3 and 5) of my Arduino. They run fine with the 5V power from the Arduino, even if it draws its power from an USB port.
On the Arduino, a very simple sketch measures the control pulse lengths via "pulseIn". During the first five seconds, the gathered values are investigated for their minimum and maximum, so you will have to turn the knobs on your RC controls to their farthest extend here. The range of the pulse lengths is then mapped to a single byte for each channel.
The actual Pong game runs on a PC within the Processing IDE. To achieve this, I adapted the "SerialCallResponse" example sketch and added a Pong implementation in Java. There is a class called "ControlValues" which serves as an interface between the game and the Processing sketch. This approach is in no way thread-safe, but since game is timer-based and the Processing sketch is event-based, it seemed the easiest way to connect both using static variables.
The Processing sketch first starts the game and then begins querying the Arduino for new control values. To simply retrieve the values, it sends an 'A', to which the Arduino responds by sending the current values.
By sending a 'B' or 'C', the sketch can make the Arduino play some beeps in addition to sending the values. This should give you the real retro feeling! To hear the beeps, simply connect a speaker to port 7 (via transistor or op-amp). You may notice that sometimes a beep isn't played (ball touches the paddle, but there's no sound). This is due to the threading problems mentioned above.
To play you can download the Arduino sketch and Processing sketch.

Dienstag, 3. Januar 2012

IPM V2 update

Hey everyone! I think it's time to wish all of you a Happy New Year first ;)
Then, I'll show you what I did while I left you alone out there all the time...
The Internet Personal Messenger V2 now features almost the same functionality as the old V1 one. Here's a picture of the current hardware setup (still missing the speaker, though):
I'll post the setup's schematics next time - and I'll also show you the code, but at the moment, there are still some memory leaks I have to fix.
Ah, by the way, the TFT is quite nice and really cheap! It's got an ST7735 controller on it. The library seems to originate from ladyada but the one I got shipped with the TFT was pretty buggy. The software mode was really slow too. If you'd like to get my improved version, please mail!
I'm using the software SPI for the TFT in my sketch as at was impossible to get it running on the same bus the ethernet controller and the TF card are using. The controller and the card use SPI transfer mode 0, the TFT uses mode 3. As mode 3 seems to be just the inverted variant of mode 0, there may be a possibility to use the same bus with all three devices if you'd use an inverter to connect the TFT to the bus. I didn't test this though, as things run fine for me the way they are ;)
That's it for now! Keep up gadgeting!