## Circuit 2: Potentiometer

Circuit 2: Potentiometer – this involves using a potentiometer to change the rate at which an LED blinks. A potentiometer is just a fancy name for a variable resistor. A resistor is very simply, something we use in electronics to control the current flowing through a circuit. The higher the resistance, the lower the current (see Ohm’s law for more on this relationship). We are now able to measure this using an analogue pin on the Arduino and make use of it within a Python programme running on our Pi!

It will be a good idea to read the SparkFun online guide to circuit #2 first – here.

Step 1: set up your Raspberry Pi and Arduino nanpy mashup (see here to find out how)

If you have used your Arduino using the Arduino IDE since you uploaded the special nanpy ‘firmware’ you will need to upload it again.

Step 2: write a cool Python script (or just use the code here)

''' import modules needed '''
from nanpy import Arduino
from nanpy import serial_manager
from time import sleep

''' create a serial connection '''
serial_manager.connect('/dev/ttyACM0')

''' Set analogue pin A0 to input mode '''
POT = 0
Arduino.pinMode(POT, Arduino.INPUT)

''' Set digital pin 13 to output mode '''
LED = 13
Arduino.pinMode(LED, Arduino.OUTPUT)

''' decide if you want to print out delay each loop '''
printDelay = True

''' let people know the LED fun is about to start '''
print "starting"

''' while True basically means do this forever (or until someone presses control and c) '''
while True:
# turn on LED
Arduino.digitalWrite(LED, Arduino.HIGH)
# wait (according to reading from potentiometer)
if printDelay:
# if printDelay == True, print out delay
print 'delay: ' + str(delay)

sleep(delay)
# Turn off LED
Arduino.digitalWrite(LED, Arduino.LOW)
# wait (according to reading from potentiometer)
sleep(delay)

Step 3: set up the circuit

See SparkFun documentation here.

Step 4: play with the potentiometer and watch to see your potentiometer blink at different rates

What happens if you change the number 1500.0 in our code?

What happens if we just use the reading from A0 without dividing it by a number at all?

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.

## Experiment: use an arduino as a slave to your raspberry pi

Why do this?

If you have got past the initial excitement of having a Raspberry pi, and tried getting into experimenting with inputs and outputs (i/o for short), you might have stumbled across the fact that the Raspberry Pi only has the ability to read digitally from it’s GPIO (general purpose input/output) pins.

So if you have a variable resistor (potentiometer) or a light dependent resistor (or any other analogue sensor) – you won’t be able to measure anything but 1 or 0 (that is how digital works, you are either HIGH or LOW, as opposed to analogue which can be anything in between). Now there are some cool ways around this if you are into your electronics (see here or here). But there are a couple of good reasons for using an Arduino as ‘slave’ to read analogue inputs.

Firstly, the Arduino is very reliable and safe – it has been designed for tinkering. You can make a few mistakes (within reason) when plugging in wires and choosing resistors. The Pi on the other hand is a big wus. Plug a 5v wire into one of its GPIO digital pins (designed for 3.3 volts) and you are likely to fry it! The other big reason to slave the Arduino – is that you can get the full power of Python (including libraries like PyBrain for Neural Networks) hooked up to the outside world through the Arduino’s analogue capabilities.

Yes, using the Arduino IDE (integrated development environment aka a program that makes it easy to write Arduino software) is good and more than enough to keep anyone going even on very complex projects. But using BOTH the Pi and Arduino has it’s advantages IMHO. You get the power of the Pi and Python (think camera, image processing, audio etc) as well as the analogue, safe, reliability of the arduino. (some will be thinking it might be easier to just get a breadboard and a 10 bit ADC, and you might be right, but I would argue that, once set up, this is easier for those new to electronics).

[all experiments are conducted at your own risk]

Step 1: Install the Arduino IDE

Make sure you have an internet connection. Open up LXTerminal and type in:

\$ sudo apt-get update

This updates the Raspberry Pi with an up to date list of software that is available.

Then type in the following:

\$ sudo apt-get -y install arduino

This installs the Arduino IDE on your Pi using the program ‘apt-get’. The -y just means say yes to any questions during the installation.

You might be wondering why we have to install the Arduino IDE after all the fuss about using Python to connect with your Arduino. The reason is – we can use it to install Sketches/firmware on the Arduino, which is really handy for trouble shooting (more on this later).

Step 2: Install nanpy (a Python library) using setup tools

nanpy will help us write the Python code which will help us set up the Arduino as slave to the Pi! AKA we will be able to read and write from the Arduino’s analogue pins.

