---

Thursday, July 17, 2014

Raspberry Pi Model B+ Review

CPC very kindly sent me a Raspberry Pi model B+ to try out.

As you can see, there are a few changes when you compare it to the Raspberry Pi Model B in the middle and the model A on the right. This board is a pretty serious upgrade to the Model B while still being very affordable at just £22.87 + VAT (about $40).

Raspberry Pi, models B+, B and A

The most obvious change is that there are now four USB ports rather than the two of the Model B. This is a great improvement and removes the need to have a USB hub connected to the Pi. It means you can have a keyboard, mouse, USB WiFi dongle connected and still have a spare slot for a USB pen drive.

I think that the provision of four USB ports is extremely significant, because it marks out the Raspberry Pi firmly as a real computer and not just another tiny Linux board designed to be used as an embedded controller.

This brings me on to another obvious change. The GPIO port has grown from 2 rows of 13 pins to 2 rows of 20 pins. Many people will never use the GPIO port on a Raspberry Pi, content to just use it as a computer. But if you want to use your Raspberry Pi to control electronics, you now have some more pins to do it with. The additional pins are at one end of the board to maintain compatibility with existing add-on boards.

Another change is the removal of the little-used composite video socket. This allowed you to attach AV monitors of the type used in CCTV to the Raspberry Pi. This connection is still available but supplied as an extra connection on the Audio jack, which is now an AV jack, combining both audio and video.

