Showing posts with label Diary. Show all posts
Showing posts with label Diary. Show all posts

Tuesday, 10 February 2015

Raspberry Pi Diary - Scratch GPIO and 7 Segment Displays

Installing Scratch GPIO

The standard version of scratch can't control the GPIO, so you need to install ScratchGPIO7 before you can play with LED's and switches. I googled the install instructions but here they are if you need them:-

wget http://bit.ly/1wxrqdp -O isgh7.sh

sudo bash isgh7.sh

If you need to add the desktop icons to other users you can specify user name on that last command:-

sudo bash isgh7.sh fred

(nb. make sure you have an internet connection first!)

Use the new desktop icons to start scratch and it will ensure a background python task is running that enables the GPIO control.

There's a simple code example that toggles pin 11 between low and high. We attached an LED to this pin, (using a 470R resistor) and connected the other end to one of the ground pins. (doesn't matter which)

Success - a flashing LED!


Moving on from Basics

The plan was that I'd set my 8 year old a task of driving one of his 7 segment displays using the Raspberry Pi, and maybe get it counting 0 to 9.

It seemed like a suitable jump of of complexity both in software and breadboard wiring. (perhaps it was a jump too far) Here's what happened!


Circuit Debugging

My son disappeared for half an hour and returned with breadboard, 7 segment display, and T-Cobbler carefully connected with jumper wires. He plugged it in to the RPi, loaded up the pin 11 demo program and clicked the green flag icon to run the program. The scratch variable was clearly cycling on and off on the screen, but none of the segments lit. We ended up tearing the circuit down trying to get it to work and along the way discovered a few problems..

1. The T-Cobbler board has 40 pins that need to be inserted into the breadboard. That takes more insertion force than you'd think.

2. The LED display was of the common anode variety. This means that all the anodes are connected together and the segments lit by pulling the individual cathodes down to ground.

(So he had connected the LED segments the wrong way round.)

A quick flick through the Maplin catalog confirmed you can get common cathode versions.

Driving Common Anode Displays

My initial thought was we'd have to use a transistor inverter to drive each segment, but that's a fair bit of extra complexity and not strictly necessary.

A simple inverter circuit is not necessary.

Each GPIO output actively pulls high or low, so if you connect the common anode to 3.3v then any low pins connected to the cathodes will turn the display segment on.

Connecting a common anode display to a Raspberry Pi

The only hitch is the logic is the other way around! (pin low = segment on)

But it's only just occurred to me that we could do this after reading the Raspberry Pi GPIO Documentation and seeing an LED connected this way. (Must try this tonight!!)

Wednesday, 4 February 2015

Raspberry Pi Diary - Breakout Boards

Interfacing 101

One of the main reasons why I bought the Raspberry Pi was to bring together the two worlds of electronics and computing for my two youngest sons. The oldest of the two already has various components and breadboard to play about with, and he's already been experimenting with scratch for a while now.

The great thing about the Raspberry Pi is that it has those GPIO pins just waiting to connected to LEDs, switches, sensors or the wide variety of add-ons that you can buy these days. I thought I'd start by getting a simple breakout board from Maplin.

GPIO Breakout Board
I got one, but lets just say I made a few mistakes!

Mistake #1

It comes in kit form, requiring the ribbon socket and header pins to be soldered together before you can use it. There's a simple diagram that suggests how the ribbon connector should connect to the GPIO pins and which way it should fasten into the breakout board. Seemed simple enough but it wasn't obvious which way up the board should go.

One end of the breakout board
One end was labelled 'GPIO HEADER' (see diagram), so I concluded that it belongs this way up and started soldering the socket. After I'd done about eight I started to get the niggling feeling that it wasn't correct. I stopped and traced the wiring only to find I actually had the board upside down!!!

Now unsoldering a double-sided board is a nightmare, and my desoldering pump just wasn't doing the job. In the end, I levered the socket away from the board leaving the soldered pins still attached. These were then individually removed with a hot soldering iron and a pair of pliers.

