Nerf Gun Shooting Gallery

This is a work in progress as it has turned out to be far more complicated than I thought it would be! I’ve learned a lot about how to design parts for my 3d printer and how to use the laser cutter at Reading Hackspace too though so already winning!

Over the passed few years my friends in the Reading Beer Festival Games Team have been talking about building a shooting gallery using Nerf guns to keep things nice and safe.  This year I offered to give it a go and the spec quickly escalated/became more fun!

As I’m building this more for the team than the players it needs to be easy for them to use while dealing with the festival punters who are typically moderately inebriated…  Resetting the board easily, keeping track of the score and setting up for the next game seems like the three things to concentrate on.

The game works, or will work, as follows:

  1. Press the start button, the counter should reset along with the targets
  2. Give the player a Nerf gun and a clip with 12 darts
  3. The player shoots the targets, which reset once hit, and the score is tallied

Having a bunch of clips that have 12 darts and a button that resets the game means resetting should be a lot easier than having to do it manually so that’s easy win, enter the Arduino!

I bought a bunch of hobby servos of eBay to use to reset the targets and designed a hinge with a magnet to hold up the target and a switch of some kind to track when a target is hit.

I’ve got a design working for the hinge but need to replicate it for all five targets.  More details once it’s complete but here’s an incredibly satisfying video of the mechanism in action!

DeskCycle Stats Update

A long while back now I bought a DeskCycle to use at work to help my body stay more active whilst at my desk, standing desks aren’t an option so this seemed ideal.  I’m also a massive geek, which is a massive surprise I know, so I built a PC interface for it using an Arduino and a desktop display using a Unity application.  I’ve been using this for the last year and a half according to the CSV logs.

The DeskCycle has developed a squeel at certain speeds so I though I’d throw a tweet towards the manufacturers to ask how to oil it and to quote my distance too, I used a simple powershell script to get a CSV of the total distance for each day then threw it into Excel.

deskcycle-distance

As of about half an hour ago I’ve cycled a virtual 3159 miles at an average 9.46MPH.  Damn I need to add an odometer to my display!

The powershell script is as follows for those interested, it gets a list of all CSVs, gets the last line from each and spits it out into a new file. Very handy!

$alldata = "DateTime,Speed (MPH),Cadence (RPM),Distance (Miles),Duration (HH:MM:SS)`r`n"
Get-ChildItem -Filter *.csv | 
Foreach-Object {
 $content = Get-Content $_.FullName -tail 1
 $alldata += $content + "`r`n"
}
$alldata | Out-File alldata.csv

1st Gen Roomba Overview

Before I can rebuild Bumblebee, my 1st generation Roomba, I need to figure out how he works.  I’m going to split this into three sections; Power , motors and sensors.  I’m going to cover how to interface with each of these in future posts.

Power

This was simple enough, I charged the battery and put a multimeter across the terminals, the battery showed 16v across the terminals.

Motors

A quick count shows that there are five motors.  One for each wheel, one for the brush motor, one for the side sweeper and one for the vacuum.  From the fact they all seem to have a black and red wire going into them and from the age of the device I took an educated guess and assumed they are simple DC motors.  In order to test this theory I took the probes from my voltmeter, plugged them into my bench supply and poked at the motor terminals with the voltage and current limit set low.  With this simple setup I was able to give the motors different voltages and easily reverse the polarity, sure enough the speed changed with voltage and direction changed with polarity.  The wheel motors will need to run in either direction but the other three only need to run in one direction.

Sensors

There turned out to be a lot more sensors than I realised and it’s quite a packed little robot!  The sensors fall into two categories; IR sensors and switches.  The microswitches are on either wheel and the caster wheel at the front, it looks like all three are currently wired to the same header so the robot knows only that one wheel is up and not which.  The rest of the sensors are a bit more convoluted.

Wheel Encoders

The drive wheels have an encoder each with four wires going in, once I’d opened one up it turned out that they are comprised of an IR LED and a light dependent resistor.  I checked to see if they were IR by giving them just over a volt and there was no light, I then got out my phone camera and saw the telltale purple glow.  Shortly after this I realised the error of my ways as the LED went out, without a current limiting resistor I burnt it out!  Thankfully the LDR worked with visible light so I ended up replacing the LEDs on both sides with red ones.

Cliff Sensors

Along the underside of the bumper there appears to be four cliff sensors, again IR LED/LDR combos which in this configuration are known as IR distance sensors.  I’ve used these long ago when I built a PIC16F84 based robot at college so these aren’t a mystery.  The resistance of the LDR varies depending on how much light bounces back, you need to calibrate them in your code or circuit but they are simple enough.