\$ wget http://bootstrap.pypa.io/ez_setup.py - O - | sudo python

(Make sure to use a capital O, not a zero, or you will get errors.)

Step 3: Install pyserial

nanpy needs to be able to talk with the Arduino using what is called a ‘serial connection’. To do this we need to install pyserial.

\$ wget http://pypi.python.org/packages/source/p/pyserial/pyserial-2.7.tar.gz

Now use tar to ‘unzip’ it:

\$ tar zxf pyserial-2.7.tar.gz

(hint: if you press tab after starting to type ‘pyserial-2.7.tar.gz’ it will autocomplete the rest – which means no more typos! If you get nothing, try pressing tab twice)

Next move into the newly ‘unziped’ directory:

\$ cd pyserial-2.7 (again tab works a treat here)

We can now use python to install the pyserial library:

~/pyserial-2.7 \$ sudo python setup.py install

Step 4: Install nanpy 0.8

Move back to the home directory if you haven’t already:

~/ cd ~

\$ wget https://pypi.python.org/packages/source/n/nanpy/nanpy-v0.8.tar.gz

Like we did in step 3, just go ahead and unzip it and install it.

\$ tar zxf nanpy-v0.8.tar.gz

\$ cd nanpy-0.8

~/nanpy-0.8 \$ sudo python setup.py install

Step 5: This step is not entirely needed (see step 1) but is a good way to check everything is okay with the Pi → Arduino usb connection.

Open the Arduino IDE from the Pi menu:

Menu → Programming → Arduino IDE

Plug in the Arduino to a powered usb hub – not directly into your pi. This makes sure the Pi gets enough current to work properly.

Click Tools → Serial Port and select ‘/dev/ttyACM0’

This tells the Arduino IDE where to connect, in this case ‘/dev/ttyACM0’.

This opens a ‘sketch’ which will blink on and off the orange LED built onto the Arduino (pin 13).

If everything is okay, you should see a blinking light on your Arduino?

Step 6: Upload a special firmware used to work with nanpy v0.8

Your Arduino will need you to load a special sketch on it (firmware) for it to work with nanpy. To do this, you will need to make it first.

Move from the nanpy-0.8 directory into the firmware directory using cd:

~/nanpy-0.8 \$ cd firmware

Then type in the following:

~/nanpy-0.8/firmware \$ export BOARD=uno

~/nanpy-0.8/firmware \$ make

(you will get lots of output)

(you should see upload progress displayed)

Step 7: Run a simple python script to see if it is working

Now to test out your first Python AND Arduino experiment!

First we will write a simple python script using the text editor nano.

When nano opens, type in the following Python code:

''' import from nanpy and time modules '''
from nanpy import Arduino
from nanpy import serial_manager
from time import sleep

''' create a connection to the Arduino '''
serial_manager.connect('/dev/ttyACM0')

''' set pin 3 as an output '''
LED = 13
Arduino.pinMode(LED, Arduino.OUTPUT)

''' set the blink rate '''
delay = 1

print "starting"

''' while true aka start an infinite loop of led blinking '''
while True:
Arduino.digitalWrite(LED, Arduino.HIGH)
print delay
sleep(delay)
Arduino.digitalWrite(LED, Arduino.LOW)
sleep(delay)

Press control and x to exit the file.

Type y to save changes.

Then type:

and watch the led on your Arduino blink. When you are ready, press control c to end the script.

Sources

Special thanks go to the following for inspiring and informing this post:

themagpi.com

Tony Goodhew and Raspberry Pi forum community

nanpy V0.8

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.

## Khaya Centre Mount Olive 2014: visit+

Other things we achieved during the visit…

We managed to get www.codecademy.com working (after installing gnash) which was really exciting.

Loom Bands

Yes, loom bands have made it to Lehae! Nyah taught one girl how to do a loom band bracelet and by the last day, it had gone viral. And one of the trustees was very happy when she got her turn to learn too. She also saw the educational benefit of loom bands for the Khaya Centre: to strengthen hand and arm muscles for learning to write and hand eye coordination (we’re glad someone has found a benefit to loom bands).

Rainbow FM

Yes we did – we got on the radio in Jo’burg to talk about Urban Shift’s painting project and Project Pi.

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.

## Khaya Centre Mount Olive 2014: Visit

Visit: July 2014

Even with Tyson’s meticulous planning (yes Tyson is the master planner when it comes to details) , we just had to hope we had done enough. There were just so many unknowns. Who would I be working with in Lehae? What was the electricity like? Would there be Wifi? Would there be an electrical store near by if I needed any extra supplies?

