Monday, November 23

Installing Rasbpian with Noobs

You bought yourself a shiny new Raspberry Pi, maybe the brand new Pi Zero and now you are really fidgety about doing something exciting with it but ... there are a few things that need to be done first.

I have provided three complementary videos that you can watch to go through the entire process or if you prefer you can go through the following brief instructions

This is in a nutshell what needs to happen:

  • Get an SD card
  • Format the SD card
  • Transfer NOOOBS onto the card
  • Boot your Raspberry Pi with NOOBS
  • Select and install the Operating System

The first thing you need to do is to get yourself an SD card with a suitable Operating System installed on it so that the Raspberry Pi can run all the basic software that is needed for it to do anything.

At this point NOOBS is your friend!

NOOBS is a piece of software that will help you installing the Operating System onto the SD card.

This can go either of two ways:

  1. Buy a card with a preloaded NOOBS on it
  2. Reuse one you already own and prepare it with NOOBS yourself.

The preferred Operating System for the Pi is Raspbian and its latest incarnation is called Jessie. The names of the versions of this OS are coming from Toys Story, the previous one in fact was called Wheezy!

Now Wheezy's character was a bit chubby and Jessie's was quite slim in the cartoon but despite this you will need a bigger SD card to store Jessie than you would have with Wheezy as the OS Jessie is a bit bigger than its predecessor. With this in mind make sure you use at least an 8 GB SD card for your Pi.

  • Follow this section only if you are reusing you card

If you are going to reuse your card you have to first format it or in other words prepare it to be able to transfer NOOBS onto it, to do so you can use a software called SDFormatter. It is a really easy install to perform and you can use the videos provided if in doubt.

Make sure to backup the contents of your SD card before proceeding as the tool will delete all files in it

Select the right drive letter corresponding to your SD card and click on Format. You will have to accept a couple of alert messages and you card will be ready shortly after.

Once the card is formatted you will need to transfer NOOBS on it. First of all let's get hold of NOOBS.

Once downloaded (it will take a while) it will have to be unpacked in a temporary folder of your choice.

With the content unpacked you will now have to select all the files and copy/paste them onto the SD card you have just formatted (that also will take a while).

The card is now ready to be ejected from the card reader and plugged into the Raspberry Pi.

  • Whether you have used your own card or purchased one with NOOBS pre-installed this is what needs to happen next

Make all the necessary connections to the video, the network, the mouse and keyboard and finally plug the power supply in.

After a short while you should lend onto this page

Select install near to Raspbian and ... after a while and a few rather useful information displayed during the installation, the process will terminate and prompt you for restarting into Rasbpian for the very first time.

Great! You made it, your Raspberry Pi is now ready for many adventures to come

Here are the embedded videos mentioned above

HW preparations to get started

Prepare the SD card, get hold of Noobs and transfer it onto the card

Connecting all up and install Raspian

Friday, November 20

Electronics Recycling Dumpster Diving

I have been very surprised time and time again every time I would go to the recycling centre by the amount of good quality things that get thrown away on a regular basis. Each time I would visit to dump I have always find time to have a peek at the electric and electronic appliances skip.

It is amazing to notice how people overcome their imposed limits and would pick things up as well as chuck their stuff away. Especially on a weekend there will be even some habitué who would always be at the recycling centre to be sure never to miss the best "donations" of the day and I thought : "Why not?" Why shouldn't we all do that without inhibitions and in fact with some sense of pride. "I recovered something from the garbage and gave it a second life"

It is a win!, win^2! loose?
It is a win for me as I get something for free.
It is a double win for the environment as the item doesn't need to be created again just for me and doesn't need to be destroyed. Destroying is the counterpart of creating and it is the counterpart of the costs that are not quite taken into account when giving a value to an item as it hits the market. Destroying or in the best case recycling costs money in the act of collecting and transforming our "garbage" and worse of it all, leaves a heritage to the future generations that will have to find a way to deal with it, most probably with additional costs.
It is a loose for industry maybe. Well industry needs to modernise itself and find a different way to survive, why not re-purposing items and reselling them?

Rant apart, here is the video of what I found at the recycling centre and the hurdles I had to overcome to get my bounty.

Thursday, November 19

Electronics Recycling at the local Charity Shop

Every Tuesday morning a volunteer helps the local charity shop to PAT test all electrical donations. On Tuesday afternoon I would be visiting the shop to see what goodies has the generous community given away.

In October I found a nice Kensignton laptop stand which came connected to a WiFi USB card from Netgear.

In the video below I went through this £5 purchase to see what could be salvaged and what could be chucked away.

Sunday, November 1

Halloween Automated Scarer 2015

A pinch of pygame, a hint of scapy and the Halloween concoction is ready!