Wall Sensor

This is an IR distance sensor on the right hand side of the bumper, it works the same as the distance sensor.

Bumper

This one confused me for a while as I couldn’t see any switches on the end of the arms of the bumper, I ended up taking the bumper out which required removal of the logic board and the penny dropped.  At either end of the logic board there is an IR/LDR pair and when the bumper is hit the light level changes.  I wondered to start with why they didn’t just use a switch but the video linked at the top of this page explained it all.  A switch would be hammered that often it would fail in no time, the design of the bumper mount also cleans the area between the LED/LDR too which is handy.

IR “Eye”

On the top of the bumper at the front is a 360 degree lens which directs light on to an IR sensor of some kind, I’ve not dug deeper in to this one yet.  I believe it acts like an IR receiver for a remote in a TV as it is used with the Roomba’s virtual wall.  If the robot detects the IR code that is being sent out by the virtual wall it acts as though it hit a solid object, this is useful for preventing your hoover from escaping.

 

I’ll cover how I use each of the above in upcoming articles for each part above.

Project Bumblebee

Bumblebee?

 

Bumblebee is my Roomba, so named as long ago he lost his voice.  About a year ago his logic board started playing up and though he was still able to clean, at the end of each cleaning cycle he wouldn’t go into standby and his battery would drain in no time.  At that point he stopped actively gathering dust and started doing it passively as he sat behind my sofa.

Bumblebeee MK2

Since a kid I’ve always wanted to build a robot and figured I’d kill two birds with one stone and use Bumblebee as a chassis for a mobile robot, he already is one after all, but also have the aim of returning his base functionality of being a robot hoover.

The Plan

Bumblebee is an original model Roomba from 2002, he was a gift from a friend who knew I loved to tinker and gave me him broken.  If I could fix him I could keep him, thankfully an easy fix as the battery was dead.  This model is very simple in it’s function and behaviour, it has no mapping capability, no dock or wireless control.  It apparently can be controlled using IR but I’ve never had a remote.  It also lacks the diagnostics port that the newer models have that make hacking a Roomba really easy now so this is going to be a bit trickier, a lot more education and most importantly more fun!

The parts I’ve used to partially resurrect him are a Arduino Leonardo and an Adafruit Motor Controller Shield.  I’ve also a Raspberry Pi 3 to add into the mix, for Wifi control and more processor intensive tasks.  The idea is to use the two to thier strengths; the Arduino will control the motors and read the sensors allowing for real time override in case of collision and the Pi will be able to sit back and give out the orders.  It’s a classic split for mobile robots but thankfully very cheap to implement now.

Current State

As I said I’ve been working on this for a while, I’ve a load of notes to type up and a loads of “learning experiences” to share.  Mostly when I made a rookie error and burnt out one of the motor controllers…  I’ve now got the motors under control over serial, I’ve also a simple console application that lets me drive him around and toggling the sweeper/vacuum fans on, here’s a video of him in action:

Next Steps

My next item to look at is getting sensor data into the Arduino, first up the encoders.  Encoders are devices that allow you to measure the movement of a wheel, you’ve likely used a rotary encoder on a hifi to control the volume, and the Roomba has one is each wheel.  Right now I can control how much power goes to each wheel but because of differences in the state of the gearboxes, carpet and who knows what other factors, the wheels spin at different speeds.  By measuring the speed from the encoders we can compensate for this, we can also use them to calculate the distance we’ve travelled.

After that is the rest of the sensors, those I’ve found so far are;

  1. Cliff sensors – these are under the bumper and detect drops to prevent him falling down stairs, I think there are four of them and they appear to be IR distance sensors
  2. Bumper sensors – these detect collisions, I think there is one at either end of the bumper so I’ll know if I’ve hit something to the left or right
  3. Wall sensor – another IR distance sensor mounted on the right of the bumper, this allows for wall following behaviour
  4. Wheel up/down switches – One on each of the drive wheels and one on the caster at the front.  They detect if the wheels are up or down and can be handy for detecting when we’ve beached ourselves.
  5. Wheel encoders – these were IR LEDs and a light dependant resistor.  I blew one of the LEDs by accident so replaced them both with red LEDs.
  6. Beacon IR Reicever – Not sure how this works yet, it’s a 360 lens on the top that receives a beam from the virtual wall, a device you place by your door to stop him escaping, I’m hoping to add more sensors to make this redundant.
  7. Buttons – there are three buttons for room size to start different cleaning cycles.  They could be useful though I may not bother with them.

