My Journey to learn to program (and play with the Raspberry Pi)





**This page is continuously in development. I will be adding to this as I find out info that I think will be useful and as I progress in the project. So make sure to save the page and keep coming back for updates!**

For me knowledge is like a drug. Any attempt at relaxing usually ends up with me trying to learn something.

Learning how to program is something I have been yearning to understand for a few years. However, due to things like uni and trying to figure out the world of work I have been putting it off.

I can put it off no longer. I have borrowed my dad's Raspberry Pi and found myself some books :) Of course, I am also armed with my trusty notebook.

So I figured there must be others like me who want to give this programming thing a go with 0 base knowledge.... So with this in mind I thought that I would detail my journey on this page on how to set up your Raspberry Pi.


Contents

Prologue - What can the Raspberry Pi actually do?

Part 1 - Getting the pieces together

Part 2 - Set up your SD Card

Part 3 - Setting up your Raspberry Pi

Part 4 - Working out what to do next

Reference books, sites and other useful links I've read


The Raspberry Pi isn't actually hard to plug it and get working



Prologue - What can we make this Raspberry Pi actually do?


Contents


What do you want to do with it? Lets learn the Language

The different types of projects already done with the Pi

The different types of Raspberry Pi and the available add-ons















With most things I tend to have a habit of diving straight into a project with a long term aim but no specific direction. So, at the time of writing this part I have got to the point where I have switched on the Raspberry Pi and I have a desktop screen (like windows) that I can see. This is the news I excited reported to a friend of my who works as a programmer.

He then asked me - "What do you actually want to make it do?"

That stumped me. What did I actually want to make it do? What could I actually make it do?

In addition to this, the books that I had started reading about learning to program have commented that having a project will help you learn to program quicker. It will also make you more likely to complete the project if you actually want to see the finished product.

So I thought I would do some research. This is the perk of coming to this relatively late. There are loads of other people who have already had a play with the device. There is so much information and help available now that you do not need to feel overwhelmed by this concept. All you need to do is a bit of research.

My naivety was initially exposed with the realisation that there is more than one programming language. The Raspberry Pi is uses a language called "Python". Apparently this was picked because it is really easy to learn and widely used - so actually really useful to know as well. It is described as a "High Level" language because it looks pretty close to plain English in terms of how you write it. Within the language of "Python" there are also a number of different variations - designated by numbers.

This is where you need to be a little bit careful. Depending on when the text books you have were released will depend on what number python language you are using. I do not currently understand what can and what cannot be crossed over.

The original variation was 2.X and this has, apparently, a huge amount of add ons that are available in open source (free!) bits of code to download. The 'upgrade' 3.X was arrived in 2008 - so that original issue is probably void now anyway.  My book Raspberry Pi for beginners [mag book] (2013) has chosen to use 2.7. Currently, I can't find anything in Raspberry Pi User Guide [Eben Upton (Creator of the Raspberry Pi) and Gareth Halfacree] (2013 reprint) that tells me which language it uses. Both of these books include a couple of small projects.

With the arrival of 3.X, 2.X is now known as the "Legacy" language. The last update (2.7) was added in 2010. While there is continuing support for this, there will be no further updates. 3.X has been significantly updated in comparison to it's predessor. The coding is now significantly easier for beginners to learn and has much greater Unicode (check out the definition below if -like me - you have no clue what that is) support.



If you are already a Python 2.X user and want to move to 3.X I warn you that there is no backwards capabilities. This is primarily because of how the language has been redesigned and it also made this redesigning a lot simpler. A lot of bugs that you would have been aware of in 2.X have been removed with 3.X and issues are a lot easier to find and resolve.

However, if, this me, you want to actually learn properly how to program I also recommend a Python teaching text book like this Python Programming. Third Edition. For the absolute beginner. [Michael Dawson] (2010). This is recommended for students who have literally never even heard of the Python language before. There is also a sequel if you progress to that point that you can buy.


As my dad brought the Raspberry Pi, I did not have that initial stage of research before purchase. As a result I had not actually realised that there are different types of Raspberry Pi that you can buy.

There are also different brand variations of the micro computer that have also now popped up. This is really great news for the industry as it gives people loads of choice. But, for now, I'm just going to stick to the Raspberry Pi.