Getting on the plane was exciting, I just had to stop thinking about it all and relax. Well that was until our flight was delayed and we had to spend 24 hours in Amsterdam. This was in some ways a mixed blessing – we got chance to get to know each other as a team which we had not had much chance to do before setting off.

Arrival – Nelson Mandela Day

Our first day of work was amazingly on Nelson Mandela day.

We had the opportunity to help with volunteers from businesses in Johannesburg who had come to help paint houses and plant little mini vegetable gardens for some of the families accessing the Khaya Centre.

Setting Up

Mandla, project lead South Africa side, set straight to setting up the Pi’s. I just took the pictures. And as we talked, I found out he has a background in business management and was taking time out of his studies to support the good work of the Khaya Centre.

Once the hardware was all good. I set on checking the Pi each had a working operating system, Libre Office installed and setting up Wifi (via a wireless router which connects to the internet via 3G).

Training

The first step was to figure out what people already knew about Linux and computing in general, and how confident they felt learning about what they didn’t know (and how much time they could give to this from their other duties). We also looked at what we knew about Libre Office, Scratch and Minecraft (which for Nyah, aged 10, was a lot more than the rest of us put together). We then looked at spending some time on what I called ‘deep emersion’ or in other words – having a play with a Pi for a while.

We decided to start the project with four groups. Two groups from the primary aged children and two groups of ‘seniors’. We planned out a basic introductory lesson, based upon some teaching from the front but also using Nyah (aged 10) to do a bit demonstrating, as well as time for unstructured exploration with some adult facilitation as needed. A big inspiration for the project and the style of delivery, was to try and get away from more formal modes fo instruction, and encourage the children and young people to learn by doing, and showing each other as they learnt. A key influence here was Sugata Mitra’s work.

Running the first sessions

The first impressions seemed to be unbeleif, then followed by excitement. This was the first time some of the younger children had used a computer, so coordinating the mouse and keyboard took a bit of time. But even within the first session we were seeing children teech each other how to move around in Minecraft and create sprites in Scratch (seniors).

Governance

I was shmoosing at a lunch one evening, kindly put on by one of the Khaya Centre trustees. I got talking with a retured high school principal. We were talking about Project Piu and the benefits. He seemed to see the educational benefits and we soon got talking about managing such a project and ensuring long term impact and quality. OFSTED came up, and I aksed him if he wouldn’t mind playing a kind of OFSTED role for the project. Perhaps with less fo the inspection feel and more of the supportive and guidance/leadership vibe. Within half an hour we had set a date for him to visit the project (the last day of the trip) and meet with Mandla (project lead). The meeting was very productive and we agreed a plan for the next 6 months.

UPDATE: I have spoken with Valencia who tells me that Mandla has also been introduced to an ICT teacher who works at a nearby school.

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.

## Khaya Centre Mount Olive 2014: Planning

Planning

So who knew having a good ideas is just the tip of the ice burg when it comes to pulling off a quality project? Luckily for Project Pi – I had teamed up with Moira and Esther (from Urban Shift) who were already planning to take out a group from Bolton to the Khaya Centre, in July 14. They were taking four teenagers and one adult – to help with a project to help improve the quality of living for 15 households in Lehae project. They had been out before as part of the building of the centre and wanted to follow up with some targeted outreach to families accessing the Khaya Centre. It made a lot of sense to partner up with this venture and go out as a group. We arranged with Valencia to sleep within the centre and she agreed to coordinate and organise our overnight security, transport and daily food and refreshments which was fantastic.

Architecture

Tyson used his background in cloud architecture to design the Raspberry Pi set ups. This included deciding specifically what to buy, from the Raspberry Pi all the way down to the SD cards, mice, cables and monitors. Each had to be sourced, checked for availability, priced up and  checked for suitability. For example, the power supplies for the Raspberry Pi had to supply enough current for the Pi’s which were overclocked and running with USB WiFi adaptors – we found out early on that the Pi would just cut out and restart if they did not have enough current available. Tyson was meticulous with side of the project preparation, aiming to keep the number of surprises in South Africa to a minimum. We didn’t know how easy it would be to source things like SD cards, cables or monitors when in Lehae so we decided to take it all out with us.

Software

During the planning phase we tested out a number of free software packages, most of which now come as standard with Noobs (New Out Of the Box Software), a handy bundle of operating system software supplied by the Raspberry Pi foundation. These were Scratch (a visual programming language designed for kids), Minecraft Pi and Python (Minecraft Pi comes with an API that allows kids to write Python code that can interact with the Minecraft world).