This year's automated scarer was a bit more challenging than last. I stitched this together in a couple of days and ... it worked mostly as I wanted it to be. The most important thing is that children and parents enjoyed being scared by a few monstrous pumpkins and a bunch of my son's very horrific (but beautifully made) drawings.
Raspberry thirsty Vampire
Scary Witch of the South East

I wanted the animation to be easy to be activated and yes, I could have used other methods to detect people to be scared (which from now on I will refer to as scarables: a person suitable for the scarer) but I was curious about scapy and the possibility of detecting mobiles passing by.

I also found quite interesting digging through the enormous amount of information available on pygame which served perfectly the purpose of displaying the pictures and playing the sounds all of this without needing to drop into X leaving ample resources available on my RPi B

It is also entertaining to lookup the MAC addresses I collected to establish if we live in a posh area or not. The amount of Apple devices wasn't so many in the end, I will consider selling and buy elsewhere.
Ah and don't worry, the MACs I collected will be handed over to TalkTalk for safe keeping.

The Python script revolves mainly around the scapy command sniff which I used to search any broadcasting WiFi device within reach of my dongle.
The first thing to do is to setup the WiFi card into monitor mode which is done outside of python on the shell:

#/usr/bin sh
sudo service ifplugd stop
sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode monitor
sudo ifconfig wlan0 up
sudo service ifplugd start

You can verify things are set properly by issuing iwconfig, this is my output:

wlan0     IEEE 802.11bgn  Mode:Monitor  Frequency:2.412 GHz  Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

Within scapy's lamda function we need to create a list to hold the MAC addresses that we'll acquire. Around the area where I live there are normally quite a few Access Points and other WiFi devices. The first thing to do then is to store all these MACs on a file so that they will not trigger any false "scares" each time that the Pi starts. I did this by running the script in "silent mode" for a couple of hours. I had created in this way a WiFi fingerprint of the area which I stored on a file that gets read at the start of the script and pre-loads all the MACs in the neighbourhood.

if path.isfile(fileName):
    with open(fileName, 'rb') as MAC_file:
        MAC_list = pickle.load(MAC_file)

for the serialisation I am using pickle which for the purpose works just fine

From here on any new MAC detected is a potential scarable,

Scapy offers a sniff command that can take as arguments an interface and a function amongst other options.

sniff(iface = "wlan0", prn = PacketHandler, store=0)

The store=0 turned out to be vitally important as it tells the sniff command to just monitor the packets and not store them in memory. I learned this the hard way as I the Pi stopped responding all together as its memory got full.
I have obviously specified to monitor packets on wlan0 and given a PacketHandler function which I use to specify what I am interested in about the packets seen by wlan0

def PacketHandler(pkt):
        if pkt.haslayer(Dot11):
                if pkt.type == 0:
                        if pkt.addr2 not in MAC_list:
                                with open(fileName, 'wb') as MAC_file:
                                        pickle.dump(MAC_list, MAC_file)
                                        Call the Scare function

the layer I am interested in is Dot11 as in 802.11x and the packet type is 0 as in management. If the MAC is not in my list I will add it and write the list on a file.
The other very important thing that I do in the last if block is that I will start the animation for each new MAC added to the list.
Now, this could have done it in a number of ways, I wanted to explore the pygame events, I wanted to use two threads on for WiFi scanning the other for the animation, in the end at 16:30 of the 31st of November I decided to call a function directly after writing the list to a file.

image = images[random.randint(0, len(images)) - 1]
sound = sounds[random.randint(0, len(sounds)) - 1]
Scare(image, sound, screenSize)

The Scare function receives a random image and a random sound from two preloaded lists. I paste the PrepareImages only as the PrepareSounds is essentially the same

def PrepareImages():
        imagesNames = glob.glob('*.png')
        imageCache = []

        for imageName in imagesNames:
                        raise UserWarning, "Could not load images"

        return imageCache

All .wav and .png files where in the same path as the script.
Everywhere I looked for examples of pygame.image.load I found that it is highly recommended to convert the images to improve performance. I certainly noted an improvement

The Scare function looks like this

def Scare(image, sound, screenSize):
        image = pygame.transform.scale(image, screenSize)
        frame = image.get_rect()
        white = (255, 255, 255)
        black = (0, 0, 0)
        screen = pygame.display.set_mode(screenSize)

        playing =
        while playing.get_busy():
                screen.blit(image, frame)

it will resize the picture (sometimes deforming it as the source did not have the same proportions of the screenSize I selected), set the screen, play the sound.
Whilst playing the sound the picture would be displayed (blit) and a 1 second delay also added to get the shivers deep in the scarable's spine.
After the sound is played the screen turns black again.

That's it really, ciao!