The first thing you might be asking, if you are otherwise unfamiliar with the capabilities of the Pi - is what can this thing actually do? Seeing the capabilities of this little thing can really help you feel inspired. With this in mind, I have put together a Top 5 Raspberry Pi projects for you that I could find after a really quick Google search. So the possibilities, especially with the newer more powerful models are endless.

1)Create a fully functioning R2D2
No instructions unfortunately. But an amazing piece of inspiration.



2) Combine multiple Pi's together and make yourself a really cheap supercomputer. The university of Southampton have created a great set of instructions here. The (other) really cool bit is that they have built the housing out of LEGO!



3) Build a micro portable computer. Not the most elegant design at the moment. But a really cool idea. The best bit is that this is a completely open source project, so all the instructions to make it can be found here. 




4) Creating a live Google Calender for your wall - A super practical idea if you are avid user of Google calender. Think this would be ideal for a family planner as it obviously can be live updated! You can find Piney's instructions here.

My thought with this one is get yourself a smaller screen and intergrate it into something pretty. It would make this much more home decor friendly - so more applicable for use out of the office.


5) Do put up hundreds of Christmas lights every year? Well now you can also sync them to musics using your Raspberry Pi. Not useful - but significantly cool. Check out the video below.



Raspberry Pi 1 

Model A (Released Feb 2012)

Description from the Raspberry Pi Site.

Model A is the lower-spec variant of the Raspberry Pi, with 256 MB of RAM, one USB port and no Ethernet port.
This model is usually bought for embedded projects: because it’s missing a few ports and an Ethernet chip, the Model A is lighter and consumes less power than a Model B. We see a lot of Model As used in robotics; and also in projects where weight and low power are paramount, such as the very popular high-altitude ballooning high-jinks pioneered by Dave Akerman, and now being reproduced inschools around the world. Model A in combination with a wifi dongle is also ideal for users who just want a Raspberry Pi to act as a media centre running behind their television.

Raspberry Pi (Model A)



Model A+ (Released November 2014)

Description from the Raspberry Pi site

The Model A+ is the low-cost variant of the Raspberry Pi. It replaced the originalModel A in November 2014. Compared to the Model A it has:
  • More GPIO. The GPIO header has grown to 40 pins, while retaining the same pinout for the first 26 pins as the Model A and B.
  • Micro SD. The old friction-fit SD card socket has been replaced with a much nicer push-push micro SD version.
  • Lower power consumption. By replacing linear regulators with switching ones we’ve reduced power consumption by between 0.5W and 1W.
  • Better audio. The audio circuit incorporates a dedicated low-noise power supply.
  • Smaller, neater form factor. We’ve aligned the USB connector with the board edge, moved composite video onto the 3.5mm jack, and added four squarely-placed mounting holes. Model A+ is approximately 2cm shorter than the Model A.
We recommend the Model A+ for for embedded projects and projects which require very low power, and which do not require Ethernet or multiple USB ports.
See the documentation for technical details.
Raspberry Pi (Model A+)

Model B (Released Feb 2012) 

This is the one I am using to learn with.

Description from the Raspberry Pi site

Model B is the higher-spec variant of the Raspberry Pi, with 512 MB of RAM, two USB ports and a 100mb Ethernet port. It’s our most popular model: you can use it to learn about computing; to power real-world projects (like home breweries,arcade machinesmusical root vegetablesrobot tanks and much more); as a web server; a bitcoin miner; or you can just use it to play Minecraft.

Rasberry Pi (Model B)

Model B+ (Released July 2014)

This is the description from the the Raspberry Pi site

The Model B+ is the final revision of the original Raspberry Pi. It replaced the Model B in July 2014 and was superseded by the Raspberry Pi 2 Model B in February 2015. Compared to the Model B it has:
  • More GPIO. The GPIO header has grown to 40 pins, while retaining the same pinout for the first 26 pins as the Model A and B.
  • More USB. We now have 4 USB 2.0 ports, compared to 2 on the Model B, and better hotplug and overcurrent behaviour.
  • Micro SD. The old friction-fit SD card socket has been replaced with a much nicer push-push micro SD version.
  • Lower power consumption. By replacing linear regulators with switching ones we’ve reduced power consumption by between 0.5W and 1W.
  • Better audio. The audio circuit incorporates a dedicated low-noise power supply.
  • Neater form factor. We’ve aligned the USB connectors with the board edge, moved composite video onto the 3.5mm jack, and added four squarely-placed mounting holes.