Once I’ve all the sensors connected I’ll be able to hook up the Raspberry Pi to start working on reproducing his original behaviour.  After that I’ll be able to build up his capabilities over time and add a load of new ones too.  I’m not intending this just to be a hoover but a mobile robot platform that happens to be able to hoover.

If you’ve got this far, kudos!  That’s it for now, more posts will trickle out as i write up my old notes.  I’m going to carry on having fun building things and write posts in the order they happened.  Hopefully I’ll catch up fairly quickly!

Dual USB Cable for Chromecast Audio

Not long after I made the switch to Android Google announced the Chromecast Audio, a cheap little device that plugs into speakers you already own and gives you the ability to stream music from your phone or browser.  As they also include synchronising of the speakers so you can cast to multiple rooms I figured I’d give them a go.  I bought one for my living room and one to plug into a portable set of speakers that I can move around easily. The other benefit is that as it’s all controlled from my phone I can use the music app on my Pebble to change tracks and pause it without getting my phone out of my pocket or while it’s left on charge.  Daft, but fun noneless!

The only problem is that though the portable speakers have an internal battery and charge from USB, they don’t have a USB output which would have made them an ideal match.  I did try hacking in a USB cable to the voltage regultor inside the speakers but that resulted in a lot of noise and hiss on the line and I couldn’t quite get to the bottom of why.  At some point I’d quite like to make a set of portable speakers to my spec so figured I’d cut my losses and find a middle ground.

POC hack to see if the voltage regultator could power the speaker and Chromecast at the same time.  It could but not without a lot of noise.
POC hack to see if the voltage regultator could power the speaker and Chromecast at the same time. It could but not without a lot of noise.

This is the portable speaker in question, an ADX Fusion bluetooth speaker that also has an AUX input, to keep it topped up and to power the Chromecast I needed two USB cables which was a bit more of a faff than I can be bothered with.  Time to break out the soldering iron and make a cable.

I wanted to have the Chromecast almost inline with the USB cable so I plugged them in together and cut the two USB cables at the same point.  I then spliced them together and strengthened them with a bit of shrinkwrap and some electrical tape.  I also cable tied the two output cables together for even more strength and finally cable tied the headphone cable together too to tidy things up.

A simple hack to get me going again but makes the speaker a bit more convenient.

Arduino Speedometer for the DeskCycle

All my previous jobs were based in the town I live in so I used to be able to cycle to work, with my current job it’s far enough away I can’t reasonably cycle to work.  As such, and as the company is jokingly referred to as the “Cake-apult” for the amount of cake we seem to go through, my weight has inevitably increased.  To try and remedy this I’ve recently purchased a DeskCycle.  I would like to give a walking desk a go at some point but this seems a far easier solution and as sitting down for extended periods is linked to many problems I figured it worth a go.

It arrived earlier this week and I managed to cycle while sat at my desk for over two hours each day, I felt knackered by the end of it so it was certainly having an effect!  The only issue for me is the speedo.  The creators of DeskCycle designed the device such that the speedo is accurate when the resistance is set to maximum, this results in the speed and calories calculated too high if you have the resistance set lower.  They provide a calorie calculator to provide a more accurate set of results once you’ve punched in the values your speedo provides.

On to the how;

Looking at the bike it looked like the speedo works in the same way to the speedo on my road bike, a switch is closed once per revolution of the flywheel.  I connected my multimeter to it in continuity tester mode and it confirmed my theory.  As the bike uses a 3.5mm headphone jack for a cable it was simple enough to make a cable to connect to the header on my Arduino.

DeskCycle/Arduino Speedo Cable
DeskCycle/Arduino Speedo Cable

The cable has a 3.5mm headphone jack at one end, tip and ground in use, and a pair of header pins at the other.  Connected to the Arduino via a bit of breadboard, I’ve connected using pin 7 in pullup mode with the other end of the switch connected to ground.

DeskCycle/Arduino Speedo Pinout
DeskCycle/Arduino Speedo Pinout

Once connected I’ve followed the timer tutorial provided by Amanda Ghassaei to calculate the RPM by counting the interval between revolutions.  One thing I learned is that the millis() function uses timer0 internally so if you want to use that function and a timer interrupt then use timer1 or timer2.

The code can be found on github in the dcspeedo repo.

DeskCycle/Arduino Speedo Debug Screenshot

