The default SD card image that comes with of PiNet is awesome and has just about everything you could need for using Pis in the classroom or with a club. The only thing that niggled me was that you couldn't have Scratch-GPIO installed directly. You could have a shortcut on the Desktop to make it easy to install once the SD card is booted, but that seemed like a bit of a hassle, especially if you're operating somewhere with flaky (or nonexistent) Internet access.
So I set aside some time to work out away of pre-installing it on the server default image so that each clone SD card could have it ready to use when booted.
Here is my method - there may be simpler or more elegant ways but this seems to work reliably. This works with ScratchGPIO V7 as of Sept 2015.
There are two parts to the installation. You'll need some modified files which can be found on my GitHub here.
1. So clone this repo onto your PiNet server.
cd
git clone https://github.com/topshed/ScratchGPIO-on-PiNet.git
2. Then copy in the modified installer script and run it. The modified version unpacks the files needed for ScratchGPIO into /tmp as normal, but does not install them.
cp ScratchGPIO-on-PiNet/isgh7-pinet.sh /opt/ltsp/armhf/
3. Now chroot in and run it:
sudo ltsp-chroot --arch armhf
sudo bash isgh7-pinet.sh
4. Exit from the chrooted environment and copy in another file
cp ScratchGPIO-on-PiNet/installer-pinet.sh /opt/ltsp/armhf/tmp/selfextract.ZpdSK6/.
(note, your directory name will be similar but different. It should start with 'selfextract' but have a different bunch of characters at the end - use ls /opt/ltsp/armhf/tmp/ to find out what it is).
5. Next, pop back into the chrooted environment and change directory into the unpacked file archive directory.
sudo ltsp-chroot --arch armhf
cd /tmp/selfextract.ZpdSK6
sudo ./installer-pinet.sh
This installs all the necessary files but doesn't try to add desktop shortcuts or the rsc.sb file.
6. Finally, don't forget to compress the Raspbian operating system:
ltsp-update-image /opt/ltsp/armhf
7. The second stage is to add those shortcuts and the rsc.sb file manually. Exit the chrooted environment and change directory to /etc/skel/Desktop.
cd /etc/skel/Desktop
Then make a couple of directories and copy in the files from the cloned Github repo:
sudo mkdir Documents
sudo mkdir Documents/"Scratch Projects"
sudo cp ~/ScratchGPIO-on-PiNet/rsc.sb Documents/"Scratch Projects"/
sudo cp ~/ScratchGPIO-on-PiNet/ScratchGPIO7.desktop Documents/"Scratch Projects"/
sudo cp ~/ScratchGPIO-on-PiNet/ScratchGPIO7Plus.desktop Documents/"Scratch Projects"/
That should be it!
Thursday, 17 September 2015
Thursday, 3 September 2015
Raspberry Pi soars to new heights with Skycademy
This is Lego Space Marine Bob.
| Bob |
He may look like just another lego Minifig. You may even have one that looks just like him.
But Bob is rather special. He flew up to 28km above the Earth and made it back...
![]() |
| View from the onboard Pi camera from the Cirrus flight |
...in a styrofoam box with a Raspberry Pi.
| This is the payload we sent to 28km |
Although I've been back a week now, it has taken a while for just how awesome Skycademy was to sink in.
As soon as I saw it advertised, I literally dropped everything I was doing and typed up my application straight away. Launching a high altitude weather balloon with a Raspberry Pi payload and then chasing it when it returns from the stratosphere... that sounded like something I had to do. I was over the moon when I found out I'd managed to get a place and so a week ago last Sunday I headed up to Cambridge full of excitement and with a carefully selected Lego mini-figure (Bob) hoping to take a ride high above the Earth.
Day One.
First of all, let's be clear. Sending stuff up to the stratosphere is actually quite easy. Attach whatever you want to launch to a weather balloon filled with helium, let it go and... well that's it. Done.
Getting it back, that's a little harder. And that's where the Raspberry Pi comes in. So before we launched our own balloons, we got to learn about predicting and tracking trajectory from veteran of over 50 launches (and all-round HAB guru), Dave Akerman.
| Dave Akerman telling us all about GPS |
The tech to monitor the progress of your flight is deviously clever, but here's the simple version. The payload contains a Raspberry Pi with some additional hardware that lets it work out where it is (a GPS module) and transmit those coordinates back to Earth via radio.
![]() |
| PITS+ board |
Of course, being able to see that your balloon's payload has ended up in the sea is very informative but ultimately doesn't make recovery any easier. The best plan is to work out when to launch the ballon so that the weather conditions (mainly wind) keep your flight and descent over accessible land. You can also tweak things (the amount of gas with which you fill the balloon, the weight of the payload) to optimise the chances of recovery and there are some super-useful online tools to do the calculations for you.
We also covered the all-important permissions from the CAA that you need to obtain before making a flight. Being able to ask stupid questions about this whole process was invaluable and will probably save me hours of hassle and research.
I'd read about a lot of High Altitude Ballooning before coming on Skycademy but hearing about it from people who'd actually done it had the effect I'd been hoping for and really joined everything up in my head - and made it feel like an achievable goal. My own kite-mapping experiments have really been a poor man's version of HAB because I wasn't brave enough to attempt a balloon launch on my own!
| Pi A+ plus LPRA board plus camera |
Don't think that Skycademy was just sitting around listening to other people. Day one was full of hands-on activities; we split into 4 teams and constructed our payload containers; ensured the Raspberry Pi cameras had a clear view; assembled, configured and tested both our primary RTTY radio system and the backup LORA equipment and finally (and most importantly), decorated the container. Ours was quickly named the 'Dragon Toaster'.
| Dragon Toaster |
A lot of the hardware and software is still in active development so there was lots of tinkering and optimisation which was brilliant fun and really helped with understanding how everything fits and works together.
It's worth mentioning the weather at this stage. In the week before Skycademy we'd all been studying the forecast and hoping for good, calm weather to allow us to launch our balloons. The predictions just before the weekend were not at all promising, with strong wind, rain and lots of cloud promised for Tuesday. At one point it looked almost certain that even if we could safely get the balloons aloft, they'd end up in the ocean.
However, as the new week began, the forecast became less gloomy and by the end of Monday (which was a very unsettled day), we all left Pi Towers feeling cautiously optimistic that we'd at least attempt some launches early the next morning.
The uncertainty of the weather was itself a good learning point. the big thing I took away was that while you might like to make a definite plan to launch on a certain day, you really shouldn't bank on it.
Day Two
The forecast was for strengthening winds all day, with rain arriving mid-afternoon. So we had an early start (08:00 at Pi Towers) and then headed straight off to the launch site just west of Cambridge. As our merry convoy of vehicles scooted along the concrete track through the fields to our final location, we certainly drew some curious looks from the local dog-walkers.
| Arriving at the launch site |
The sun broke through the clouds and as we started unpacking our kits the temperature rose rapidly. Although it was quite gusty already, there was a line of tall trees which provided some good ground level shelter. Local knowledge of the launch site is clearly very useful.
As the teams carried out final assembly and testing, there was much to-ing and fro-ing back and forth to the cars. Like all reasonably complex tasks, there is definitely an optimal order in which to carry out the various component tasks. Having experienced HAB launchers present was a huge advantage and while many of pro-tips I picked up may seem obvious now, they only appear that way once you've spotted them.
It was also clear that working as a team of 6 was a big help. There were many instances where having a whole bunch of people who knew what they were doing meant that problems could be easily and swiftly corrected (like when we attached the payload to the parachute using the wrong ratio of line lengths). If these issues cropped up while you were attempting a solo launch and potentially demonstrating to, and looking after a group of children, it would be very easy to get flustered and make mistakes.
Finally everything was ready and Dave kicked things off with inflating his own hydrogen balloon and launching it. As it quickly sailed into the blue sky I was struck by how graceful and elegant the launch seemed. It was odd to think that this relatively leisurely ascent would continue until the balloon burst at in excess of 30km altitude.
| Dave's balloon |
Next it was our turn. Filling the balloon with helium was actually very easy, although sealing off the neck with cable-ties and ensuring there were no sharp edges took a steady hand.
| Windier than it looks |
Both teams Cirrus and Nimbus were ready at the same time so decided to launch simultaneously.
| Simultaneous launch |
This almost turned into a disaster as despite being released several metres apart, the two balloons' paths converged and their payload lines nearly tangled around each other. Fortunately Nimbus gained altitude more rapidly and they had soon separated.
| Watch out! |
For a few minutes we stood around watching them disappear into the sky. Then we realised that we needed to get chasing and quickly packed up our gear and headed to the cars. Two of our team were heading back to Pi Towers to monitor things from there while the remaining four of us went off in the car towards Norwich.
We immediately found that both the RTTY and LORA receivers were working and our balloon was reporting back its coordinates and other telemetry. I know we'd tested everything and discussed the technology in lots of detail the day before, but actually experiencing it working was very satisfying. The idea that we were tracking a balloon from a moving vehicle using Raspberry Pis as the core platform was amazing.
One thing we noticed straight away was that our ascent rate was lower than we'd intended. For the burst predictor calculations we'd been using a figure of 5m/s. Our balloon was only making 3.5m/s. When we plugged those numbers into the flight predictor, our final landing point was a couple of kilometres off the coast. Not good.
One thing we noticed straight away was that our ascent rate was lower than we'd intended. For the burst predictor calculations we'd been using a figure of 5m/s. Our balloon was only making 3.5m/s. When we plugged those numbers into the flight predictor, our final landing point was a couple of kilometres off the coast. Not good.
There was nothing we could do at this point, and it wasn't our only concern. Unlike all the other teams, our balloon was not showing up on the live tracking map. This didn't make any sense as we could clearly see the data in the car, and the first images from the Pi camera were starting to appear on the other HubHub sub-site. Our team-mates back at Pi Towers confirmed that there was a problem and started to investigate.
Meanwhile, our balloon had started to climb more rapidly and our ascent rate was getting close to 5m/s at times. It was still nerve-wracking - would the initial slow speed have already put an onshore landing out of the question? The results from the predictor were very close.
However, looking at our actual flight path it seemed that the Cirrus balloon was travelling further south than the predicted one, so we gave up trying to refine the estimated landing point and just kept a close eye on the altitude.
![]() |
| Not looking good |
However, looking at our actual flight path it seemed that the Cirrus balloon was travelling further south than the predicted one, so we gave up trying to refine the estimated landing point and just kept a close eye on the altitude.
As we approached the outskirts of Norwich it looked like the ballon was not going to make it North of the city so we headed South towards Gillingham instead. This turned out to be a good call.
![]() |
| Image from the onboard camera just before burst |
At half past 12, the balloon reached 28000m... and burst. Cirrus' Dragon Toaster was heading back to Earth. But would it descend quickly enough to avoid a watery grave? After the burst, we could see from the telemetry that the balloon was spiralling around as it plummeted rapidly. This was good! The less time it spent heading east, the better. We'd pretty much caught up with the balloon by now and so decided to stop and enjoy a picnic at a nice scenic location while we waited to see where it would end up.
| Picnic |
| A Raspberry Pie |
Despite the pleasant surroundings and tasty grub, we didn't hang around for long, because the balloon was descending quickly. We were heartened to see that although it was definitely heading east again, it seemed to occasionally pick up an onshore breeze and head west for short bursts. It passed almost directly over head (although we couldn't see it) and so we got back in the car to continue the chase. Not long after that, we lost the signal. The transmitters on the payload are very low power (mW) so our receivers will only get a decent signal when there is nothing in the way. Once the Pi is on the ground, the range is severely reduced. We decided to head for the last reported coordinates, which were a sent when the balloon was a few tens of metres up.
![]() |
| Coordinates of last position before we lost contact |
![]() |
| Actual landing site |
There it was. Mission success!
| As it landed |
Dragon Toaster recovered!
| Hurrah |
We realised that our balloon had had a very fortunate landing. We were so close to a row of trees and a number of watery areas and roads. Not to mention, on a larger scale, the sea!
![]() |
| Close to the sea |
Elated, we packed things up and started the journey back to Pi Towers. Dave had warned us that the balloons were very smelly - like a condom factory - so we sealed that up in a plastic bag.
We waited until we were back together as a full team before cracking the payload container and recovering Bob. This meant we continued to transmit pictures from the boot all the way back (and caused interference with the car's alarm).
Once back at Pi Towers we discovered why our balloon was not being displayed on the tracker page - a single character typo meant that its call-sign did not match the expected string and so packets were not being registered even though we were seeing them in the car. Oh well, something to remember to double-check for next time.
It was an incredibly successful day. Of the 5 Skycademy balloons launched, 4 were recovered. Unfortunately one seemed to have been under-filled with helium and never attained sufficient velocity to enable it reach burst altitude in time to descend before the land ran out.
![]() |
| All at sea |
After some initial assessment of the recovered images taken by the payload cameras, we all retired to a local hostelry for some well-earned refreshments and sustenance.
Day Three
This was all about reflection and planning for future flights. The prime objective of Skycademy is to build a network of HAB launchers working with children across the country.
It's easy to see how HAB is a great activity for engaging kids in STEM subjects. There is a whole bunch of science involved that can easily be tailored to the age of the pupil; the physics of gases and pressure; aerodynamics; radio wave propagation and antenna design; plus a whole load of mathematics around flight prediction. To get the whole school involved there are also plenty of non-STEM activities that can really engage the entire community through imagining and describing the flight through art and writing.
Skycademy attendees work with a range of different age groups from Primary to 6th form and nobody had problems coming up with ideas of how to integrate launching a balloon into their relevant areas of curriculum.
The Raspberry Pi Foundation has been incredibly generous and everyone who attended Skycademy has access to almost everything we'll need to launch at least one balloon in the next 12 months. Plus we all have the equipment to create a permanent tracking station so that we'll be able to monitor other HAB flights too.
![]() |
| Great views from up here |
Of course organising your own flight sounds easy and possible when you're surrounded by supportive and like-minded enthusiasts at Pi Towers. How will that enthusiasm survive when we're all immersed back in our day jobs and all the challenges of a new term? The biggest obstacles I see are finding a suitable launch location (those of us the South East have a lot of airports to dodge) and the logistical difficulties of planning an event that is so weather dependent. School fairs and football matches can still go ahead if its wet and windy. HAB flights generally cannot!
Personally I'm confident that we will be able to maintain the momentum. In our final team presentations at the end of Skcademy, everyone appeared to have a good idea about how they'd take things forward. Those of us attending this year's PyCon already have a plan for a couple of launches there.
Summary
There is only one word for Skycademy: AwEsOmE. I can honestly say it was one of the most memorable experiences of my life. If I can have so much fun while learning so much, it seems like a no-brainer than any kids who get involved with HAB will be just as engaged and excited!
Wednesday, 5 August 2015
Kite-mapping Godrevy with Raspberry Pi
After two aborted flights - one at Porth Kidney Sands (not enough wind) and the other on St Ives Peninsula (too gusty) - I was wondering if I'd ever get the Raspberry Pi kite-mapping rig up in the air while I was in Cornwall.
Fortunately our trip to Godrevy provided perfect conditions. Reasonably constant but not too gusty wind coming off the sea. The initial test flight (without the Pi) looked great and so I soon had the whole system aloft. The cliff tops above the main beach area by the National Trust car parks were a perfect launch site and also provided a nice walking route.
The line unspooled smoothly and using both the long tail and a streamer on each wing-tip, the kite was probably the most stable I've ever had it.
I strolled around the cliffs, dragging the kite behind me. Actually it moved fairly easily and it was only when I started around the top of the point by the lighthouse that the crosswind started to kick in. I was hoping to find a vantage point where I could manoeuvre the kite over the lighthouse itself, but the angle just wouldn't allow it. The kite was starting to tug quite hard so I thought it wise to bring it back to ground. Note that my young apprentices have disappeared off to the beach at this point.
I didn't need to check the altitude reading to know that this was the highest I've ever flown the Raspberry Pi. It can sometimes be a bit of a struggle to reel the kite back down but this time it was particularly tough and took over 15 minutes. My arms and shoulders were burning by the time I got down to the lst few metres and I was glad that I had my gloves on. Even then, one of them had a rip due the friction from the kite string.
The entire flight lasted just over 50 minutes and I'd managed to capture 597 images. Obviously there were a lot of images that captured basically the same scene - plus loads of the descent. Having said that, I was still impressed by how much of the land I'd covered when I assembled the images using mapknitter (embedded version below).
I even managed to snatch a quick snap of the lighthouse as the kite was getting close to the ground.
It makes me think about modifying my picavet so that it can be used to hold the Pi vertically to take some nice scenic shots instead. Something to consider for version 2.
Sunday, 2 August 2015
Raspberry Pi UnicornHat Animations
So after writing the app to create animations for the AstroPi HAT, my son asked the obvious question: could the code be modified to work with a Pimoroni UnicornHat. It is just another 8x8 LED matrix after all.
So a couple of hours tinkering later, there is now a version for the UnicornHat.
So a couple of hours tinkering later, there is now a version for the UnicornHat.
It is always tricky to photograph those lovely bright LEDs without a diffuser...
Tuesday, 28 July 2015
Raspberry Pi AstroPi LED matrix animations
When we were investigating the AstroPi board, I wrote a simple Pygame app for creating images for the LED matrix. Quite a few of the children started using this to produce singles frames to be amalgamated into an animation. Assembling the animation in this way was good coding practice but some of their complicated compositions were several hundred frames long and manually putting them together was fairly tedious to say the least.
So I decided to enhance my code to add the functionality to create and save animations directly through the app. This has involved adding some more buttons:
But essentially it works in the same way as the original, just with the added ability to step back and forward through frames.
After some initial testing, the children suggested (demanded?) some extra features that I hadn't included (e.g. the ability to delete a frame and change the speed of playback).
I also added a warning message if you try to quit without saving. Pygame's lack of a standard library of GUI tools (e.g. file browse etc) does add some limitations, so the file save/import is always via a file of the same name. Other than that though, it works pretty well.
Here are some examples of animations created using the app.
Space launch:
Tetris:
Union Flag to Raspberry Pi Logo
The code and full instructions is available on GitHub here.
Monday, 20 July 2015
Writing our Astro Pi sweaty astronaut code
Since we heard that we'd won the Primary School AstroPi competition, my Codeclubbers have been working on turning the idea - trying to detect the presence of an astronaut by the increase in humidity that they cause - into a working program.
To start off with, we generated a flow diagram of the various stages of the program, largely based on the pseudo-code that was submitted as part of our original paper entry to the competition. Pleasingly we found that this was fairly complete and most of the things we added were neat enhancements rather than modifications to the overall logic. Then we tried to identify which of these blocks would constitute a function in the code.
This was a good opportunity to talk about writing functions, passing input arguments and returning output. The children had encountered these concepts in some of the other projects we'd worked on with the Pis, but it was clear that not everyone grasped the ideas straight away. In particular, writing code that would would work on input values supplied by another function was a common cause of confusion:
'Where will |the values come from?'
"They'll be the output from Harry's code"
"But he hasn't written his code yet..."
"That's OK, just pretend he has and that it provides you with a list of values"
<Pause>
"But where will I get them from?"
Showing how to use fictitious test values when developing helped, but it wasn't until we started putting individual functions together that things started to click.
There was a lot of focus on what messages the code would display, Partly I think this was because the children really like programming funky images and scrolling text for the LED matrix, but also because they felt that it was important that program communicated what it was doing. This helped them understand what was going on but also reflects (I think) a sensible and user-centric focus to UI design. Consequently our final code is full of display messages for the LEDs and also logs plenty of data to file too.
We even had a simulated (using an Astro Pi, naturally) Tim Peake to help with our test scenarios.
Throughout the whole thing I have been consistently impressed with the calm and confident way with which the children have approached the task. When we came to testing the first full working version I was quite nervous but they seemed unsurprised that it pretty much worked first time. It was funny how, at very stages, one or other of the children would ask:
"Is our code really going to be running on the International Space Station?"
as though they thought it was some sort of trick or 'pretend' prize.
Weirdly, none of these positive benefits from working on a team project like this had occurred to me before we started - I rather blundered into them. But now I'm thinking about how to accommodate something like this in future (including at CoderDojo) rather than stick with the standard single-person project that tends to be the default for this kind of thing.
It was also obvious that the flight buttons would be much easier to press in order for the astronauts to confirm their presence. Our original design just had the joystick used for this, but we all agreed that using the buttons would be a good enhancement.
So: Flight Case Mk2, incorporating working buttons connected to the GPIO pins just like the real one. One of the useful outcomes of having children who have had (pretty much) nothing but Lego for birthday presents for the last 5 years is that we have a wide range of pieces. Combined with the superbly proportioned Pimoroni CakeBoard, and we've been able to add the flight button functionality into our prototype.
Not quite as elegant as the original - its need to be deeper to accommodate the breadboard and buttons. We've also had to make some adjustments to our code and as the end of term was fast approaching, we just adapted the existing functions rather than re-writing that entire 'wait for user input' chunk.
Of course our code isn't the most elegant or optimal software ever written. Despite my urging, some of the variables are not the most sensibly named (I haven't changed them: this is their code, not mine). But it works and manages to perform the intended task in a concise and efficient way. I think a lot of this is due to the excellent API for the AstroPi HAT, but the children's creativity and user-focused design methodology has also be a big contributory factor.
I'm incredibly proud of what the children have achieved and the positive attitude they've adopted to the whole competition. The best moments for me - apart from the phone call when we found out we'd won - were those light-bulb moments when I saw one of the children work out something they'd been trying to solve for a while. Or when we'd be discussing the code and they'd tell me that was a better way to achieve something than the one I'd just suggested.
And there were quite a few of those...
Design
I was really pleased that of all the ideas that we submitted, this was the one that was chosen because I reckoned it would be the easiest to split down into individual functions. It seemed too complicated and time consuming to get every member of the club to write their own version in full, so by allocating individual elements to different children, I was able to try to match difficulty to ability.To start off with, we generated a flow diagram of the various stages of the program, largely based on the pseudo-code that was submitted as part of our original paper entry to the competition. Pleasingly we found that this was fairly complete and most of the things we added were neat enhancements rather than modifications to the overall logic. Then we tried to identify which of these blocks would constitute a function in the code.
This was a good opportunity to talk about writing functions, passing input arguments and returning output. The children had encountered these concepts in some of the other projects we'd worked on with the Pis, but it was clear that not everyone grasped the ideas straight away. In particular, writing code that would would work on input values supplied by another function was a common cause of confusion:
'Where will |the values come from?'
"They'll be the output from Harry's code"
"But he hasn't written his code yet..."
"That's OK, just pretend he has and that it provides you with a list of values"
<Pause>
"But where will I get them from?"
Showing how to use fictitious test values when developing helped, but it wasn't until we started putting individual functions together that things started to click.
Teamwork
This approach is, of course, good experience and representative of 'proper' coding jobs. It was really good to see them working as a team, particularly when they got together in pairs (without any prompting from me) to solve problems that had an element of commonality. Taking the concept all the way from a design on paper to working code was a great project for a half-term and I could see that some of the children were really engaged with the process, thinking through the various steps and making suggestions as to ways things could be done.There was a lot of focus on what messages the code would display, Partly I think this was because the children really like programming funky images and scrolling text for the LED matrix, but also because they felt that it was important that program communicated what it was doing. This helped them understand what was going on but also reflects (I think) a sensible and user-centric focus to UI design. Consequently our final code is full of display messages for the LEDs and also logs plenty of data to file too.
We even had a simulated (using an Astro Pi, naturally) Tim Peake to help with our test scenarios.
Testing
The children all excel at coming up with 'What if...?" questions. A lot of these were really great observations (e.g. "what if the humidity doesn't go back down again straight away?") and led to our code being more robust and also incorporating an element of self-tuning.Throughout the whole thing I have been consistently impressed with the calm and confident way with which the children have approached the task. When we came to testing the first full working version I was quite nervous but they seemed unsurprised that it pretty much worked first time. It was funny how, at very stages, one or other of the children would ask:
"Is our code really going to be running on the International Space Station?"
as though they thought it was some sort of trick or 'pretend' prize.
Weirdly, none of these positive benefits from working on a team project like this had occurred to me before we started - I rather blundered into them. But now I'm thinking about how to accommodate something like this in future (including at CoderDojo) rather than stick with the standard single-person project that tends to be the default for this kind of thing.
Testing
I wanted them to think about the environment in which the code would be running - the ISS is obviously very different to the school Computing suite. So we had an idea to build a replica AstroPi flight case from Lego. Apart from being a bit of fun, this did highlight a couple of operational issues, for example the various messages displayed on the LED matrix were not all set at the same rotational angle. Obviously it is easier to spin through 180 degrees in zero-gravity, but it seems sensible to standardise the orientation.It was also obvious that the flight buttons would be much easier to press in order for the astronauts to confirm their presence. Our original design just had the joystick used for this, but we all agreed that using the buttons would be a good enhancement.
So: Flight Case Mk2, incorporating working buttons connected to the GPIO pins just like the real one. One of the useful outcomes of having children who have had (pretty much) nothing but Lego for birthday presents for the last 5 years is that we have a wide range of pieces. Combined with the superbly proportioned Pimoroni CakeBoard, and we've been able to add the flight button functionality into our prototype.
Not quite as elegant as the original - its need to be deeper to accommodate the breadboard and buttons. We've also had to make some adjustments to our code and as the end of term was fast approaching, we just adapted the existing functions rather than re-writing that entire 'wait for user input' chunk.
End of term
With only a small amount of after school tinkering (mainly to include the flight buttons) by my sons, we managed to get the whole program finished by the end of term. The final session of the 2014-15 academic year was spent on some final testing and designing some animations to display when the program starts or when there is nothing else interesting happening (e.g. between measurements).Of course our code isn't the most elegant or optimal software ever written. Despite my urging, some of the variables are not the most sensibly named (I haven't changed them: this is their code, not mine). But it works and manages to perform the intended task in a concise and efficient way. I think a lot of this is due to the excellent API for the AstroPi HAT, but the children's creativity and user-focused design methodology has also be a big contributory factor.
I'm incredibly proud of what the children have achieved and the positive attitude they've adopted to the whole competition. The best moments for me - apart from the phone call when we found out we'd won - were those light-bulb moments when I saw one of the children work out something they'd been trying to solve for a while. Or when we'd be discussing the code and they'd tell me that was a better way to achieve something than the one I'd just suggested.
And there were quite a few of those...
Thursday, 2 July 2015
Simon Says with Pimoroni ExplorerHat
The ExplorerHat was one of those impulse purchases from Pimoroni that I added to my basket when shopping for something else that I actually needed. It has sat in my to-do box for a few weeks but recently I've found the time to have a play (I've been a bit busy coordinating my CodeClub's AstroPi project).
The ExplorerHat is a great test-bed for prototyping - having four buttons and LEDs all readily available means it's easy to knock together a test circuit without fiddling around to wire up these simple and versatile components.
As a first project I thought I'd put together a Simon Says game.
The big LEDs flash in a sequence that gets longer and faster every time you successfully duplicate it by pressing the corresponding buttons on the ExplorerHat. If you get a sequence correct, all the lights flash in celebration!
Here's the wiring diagram:
And here's the (slightly rough and ready) code:
import explorerhat as eh
import time, random
target_seq = []
global user_seq
user_seq = []
user_seq = []
leds_list = [1,2,3,4]
def wait_for_press(c,e):
if c > 4:
led = c - 5
else:
led = c - 1
if e == 'press':
eh.light[led].on()
else:
eh.light[led].off()
user_seq.append(led + 1)
print 'Starting. Copy the sequence.'
level = 0
GameOn = True
gap = 0.8
while GameOn:
user_seq = []
level+=1
count = 1
print 'Starting Level ' + str(level)
for i in range(count):
led = random.choice(leds_list)
target_seq.append(led)
for seq_n in target_seq:
eh.output[seq_n-1].on()
time.sleep(gap)
eh.output[seq_n-1].off()
time.sleep(gap)
eh.touch.pressed(wait_for_press)
eh.touch.released(wait_for_press)
countdown = 20
waiting = True
while waiting:
if (len(user_seq) == len(target_seq)) or (countdown == 0):
if user_seq == target_seq:
waiting = False
#print user_seq, target_seq
time.sleep(0.5)
print 'Correct'
for x in range(0,4):
eh.output[x].on()
eh.light[x].on()
time.sleep(0.5)
for x in range(0,4):
eh.output[x].off()
eh.light[x].off()
gap = gap* 0.8
else:
waiting = False
GameOn = False
print 'Fail'
print 'You reached level:' + str(level)
eh.pause()
time.sleep(1)
countdown-=1
time.sleep(2)
The ExplorerHat is a great test-bed for prototyping - having four buttons and LEDs all readily available means it's easy to knock together a test circuit without fiddling around to wire up these simple and versatile components.
As a first project I thought I'd put together a Simon Says game.
The big LEDs flash in a sequence that gets longer and faster every time you successfully duplicate it by pressing the corresponding buttons on the ExplorerHat. If you get a sequence correct, all the lights flash in celebration!
Here's the wiring diagram:
And here's the (slightly rough and ready) code:
import explorerhat as eh
import time, random
target_seq = []
global user_seq
user_seq = []
user_seq = []
leds_list = [1,2,3,4]
def wait_for_press(c,e):
if c > 4:
led = c - 5
else:
led = c - 1
if e == 'press':
eh.light[led].on()
else:
eh.light[led].off()
user_seq.append(led + 1)
print 'Starting. Copy the sequence.'
level = 0
GameOn = True
gap = 0.8
while GameOn:
user_seq = []
level+=1
count = 1
print 'Starting Level ' + str(level)
for i in range(count):
led = random.choice(leds_list)
target_seq.append(led)
for seq_n in target_seq:
eh.output[seq_n-1].on()
time.sleep(gap)
eh.output[seq_n-1].off()
time.sleep(gap)
eh.touch.pressed(wait_for_press)
eh.touch.released(wait_for_press)
countdown = 20
waiting = True
while waiting:
if (len(user_seq) == len(target_seq)) or (countdown == 0):
if user_seq == target_seq:
waiting = False
#print user_seq, target_seq
time.sleep(0.5)
print 'Correct'
for x in range(0,4):
eh.output[x].on()
eh.light[x].on()
time.sleep(0.5)
for x in range(0,4):
eh.output[x].off()
eh.light[x].off()
gap = gap* 0.8
else:
waiting = False
GameOn = False
print 'Fail'
print 'You reached level:' + str(level)
eh.pause()
time.sleep(1)
countdown-=1
time.sleep(2)
Subscribe to:
Posts (Atom)



















