Archive for the ‘Arduino’ Category

Over the last semester, Will Byrd, myself, and others have been doing various Atari hacks. These have included things like building a ROM dumper, writing custom ROMs, breadboarding an Atari, and the hack I’m going to talk about here: using the Wii Nunchuk as an Atari controller.

The Atari has two types of controllers. One is a joystick, and the other is a paddle. Both have extremely simple interfaces. The joystick is basically five switches. There is one switch for each direction, and another switch for the button. The paddle also has a button, but also an analog twisty control. The twist control is actually just a 1 MΩ potentiometer. The Atari controller port is a standard DB-9 connector, like is used for PC serial ports. The joystick uses a total of 7 wires (five for the controls, one for ground, and one for +5 volts), so only one joystick can connect to the DB-9 connector. On the other hand, the paddle only needs one wire for the button, one for ground, one for +5 volts, and one for the potentiometer output. Because of the fewer signals, the Atari designers allowed for two paddles per port, which allows for up to four players in a single game. We found the pinout from pinouts.ru very helpful in figuring all this out.

Emulating buttons (and the joystick, which is really just four buttons) with the Arduino is fairly simple. In order to press the button, we need to do the equivalent of shorting the joystick wire to ground. In the Arduino, this is the same as doing a digitalWrite of LOW on the corresponding pin.

At first glance, doing the knob on the paddle shouldn’t be too tricky either. After all, it’s just an analog control, so we can use the analogWrite command, right? Sadly, this is not the case. The Arduino’s PWM pins are still digital; they just turn on and off very quickly, and the percentage of the time that the pins are high is how we represent analog values. The Atari paddle uses a potentiometer to vary the voltage instead. The Arduino has no way to do this natively, so we must use something called a digital potentiometer. Digital potentiometers are like regular potentiometers, except you can control them programmatically. We selected an Analog Devices AD5242 digital potentiometer, which is controlled using I2C. I found deciphering the protocol from the datasheet a little tricky, but I’ve posted the code on my Github.

To interface with the Wii Nunchuk, we used the WiiChuck adapter, which also includes sample code. The Nunchuk also communicates using I2C, so we can wire the WiiChuck adapter and the AD5242 on the same I2C bus. This took a slight modification to the WiiChuk code to make it work with other devices at the same time.

After some fiddling around with all of this, we finally got it working. Here’s a video:

Whack-A-Mole!

Posted: April 9, 2012 in Arduino
Tags: , , , ,

Over the last week or two, the A290 students have been hard at work on Whack-A-Moles. We started with a basic one mole version. An LED represented the mole state, and there was a button you could use to whack it. Once they got this working, the assignment was to scale it up and come up with the most creative version of Whack-A-Mole that you could. Here is a sampling of some of the projects students have shared online.

Eric made a version that uses servos to represent the moles. See it in action here:


Anothy’s features a 5×5 grid of LED’s, complete with Wii Nunchuk control. He demos it here:

Anthony’s web site shows how he did it, and additional video showing how everything works in depth.

Brian also has a post describing his project, complete with code. Here’s a video.


That’s all for now, but I’ll post more projects as students share them.

It turns out that many electronic components can run backwards and forwards. For example, it’s possible to use headphones as a microphone. Here’s a simple Arduino-based circuit that shows how to use an LED as a light sensor. The diagram below shows how to hook everything up.

LED Light Sensor Diagram

The basic idea is then to use analogRead() to detect the voltage across the LED. If the value is low, it means the LED is not detecting much light, while if the value is higher then there is more light present.

Three different versions of the code that goes along with this circuit is available at https://github.com/eholk/ArduinoExamples/tree/master/LEDLightSensor. The SerialOutput folder has a sketch that just dumps the values it reads to the serial port. You can use this to find a good threshold value, depending on the exact light conditions you are seeing. The Threshold sketch simply turns the LED on pin 13 off when there is light, and on otherwise. You could use this as a simple night light. Finally, the Fading sketch adjusts the intensity of the LED based on how much light is detected. It requires the output LED to be connected to a PWM pin, so if you are using an Arduino Uno instead of a Mega, you’ll want to adjust the code and the circuit to use, for example, pin instead of pin 13 for the output.

Here’s a video of the fading example.

Arduino Examples

Posted: March 7, 2012 in Arduino
Tags: ,

This semester I am assisting Will Byrd in teaching A290: Arduino Development. As part of this, I’ve decided to post some example Arduino code on Github. Here’s the link to the repository:

https://github.com/eholk/ArduinoExamples

In the coming days and weeks, I’ll try to post more detailed information about each of the examples.