Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Wednesday, 14 May 2014

Witness My Train Wreck From The Weekend

So here it is for all to see the recording of the 20 minute (was just short of 19 minutes to be precise, but seems a lot longer) talk at last Saturdays CamJam on the Pibrella in the Classroom. From my point of view this seemed like a train wreck but your mileage may vary from it.

You can see the rest of the Pi in Education track from Saturdays CamJam here

Wednesday, 19 March 2014

Learn Python Course At PRC

This post is really for those in the Peterborough area who want to learn Python.
Peterborough Regional College are looking to run an 8 week learn Python course after Easter.
It would run on a Tuesday from 6pm to 8pm and if can get 16 people signed up cost £100.

If you are interested in signing up for the Learn Python Course contact myself on the following email address:
darren.christie@peterborough.ac.uk

As an experiment this course is only being advertised via social media.

Minecraft on Pi Controlling A Robot Arm

So basically my student using the python api for Minecraft on the Raspberry Pi has coded it so that when you hit a block it controls part of the USB robotic arm.
I'll put the code up later as an update to this post.

UPDATE 1: This setup will be on show Monday 24th at our Open Evening as well for those that would like to see it in real life.
UPDATE 2: Here is a link to the Python code that was written by my student that does all the stuff you see in the video. It should link to a shared directory on Google Drive (let me know if there are any problems).
UPDATE 3: Here is a link to the java code for the status updater that was developed and shown by my student at the STEM Fair yesterday.

Thursday, 27 February 2014

My Next Practical Session - Minecraft on the Pi

So the morning programming session at the upcoming Peterborough Raspberry Jam will be the Minecraft session. Which is the one I am down for running. Once the session has run I'll put up any handouts etc on here.

Although this session will be a hands on beginners session, I'd like this to be the first in a series of sessions that build on this one. Might run these at jams and CAS meetings. That's the grand plan. But will have to see how this first one goes.

You can find the links to the eventbrite pages to get a free ticket to the Peterborough Raspberry Jam in my previous post here.

 

Thursday, 13 February 2014

Tuneful Pibrella

Continuing on from yesterdays post I promised to put up a possible solution to the challenge from the buzzer activity, which was to play a tune using the piezo speaker on the Pibrella board for the Raspberry Pi.

I do apologise for the fact that all my code does is play a scale, however in my defence I do not have a musical bone in my body.

Wednesday, 12 February 2014

Python,Pibrella and the Raspberry Pi CAS Talk 12th Feb 2014

This evening I did a talk entitled "Python, Pibrella and the Raspberry Pi" at my local CAS group (West Norfolk and Fens).
The talk started off with a quick overview of the GPIO, how to tell which revision Pi you are using. The anatomy of a Python program that uses the GPIO. It was then onto a quick tour of the Pibrella and what it offered the teacher in the classroom. The talk closed with some quick announcements about some up coming events I thought were of interest and a promotion for this blog!
It was then on to the hands on part of the session and people playing with the Pibrella on the Raspberry Pi.
Before the talk I had prepared some activity sheets each concentrating on one of the features of the Pibrella. The sheets are very basic in information they contain, and give a commented Python program for the person doing the activity to type in. After that activity has been completed people are then directed to complete one of the other activity sheets or to try a challenge.
These activity sheets especially the challenges do require some previous experience of programming in Python. And are deliberate in being a lot more challenging.

I also had a mini display of some other boards for the Pi there as well, such as the Piglow, PiLite, LEDBorg with the XLOBorg on a TriBorg!, and a PiFace Controll and Display.

I do get a bit insecure after giving these sort of talks. I keep wondering if people found them useful, did I meet expectations? was it pitched too high? or was it not detailed enough?
I love doing these sort of sessions, I love sharing ideas etc. And doing these CAS sessions fits in with my kind of hippy ideals. I like to help, I don't want anything in return, I'm not doing it for self promotion. I just want to contribute to the good of mankind! And I am hoping that was achieved this evening.

