Posts Tagged ‘Arduino’


The right tool joypad for the job

The RetroPie project is great! You can turn your Raspberry Pi into a NES/SNES Mini clone in no time and you don’t need to stop there as adding additional systems such as Atari 2600, Master System, MegaDrive, C64, PlayStation 1 etc happen almost automagically thanks to some clever install scripts. Playing these classic consoles with software emulation provides near perfect picture and sound but using a modern controller such as the Xbox 360 controller was ruining my experience and just felt wrong. I thought to myself could this be improved and decided to pay a visit to my original boxed up game consoles which have been happily yellowing (as it turns out) in my loft and gathered up a bunch of my favourite joysticks and joypads.

I then set about reverse engineering each one. All the controllers used here are originals and unmodified (‘warts and all’ – or should I say long thick cables that act as trip hazards, all part of the charm!) the propriety connectors were obtained by sourcing and cutting up extension cables as these are still being made and are readily available. This also ensures these classic joypads will still be usable on their original systems, keeping my childhood intact! Once one was completed I shared the code on my github, if interested please check them out https://github.com/jfrmilner/Arduino-USBRetroGamingControllers

With this experience, I designed a circuit board and selector system so they could all be connected and used on one system. The board acts as a shield for an Arduino Micro that expands the available pins allowing all the controllers to be connected. This works by using a series of Shift-in Registers, Shift-out Registers and some Multiplexers. The Shift-in’s handle the simple switch based controllers like the C64 joystick, the Shift-out’s control the Multiplexers (one nibble per IC) and some LEDs on the selector, and the Multiplexers connect the controllers that require direct access to the Arduino’s digital pins. The latter is required to meet the response times of ICs in the controllers which are usually Shift Register(s) or Multiplexer(s) (yes more of them). The Arduino presents itself as two joypads with native plug-and-play support for Microsoft Windows 7+ and Linux/RetroPie. The selector is simply a ring of LEDs with a potentiometer in the centre, using the knob will move the lit LED to the desired controller pictured in that position, a simple system with an unexpected bonus of being a little retro in its appearance.

The case was sourced from eBay and was chosen because of the small size and removable front panel, a handy feature providing the flexibility for future revisions. Using the graphics editor software Inkscape I created a design for the front panel and positioning of the multitude of game ports. This was imported into jscut.org and milled out on my trusty Shapeoko 2 CNC. A nice feature of RetroPie is that it has some handy shortcuts for things like Loading, Saving and Exiting games which greatly improve usability for casual users. To make these shortcuts available I added some LED Arcade buttons with custom labels which connect to an SX1509 (this simplifies LED effects and Interrupt offloading) and another Arduino 32u4 based board this time presenting as a keyboard. The overall look feels like a blending of the early Atari consoles and Arcade machine.

In efforts to keep this writeup short I’ve deliberately kept the details at a fairly high level but if anyone would like me to expand on an area then please leave a comment, same goes if you have any suggestions. I’m pleased with how this collection of hacks has turned out and most importantly I’ve had fun learning what makes all these controllers tick. As for the console, this will live in the break out room at work, coffee and a few rounds of Bomberman with the guys, ah bliss!

jfrmilner

Advertisements

In this project I detail how I created an Internet light controlled Christmas tree. Last year I heard about a great project by ioBridge Labs named CheerLights but unfortunately at the time this was late December and it was simply too late for me to join in, well not this year! The idea of CheerLights is a simple one: connect a strip of RGB LEDs to an Internet connected Microcontroller and have it query the CheerLight servers for the current colour, now the real magic here is that anyone can synchronously change the colour of every CheerLights setup by sending a Tweet with Hashtag #CheerLights, for example

Here’s a quick video from ioBridge about CheerLights including a demo

If you’d like a go yourself please choose from the following supported Colours:

Red
Green
Blue
Cyan
White
Warmwhite / Oldlace
Purple
Magenta
Yellow
Orange
Pink

You can see what the latest colour is right now by visiting www.cheerlights.com or https://thingspeak.com/channels/1417, getting the app android/iPhone and there is even a Google Chrome plugin but at the time of writing this is missing some of the new colours.

The Build

As with all projects of this nature, they can be customised to your own personnel preferences so I’ll not tell you what you should get but instead what I used for this build and I’ll try and highlight some pointers. I’ve got a few Arduino MCUs now, in fact I’m beginning to wonder if I’ve inadvertently become a collector as it seems I’ve just about one of each type, so from my stock I decided on a combination of Arduino Uno and Arduino WiFi Shield. The only real requirement here is that you use an MCU that you are comfortable with, if you have the same hardware (or similar – replacing the WiFi Shield with the Ethernet Shield would require minimal code changes) then you can simply upload my Sketch and away you go.
To control the LEDs I decided to use the FastLED Animation Library. This is quite a mature project and the library makes for some simple and easily readable code. FastLED supports popular LEDs including Neopixel, WS2801, WS2811, WS2812B, LPD8806, TM1809, and more so plenty of options. I went with a string of 25 WS2801 from raspimart.co.uk.

WS2801

 

You’ll also need a Christmas Tree, I picked up a desktop sized one from eBay – http://www.ebay.co.uk/itm/381033205884

ChristmasTree

 

Power

Be sure to get a power supply that can output at the correct voltage and has sufficient ampere to run the lights. Looking at the spec of my lights I know I needed a 5volts 2A (60mA*25=1500mA) AC Adaptor. I used a single AC Adaptor to power both the Arduinos and the LEDs with a splitter.

Tip: Don’t use the VIN on the Arduino to power more than 1A as this is the maximum tolerance of the forwarding diode, instead use a splitter.

The Code

Sketch flow
Boot up and connect to WiFi (halt on no connection) and run the Startup Routine (clears LEDs Black-White-Black)
Set current colours to black.
Start loop – { Check for current colour via ThingSpeak API
If it’s the same as the last check then wait and check again, if we’ve checked a couple of times without change then play either the Sparkle* or Twinkle* effect.
If the colour is different; then transition from the original colour to the new colour via the RGB colour wheel (see below image) using the shortest path, for example Red>Green would transition via Orange and Yellow or Blue>Red would transition via Magenta-Pink.
}

RGBColourWheel

 

*The Sparkle effect increases the brightness of a single LED and runs that back and forth over the strip.
*The Twinkle effect creates a FastLED Colour pallet of the current colour with black stripes which is then looped over the LED strip.

FastLED
I’m using the FastLED library which made coding these transitions and effects extremely simple.. The FastLED library has a lot to offer, one of my favourites is its ability to allow for compact colour palettes which use very little of my precious Arduino RAM, here’s a sample of the help section which explains this feature:

Normally, in computer graphics, the palette (or “color lookup table”) has 256 entries, each containing a specific 24-bit RGB color. You can then index into the color palette using a simple 8-bit (one byte) value. A 256-entry color palette takes up 768 bytes of RAM, which on Arduino is quite possibly “too many” bytes. FastLED does offer traditional 256-element palettes, for setups that can afford the 768-byte cost in RAM. However, FastLED also offers a compact alternative. FastLED offers palettes that store 16 distinct entries, but can be accessed AS IF they actually have 256 entries; this is accomplished by interpolating between the 16 explicit entries to create fifteen intermediate palette entries between each pair.

If you’re interested in lighting effects then I suggest you take a look at the Wiki

You can pick up a copy my code from GitHub – https://github.com/jfrmilner/Arduino-CheerLights

Here’s a quick demo of it in action

Thanks for reading and good luck with setting up your tree

Merry Christmas!

jfrmilner