The Model B+ is perfectly suitable for use in schools: it offers more flexibility for learners than the leaner Model A or A+, which are more useful for embedded projects and projects which require very low power, and has more USB ports than the Model B.
See the documentation for technical details.
Raspberry Pi (Model B+)


Raspberry Pi 2 

Model B (Released Feb 2015)

Description from the Raspberry Pi Site.

The Raspberry Pi 2 Model B is the second generation Raspberry Pi. It replaced the original Raspberry Pi 1 Model B+ in February 2015. Compared to the Raspberry Pi 1 it has:
  • A 900MHz quad-core ARM Cortex-A7 CPU
  • 1GB RAM
Like the (Pi 1) Model B+, it also has:
  • 4 USB ports
  • 40 GPIO pins
  • Full HDMI port
  • Ethernet port
  • Combined 3.5mm audio jack and composite video
  • Camera interface (CSI)
  • Display interface (DSI)
  • Micro SD card slot
  • VideoCore IV 3D graphics core
Because it has an ARMv7 processor, it can run the full range of ARM GNU/Linux distributions, including Snappy Ubuntu Core, as well as Microsoft Windows 10 (see the blog for more information).
The Raspberry Pi 2 has an identical form factor to the previous (Pi 1) Model B+ and has complete compatibility with Raspberry Pi 1.
We recommend the Raspberry Pi 2 Model B for use in schools: it offers more flexibility for learners than the leaner (Pi 1) Model A+, which is more useful for embedded projects and projects which require very low power.
Raspberry Pi 2 (B+ Model)

Additional Add-ons

The Raspberry now even has it's own set of additional gizmos you can attach to create some really funky kit. This has the major advantage of hugely expanding the possible projects you can do - hence why it is worth knowing about them before you get started.

Camera Module

Description from the Raspberry Pi site.

The Raspberry Pi camera module can be used to take high-definition video, as well as stills photographs. It’s easy to use for beginners, but has plenty to offer advanced users if you’re looking to expand your knowledge. There are lots of examples online of people using it for time-lapseslow-motion and other video cleverness. You can also use the libraries we bundle with the camera to createeffects.
If you’re interested in the nitty-gritty, you’ll want to know that the  module has a five megapixel fixed-focus camera that supports 1080p30, 720p60 and VGA90 video modes, as well as stills capture. It attaches via a 15cm ribbon cable to the CSI port on the Raspberry Pi.
The camera works with all models of Raspberry Pi 1 and 2. It can be accessed through the MMAL and V4L APIs, and there are numerous third-party libraries built for it, including the Picamera Python library.
The camera module is very popular in home security applications, and in wildlife camera traps. 

Camera Module for all models of the Raspberry Pi

Pi NOIR Camera

Description from the Raspberry Pi site.

The Pi NoIR gives you everything the regular camera module offers, with one difference: it does not employ an infra-red filter. (NoIR = No Infra-red.) This means that pictures you take by daylight will look decidedly curious, but it gives you the ability to see in the dark with infrared lighting.
We bundle a little square of blue gel with the Pi NoIR, which you can use with the Pi NoIR to monitor the health of green plants. The Pi NoIR is very popular among wildlife hobbyists: with a few infra-red LEDs, you can monitor what nocturnal animals are doing in your garden without disturbing them.
The camera works with all models of Raspberry Pi 1 and 2. It can be accessed through the MMAL and V4L APIs, and there are numerous third-party libraries built for it, including the Picamera Python library.
Pi NOIR camera for all Raspberry Pi Modules

Compute Module

Description from the Raspberry Pi site.
The Compute Module is a Raspberry Pi in a more flexible form factor, intended for industrial application.
The compute module contains the guts of a Raspberry Pi (the BCM2835 processor and 512Mbyte of RAM) as well as a 4Gbyte eMMC Flash device (which is the equivalent of the SD card in the Pi). This is all integrated on to a small 67.6x30mm board which fits into a standard DDR2 SODIMM connector (the same type of connector as used for laptop memory). The Flash memory is connected directly to the processor on the board, but the remaining processor interfaces are available to the user via the connector pins. You get the full flexibility of the BCM2835 SoC (which means that many more GPIOs and interfaces are available as compared to the Raspberry Pi), and designing the module into a custom system should be relatively straightforward as we’ve put all the tricky bits onto the module itself.
The compute module is available for purchase in single units, or in batches of hundreds or thousands. To get started designing a PCB to use the module, we provide an open-source breakout board with a single module in an affordable development kit.
Compute Module for Raspberry Pi
Compute Module Development Kit