With that in mind here are the ...

Resources from talk

Please feel free to download and re-use and edit to your hearts content to meet your own needs.

The slides (powerpoint format) for the talk can be found here (this is a shared link to a file on Google Drive).
The LED activity sheet can be found here.
The Buzzer activity sheet can be found here.
The Switch activity sheet can be found here.
And sheet of some ideas for student projects can be found here.
And it's the same again for the four documents above, the are word documents (docx) and a shared link to the file on Google Drive.

Some thank you's

A big thanks to Michael Horne who runs the excellent Raspberry PiPod blog and CamJam (along with Geeky_Tim) for the loan of the Pibrella's for the session tonight. A big thanks also to Pimoroni and Cyntech for agreeing to the load also, and for getting back to me speedily with some last minute questions I had.

The next blog post will be the code for the challenge on the Buzzer activity sheet, which is to play a tune using the buzzer on the Pibrella.


Wednesday, 22 January 2014

Simple Pibrella Python Demo

I think it was mentioned in my post yesterday that next month I will be running a practical session at my local CAS Hub on the Raspberry Pi using Python and the Pibrella add on board (soon to be available for purchase). Luckily I had been loaned a pre-release model so that I could start writing the session and developing the code and activities with it.

As a simple taster of what's involved with using the Pibrella on the Raspberry Pi with python I present this short piece of demo code that switches on the Green LED of the Pibrella for 3 seconds.

Once I have done the taster session next month I will put up all the resources I created for that for people to download, mock etc.

A big thanks to Michael Horne for the loan of the Pibrella, and providing the GPIO pin outs for it.

If you are a Scratch fan (I wasn't, but I'm warming to it) you can also use the Pibrella with that on the Raspberry Pi if you use Scratch GPIO. You can find out more here.

Tuesday, 21 January 2014

Coffee Anyone?

 

