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)

Oracle APEX - Advanced Tabular Form Validation

Introduction

In my previous APEX post I took you through a method of adding click-able column help to your tabular forms. I also needed to add validation between my columns, and initially it wasn't clear how I might do this. You can validate against static values, normal item values, or just check for nulls, but nowhere can you validate against a value from another column on the same row.


Tabular Form Requirement

Just to recap from before, I have a table of measures with three columns to hold the weighting, cap and uplift values for each. (shown below)


My Tabular Form
The validation I wanted to add was to ensure that if a Cap value is added then it must be greater than the Weighting value.

One way of performing this type of validation is to use some jQuery code which runs on the browser, but generally its not recommended for security reasons. Instead we'll use a method that replies on the inherent use of collections for tabular tables and write our validation using PL/SQL.

Creating the Validation

1. Run the page containing your tabular form and inspect the input fields from the columns your need to validate to get their id's.

The HTML for the first Weighting field is:-
<input id="f03_0001" type="text" value="0" maxlength="2000" size="2" name="f03"
autocomplete="off">

The HTML for the first Cap field is:-
<input id="f04_0001" type="text" value="0" maxlength="2000" size="2" name="f04"
autocomplete="off">

So the two pieces of information we need here is f03 and f04.

2. Create a page level validation and give it a suitable name. (I'm going to call mine "Check Cap Values Exceed Weighting")

3. Select 'PL/SQL' as the validation type.

4. Then select 'Function Returning Boolean'.

5. Here's the code I entered:-

BEGIN
  FOR i in 1..apex_application.g_f03.count
  LOOP
  IF apex_application.g_f04(i) IS NOT NULL
    THEN IF apex_application.g_f03(i) IS NOT NULL 
      THEN IF TO_NUMBER(apex_application.g_f04(i)) <= TO_NUMBER(apex_application.g_f03(i))
        THEN RETURN false;
      END IF; 
    END IF; 
  END IF; 
  END LOOP;
END;

NB. APEX automatically creates a collection for each column in a tabular form ("apex_application.g_f01", "apex_application.g_f02" etc...) This function loops through the values in columns 3 and 4 comparing the values. 

It's reasonably simple, just don't forget to turn these values into numbers before you do your comparison, or you'll find that 8 is greater than 10 and your validation won't work as you intended!

6. Enter the following for Error Message:-

Cap values must be greater than Weighting, or left empty.

7. Finally set the condition to When Button Pressed 'SUBMIT'.

That's it!

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!

Monday, 19 January 2015

Oracle Apex - Adding Tabular Form Help

Introduction

If you use Oracle APEX I'm sure you like the pop-up help text that you can assign each of your region items. It's part an items configuration, just ensure the UI template "Option with Help" is selected, scroll down to Help Text box and type it in. (Simple)

That's all great, but when I recently found I needed to use a Tabular Form (which is a like an editable report) I went to the column definitions, scrolled to the bottom of the config page, but found it didn't have anywhere to enter help.

Tabular Form Column Help

In the past it's not been a big deal, nobody really asked for it, and you could always add extra stuff to the Page Help,.. but it's not ideal. For this tabular form I needed to be able to explain what the columns were used for because the heading title doesn't do a good job of describing it.

I remembered the method I came up with for Region Help, and figured I'd have a go at adapting this for the column titles. I particular liked this idea because it kept things simple. It uses dummy items to hold the help text which means the help also gets added to the page help without any extra work.

Here's my tabular form:-

My APEX Tabular Form

So lets get right into it using our example above which was on page number 30...

1. Create four Display Only items and ensure you have the 'Optional with Help' UI template selected:
  • P30_MEASURE_HELP with label "Measure Column",
  • P30_WEIGHTING_HELP with label "Weighting Column",
  • P30_CAP_HELP with label "Cap Column",
  • P30_UPLIFT_HELP with label "Uplift Column".
    (NB. the label defines how it will look in the page help)
 
2. For each set the help text (as you would for a normal region item).

3. Run the page and you will see these extra item labels showing on your screen, don't panic, this is only temporary. If you have Firebug installed, right click the label and select Inspect Element.

(Which ever browser you use find a way to see to the link html.)

4. Copy the html to your clipboard and paste it into a text editor. It will look similar to this..

<a class="optional-w-help" tabindex="999" href="javascript:popupFieldHelp('2859011741903715','641282443145')">Uplift Column</a>

5. There are two numbers here that are passed to the popupFieldHelp() function, the first one is the help unique id. The second number is your session id which we need to replace so it always shows the current session number. Delete the second number and enter '&APP_SESSION', then remove the word 'Column' from the link text.

The line should now read...

<a class="optional-w-help" tabindex="999" href="javascript:popupFieldHelp('2859011741903715','&APP_SESSION.')">Uplift</a>

6. Now edit the page, right click the report and select 'Edit Report Attributes'.

The completed changes to the report headings

7. Paste your html into the correct heading, and then repeat for the other three items.

8. Finally re-edit your help items and set them to 'Hidden'.

That's it, you're done. Now when you hover your mouse over the titles the '?' appear. All that remains is to click them all to make sure it works.

Sunday, 4 January 2015

Playstation 3 Super Slim 12Gb FULL

A Christmas Gift

My oldest son decided he needed to have a PlayStation 3 so that he could play online with his friends. He'd originally wanted it as a birthday present (with a TV) for his bedroom, but we figured it was too much - that and the fact we'd never see him again!! Instead we decided to make it a joint Christmas gift for all and locate it in a communal area where it could be plugged into the computer display.


We picked up a Sony PS3 Slim Console with 12GB Hard Drive from Argos for a reasonable price. I did wonder at the time why it only had 12Gb when they're usually 500Gb, but what did I know? - I didn't give it a second thought, just wrapped it up and stuck it under the tree.

Fatally flawed PS3 Slim 12Gb


And on the big day the kids were happy racing cars, jumping from platform to platform and generally shooting anything that moved. We'd selected a variety of games to suit their age range of 6 to 14, and despite the Playstation Network being attacked on Christmas day, they were still able to play without problems. (Boy am I glad we hadn't bought an Xbox One!)