Botched breakout board with removed socket pins.
Now I'll have to drill out the remaining solder before I can start again. (This wasn't going well!)

Mistake #2

It wasn't until my son came through to check how I was getting on that I realised my next mistake. I was explaining to him about how the ribbon plug would fit into the GPIO. When I went to demonstrate this I spotted my next mistake. (this one pretty fatal)

This was a 26 pin breakout board for the original Raspberry Pi, but I'd bought the newer RPi B+ model, which has a 40 pin GPIO. The ribbon plug won't fit and if you try to force it you'll end up bending some of the pins. (darn!)

Let's do it Right

All I can say is "Cobblers" - or to be more exact Adafruit's T-Cobbler Plus. As soon as I opened the bag I was immediately impressed by the improved quality and the neat screen printing showing (without doubt) which way the socket should be soldered.

You can bet I still checked it carefully before I started, but within about 10 minutes it was done.

The assembled Adafruit T-Cobbler Plus
My son quickly relieved me of it and started building a circuit to light his 7 segment LED display.

(More about that another day)

Thursday, 29 January 2015

Raspberry Pi Diary - Refuses To Boot

Getting Nowhere

I've wasted a lot of time over the last 24 hours trying to get my 32Gb SD card formatted correctly. Today I tried loading the raspbian image file (from http://raspberrypi.org/) to the card using the 'dd' command in a terminal window.

It all looks OK yet the Raspberry Pi fails to see the card when you power it on.


A Hint at What Was Wrong

I found a few web pages that stated some SD cards just didn't work, and set about reviewing the http://www.raspberry-pi.co.uk/2012/06/07/compatible-sd-cards/ list to see if mine was supported.

But my card is a cheapo unbranded card from ebay and I wasn't able to see a brand name. Though not really conclusive, I began to suspect that this was the problem.

I gave the card to a work colleague who promised to try it out on his Raspberry Pi tonight.


Lets Try Another

In the mean time I borrowed a Kingston 8Gb card from my son (who's also keen on getting this working), carefully backing up his contents before starting work. We did exactly the same as before:-

  1. Format the SD card using SDFormatter (just a quick format this time).
  2. Copy the contents of the NOOBS folder onto the root of the card.
  3. Clean out the dot files that the Mac OS insists on adding (using CleanDisk).
Then we removed the card from it's adapter, slid it into the Pi's microSD slot and powered it up..... It started booting (whoop!!)


The NOOBS Install Menu
It takes about 20 minutes while it alters the partitions and then installs your selected OS.


Install the OS
I'm amazed how slick the process is after that. It runs fine on my TV, and the sound even works via HDMI. Next step is to get my bluetooth dongle working. :-)

Wednesday, 28 January 2015

Raspberry Pi Diary - There's power but screen is dead

We are Noobs

I ordered a Raspberry Pi B+ from Maplin last week and it arrived the other day. All the other parts had already arrived, and we'd downloaded NOOBS (which we definately are!!) and copied the files onto the micro SD card ready.


Rashberry Pi B+ in it's Pibow Coupé case

Tonight we put everything together, plugged it into our TV, borrowed the USB keyboard from the kid's computer and plugged the Pi into 5v power supply.

We got lights, but the screen remained blank!

Tried it on the monitor in the other room, still nothing.


Why Won't it Work?

The thing we noticed was the green ACT light wasn't flashing, which indicates that the Pi isn't booting. The two main causes of this are:-
  • Power supply has insufficient current.
  • The card isn't readable.

First I switched to my iPad charger unit as a power supply,.. but still nothing! (both LEDs still on solid)

After a little bit of googling it seems that the card isn't readable. If you format the SD card using SDFormatter using a Mac (which I did) then make sure you use the Full Overwrite method. Damn, that's gonna take some time.


Full Format The SD Card
The screen grab shows attempt number two, the first time (after about an hour) I brushed against the card in the reader slot and it crashed the software. Had to fix the format in Disk Utility and start again.

In the mean time I've re-downloaded the NOOBS software for when the card is ready. I'd like to rule out bad files too while I'm at it.

Overall - a disappointing start!