This Friday I'm lucky enough to have been given permission to attend the Games Britannia Industry Speakers Day by work (I also have a ticket for the event as well). It would be really cool to meet up with folks while there if you are attending. Looking at the schedule for the event there are breaks at 14:30 and 17:15. Plus the usual before and after opportunities to mingle and socialise.
I'll be looking something like the following:
Above photo taken at the Indie Coffee meet up just before Christmas, photographer Shahid
So either drop me a line via twitter (@whitespider1066), or leave a comment below, or just come up and introduce yourself on the day.
While I'm pretending to have a social life I may as well mention that on the 8th February I'll be at the Cambridge Raspberry Jam (better known as CamJam). Followed by running a hands on session at my local CAS hub (that's the West Norfolk and Fens) on python, the Raspberry Pi, and the new add on board the Pibrella. I then have a couple of weeks off! There is then a STEM Fair at PRC on 19th March which I think local schools are coming too, and I am doing adhoc 5 minute talks for teachers of lesson ideas using the Raspberry Pi. But before the STEM Fair you will find me at the first Peterborough Raspberry Jam. I'm running the Programming Minecraft in the morning, and just enjoying the jam in the afternoon.
So I hope folks can make some of these events even if you ignore me, as I think you will have a cool time.

 

Sunday, 12 January 2014

Career Hack Slightly Longer Example

Thought I'd put up a slightly longer python example of using the LMIforAll api.

For those interested I wrote this example on the iPad using pythonista. Which is a python app allows you write and run python code on an iPad. The version of python it uses is 2.7, and has the requests module. However it doesn't have numpy,scipy and matplotlib, which is a shame as they would turn it from an interesting little app into something a lot more powerful and useful. Although it does have the python image library, Dropbox and Evernote support. Add the csv module (which would have to work with the Dropbox module to allow you to access csv files) to the wish list of modules I'd like to see pythonista support. Hopefully my wish list will get added in the future. It would be really cool to see the iPad become an amazing python platform too.

Anyway here's the code:

Wednesday, 1 January 2014

Reading in a CSV File

So before I get on with the code and discussion for this post, let me tell you a little bit about the setup I develop in at home and for work.
I use a 15" Macbook Pro with 4GB of RAM (I really should upgrade this), with a 2.2 GHz Intel i7 processor (4 cores) and an Intel HD Graphics 3000 GPU running OS X Mavericks (Late 2011 model). I have also boot camped my Macbook Pro so that I have what I call my "dirty side" of the Mac, which is running Windows 7.
The "dirty side" I use for XNA and C# (Visual Studio 2010), and now also Game Maker Studio. While the Mac side is used for everything else, so Python, Objective C, and when I get a chance to look at it Unity.
For Python I either use my Mac or I use one of my many (5 at the last count) Raspberry Pi's (You will in future posts get to see code developed on the Pi specifically - well you have to, to use the GPIO etc).
The majority of the Python code that will appear on this blog will be 2.7. The main reason being this is the version that is used by Codecademy at the moment, and my students are using this to learn the basics of Python. So until Codecademy offers Python 3.x then that's the version I will stick with. Don't want to confuse the students too much. They are having to learn Python and C# already.

Right on to the main point of todays post, which is a follow on from yesterday where I talked about using Open Data.
If you remember I mentioned yesterday one source of Open Data being the MP Expenses data that is published. Today I will use that data for showing how to read in a csv file using Python.

I downloaded the csv files for 2010,2011,2012 and 2013. Which gave me four csv files that need reading in.
In a text editor I removed the first line of each file, it's the header giving the name of each column in the csv file. This was to make the next step easier. NOTE I made a copy of these headings to use later.
The next step I did was combine these into a single file to read in. I did that with the following command line:

cat mpexp2010.csv mpexp2011.csv mpexp2012.csv mpexp2013.csv > mpexpall.csv

Remember I develop on a Mac so this should work for Linux based systems as well (that includes Pi's), sorry Windows users you are on your own here. You will also note my filenames are different to the ones downloaded. I renamed the files for easier typing on the command line, and to make it more obvious what the data was.
To recap where we are, we have a single csv file of all the MP Expense data, and a copy of the column headings that looks something like the following:

Year, Date, Claim No., MP's Name, MP's Constituency, Category, Expense Type, Short Description, Details, Journey Type, From, To, Travel, Nights, Mileage, Amount Claimed, Amount Paid, Amount Not Paid, Amount Repaid, Status, Reason If Not Paid

The headings need cleaning up for our use, there are extra spaces in there and punctuation. So I edited the headings to look like the following:

Year,Date,ClaimNo,MPName,Constituency,Category,ExpenseType,ShortDescription,Details,JourneyType,From,To,Travel,Nights,Mileage,AmountClaimed,AmountPaid,AmountNotPaid,AmountRepaid,Status,ReasonNotPaid

These edited headings I then put back into the single csv at the start. I didn't have to, we could read in the csv file without them.

So now we need to read in our csv file. Below is the commented Python code to do this.
So that bit of Python code has read in our csv file of MP Expenses, and placed it into a list of dictionaries for us.

Lets do something "interesting" with this data now and calculate the average or arithmetic mean of the rent paid by MP's in 2012/13. Add the following code to the end of the code above that reads in the csv file.
So where next? Well there are libraries like numpy, scipy and matplotlib that can be used to help visualise the data (see further reading section below for links to books and a useful web page).
The above could of also been done in Excel, as could any further manipulation and visualisation of the data.
In fact which ever way chosen getting the students to present their visualisations as infographics would be a great way for them to present their work.

Further reading:
You can read more in the official documentation on csv files here.
2. Numerical and Scientific Python and Data Visualisation
Python Data Visualization Cookbook
Python for Data Analysis

Saturday, 28 December 2013

CareerHack AppChallenge 2014

The UK Commission for Employment and Skills (UKCES) are running a competition. They are billing it as a £20,000 App Challenge. Which technically it is, HOWEVER that is the sum amount of the prize money on offer. The actual first prize is £10,000, with a second prize of £5,000. Now that doesn't add up to £20,000 does it? Well it does if you add in the special prize of £5,000 for any student in the age range 16-24, and studying in Further Education within the UK. Pretty good hey?

So what are UKCES looking for to be in with a chance to win this money? They are looking for people to design apps that use the data from the Labour Market Information (LMI) for All website in "new and innovative ways".

The contest started on the 18th November 2013, and closes at 5pm GMT on the 21st February 2014.

Go read up on the rules etc (links below)

You can contact on Twitter: @appchallenge and @lmiforall
They mention these hashtags to use: #careerhack #lmiforall

Further Info Here:
Contest Web Page
UKCES Page
LMI for All Website

When I get back I will be encouraging my students to enter this competition. I think this is a great idea, and I hope some of them will take up the challenge. It would be nice to use our STEM Fair in March to show off some of the entries.

Now here is a first, considering the name of this blog, there hasn't been any coding so far.
So I knocked up a small Python program that accesses the LMIforAll api to get a list of Standard Occupational Codes (soc) for a keyword. A lot of the other api's need this soc code to work.



Not the best example, and not the best coded Python by a mile. But it does give a very simple example of accessing the LMIforAll api, which is sadly missing at the moment from their site.
I say sadly considering the fact they have a special prize for students, and with the popularity of Python in schools/colleges I think this is a little bit of an oversight. Yes they have an example of a web app (HTML/javascript if I remember correctly, I didn't investigate it too much), and there is an Objective C example I came across, but nothing in Python.

You can get further info on the requests library here. How to install the requests library here.

UPDATE1: Added use of Syntax Highlighter for displaying the Python code
UPDATE2: Note the Python code is 2.7 

Friday, 29 November 2013

Another Open Day Another Display

This week instead of a parents evening we had an open day at work. Which was very busy. So busy in fact I didn't even get a chance to make use of the free beverage that we are entitled to for doing the open day. Anyway I had my Raspberry Pi's out again. This time I had two running, one with the Pi-Lite (with the same code as the parents evening but different message scrolling), and the other running the Pi Glow. I was going to write some Python to show off the Pi Glow, however after running the demo code that came with it, for my needs I couldn't improve on it, so I ran with that. You can see the setup running in the embedded Instagram clip above.

So now I am 50% there of having my own version of the PiHub demo I saw at the last Cambridge Raspberry Pi Jam (CamJam). Which was basically 3 Pi's running off the one PiHub (see below). Next one I will add to this demo will most likely be a Pi running the PiFace Control and Display. I'd like to get the case for this however at the moment it's a fiver under their limit for using a debit/credit card with them, and there is nothing else I want from them!!! What a ridiculous limit, oh well I'll make do without for now. The other Pi for my demo will most likely be the PiBrella (not yet got my hands on one hopefully at the next CamJam, but shown briefly in the clip below) or the LedBorg (which I have on my Model B revision 1 Raspberry Pi).

What I like about having Pi's set up at events like the open day or parents evening is they firstly look interesting. Secondly they are a talking point for prospective students and their families. While we are talking Pi's and what they can be used for, I'm able to talk about the projects one or two of my students are currently working on (I'm lending Pi's out at the moment in the hope we will have some interesting projects to show at the next STEM Fair at work sometime after Christmas, like a USB Robot arm controlled within Minecraft on the Pi). Sometimes the prospective student will have one at home that they have not used, and it gives them a little inspiration to go back home and try doing something with it.
Anyway I hope this post has given folks some more ideas for using Pi's at open days. I'd love to hear how you have used them.

Friday, 22 November 2013

An Hour of Code

Over in the US of A they have a Computer Science Education Week running from the 9th to the 15th December. Which frankly I think is a fantastic idea. Part of this week involves an activity called "An Hour of Code". As the CSED Week site describes it, an Hour of Code is:

"... a one-hour introduction to computer science, designed to demystify "code" and show that anyone can learn the basics to be a maker, a creator, an innovator."

If you look on the site there are links to some tutorials that teachers/lecturers can use for their Hour of Code. If I remember correctly I think some UK teachers/lecturers are also going to participate and run sessions.

I am going to run an Hour of Code session for my Level 2 tutorial group that week. It also happens to be their final week before breaking up for the Christmas holidays (don't worry non teaching readers I will still be working right up to Christmas Eve).
I'm undecided at the moment if I will run my Hour of Code with Python or C#. My C# activity is more visual and has the students producing a little app that moves a picture box round the screen depending on which buttons they press.
Actually while typing this I may go with a Pi/Minecraft/Python activity - students love Minecraft and those sessions at Raspberry Pi Jams are always popular. The only drawback is the setting up and packing away, and at the moment I only have 5!
Right I have some thinking to do, and you now know about the Hour of Code.

Parents Evening Name Tag

This Wednesday was our parents evening. So I quickly cobbled together a 'hi tech' name tag for the table I was on (hopefully that's what you will see above (direct link).
The name tag is basically a Raspberry Pi (Model B to be specific) with a Pi-Lite being powered by a battery extender, and a glowing USB cable.
I ran the Pi 'headless' (i.e. without a monitor or keyboard). To start off the python script I had to ssh into the Pi from my Macbook Pro using an ethernet cable (DadHacker link).
The actual script I used was a modified version (read cut down to just one string) of this one from Raspberry Pi Spy.

What to say?

First posts of a blog are always hard, well for me they are.

Last week I did a talk at a local CAS (Computing at Schools) meeting on Python and KS3. I knew I was going to be doing this talk for a while (before the Summer holidays), and I had been thinking "how do I support this talk?".
The idea of a blog quickly came to mind, and the name manic coding followed very quickly after. It kind of reminded me of my old retro games I enjoyed playing, such as Manic Miner and Jetpac. But also I thought it caught the mood of programming in education at the moment.
With the change of direction within the curriculum, moving from ICT to computing, there seems to be an air of panic. Due mainly to the Government not putting in any training budget to bridge the skills/knowledge gap, and expecting teachers to somehow get the knowledge and expertise required.
Luckily there is a great community out there on the CAS website, where sharing resources, constructive and informative discussion are the norm.

So here we are with the first post of Manic Coding.


NEWS: Wolfram Alpha comes to the Pi
Yesterday Wolfram Alpha announced to the world that in future releases of Raspbian the official Linux distro for the Raspberry Pi will now include a version of their Wolfram Language and Mathematica software.
As they point out in the post announcing this, the only other time that there software was bundled with a machine was the Next Cube from Next, which later got bought out by Apple and provided the basis for OS X. I wonder what did happen to the CEO of Next? (Yes I know it was Steve Jobs)

Wolfram Post Announcing Now on Raspberry Pi
Raspberry Pi Site Announce Wolfram Language and Mathematica on Pi, also includes how to get hold of it now.

What is exciting for me about this announcement is the fact that the Wolfram Language also supports physical computing via the GPIO (there is an example in the Wolfram link).
I've not used either the language or Mathematica, but I will be playing with it over the next few months (I'm sure I will write something about it on here).
I do like the potential that this gives for making some interesting lessons, and opening up the Pi for use in other subjects other than computing.

With Java (or the official Oracle port now part of Raspbian) the Raspberry Pi is becoming a nice little machine for those with a small budget to learn to program. For me the big advantage of the Raspberry Pi over using a PC/Mac/Linux computer is the cost and how easy it makes physical computing and connecting devices. It's being able to light up LED's, use a sensor, or control a robot that brings life to  the subject and gets children hooked.

See ya in the next post...

PS I think I'm down for doing a second talk in January on the Raspberry Pi and the devices that you can attach to it. I'm not sure how this will work yet. But an idea is formulating in my head as I type this up. I want it to be very hands on this time.