Out of Space

The problem occurred the following day. They'd created three accounts and run a variety of games using them, but it had already gotten to the stage were no new games could be loaded because the disk space was down to a few hundred megabytes. I was surprised just how little time that had taken!!


So my first thought was, "how do I clear some space down?"



My web searches proved to be fruitless, it didn't look like you can do any sort of housekeeping on the disk. So I widened the search to see how others had solved the problem. It became apparent that the only way to solve the problem was to fit a laptop HDD and turn it back into a full-size Playstation. It turns out that there's a disk slot in the side of the console behind a clip-on panel. Using it doesn't invalidate the warranty, or need any tools, but does require the purchase of a special Sony drive caddy!



A Cheap & Dirty Solution


Eventually I found Quentin's Youtube video which explains how to fit a HDD using an old credit card instead of Sony's caddy. (To be quite honest why isn't the caddy included in the box if the console is almost unusable without a disk?)


i

The instructions in the video are simple enough to follow, so I raided an old 300Gb USB disk drive for it's HDD and unplugged the Playstation ready to start.

Always a Catch!

The biggest problem I had was trying to figure out how to remove the disk hatch from the console. It runs the full length of the right of the case, but there are no screws or obvious catches. I couldn't figure out how to open it (the manual didn't say either) so I resorted to carefully unclipping the catches with the plastic credit card that I'd ear-marked for the job.

I can now report that all you need to do it push the cover towards the back of the case by either pressing the side firmly, or inserting your thumbnail into the front corner and pushing back gently.

The disk can then be slotted down into the drive space, although it took me a few attempts to locate it into the sockets. The credit card was then cut into to two and used just like the video suggested. Perfect!

Finishing Off

The final step involves starting up the console, it then detects and formats the disk, and then copies the user data from it's internal 12Gb flash drive. It takes about ten to fifteen minutes and then you're good to go.

Thanks a lot to Quentin for this tip,.. it sure was a life saver.