Next up is a simple application that reads the RPM and calculates speed and distance to display it on my PC to start with.  I’m intending to add some cool functions like map integration to do virtual challenges such as Lands End to John O’Groats and similar which should be good for a laugh.

Also, this same code will be the basis of the digital speedo adapter for my Mini so two birds with one stone!  As practice for my Mini speedo, and more practice for stuff for work, I’m going to write it using C# and Unity 5.

Update:  The Unity part is done, more information here.

Dad’s Clock

Work has been mental for a few months so despite doing odds and sods on Hugo and a buttload of work on our illegal fishing project at work (hopefully more on that soon) I’ve not posted anything in a while so thought I’d post about a clock I’m building for my Dad.

My dad’s an engineer, heavy fabrication mostly, designing and building access platforms for the nearby oil refinery for over 40 years and since he drove me school on my first day on his crane he’s been a big influence.

Dad's Crane

As a reference to his engineering heritage and my current work  with satellite data I’m building an Arduino based clock that uses the GPS time signal to set the time and uses a set of voltage panels as the face.  The GPS receiver is the Adafruit Ultimate GPS board and I’m using a DS1307 based board for the real time clock.  The Ultimate GPS board is a bit OTT but it does allow me to receive a time signal indoors, as I only need one signal to get the time rather than the multiple signals needed for a full fix it works quite well.

The code is a work in progress but you’ll find it on my github page.

TaW: Week 12 – ARC Reactor

This weeks thing was built for a friend for the Iron Man inspired dress she has made for Iron Fest.  The ARC reactor is made using 11 superbright 3mm LEDs connected to a pair of AAs.  It is then sewn onto a scrap of denim from an old pair of jeans for a bit of structure and covered in white fabric from an old t-shirt.  The dress was made by Miss Jones herself, including the repulsor glove, the latter using an EL panel left over from one of her Tron routines.  I don’t have a pic of the reactor completed but it works best as part of the outfit after all;

Iron Mo(jo Jones)

The actual structure of the reactor is really simple, I set out the LEDs in the required pattern using blutak then bent the pins so when soldered together the pins themselves form the structure.  This makes for a far lower profile and easier to integrate into the outfit.

TaW 12 - ARC Reactor

Controlling a Syma S107G with an Xbox 360 Controller

As a tie in to my No ‘Air Ambulance Challenge, a sponsored body wax for the local Air Ambulance charity, I’ve decided to upgrade my old project by swapping the RC car out for a Syma S107G.  If you enjoyed this post, please donate a few quid or whatever you can here.  It’s for a very good cause and as it’ll put me through a *lot* of pain you can be sure I’m not asking for my health!

I tried to implement the IR protocol in C# using the .NET Micro Framework for the Netduino but it proved more than a little tricky to get the timing right.  As there are a few implementation out there for the Arduino I decided to stand on the shoulders of giants and build on top of existing code, two in particular.

http://www.kerrywong.com/2012/08/27/reverse-engineering-the-syma-s107g-ir-protocol/
http://abarry.org/s107g-helicopter-control-via-arduino/

One thing worth of note is that my helicopter uses Channel B, as you can see in the comments in my code (heavily based on Kerry Wong’s) it is easy to switch between the two channels.  For the serial control aspect I implemented a similar method as with my Netduino project and in Andrew Barry’s implementation.  For the Xbox 360 Controller interface, I updated my previous application to listen for the trigger for the throttle and the right analogue stick for pitch and yaw.  I had some fun when I got the values backwards and I slammed the copter into a wall.  Thankfully they are built tough to survive kids and geeks alike…

The IR emitter is  a 500Ohm resistor inline with a pair of IR LEDs, connected to Pin3 on the Arduino.  Video demo below;


Xbox 360 controller interface to enable control of a Syma S107G.
Xbox 360 controller interface to enable control of a Syma S107G.

You can find the code here Syma360.

TaW: Week 6 – Arduino Based Syma S107G Tx and Xbox 360 Controller Interface

After the last two TaW items have been less than successful, and as a last minute tie in to the No ‘Air Ambulance Challenge I’ve decided to upgrade one of my old projects.  Rather than an RC car I’ve gone with a Syma S107G 3ch helicopter and standing in for the Netduino is an Arduino.  I had a go at implementing the IR protocol in the .NET Micro Framework but it proved a little tricky.  More information can be found in this post along with a video demo.

Xbox 360 controller interface to enable control of a Syma S107G.
Xbox 360 controller interface to enable control of a Syma S107G.