All posts by admin

Raspberry Pi Networking Files

More for my reference, as I keep forgetting the files – these are the files you need to edit when connecting to a network – which I have had to do lately when driving the car around work.

/etc/network/interfaces

In the interfaces file, I have set a static IP of 192.168.0.24

auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface wlan0 inet static
address 192.168.0.24
netmask 255.255.255.0
gateway 192.168.0.1
wpa-ssid “NETWORK-NAME”
wpa-psk “NETWORK-KEY”

 

/etc/wpa_supplicant/wpa_supplicant.conf

In the wpa_supplicant.conf file, multiple networks settings can be specified, I added my work network in here too, but had to use the field ‘scan_ssid=1′ to indicate it was a hidden network, and put the network name and key in as normal. When you fill in the form to connect to a network in the WiFi Config application, it adds an entry here with your entered data – so a good place to look if you mistyped a value. After returning home, I found that my home network had ‘disabled=1′, and it wouldn’t automatically connect. Without that line, it connects automatically.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid=”NETWORK-NAME”
psk=”NETWORK-KEY”
proto=RSN
key_mgmt=WPA-PSK
pairwise=TKIP
group=TKIP WEP104 WEP40
auth_alg=OPEN
}

 

Matt

Raspberry Pi Endeavors 8 – Headlights and New Interface

Finally got the 20,000 mcd (micro candles?) super bright white LEDs from eBay, and attached them to the solder board in two sets of 3 LEDs. I have wired these up to seperate GPIO pins for now, in case I want to control the left / right headlights separately - but might change this as I’m rapidly running out of GPIO pins.

Headlights on Pi Car

 

I have also got round to redesigning the UI, which previously was all stock HTML buttons, stock jquery slider etc. Designed a few buttons on Fireworks, got some JavaScript to make the hazard warning lights button flash when they are on using setInterval and setTimeout (similar to sleep();).

Updated UI

Updated UI, with headlights on

Matt

Raspberry Pi Endeavors 7 – Hardware Parts List

I started off this project wanting to use the Mr.Basic 4wd microcontroller chassis, but after 2 bad experiences with them having so much resistance that they couldn’t turn their wheels, moved to a slightly beefier 4 motor chassis.  I got both a clear and black acrylic set of these from eBay (China), and have found them both to be of a much higher quality.

Parts list for my project:

Raspberry Pi

Funnily enough, you will need a Raspberry Pi for this. Get one from RS electronics / Amazon / eBay etc. About £25

Raspberry Pi

Raspberry Pi case

This “Environmentally Shell Kit Box For Raspberry Pi” case from oig.buy on ebay is the same style as the clear chassis I got, and provides very easy access to all parts of the Pi whilst protecting the top and bottom. Around £3

Pi Case

“Environmentally Shell Kit Box For Raspberry Pi” – eBay

1A micro USB charging cable

Good for powering the Pi or recharging the mobile phone battery pack that powers the Pi. I picked some up on eBay for £4.50.

Micro USB Charger

 

Webcam

I picked up a couple of Logitech B910′s from Scan’s eBay store for £45 a pop, after using an old Microsoft lifecam, which worked fine, but the quality wasn’t so great, but you can pick them up for about £6.

Hello Kitty Webcam

The Hello Kitty webcam that Nick favoured

 

USB WiFi adapter

Eximax make great USB WiFi adapters that work natively on Mac and Linux (as well as Windows), and we found these to be awesome – as they just worked. It looks like Edimax recently just released a new black version, which I picked up for £15 on eBay. I also got a white, fairly new one that was a dongle plus antenna (all in one), and Nick used a white just antenna model, and all 3 models have been brilliant.

edimax USB wifi

 

12000 mAh mobile phone battery charger

I bought a couple of 12000 mAh mobile phone backup battery chargers to power my Pi when it goes mobile, and they last for somewhere near 8 hours. They are charged by a mini/micro USB cable, and output 1 and 2 amps over USB. Each cost around £17, and came with many little adapters to charge a variety of different phones, including micro USB for the Piberry Ras.

Mobile Charger

 

 

Electronic Components

4wd chassis

Around the £20 mark from China, I got 2 x 4WD, 4 motor chassis. [Clear one] [Black one]

Clear Chassis

Clear Chassis

Black Chassis

Black Chassis

Raspberry Pi Cobbler GPIO Super Start Kit from 4tronix_uk’s eBay store.

Including a huge breadboard, Adafruit cobbler cable and header, switches, resistors, LEDs and jumpers, the Cobbler Super Starter Kit was very useful starter kit full of essentials for messing around with the GPIO pins, and at £22, didn’t break the bank, and no soldering was required.

Cobbler starter kit

Raspberry Pi Cobbler

Including cable and header to extend the GPIO pins of the Pi to the breadboard, very good one made by Adafruit, although others are available such as this split one by Mallinson. I have one of each, but am yet to use the Mallinson one.