There are other changes, both cosmetic and improvements to the design.
  • The corners of the PCB are rounded off, which makes it look a bit sleeker and more professional. Not that that makes a blind bit of difference really.
  • Of more significance are new mounting holes arranged in a rectangle, rather than at random locations on the board.
  • The sockets aren't all in the same place (so you'll need a new case)
  • The power supply is now reverse polarity protected and the linear voltage regulators (which get hot) have been replaced by switching regulators (which don't).

Does it Work?
All in all, all these improvements are very welcome. I think that the Raspberry Pi foundation have hit the nail firmly on the head with this update. But of course the million dollar question for all of us who have model B boards is 'will our stuff work?'

Since I was using a full-sized SD card in my model B, I obviously could not just use the same SD card. Even if you are using a micro SD card in an adapter on a model B, you will still need to upgrade Raspbian to the latest version using a model B before moving the SD card over to to the B+. This is because the B+ uses a different Ethernet controller chip.

When setting up a Pi, I prefer to create a full Raspbian iso disk image using Pi Filler rather than use Noobs. This is because I generally use my Pi through SSH and VNC rather than attach keyboard, mouse and monitor. Noobs needs a keyboard mouse and monitor.

So, I created a micro SD card using the 2014-06-20 distribution of Raspbian. The Pi looked happy until I tried to ssh to it. No response. So, I plugged keyboard, mouse and monitor in, and rebooted. It did boot, but with a load of errors and then failed to run raspi-config.

Now that I had the Pi all accessorised, I thought I might as well try the latest Noobs and this worked perfectly, first time.

Lesson - if upgrading from a B, copy the stuff you need off to a flash drive, then run Noobs on a new micro SD card.

Next, I though I should try out the GPIO connector, so I put together the Charlieplex LED project from the Raspberry Pi Cookbook.



This all worked fine.

I also thought I had better check out the RasPiRobotBoard V2 and make sure that all was well with that. It was, so all in all no compatibility problems so far.

Next, I thought I had better test out I2C, so I plugged an Adafruit LED Backpack into the I2C socket of the RasPiRobotBoard, loaded up the Adafruit example code and everything worked just fine.



I didn't try out any of the new GPIO pins, but I have no reason to doubt them. You can find a pinout for them here. My next job is to update the Raspberry Leaf and make a B+ version.

Conclusion
I love this board. There's nothing wrong with the plain model B, but this positions the Raspberry Pi as the undisputed ruler of the Single Board Computer.


Books.
You may be interested in the books I have written about the Raspberry Pi.


Thursday, June 19, 2014

Raspberry Pi Battery Power

The Raspberry Pi uses a pretty modest amount of electricity and it is perfectly possible to run in for short periods using batteries. In this post, I will look at some of the options for making your Pi run on batteries.



How Long Will the Battery Last

Whatever technology you use to battery power your Raspberry Pi, there is one key figure for the battery that you use that will determine how long you will get. This is the battery capacity in mAh (milliamp hours). So, if a battery describes itself as 1000mAh, then it can supply 1000mA for one hour before they go flat. This is an approximation so you may get more or less time.

Now, a Raspberry Pi without anything at all attached to it (no keyboard, mouse, display or WiFi dongle) will use about 400mA. Attach WiFi and a couple of peripherals and this will typically jump to about 600 mA or more. This will actually fluctuate quite a lot, depending on how busy the Pi is. So, driving video, or running a complex program will increase the power even more.

If are pessimistic and assume that the Pi will use 800mA, then we can expect about 1000 / 800 = 1.25 hours of operation from a 1000mA battery. Double the battery capacity to 2000mAh and we should get twice as long.


Battery Booster

The first and simplest option is to use a USB backup battery designed to give the battery of a smartphone a boost. You can see the battery plugged in an charging below.



These batteries actually include not just high capacity light weight Lithium Polymer (LiPo) cells, but also a charging circuit and switch mode voltage regulator. The charging circuit comes into operation when the battery pack is plugged into a USB socket on a power supply or your computer. This charges up the cells ready for use.

When you are ready to power your Raspberry Pi with one of these, you unplug it from its USB power supply and swap the lead over so that it is now providing power to the Raspberry Pi through its micro-USB lead (see below).



These devices can be bought on eBay or Amazon very cheaply and at a variety of different capacities. If you are going to use WiFi on your Raspberry Pi, then you will need to look for one that can supply 1A (1000 mA). Be aware, that many of these are only rated at 500mA. You may be lucky and this may be able to keep up with the demands of a Raspberry Pi with WiFi dongle, but then again, it may just crash unexpectedly or just die. So for a little bit extra look for one that will supply 1000mA.



LiPo Racing Pack

R/C vehicles use high capacity LiPo battery packs. These can also be used with your Raspberry Pi.



Unlike "battery boosters" these batteries do not have built-in chargers or voltage regulators. You will need to provide both these features separately, in the form of a battery charger and a switching voltage regulator circuit such as that found on the RaspiRobotBoard v2 (RRB2) from MonkMakes. The RRB2 actual provides other features such controlling motors, so if you are making a robot, then this may be a good option.

Racing packs suitable for the RRB2 should be of the two cell (7.4V variety). Having charged the battery you can connect it to the screw terminals on the RRB2 that will then provide all the power that the Raspberry Pi could need (up to 2000mA of current, with peaks of 3000mA).

A racing pack will generally have one set of leads for charging and a different pair of thicker wires for powering things from. A pair of male to male header wires will neatly connect the battery pack to the RRB2.

This approach is great if you are making a robot, because the RRB takes power for the motors straight from the battery.


AA Battery Pack

As well as using a RRB2 with a LiPo racing pack, it will also work just fine with an AA battery pack. You will need six cells, especially if you are using rechargeable batteries, which are a slightly lower voltage than alkaline cells.



The battery box is attached to the screw terminals of the RRBs just like the racing pack.

A set of fresh AA batteries will typically provide about 2000mAh.

Conclusion

If you just want to power the Pi on its own from batteries without making a robot, then the battery booster is the best option. However, if you are planning to control a motor or need some of the other features of the RRB2 such as using 5V I2C displays then the RRB2 with either an AA battery pack or LiPo racing pack is a good approach.



Books.
You may be interested in the books I have written about the Raspberry Pi.



Monday, June 9, 2014

TI Programmable 57 Calculator Battery Conversion

As a teenager, I had one of these calculators and I recently came across a non-functional one advertised on eBay and couldn't resist.


These calculators used a strange battery pack that had two NiCd AA cells, along with a buck-boost chip to raise the voltage to 9V. Of course 30+ years on and in most cases these batteries leak and destroy the buck-boost PCB. 

Fortunately its pretty easy to replace the NiCd pack with a PP3 9V battery.

To make this adaptation, you will need a PP3 9V battery clip and a 3 pin 0.1 inch header strip. Solder this up as shown below, with no connection to the middle pin.

Next, you will need to disassemble the battery box. Be careful with this, if the batteries have leaked you will find nasty stuff in there. Once its apart, clean it really thoroughly and dispose of the corroded innards properly.

Unplug the three way socket from the battery pack. This is what we will be connecting to the lead we have made.

IMPORTANT: ON THE TI-59 CONNECTOR, THE RED LEAD IS NEGATIVE AND THE BLACK LEAD POSITIVE.

Although it feels completely wrong, you need to connect the red lead of your battery clip to the black lead of the calculator's connector, as shown below:




I took my calculator case apart (I wanted to see what was inside). You probably don't need to do this, just to do the battery mod.

Finally, fit everything back together again. Getting the battery in just the right place for the back to fit on is a little tricky, but it will fit.


Fit the back of the battery box onto the back of the calculator and you are done!

One of the things that attracted me to this calculator is that as a teenager, this was one of my first experiences of programming. The Wikipedia page for the TI-57 is very informative and also has an example program to run (dice).

You can also find the manual for the calculator as PDF online.

Thursday, June 5, 2014

Building the MonkMakes Raspberry Pi Robot Kit

The latest product from MonkMakes is a robot kit that I have designed using the RaspiRobot Board v2 (RRB2). The kit is available from MonkMakes.



Overview

The kit comprises:
* a robot chassis, including two gearmotors and a 6 x AA battery holder.
* a RaspiRobot Board v2 (RRB2) that plugs onto the Raspberry Pi and controls the motors, as well as providing power to the Raspberry Pi itself. It uses a switch-mode power supply that can provide the Pi with up to 2A of current. Plenty for a WiFi dongle, display and pretty much anything else that you might want to attach to the Raspberry Pi.
* a HC-SR-04 Ultrasonic rangefinder

Construction

Building the robot is in three phases, first assemble the robot chassis, then fit the Raspberry Pi ad wire things up and finally install the software onto the Raspberry Pi.

Step 1. Check the Packing List

Note the bolts for the chassis come in three sizes. Lets call them short, medium and long. The short and long bolts take the same sized nuts. The middle bolts, used to attach the Raspberry Pi to the Chassis take smaller M2.5 nuts.

Chassis
1 x Laser cut robot platform
2 x Germotors
2 x Wheels
1 x Castor
8 x Short (8mm) bolts for attaching gearmotor assemblies and castor
4 x Brass spacers (10mm) for attaching the castor
8 x Nuts to fit short bolts and long bolts
2 x Medium (12mm) M2.5 bolts to attach the Raspberry Pi to the chassis
2 x Nuts to fit Medium bolts
4 x Long (30mm) bolts to make gearmotor assemblies
2 x Metal plates for fitting the gearmotors

Other
1 x RaspiRobot Board v2
1 x HC-SR-04 Ultrsonic Range Finder
1 x Battery holder for 6 x AA batteries
2 x Self-adhesive Velcro(TM) pads

Step 2. Peel the protective paper layer of the acrylic plastic chassis

The chassis is laser-cut plastic and has a protective layer of paper on both sides. Peel this off.




Step 3. Attach the Castor

Push a small bolt through each of the four holes on the castor and fit a nut behind it. Tighten the nut with pliers, holding the bolt in position with a screw driver. Then fit the remainder of the bolt onto the spacer and tighten up.



Finally push the spacer bolts through the four holes at the end of the chassis and secure with nuts.




Step 4. Attach the Gearmotors

Each of the two gearmotors needs a metal plate attached to it using the long bolts and nuts. One edge of the plate has threaded holes in it which will be used to bolt the motor to the chassis. Make sure that the holes are positioned as shown below so that the motors will fit the same way arround to the chassis.



Now, you can attach the gearmotors to the chassis, with the motor end of the gearmotor towards the castor, as shown below. You can also attach the wheels now.



Be careful not to tighten up the screws too much or you will crack the acrylic chassis.


Step 5.  Attach the Raspberry Pi

Use the two thinner "medium" bolts and nuts to attach the Raspberry Pi to the chassis. Put the bolts through the two holes on the Raspberry Pi board (note that the original revision 1 boards do not have mounting holes and the Pi will have to be attached in some other way.

With the bolts in place position the Raspberry Pi on the top side of the chassis at the opposite end of the board from the castor. Place one bolt through the wide center slot at the edge of the board and the other bolt near the middle of the board will find another hole in the chassis.

Fix the Raspberry Pi in place with the nuts. Do not tighten them too much.





Step 6. Attach the Battery Box

The battery box is attached to the chassis using self-adhesive velcro pads.

First, stick the 'hook' part of the velcro to the bottom of the battery box in roughly the positions shown below:


Next, peel the other half of the pads off their backing paper and place them onto the parts already attached to the battery box with the adhesive side up.


Finally, you can press the battery box into place with the wires towards the Raspberry Pi.



Do not put the batteries into the battery holder yet.


Step 7. Attach the RaspiRobot Board v2 (RRB2) and wire up

We are now ready to wire up the remaining components. Attach the RRB2 to the raspberry Pi. Make sure that all the holes on the socket line up with the pins. Your Raspberry Pi should be powered off while you do this.

Thread the wires from the motors through the big hole in the middle so that they can reach up to the screw terminals on the RRB2. The connections are as follows:


  • The leads from the left motor should go to the two screw terminals on the left of the RRB2.
  • Those for the right motor to the center two screw terminals.
  • The battery box negative lead (black) goes to the screw terminal marked GND
  • The battery box positive lead (red) goes to the screw terminal marked Vin on the right of the row of screw terminals.




At this point, you can also attach the HC-SR-04 ultrasonic rangefinder to the socket labelled "sonar" on the RRB2 facing over the battery box.




Step 8. Fit the batteries and then disconnect

Before we install the test software, we can do a quick test with batteries to make sure our basic setup is ok.

First, make sure that your Raspberry Pi is not powered by its USB lead. We are going to let the RRB2 supply it with power using the batteries. So, fit the batteries (regular or rechargeable) and you should see the LEDs on the Raspberry Pi start to flicker as it boots up. The two LEDs on the RRB2 should also light up.

If this test is successful, then you can now pull one end of the batteries out of the battery holder to act as a switch, because while we are setting up the software, we may as well save the power from our batteries and use the USB power lead to the Pi.

Note. It is important not to power the Pi from its USB connector and using batteries at the same time. One or the other, but not both, or you could damage your Raspberry Pi.


Step 9. Install the Software

To control the RRB2, you need to download and install a Python library onto your Raspberry Pi. The Python library also includes an example program that will make the rover wander around until it detects something near and then reverse away from it, turning a random amount before setting off again.

You can find full instructions for using this library at raspirobot.com.

Before you start, pull the wheels off the gearmotors to stop the robot accidentally driving off your table.

You could attach keyboard, mouse and monitor to your Raspberry Pi, but they are not very portable, so it is better to use SSH. See the tutorial for doing this here. You may also wish to do this over WiFi (see instructions here).

Powering the Raspberry Pi from its USB connector and with a network connection, use SSH to, run the following commands:

$ wget https://github.com/simonmonk/raspirobotboard2/raw/master/python/dist/rrb2-1.1.tar.gz
$ tar -xzf rrb2-1.1.tar.gz
$ cd rrb2-1.1
$ sudo python setup.py install
Having installed the library, we can do some basic tests on the RRB2 using its built-in LEDs. We can experiment with the RaspiRobot Board v2, even without any motors.
Open a Python console (Python2 not 3) by typing the following into a Terminal window:
 $ sudo python
Then, within the python console, type the following, one line at a time:
from rrb2 import *
rr = RRB2()
rr.set_led1(1)
rr.set_led1(0)
rr.set_led2(1)
rr.set_led2(0)
This should turn the LEDs on the RRB2 on and off.


Step 10. Run the Rover Example.

Disconnect the USB power connector from the Raspberry Pi and push the battery you were using as a switch fully into the battery holder. The raspberry Pi should boot up, powered from the batteries via the RRB2.

Leave the network (or WiFi) connected so that you can SSH onto the Raspberry Pi.

To run the obstacle avoiding test program, enter the following commands into the SSH terminal:

$ cd rrb2-1.1/examples
sudo python rover_avoiding.py

Although the program is running, the robot will not start to move until SW2 on the RRB is closed. So using a screwdriver, momentarily short together the connections for SW2 as shown below.



Books.
You may be interested in the books I have written about the Raspberry Pi.

Tuesday, April 29, 2014

Review: Scana Plus Logic Analyzer

When IkaLogic (www.ikalogic.com) offered to send me one of their Scana Plus logic analyzers, I was delighted. Not least because the software to support this USB Logic analyzer is available for Mac. So no more having to crank up a virtual machine running XP and wrestle USB drivers into submission!

Overview



The device costs €199 (at the time of writing) direct from the Ikalogic store.

An oscilloscope will often have just two channels and require a fair bit of interpretation when it comes to working out how the irregular square-wave translates into 1s and 0s and indeed how those 1s and 0s translate into messages. A Logic Analyzer is designed to capture and analyze such signals with ease.

Unboxing and Installation

When the unit arrived, I was surprised at just how compact it was. This tiny unit is capable of 100 MHz sample rate on 9 channels, with capture times only really limited by your computer's memory and disk capacity.



The box includes everything you need:

  • Scana Plus unit itself
  • USB Lead
  • 10 x test clips and cable. (9 channels + ground)
The ScanStudio software is a free download from here. If like me, you are a Mac user then you will be glad to see that the software is available for Windows, Mac and Linux. 

After installing ScanStudio, I plugged int he unit, but couldn't get it to connect. Eventually, I realized that if, like me, you are using OS X Mavericks, then you have to run a menu option from ScanStudi to install the USB driver. 



I did they, and hey presto the device connected just fine.

Using the Scana Plus

The Scana Plus uses your Mac, PC or Linux computer running a program called ScanStudio to display the waveforms captured and optionally the results of their analysis.

The example above is the data coming from a 1-wire temperature sensor (the BS18B20) connected to an Arduino Uno board.

ScanStudio has the concept of "decoders" that you can apply to the data being sampled. It comes with a number of these pre-installed into your "Library/Application Support/ScanStudio/decoders" folder (on Mac) but you can also add other decoders or even write your own in JavaScript.



You can see the results of applying the 1-Wire decoder to the data in the closeup below:



You can see that the values of the data are displayed as hex. Great for trying to work out what's going on with some thoroughly unpleasant message format.

Conclusion

While cheaper logic analyzers are available, three features of this device make it worth a few extra dollars:

  • 9 channels - many logic analyzers are 8 channel. That extra channel makes it possible to analyze an 8-bit bus with an extra clock signal.
  • For this price range you would not normally expect 100 MHz sample rate.
  • Software compatible with platforms other than Windows.
   




Friday, February 21, 2014

Raspberry Pi Fridge Minder: receive an email when the door is opened

I decided to see what other kinds of project can be made from the MonkMakes Raspberry Pi Electronics Starter Kit, that I designed.


The kit comes with project cards and a link to download the accompanying Python scripts. And projects already include a light meter and email notifier, so I decided to combine these two projects into one and make something that will send an email whenever the fridge door is opened. 


This is particularly timely as the MonkMakes team are trying to loose some weight at the moment. The paper template on the Raspberry Pi GPIO connector is called a Raspberry Leaf.

It turned out to be pretty straightforward. The breadboard layout is shown below:


BTW. A big thank you to Fritzing for a great design tool.

The photoresistor needs to be inside the fridge, so we can use two of the male to female jumper leads. This will of course also provide us with proof to the eternal question of whether the light really goes off when you close the fridge door.

You can see the completed breadboard and Pi below.


To install the program on the Raspberry Pi, you probably want to connect using SSH (see this Adafruit tutorial). Run the command "nano fridge.py" and paste the following code into the editor.

# fridge.py

import RPi.GPIO as GPIO
import time, math
import smtplib, time

SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587

GPIO.setmode(GPIO.BCM)

a_pin = 18
b_pin = 23
led_pin = 24

GPIO.setup(led_pin, GPIO.OUT)
GPIO.output(led_pin, False)

def discharge():
    GPIO.setup(a_pin, GPIO.IN)
    GPIO.setup(b_pin, GPIO.OUT)
    GPIO.output(b_pin, False)
    time.sleep(0.01)

def charge_time():
    GPIO.setup(b_pin, GPIO.IN)
    GPIO.setup(a_pin, GPIO.OUT)
    GPIO.output(a_pin, True)
    t1 = time.time()
    t2 = t1
    while GPIO.input(b_pin) == 0:
        t2 = time.time()
        if (t2 - t1) > 1.0:
            return 0
    return (t2 - t1) * 1000000

def analog_read():
    discharge()
    return charge_time()


def send_email(username, password, recipient, subject, text):
    print(username, password, recipient, subject, text)
    smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(username, password)
    header = 'To:' + recipient + '\n' + 'From: ' + username
    header = header + '\n' + 'Subject:' + subject + '\n'
    msg = header + '\n' + text + ' \n\n'
    smtpserver.sendmail(username, recipient, msg)
    smtpserver.close()

username = raw_input("Sending gmail address? ")
password = raw_input("Sending gmail password? ")
recipient = raw_input("Send email to? ")
subject = "FRIDGE VIOLATION"
message = "Someone just opened the fridge door!"

while True:
    reading = analog_read()
    if reading > 0: #dark so timeout
        GPIO.output(led_pin, True)
        send_email(username, password, recipient, subject, message)
        time.sleep(120)
        GPIO.output(led_pin, False)
    time.sleep(0.1)

You can test out the program without installing it on your fridge. Start the program using the command:

sudo python fridge.py

There may be a few warnings about GPIO channels being in use, which you can ignore. Cover the light sensor with a cloth or place it somewhere where it will be completely dark.

You will be prompted for your gmail email address, password and who you want to be sent an email when the fridge door is opened.


$ sudo python fridge.py 
Sending gmail address? myname@gmail.com
Sending gmail password? jkshdgfkayig
Send email to? youremail@somemail.com

When its running, you can uncover the sensor and you should see some trace that the email has been sent. Similarly, any errors will appear. 

The light sensor having fairly thin wires attached can just be shut in the door.




You may be interested in the books I have written about the Raspberry Pi.


Friday, January 31, 2014

BeagleBone Black Collars

Almost a year ago, I posted a blog entry on the Raspberry Leaf. A template to tell you which pins are which on the GPIO header. This was hugely popular and many people downloaded the PDF and printed their own leaves. Since then MonkMakes has been selling large numbers of ready-made and drilled leaves for the Pi.

I have just finished a book on the BeagleBone Black and of course suffered the same problem of working out which pin is which. Even worse on the BBB because it has so many GPIO pins.

So....... drum roll please ....... Enter the BeagleBone Collar!


These have self-adhesive strips on the sides and fit onto the edges of P8 and P9 like ears (another candidate name).

Here is the PDF.

But if you want a ready-made one with self-adhesive tabs, visit monkmakes.com