02 April, 2014

Raspberry Pi East Rand Jam Session #1

Some background

I bought a Raspberry Pi a long long time ago ... when it was still R 360.00. They are now over R 500 with the exchange rate.

I have been wanting to play with the RPi for quite some time now, but have just not had the will power or energy to do anything other than the XBMC setup.

Clive, a friend from work, said he was also interested in jamming a bit with the RPi so we set a date for Sunday the 30th March. We went out to a local electronic shop the week before to buy a few parts such as LEDs to make a basic circuit we could connect to the GPIO pins. We also got a USB keyboard and mouse from Matrix warehouse.

I had also advertised the Jam session on the RaspberryPiAfrica facegroup page. But no-one was interested in joining us. Pity.

Soon enough Sunday morning arrived and after a lekker breakfast we set up ourselves up close to the ADSL modem so we could connect our RPi's to the internet.

We had both already downloaded NOOBS 1.4.3 and we copied the unzipped files to the 8 Gig SD cards we had previously bought (also from Matrix computers in Edenvale).

Then we booted them both up and told the NOOBS interface we wanted to install Raspbian as per this page.  We only had one HDMI screen at this stage so we took turns to use the screen as and when each RPi needed the next command instruction.

(Task 1 - Remote desktop)

Then I remembered one can Remote Terminal into the Pi and a quick search later we found this command which we both executed on our RPi's:

sudo apt-get install xrdp

From then on we could remote terminal into the Raspberry pi's.
Oh yes on the ADSL router I gave both Rpi's pre-defined DHCP IP addresses so the IP addresses would remain the same after reboots and for the next jam session(s) as well.

(Task 2 - FM Transmitter)

Our first real project was the FM Transmitter.
We found this info and followed the 3 or 4 easy steps. However I don't know what the micro usb cable is meant to be used for, and we used a single wire (incorrectly!) to connect to pin 4.

We got a total distance of about 5 to 7 meters, and I think we were using the wrong pin. I'll redo it at our next jam session.

Clive also had a look at how it works, and saw it was based on a simple c++ program.

(Task 3 - Blinking LED)

We then set out to do the Blinking LED.

This took us quite awhile to complete.

We initially used this web page, but I found the instructions were not that clear (the unclear bit was where the GPIO software was to be downloaded from. Later on I realised the link was there... it was just not obvious). We also had to figure out how the breadboard worked, as it has been close to 20 years since I last worked with electronics down to this level.

We each built our LED circuit. We linked a 270 ohm resistor to positive and the other side to the LED. Clive remembered that the leg length of the LED denotes to which side of the circuit it should be connected. The other side of the LED was then connected to ground. We then tested each of our circuits with 2 penlight batteries (close to 3 volts) from my trusty GPS receiver.
The circuit worked!
Then it was time to link it up to the RPi.
I know one has to be very careful when connecting the pins of the Pi, as an incorrect connection can blow the chip. So we took our time to understand how the GPIO pins work.

From this page we saw we needed to download some stuff (We also used some info from here) After getting the code into the directory,  unzipping it, building it,  and then finally executing the following commands:
  gpio -v and
  gpio readall
and checking the output we realised we had two different version of the Pi.

Both Clive and I have the version B boards, but Clive had the revision 1 board and I had the revision 2 board. And there were pin differences. After a lot of head scratching and googeling we realised there are chip pins, output pins and BCM pins. All very confusing, but the output pins we would be using for GPIO0, GPIO1 and GPIO2 were the same on the two boards.

Note: Since Clive works quite a bit with Java he knew all the unix commands quite well, and he mentioned that the jar files Java uses are a lot the same (as in use) as the tar files unix uses.

We linked up our circuit wires to the Pi on output pins 9 and 11 (from my understanding pin 6 was the same as 9) and executed the following commands (as per this page)
  gpio mode 0 out
  gpio write 0 1 and
  gpio write 1 1 

It worked!

Clive wrote the python script to automate the blinking and once it was running on his Pi, we copied it over to my Pi (with some difficulty). I must also note Clive knew "vi" (a unix editor) quite well. I don't know it at all. (I have used it in the past and didn't like it then, and don't like it now). I resorted to opening the file in "File manager", by navigating to the file and then right clicking on it and editing in a nice GUI environment. Much easier, and more intuitive.

This was the first time I ever played with Python. Up to now all I knew about Python was that indentation is a way of grouping commands. The script was easy enough to understand.

We then set out to build another 2 LED circuits and soon had them hooked up as well.
I modified my python script to blink as per the video below.

Not exactly as I wanted it (2 LEDs must stay on all the time). I'll fix that in our next jam session (if there is time). The plan is also to build a little traffic light out of the 3 colour LEDs.

We started at 10 AM and by now it was already 4 PM. 6 Hours in total spent playing with the pi, and getting 2 "interface-with-the-real-world" projects done.

For our next jam session we hoping to have a few more people over on the 11th May, and we planning to do the following:
  1) Get a usb camera to work over the internet.
  2) Get a traffic light to work (playing with python)
  3) Get some switches to plug into the breadboard so we can read from them, and then do something with the LEDs.
  4) If there is time left, check up on the FM transmitter and see if we can get more distance out of it.

One thing though ... I think one has to be very careful by getting to much information on the net about the RPi. If one web page tells you to do one thing it might be with their specific code or binary file. Applying this to some other binaries downloaded might end up in disaster.

I will blog again as to the results of the next JAM session.

If you are interested in joining us then visit the RaspberryPiAfrica page on Facebook

And in the wise words of RWJ .... "I approve this post" - Over and Out.