Raspberry Pi: Let's light up the (hello) worldThere's a light, that shines, special for you, and me..
Soldering complete and Occidentalis installed, it is time to start learning how all this stuff works. Plus check that my soldering isn't so bad that it has destroyed my Cobbler.
From a quick bit of googling I started with the HelloWorld project:
Hello World: PythonSo there are a tonne of hello world pythons tutorials and examples, so I won't dwell on this.
- from the shell (I setup wifi connection & then ssh on to the Pi so I can work from my normal desktop - I also installed vim - you can either install vim or use your preferred editor) run:
In the editor enter the following:
Exit and save the file (:wq)
- From the command line run
sudo python helloworld.py
Hello World with Lights OnSo, the above was trivially easy and kinda pointless - but I did actually go through that, really just to make sure python was behaving and so I had a working baseline to go from.
So next I wanted to do a Hello World equivalent with hardware - the simplest thing to do seemed like a script that instead of printed hello world, just switched on a light briefly.
- If you opted not to install the Occidentalis OS (mod'd Wheezy OS packaged with stuff if you are planning on doing hardware stuff), then you will need to install some extra bits and pieces (you may already have them installed anyway, but running this won't do any harm - will just print the message saying its already there):
sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install RPi.GPIO
- Connect your Pi to the cobbler using the provided ribbon cable - plug the cobbler into your breadboard so it straddles the break down the middle (See photo below of the final setup of my breadboard for this experiment)
- Using a standard jumper lead, connect the ground on the cobbler to the -ve power rail on the breadboard (in this case mine is the purple-ish rail as you can see in the photo, the ground on the cobbler will be labelled GND). This is always best practice.
- Connect a resistor from the Pi Cobbler plug 23 to one of the free holes not linked to the cobbler (the resistor is needed to reduce the power - without one of these you will just blow your LEDs)
- Connect the +ve leg of the LED (the longer of the two legs) to the -ve power rail that we plugged the GND into, and the shorter LED leg into a hole in line with the resistor we plugged in (again, see photo below for final setup - although ignore the surplus resistor - that's not doing anything, I juts forgot to remove for the photo)
Now that the hardware is all connected, we need to update our simple helloworld script to control the light. So again, run vim hellolightworld.py and enter the following script:
Now save and exit that script, then go to the shell and run python hellolightworld.py and watch that little sucker flicker on briefly!