Monday, November 3, 2014

Preparing for 2015 after school computer club

Over the past 2 years I have done a Code Club at my kids school using Scratch and last year included a bit of Arduino. Now in the UK computing is part of the school curriculum so the Code Club learning is now done in school time meaning there is not need for it to be done after school.
With this in mind for 2015 I've decided to ramp up the difficulty and go Arduino all the way with a robot course.

This time limited to 10 kids working in pairs as the complexity is higher and the projects will most likely be done over multiple weeks.

This will give the ability to build everything from a pre-programmed robot to a line following robot or an object avoidance robot. Also included an infrared sensor and remote so the kids can make a remote control robot.

All going well the kids will also be able to decorate their robots with unique bodies to make them more exciting.

In addition to the parts below I also have 36 rechargeable AA batteries for the club.

I'm looking forward to January already.

Below are the list of parts I plans to have for the 8-9 week club. 5 kits

ItemeBay LinkPriceQTYTotal
Robot Deck£7.485£37.40
DC Motor H-Bridge£1.555£7.75
Arduino Nano compatible£2.895£14.45
5 x Breadboard 400 tie£9.491£9.49
Line following sensor£1.195£5.95
10 x Ultra Sonic sensor£8.991£8.99
Infrared sensor + Remote£1.355£6.75
Wires M-M£1.991£1.99
Wires M-F£1.991£1.99
Wires F-F£2.241£2.24
Keypad 4x4£0.995£4.95

Tuesday, October 14, 2014

5th Egham Raspberry Jam - 5th October - Report

A year after the 4th Egham Raspberry Jam the 5th Jam was held.
A bit of fun getting it organised but in the end it was really worth it.

I put the list in Eventbrite and the Raspberry Pi Forum with a month to go and began tweeting and spreading the word.

With such a long gap between Egham Jams I was wondering if people would turn up.

On the day about 40 people came which was fantastic and there was a brilliant variety of projects on show.

Everything from home made conductive paint being used to add glowing eyes to Halloween pictures to 3D printers controlled by Raspberry Pi.
There were (count them) 4 robotic arms. A scalextric controlled from Scratch. A section of model train train controlled using the DCC protocol from RISC OS.
A Thermal printer that gave you a crossword, word search or Sudoku at the touch of a button and a nice big robot that looked like it could do some serious moving.

Also Stephen Cornes did a fantastic timelapse video of the day. For some reason I cannot embed it here. Not sure why but the link is below.

Roll on the next Egham Raspberry Jam.

Below are some of the pictures from the day.

Raspberry Pi model B+ composite/RCA video/audio adapter

With the release of the Raspberry Pi model B+ the previous arrangement from the A/B of having a 3.5mm stereo audio jack and an RCA for video has been changed to a single 3.5mm jack that includes stereo audio and the composite video.

I kept reading online that the arrangement was the same and the iPod and also the Zune so there are loads of cheap cables and adapters out there that work.

After lots of searching I found a number of cables that looked like they would work, but since they were all cheap no specifications for the wiring were listed.