Mallinson connector

Mallinson GPIO Connector. Like Adafruit’s, but split at the end.

Breadboard

A 400 point breadboard is sufficient for the cobbler and motor chip.

 

Male to male jumper cables

I got a pack of 65 in my super starter kit, plus more from Maplin. Could make them yourself with bits of wire, but its handy to have the jumpers for quick prototyping.

 

LEDs and resistors

Handy for troubleshooting and emergency lights. I used some 20,000MCD super bright blue LEDs for my emergency lights, with 330 Ohm resistors, but they also seem fine without resistors, and a lot brighter. Waiting on some super bright whites for my headlights.

LEDs

 

L293D motor control chip

I just put the motor chip straight onto the breadboard, straddling the central divide.  They cost about £3 a pop, and one chip can control two separate (sets of) motors, at different speeds, if you have two pulse width modulation outputs on the device (for the Pi, you would have to do one in software).

L239D Chip

Red and black wire

Wire is always helpful with electronics.

8 AA battery holder

To provide power for the motors

8 AA battery holder

 

8 x rechargeable AA batteries

I already had a set of 2600 mAh ‘hama’ AA batteries (cells) and a charger that I got from 7dayshop many moons ago. I managed to find another very similar set on eBay for £13. These high capacity AA cells have kept my Pi driving on and off for a week now, and kept my Xbox 360 controller going for months of light use. Heavily recommend getting rechargeables and a charger – saves the environment and you buying tons of batteries.

Hama battery charger

Other Tools

Pretty handy to have:

  • Wire cutters
  • Wire strippers
  • Pliers
  • Screwdrivers
  • Tape/sticky velcro
  • Multimeter
  • Soldering Iron, solder, safety glasses etc

 

Raspberry Pi Endeavors 6 – Power!

Having only 6 AA batteries for the 4 motors wasn’t enough, and even with my super friction-reducing sellotape, the car struggled to turn on the spot, with 1 or 2 engines  normally stalling. A maximum of 9v was being provided for the 4 6v motors (connected in parallel), resulting in around 2 volts per motor (max) at a quick guess. I grabbed an 8 battery holder from Maplin, hooked this up and the car is much happier now – can turn on the spot well, and goes a bit faster too.

Hazard Lights on

Pi Car 01 with hazard warning lights flashing

As well as my emergency lighting system (ELS), I made a tiny script to simulate hazard warning lights, for when the car is just pulled over at the side of a room. The interface to control the vehicle is very simple – yet functional! When time allows, I will break out the CSS and get it looking a bit fancier.

Pi Car 01 Interface

Pi Car 01 Interface including view from the onboard camera looking out of its garage at the parking marks (sellotape on the floor) and a captivated audience

The two fields at the bottom show the JavaScript and the driving shell script reporting the key down (e.g LEFT), and the key up (all off). This is helpful for diagnosing issues such as when the off instruction arrives before the on one, and so the car starts driving and doesn’t stop. This may be fixable by getting the page to constantly tell the Pi that ‘up’ is held down, and then if the Pi notices an absence of these instructions, it will know to stop.

Matt

Raspberry Pi Endeavors 5 – Building The Car

Unfortunately both Mr.Basic 4wd chassis’ that I got had such high resistance in them, they could barely spin their own wheels, let alone drive along the floor. I got these sent back and went for a larger vehicle made from 2 pieces of acrylic and 4 motors connected directly to 4 wheels, that I picked up from ebay for about £20 [from China].

clear chassis photo

I then followed Adafruit’s guide: Lesson 9. Controlling a DC Motor. This is a great guide to power one motor – to power another, just connect another 2 input wires symmetrically on the other side, same with the outputs to the motor. You also must connect the PWM pin 18 to the EN2 [right hand side PWM pin on the chip] to allow the Pi to control the speed of both motors. If you wanted them to go different speeds, you would have to use software to emulate a PWM pin, and then connect that to the chip – as the Pi only has one PWM pin.

L293D Chip

Picture: Adafruit Learning System (Lesson 9 DC Motor)

I then used a Raspberry Pi Cobbler from Adafruit to gain easy access to all of the Pi’s GPIO pins on a breadboard. On the breadboard, I placed the cobbler, L293D motor chip, and connected them both up with jumper wires, adding the batteries for the motors to the positive and negative rails. [Follow Adafruit’s guide!]

Wiring diagram

Picture: Adafruit Learning System (Lesson 9 DC Motor)