Description from the Raspberry Pi site.

The Compute Module Development Kits is a prototyping kit for those who wish to make use of the Raspberry Pi in a more flexible form factor, intended for industrial application.
The compute module contains the guts of a Raspberry Pi (the BCM2835 processor and 512Mbyte of RAM) as well as a 4Gbyte eMMC Flash device (which is the equivalent of the SD card in the Pi). The accompanying IO Board is a simple, open-source breakout board that you can plug a Compute Module into. The board hosts 120 GPIO pins, an HDMI port, a USB port, two camera ports and two display ports. Designing the module into a custom system should be relatively straightforward as we’ve put all the tricky bits onto the module itself, and you have the freedom to add extra components and place parts exactly where your product needs them.
The compute module is available for purchase in single units, or in batches of hundreds or thousands.


Compute Module Development Kit for the Raspberry Pi


So now you know all the techn


Part 1

To get started with your Raspberry Pi you will need about £100 and the internet:

- A Raspberry Pi (obviously) --> RS Electronics about £30 [But I got this from Dad]
- 8GB SD Card [Also from Dad]
- Monitor [I am using an old TV screen with a HDMI port]
- Multi USB Hub [Also from Dad]
- Additional extensions to USB (Dad's idea to save wear & tear to the USB port) [Dad again]
- Micro USB charging cable [This was mine! Perk of storing nearly every charging cable from every device I have ever owned]
- USB keyboard [Found that my desktop keyboard wasn't USB :( However, I then remembered that I happened to own a USB keyboard from when I used to used my Nexes as a keyboard at Uni.]
- USB mouse [Struggled to find this one. I eventually hunted one down - located in my stationary box of all places]
- Ethernet Cable [This originally came with a Wi-Fi extender. Didn't need that for the extender, but it might be super useful for this! Might also end up using the extender in combo to get cabled internet for my room to do this].
- Because of the relatively delicate nature of the Pi I have purchased a clear case from amazon (I also love the look of a circuit board so it didn't seem right getting one that wasn't clear). You don't need one, but it will help it last.
- A notebook, Pen & Highlighter
- Books to help you along - I have myself
Raspberry Pi for beginners [mag book] [Brought this from a service station]
Raspberry Pi User Guide [Eben Upton (Creator of the Raspberry Pi) and Gareth Halfacree] [This was also from Dad]
Python Programming. Third Edition. For the absolute beginner. Michael Dawson. [This is perfect if, like me, you are completely starting from scratch]

Clear Raspberry Pi case from amazon


So once you've got all the kit you are ready to begin.



Get all the pieces you need together before you get started








Part 2

Now you need to set up your SD Card.

Firstly: Pop your SD card into the reader in your computer

Second: Head over to this website to download the "image writer for windows". This needs to be moved onto your SD Card.

Thirdly: Head to this website to get the 'image' for your operating system. I was going to be brave and install the Raspian image (as per instructions from my book). However, after reading the info on the site I realised that (as I am a totally programming Virgin) that the NOOBs version could be my safest bet! Download the Zip folder and extract that onto the SD card.

Fourth: Once everything is safely copied to your SD card, safely remove it from your computer.

This uses less than 600mb. So an 8GB is more than big enough for an SD card.



Part 3

The next part of the plan is to set up your Raspberry Pi. 

This will take you about a hour. So don't copy me and start a 10pm at night when you have work in the morning (even when you are really excited!!)

Plug all of the bits in that you have collected to your Raspberry Pi. This is where you will find the perk of the extender multi USB port. It helps space things out a little more. 

Plug everything into the right places in your Raspberry Pi


If you are anything like me you will now be wondering where to plug in your SD card. Turn it over. You will see a slot. Just slot it into there. 

Slot in your SD card
The port in on the bottom



Once this is done, plug the HDMI cable into the monitor. 

You may have noticed that your Raspberry Pi does not have a 'power on button'. To turn it on, plug it into the power and you will have lift off. 

This will now appear on your screen (see below). Don't worry (as I initially did) this is totally normal. 

Don't worry when the Pi starts doing the partition processing.
This is meant to happen


Once that has been completed (it literally takes a few minutes), this will appear on you screen. 

Select the operating system you want to install)

So select the top option (Raspian image) and select install. This will table about 20 minutes to fully set up. There are a few messages the loading screen provides, so I thought I would take a picture and upload here to save you some time :) 

Welcome to your Raspberry Pi.
We're currently setting up you SD card but don't worry,
you'll be about to start programming very soon. 
When Raspbian boots up you will need to log in to the system.
The default username for RASPBIAN is pi, with the default password raspberry
The first time you boot up Raspbian, you will see a
configuration program called raspi-config

In raspi-config you can choose to always book in Graphical User Interface (GUI)
or into Command Line Interface


A GUI has icons and windows much like Microsoft windows or OSX.

A Command Line interface allows you to type commands into your
Pi directly.

If you want to start the GUI from the command Line Interface,
you can type:
startx

There are many great programs already pre-installed on Raspbian,
just waiting for you to boot up and play.

If you're new to programming we recommed starting with
a pragram called scratch.

This can be launched by clicking on the following icon on the
desktop (see the yellow cat)
Raspbian is a free operating system based on Linux and optimised
for the Raspberry Pi.

An operating system is the set of basic programs and utities that make
your Raspberry Pi run, 

You can also download additional programs or even
sell your own content on
The Pi Store
http://store.raspberrypi.com


Win! My operating system is successfully installed! 

So once you hit this enter key - the screen starts doing this.
If, like me, you are a beginner, you will have no idea what the text means. 
Don't worry the screen quickly changes to the list. 

Option 1. Don't worry about this. I hit enter and it told me that because I have used the NOOB setup this has already been set up. 
Option 2. This is the option you need if you want to change and set up the password for your Pi. I didn't bother as I am not currently moving it around. 
Option 3. This is the one you need to pay attention to. If (like me) you are a beginner - arrow scroll down to option 3 and hit enter. Once you are on this new screen scroll to select to boot up to the desktop style screen. 

You don't actually need to worry to much about the other options. At this point I scrolled down and hit the finished button.

If I find out any more info about the other options I will add them in later. 





Part 4 - Starting to program

So, at this point I have successfully installed the operating system onto the Pi. Now all I want to do is get started with the programming.

What you need to do now is click on the menu button on the top left corner of your screen, This will cause a drop-down menu to appear. Select 'programming' and then select 'Python 3' from the drop down menu. We'll explore the other options at a later date.


This will bring up the Python Shell onto your screen. From here is where you will add in the code for what you will program.



Success! My first little bit of coding! You'll notice a few failed attempts... Turns out whoever printed the keyboard got the @ and the " mixed up..... That was confusing. However, it does allow you to see the difference in the colour coding. So it is really easy to see where the error is and what code works.


This is the screen in which you can write programs you want to happen now. If you want to write a program to use later you need to use IDLE. To open this you need to select "File" and "New Window". This will bring up a new screen that won't run the command.

Coding notes:

Python is case sensitive: all functions must be written in lower case


Reference books, sites and other useful links I've read

Raspberry Pi Projects
Top 15 Projects for the Raspberry Pi by IT Pro
This is a mix of projects with instructions and just inspiration. Some of the projects are more useful for the day-to-day and some are just awesome!

12 Cool Projects for your Raspberry Pi by Lauren Orsini 
Some funky projects that really highlight the capabilities of this tiny machine.

Products for the Raspberry Pi

RaspberryPi.org/products
This is a link to the different types of Raspberry Pi products. 

Books for the Raspberry Pi


Resources for information about Python coding

This takes you through to a really useful site about Python if you want some additional resources. 

This is a really comprehensive document for anyone interested in the differences between 2.X and 3.X. Really useful if you have been using 2.X and what to move to 3.X. If you know nothing about Python (like me) this isn't for you quite yet.

Python 3 Q&A
A lot of it made sense to me. This is a really good layman article about the differences between Python 2 & 3.

Pragmatic Unicode
"Why Python 3 exists". I haven't watched this yet. Looking at the summary it is more geared up to those who already know something about programming. It is to advanced for me at the moment. But I plan  to come back to it in the future!


No comments:

Post a Comment

Please let me know what you thought of this blog. Would you like to see more of this type of posts? What did you like most about it?