From the Schematic ( the arrangement needed from tip to base is.

Tip - Audio Left
Band 1 - Audio Right
Band 2 - Ground
Base - Composite Video

It doesn't really matter if the audio connections are reversed as you could just swap the leads, but getting the ground or the composite in the wrong position means no video would be output and in the case of ground no audio also.

So, I went mad and took the plunge to buy a £2.00 adapter from eBay and see if it works.

Here it is plugged into the Raspberry Pi Model B+

RCA/Composite video adapter for Raspberry Pi B+

It covers the HDMI port which isn't a problem. As, when I'm using composite I'm not using HDMI.

I am delighted to say it works perfectly. The wiring is correct. I plugged it into a television and up popped the display from my RetroPie install. Playing Double Dragon on the big screen.

Double Dragon played over composite with stereo audio
The price was only for the adapter, but I had an RCA cable from my kids Karaoke machine, but if you don't have one handy then this one for £1.99 also from eBay would work.

Meaning for £4.00 all in you  have an adaptor for B+ to connect to composite and analogue audio as well as the required connecting cable.

I like that it is a 2 piece configuration as a composite cable can have other uses.  I spliced one before to work with an Arduino and the TV-out Library.

Gathering more bits.

Saturday, September 20, 2014

Setting up RetroPie on Raspberry Pi with USB gamepad

Every since it started I've watch the development with RetroPie a Raspberry Pi image that includes a number of console/computer emulators optimised for the Raspberry Pi.

I'm not a major gamer but sometimes a bit of nostalgia is worthwhile so I decided to install RetroPie

A few things to note. RetroPie is built on Raspbian, so the foundation is solid.
You can even use raspi-config to expand the SD partitions and set overclocking and GPU memory split.

The easiest way to use RetroPie is to download the pre-made image from the website

Use your tool of choice to burn the SD card.  I did it on Windows 7 so I used Win32DiskImager

Once install in the Pi and all cables attached I added power.
Up comes the lovel RetroPie splash screen and it boots straight into Emulation Station which is a great front end giving access to the emulators where roms are available.
Splash Screen

On first boot Emulation Station prompts you to configure your controller/gamepad to operate the menus in Emulation Station. This confused me a little as I thought it was asking to configure the gamepad for the games.

But once I got a few roms on it became clear the this setup was only for Emulation Station and for that it worked perfectly.

I quit Emulation Station and ran raspi-config to expand the partition, split the memory 256MB/256MB as I read the PSX emulator may need it and also to do some minor over clocking (it can't hurt to have a bit more speed)

Then to get RetroPie setup correctly.

From the home directory do:

cd RetroPie-Setup
sudo ./

This brings up the RetroPie configuration menu.
I selected Option 1 to do the Binaries-based INSTALLATION.
RetroPie comes with the bare minimum to get going in the image so you have to do this to get the other emulators.
As expected this can take a bit of time. 
Main Menu for retropie_setup

Once this finished I then selected option 3. SETUP (only if you already have run one of the installations above)

This is where you get the extra options to customize RetroPie.
If you are building a cabinet or want that genuine old school feeling of using original controllers there are a number of tools in the SETUP menu to make it a lot easier.  I was not interested so the only thing I enabled here is 310 SAMBA ROM Shares.
This enables SAMBA shares so you can drag and drop files from your computer to the Raspberry Pi making it much easier to get ROMs into RetroPie

SETUP menu 
At this stage RetroPie has all the emulators installed and the menus works but there are no ROMs and the games (once ROMs are copied across) will only work with the keyboard.

I mentioned I enabled SAMBA above so I could copy ROMs across. In the end I didn't use this. I used WinSCP which allows you to login to the Pi and drag and drop files from your computer onto the Pi in a nice GUI tool 

You have to copy the ROMs to the relevant folders for the different emulators.
Really simple. Reminded me of the olf Windows 3.11 FileManager with 2 panes to drag and drop between.

Last item was to get the gamepad working with the games and not just the Emulation Station menu.
This took a bit of hunting online as I have a feeling the method may have changed in the last update of RetroPie to v2.3.

In the end the method I found that work for me with my gamepad was from a reply on the following webpage. from user flipbug

sudo chown pi /opt/retropie/configs/all/retroarch.cfg

cd /opt/retropie/emulators/RetroArch/installdir/bin

sudo ./retroarch-joyconfig -j 0 >> /opt/retropie/configs/all/retroarch.cfg

The first command gives the user pi the right to change the retroarch.cfg file.
The second goes to the directory where the retroarch-joyconfig command is located
The final command rund retroarch-config and outputs its results to retroarch.cfg 

I found the tool to be a bit sensitive when dealing with the analog sticks so ended up having to do it a few times.

In case my configuration matches some elses here is the configuration I use.

input_player1_joypad_index = "0"
input_player1_b_btn = "2"
input_player1_y_btn = "0"
input_player1_select_btn = "8"
input_player1_start_btn = "9"
input_player1_up_btn = "h0up"
input_player1_down_btn = "h0down"
input_player1_left_btn = "h0left"
input_player1_right_btn = "h0right"
input_player1_a_btn = "3"
input_player1_x_btn = "1"
input_player1_l_btn = "4"
input_player1_r_btn = "6"
input_player1_l2_btn = "5"
input_player1_r2_btn = "7"
input_player1_l3_btn = "10"
input_player1_r3_btn = "11"
#input_player1_r3_axis = "+3"
input_player1_l_x_plus_axis = "+0"
input_player1_l_x_minus_axis = "-0"
input_player1_l_y_plus_axis = "+1"
input_player1_l_y_minus_axis = "-1"
input_player1_r_x_plus_axis = "+3"
input_player1_r_x_minus_axis = "-3"
input_player1_r_y_plus_axis = "+2"
input_player1_r_y_minus_axis = "-2"

It was a bit of a trial and error session getting RetroPie working but in the end I have a fantastic emulator system set up on a model B+ that looks well and performs brilliantly.  I am really impressed at how well it runs PSX games as from a raw CPU power I always though the PSX and the Raspberry Pi would be quite similar.

Now all I have to do is actually be better at the games to fully enjoy them.

Thursday, July 3, 2014

Paper Marble Run - something different no electronics

I'm a big fan of encouraging creativity with low cost resources. I previously hacked a £6.00 remote control car to control it from a Raspberry Pi using Scratch and used a low cost eBay robot vehicle deck and wheels with a clone Arduino Pro Mini (all in for <£15.00).

Well some people aren't that into electronics and programming but are still looking for creative solutions.

I came across Marble Runs/Roller Coasters that you can buy and did a search online and found you can make you own from copper wire and also from stiff paper (200gsm). Never one to miss a chance to try something new I looked at the videos and made up templates for the paper marble run sections and began construction

After a fair few iterations and a lot of really small pieces of tape to put the bits together I finally had a set of templates that can be used to make a paper marble run.

This is the first video of the marble run. I really like the funnel and also that the marble comes off the end just below the funnel and because the moment is right it drops into the next channel/track section.

There is a fair bit of work in getting it stable and modifying the length of the straights and the curves so they work.  This is real tinkerer construction as the parts are not perfect and the design is evolving so regularly pieces need to be shortened, or bits added or the angle of the track needs to be modified to make it work.
Great fun going through all of this and learning about the properties of the paper, how strong the tape is and how to keep the marble going.

I then extended the run another bit. I like this view. There is something pleasing to me about the curves on the left section.

Finally I added a bumpy track and also a 'ladder' (no idea if that's it's name but it's the name I use) and more curves. This made the whole think a lot taller and works well. It does kind of unbalance the look and style of the overall marble run, so I think it is less pleasing to the eye than the earlier version.  Feels like when a skyscraper adds a large antenna to the top to officially be taller.

Here's the final video of the current Marble Run.

Overall I'm happy with the results and plan to make more runs.  A nice way to spend an afternoon/evening being creative.

Sunday, April 6, 2014

HC-06 Bluetooth Slave Only

I bought a Bluetooth adaptor from eBay a while back and configured it allow me to login to the Raspberry Pi over Bluetooth.
As part of this I changed some of the settings on the adaptor and like a proper hacker didn't write down the changes anywhere and then lost my code when the Raspberry Pi SD got corrupted and I installed Lubuntu on my netbook (was XP).

After doing a lot of searching online I found details for the HC-05 and how to reset it by setting the Key pin HIGH and putting it into command mode.

After about 5 hours of messing with the adaptor and even noting the Key breadboard pin wasn't connect to the Key pin on the board, so shorted the pads on the back of the board. Then desoldered again

Nothing worked.

Then checked if what I really had was a HC-06. The Slave only version of the HC-05 board and guess what it is an HC-06 board and so the Key HIGH method doesn't work.

Note the little transistor near the header
Haven't seen this on any of the HC-05 modules
Also, on the back of the board there are 2 sets of pads not populated.

But from reading the following Google DOC ( discovered you can reset the HC-06 by setting PIN 11 to LOW on the module.
I did this, cycled the power and now I could connect at 9600.  All good.

I downloaded the Sketch from here:
And it worked.

So, no Master mode (cannot initiate pairing) but it's now working so I can have some proper fun with it.

Sunday, February 23, 2014

Arduino Compatible robot for £15

I was looking for a low cost way of building a vehicle controlled by an Arduino or Raspberry Pi and eBay once again came up with the solutions.

1 x Smart Robot Car Chassis Kit  - £7.60
1 x L298N - £1.86
1 x Arduino Compatible Pro Mini - £2.53

Total Cost: £11.99

The Smart Robot Chassis comes with 2 motors and wheels.  It comes with the encoding wheels for optical encoder to measure rotation, but without the electronics.
All the parts with chassis. 

The L298N is a Motor Driver Module
That's it on the right next to the battery pack

While the Pro Mini is a small Arduino compatible board that I previously blogged about programming ( and soldering the headers (

You need a USB to serial adaptor to program it. For this adaptor you have to solder a pin to the DTR and then attach that to the RST line on the Pro Mini when programming.

I built the Chassis and attached the L298N
All the parts

Bits for the front wheel mounting
Screw the spacers to the chassis

Attach the swivel wheel to the spacers.
Note nuts not in original picture

Parts for motor/wheel mount

Use small screws to attach pillars to chassis

Parts for connecting motors

Screw motor to the outside of the pillars.
Note: make sure to have motor connectors on the inside
for easy cable management

Add the encoder wheels if you want and the actual wheels

See in front of batter holder are the two holes where
the battery holder will be bolted to.
Use 2 of the slightly longer bolts for this.

All finished.  Still needed to solder the wires to the motors.

The L298N is then wired.

+ Battery to VCC and 5V on the L298Nand RAW on the Pro Mini. The L298N appears to be OK with 6V going to the 5V line. And the Pro Mini doesn't complain about the 6V from the batteries either.
As always connect all the GNDs together

Then for each motor connect Out1 and Out2 to one Motor and Out3 and Out4 to the other motor. Depending on which way around you do the connection will decide which way the motors spins, so if this is wrong you can either swap the wires or modify the code.

Then for control from the Pro Mini I connected

IN1 to 3
IN2 to 5
IN3 to 9
IN4 to 10

The eagle eyed will have noticed these are 4 of the PWM lines so in the future I can enable speed control by driving using PWM rather than digital.

Uploaded the following Sketch tot he Pro Mini and let it rip - see video at the bottom

// motor driver using PWM

int lb = 3;
int lf = 5;
int rb = 10;
int rf = 9;

void setup() {
  // put your setup code here, to run once:

  pinMode(lb, OUTPUT); 
  pinMode(lf, OUTPUT); 
  pinMode(rb, OUTPUT); 
  pinMode(rf, OUTPUT); 
  digitalWrite (lb, LOW);
  digitalWrite (lf, LOW);
  digitalWrite (rb, LOW);
  digitalWrite (rf, LOW);


void loop() {
  // put your main code here, to run repeatedly: 
    digitalWrite (lf, HIGH);
    digitalWrite (lb, LOW);
    digitalWrite (rf, HIGH);
    digitalWrite (rb, LOW);


    digitalWrite (lf, LOW);
    digitalWrite (lb, LOW);
    digitalWrite (rf, LOW);
    digitalWrite (rb, LOW);


    digitalWrite (lf, LOW);
    digitalWrite (lb, HIGH);
    digitalWrite (rf, HIGH);
    digitalWrite (rb, LOW);


    digitalWrite (lf, HIGH);
    digitalWrite (lb, LOW);
    digitalWrite (rf, HIGH);
    digitalWrite (rb, LOW);


    digitalWrite (lf, HIGH);
    digitalWrite (lb, LOW);
    digitalWrite (rf, LOW);
    digitalWrite (rb, HIGH);


All worked well.
Next I need to put in place a way of controlling it remotely.
The adventure continues.

Note: This chassis and L298N should also work with a Raspberry Pi. Need to be more careful with the power and a few other bits.