So now the Pi is connected to the breadboard, on which is a motor chip that controls the motors using inputs from the GPIO pins. If your batteries are charged [like mine weren't first time - diagnosed by putting an LED on the motor wires, and it glowing very dimly], you are ready to start asking the motor chip to power the motors. Again, follow the Adafruit instructions that get you putting e.g pin 4 high, which signals the chip to drive the left motor in one direction. You must also set the PWM (value of 0-1024 I believe) that controls the speed of the motor. I use at least 500, but normally closer to 1000 – as the if it is to low, the motors ‘stall’ and wont turn.

All you need now is some software to control it. Me and my housemate use an index.html file hosted on the Pi that calls a bash script whenever a directional key is pressed, then when it is let go, it runs an off script that turns all control pins back to 0. You can also use Python. I used Python to make the script to control the flashing emergency LEDs [superbright blue LEDs].

More soon!

Matt

Generate Many MAC Addresses – Keyboard and Mouse Recorder for Mac

I needed to generate a lot of unique MAC addresses for my virtual machines, and VMware has no function that I can find in vmrun to generate one. However, in the ‘Network Adapter’ settings of any VM, you can pummel ‘Generate MAC Address’ to create new, unique ones. One option was to generate that address, copy and paste it into a text file, and repeat – but I didn’t fancy doing this for however many I’d need (probably hundreds) – so I Googled for a ‘Ghost Mouse’ piece of software – and came across Keyboard and Mouse recorder for Mac by softonic.

 

Great. It recorded my mouse and keyboard inputs of generating, copying, alt-tabbing, pasting, hit enter for a new line. I could also loop this process – but only to a maximum of 10 times without registering. I didn’t fancy pressing the play button whenever it finished (about every minute) so after looking for a command line way to start it (thought I could use a minutely CRON job..) I found no man pages or anything. Therefore I just fired up a new instance of  the application, and got that to click the play button on the first one, and then stop recording after about a minute. Putting this on a 10x loop as well, it will press the play button on the 10x generate loop, 10 times – so generates them in batches of 100. Win.

“Wherever possible, cheat”

Matt

Raspberry Pi – Networking Script Change

Made some modifications to my script – made a function for writing to the file, which saved a lot of reused code, and instead of assuming that it could ping Google if the result wasn’t ‘unknown host www.google.co.uk’ – changed it to detect the words ‘ bytes from’ – from ’64 bytes from x’.

Find the code at: http://www.matthewrobbins.co.uk/files/connectiontest.py

Next up – try and make a script that detects if mjpg streamer is actually broadcasting video – if not, restart the service (this can fix issues that arise if the webcam is plugged in after boot)

Matt

On the BBC News! – Raspberry Pi Cambridge Event

A few weeks ago, I shot up to Cambridge to help out with a Raspberry Pi event at Chesterton Community College where Raspberry Pi founder Eben Upton took great pleasure in announcing that they would be providing 15,000 Raspberry Pi kits to school children in the UK, through a grant from Google.

Me and a Pi

Chatting to a group of primary school children about what the Pi is.

I think this is a fantastic initiative, and the RPi is the perfect, standard, versatile and powerful bit of kit to get people learning real computer modules – from Java and Python programming, use of Unix operating systems and their services, to lower level component control with the GPIO pins and SPI and I2C interfaces. I really do hope that schools adopt the Pi, and get students introduced to programming and real computer science so that they can become interested in the subject area if they wish, and start pursuing cool projects.

Matt

Raspberry Pi Endeavors 4 – Hardware

A week or so ago, I decided to my own version of Google Glass by selotaping the Pi, webcam and Nick’s battery pack to my hat. Here is the result:

Glass Hat

I also received my Mr.Basic 4wd chassis, which I discovered was faulty, after I had built it.

The kit:

Basic Kit

Partially built:

Half built

Built with motors:

Built Mr Basic

It looks like a really promising design, so I have ordered another one from Bizoner in China, they seem quite hard to get hold of around here. Also ordered a slightly larger one for Nick. Pictures to be posted when they arrive!

We also grabbed a couple of RC cars from Argos, and I proceeded to take mine apart to discover what kind of voltage the motors were using etc:

RC Car being held by third hands, being measured by a multimeter

Matt

Raspberry Pi Endeavors 3 – Battery and Other Components

My networking script has only restarted my networking adapter once since I got my new Edimax adapter, the log shows (I save the print statements to a text file now) it tried to ping Google twice, couldn’t, restarted the networking service, then was fine.

Networking restart script showing 1 restart

I also have my webcam displaying a live stream to a website, along with Nick’s too:

The webcams output on a webpage

The webcams output on a webpage

I have also got my Pi running on a mobile 12000mAh phone portable charger, which seems to power it for about 8 hours on its first run. The charger has a 1 and 2 amp output which is useful, and it charged by its own micro USB cable – the same one that I connect to the Pi to power it.

Mobile phone battery charger

Mobile phone battery charger

Also got some superbright LEDs – blue and white – for when our 4wd chassis’ eventually come, as well as some smaller breadboards and some resistors.

Just got an email this morning that Bizoner.com has finally processed our order of 4wd chassis’ so hopefully they will come next week.

Matt