We also decided to install Libre Office, Chromeum and gnash. Libre Office is a free office suite which Valencia thought would be very useful for teaching basic word processing and spreadsheet skills as well as writing CVs. Chromeum with gnash (an open source version of Flash) was also installed to allow access to Codecademy.com, an excellent website for learning to code Python (and many more languages).

Teaching and Learning

Right from the start, I had been really keen for this project to be more than just an ICT suite. I wanted the way kids were taught and encouraged to interact with the Pi to be ‘child led’. I had been really impacted by a number of key people:

• Seymour Papert – I had experienced first hand as a child the thrill of making a Logo turtle/robot move by typing in simple lines of code. Having to persevere and iterate to make it move in the way we had imagined.
• Sugata Mitra – and his experiments with putting high speed internet into rural villages in India, leaving children to explore and find for themselves answers to their questions, spontaneously teaching peer to peer.

As well as the materials developed by Craig Richardson (http://arghbox.wordpress.com/) – a curriculum for learning Python using Minecraft Pi.

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.

## Khaya Centre Mount Olive 2014: Background

Background to trip

I first met Valencia in September 2013. Valencia leads a vibrant and growing project in Johannesburg, South Africa – called The Khaya Centre Mount Olive. The project is located in Lehae, amidst an expansive housing project built to accommodate beneficiaries of Eikenhof and Thembelihle settlements (see here for more on the Khaya Centre). At the time, I was with a group called Urban Shift who had first met Valencia, whilst helping to build the Khaya Centre in 2012. As we got talking, I was struck by the passion Valencia had for her project, and the vision she had for its future.  (Hear Valencia talking about her project here)

There was a moment, where the conversation seemed to really come alive , Valencia was speaking about the limited access to IT her centre beneficiaries and members of the local community have, and I suddenly thought about Raspberry Pi. What if these small, relatively cheap and easy to maintain little computers might be suitable for her projects needs? I myself was experimenting with three of them with my three kids at home with interesting results.

The next day, I excitedly took a Raspberry Pi along to a charity Valencia was visiting (HAFWAY). We managed to get the Raspberry Pi hooked up to a TV and some WiFi – and after a bit of surfing the internet, playing with minecraft and looking at scratch, it seemed that she liked what she saw. We tentatively agreed to pursue the prospect of bringing a number of Raspberry Pi out to the Khaya Centre. I had no idea how many, or how we would fund this. But there seemed to be a match with some of her projects needs and the what she saw the Pi could deliver.

I had originally been put on to Raspberry Pi by an IT savvy friend, Tyson, who worked for an innovative IT company in Manchester, UKFast. I asked him if he wouldn’t mind spending some time with me exploring the possibilities of the Pi and in particular, if we could set up the Raspberry Pi for use in an internet cafe. At this stage I was wondering if it might be helpful for the Khaya Centre to have the ability to use the Pi to create a small revenue, adding a certain degree of ‘sustainability’ to the project. I wondered – would it be possible for members of the local community to pay a small amount to use the internet or write and email CVs? I liked the idea of the project having the ability to pay for itself over time, to have a small business enterprise feel to it – not just an ICT project. Not just setting up an IT suite. I liked the idea of involving the community and as I recalled – this had also been something Valencia had specifically mentioned during her visit to the UK. Valencia had also spoken about other projects of this kind at the centre. A sewing project that enabled local women to sell what they made and a similar project involving growing garden vegetables.

Tyson and I had set up a google+ community group where we could share ideas in between meeting up. Tyson had also added some other friends who had experience in networking and linux (the operating system used on the Raspberry Pi). This had been a good place to let the project evolve. But come March, I noticed things had somewhat stalled. I remember that went to sleep one night wondering if the project would ever come to anything. The diea seemed good, people had shown interest. There was a fit between the technology and the Khaya Centre’s needs. But one question remained. How would we fund the project?

But then I got an email. It was Tyson, letting me know that his employer, UKFast had agreed to fund 10 Raspberry Pi and all the extras (see press release here).

It was April 2014 and all of a sudden – this was it – Project Pi was on.

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.

## Valencia talking about the Khaya Centre

### Tim Greenwood

Tim currently works for Living Systems. His background is in psychology, and he has been working as a psychologist within education and the community for the last ten years. He recently gained a Masters of Arts in Management, Learning, and Leadership from Lancaster Business school focusing on the use of Action Research to promote curious and evolving ways of working with individuals, groups and organisations.