Tag Archives: Python

Controlling electrical sockets with Energenie Pi-mote

via Raspberry Pi

Last Christmas I decided I had spent enough time bending over the various chairs to reach the switch to turn on and off the Christmas tree lights. So I bought a set of Energenie remote-controlled mains switches.

I decided that this would be a great device to wire up to the Raspberry Pi, because I could then program the Pi to control my Christmas lights during the day. Unfortunately, the small remote control supplied with the distribution board does not have any mechanism of external control.  So I got in contact with Energenie, the manufacturers of these great devices, to invite them over to Pi Towers and show them what a great thing Raspberry Pi is and why they should create a Raspberry Pi add-on to be able to control the devices…

A couple of months later I get a visit from their team, who showed me the results of quite a bit of engineering (and a little fun I think):

pimote

A little bit of information from the guys at Energenie:

The Pi-mote control is an add on board that permits control of 433mHz radio controlled electrical sockets. Easy to install and command, the product provides a simple and safe way to add control of mains powered devices and appliances to your Raspberry Pi.

Energenie make a range of compatible sockets which can be operated by Pi-mote control. If you already own Energenie sockets, these are backwards compatible with Pi-mote Control.

A starter kit is available which includes the Pi-mote Control and 2 13Amp electrical sockets for use in standard UK 3-pin mains sockets. Some Python code to enable simple on-off control of these sockets will get you going out of the box.

While Amy Mather was in the office earlier in the year to do some work experience, I asked her to think of something she could do with the system and to write some code to prettify the existing Python code. She started by writing a basic function to control power sockets using some binary logic, and proceeded to hack one of the built-in Python games in Raspbian to make it play a song and turn on some disco lights when the player wins the game. Cue the music:

…finally Rick-Rolled the Raspberry Pi blog!

See Amy’s example code and the modified memory puzzle game on her GitHub.

The basic usage for Amy’s energenie module looks like this:

from energenie import switch_on, switch_off
from time import sleep

# turn a plug socket on and off by number
switch_on(1)
switch_off(1)

switch_on(3)
switch_off(3)

# turn all plug sockets on and off
switch_on(0)
switch_off(0)

# turn some plug sockets on, then turn them off after 10 seconds
switch_on(1)
switch_on(4)
sleep(10)
switch_off(1)
switch_off(4)

Want to control something simple from your Pi? Washing machine, Vacuum cleaner, liquidiser (create your own cat scarer):

Buy yours at energenie4u.co.uk!

Boris, the Twitter Dino-Bot

via Raspberry Pi

UK teachers: want two days of free, top-class CPD? Check out Picademy, and send us your applications!

What do you get if you cross a PiFace with a rubber dinosaur from Marks and Spencer?

Twitter magic, that’s what.

Teacher Dan Aldred has come up with a thing of beauty: a hack that makes your desktop dinosaur roar whenever it’s mentioned on Twitter. (What do you mean, you don’t have a desktop dinosaur?)

Boris, scaring the living bejezus out of all comers.

Boris, scaring the living bejezus out of all comers.

The build itself is simple enough – you can do the same with any kids’ toy that uses a button or switch to make a noise. Dan built a bridge across Boris’s switch using tin foil, our favourite hacker tool. He hooked Boris up to the PiFace GPIO expansion board (the PiFace site is currently the only site on the internet that features a picture of me crouching like a preying mantis in a cardigan on its front page), got Python talking to the Twitter API and wrote a simple program to tell Boris to roar whenever the string “ROAR” is tweeted at Dan’s account. All very easy, but the results are magic.

Boris, innards exposed.

Boris, innards exposed.

Here’s Boris in action:

You can send Dan a tweet yourself – he’s @Dan_Aldred. (Just think! If enough of you tweet “Roar” at him, he’ll either be driven mad or forced to power Boris down.) We love it, Dan. Boris is a thing of beauty, and a great learning exercise. Dan has made full instructions and all the (very simple) Python you’ll need available at his website: if you’ve got some time this weekend and are in charge of a bored child, I can’t think of a better way to spend a couple of hours.

Minecraft Pi recipe cards to download and keep

via Raspberry Pi

We think Craig Richardson’s brilliant. His Python Programming for Raspberry Pi book (available as a free download) remains one of the very best tools for stealthily teaching rigorous and useful computing concepts and programming tricks to kids that we’ve seen. Kids love Craig’s resources (we’ve found it hard to make them stop working and pack up to go home when we’ve run Craig’s bag of tricks in workshops); and whether you’re a teacher, a parent or an interested learner of any age, you’ll find something in there to get your teeth into.

Craig’s Minecraft resources will be available to buy in print later in the year (we know a lot of you prefer to have textbooks and other reference material available as a dead-tree book). Speaking of dead trees, Craig’s preferred method of teaching times tables is to get kids fighting Minecraft trees. It goes down about 1000% better than number squares.

Not prepared to stop at one giant tome of Minecraft goodness, Craig is working on new materials all the time: his latest batch is a set of recipe cards for workshops or the classroom, which we used at the first Picademy for teachers.

Recipe card

 

Craig says:

Minecraft: Pi Edition has huge potential for engaging people with programming. The Minecraft game is hugely popular with children and adults alike, as it allows enormous creativity. Combining it with Python programming on the Raspberry Pi opens up an even greater level of creative freedom, and is a massive incentive for learning to program.

Following on from the first draft of my Python Programming with Minecraft Pi book, I developed a set of recipe cards.

The recipe cards provide short example Python programs that interact with Minecraft Pi. They are designed to be accessible for complete beginners. Each recipe card teaches the basics of a programming concept, such as variables or loops, and includes detailed explanations of how the code works.

When using the recipe cards to teach programming in workshops I’ve found that it is essential to leave scope for creativity. Having the opportunity to play and incorporate their own ideas into their programs is hugely beneficial for adults and children. It is more engaging than just copying code and helps develop a deeper understanding when they’re learning to program.

Creative freedom is one of the reasons that Minecraft is so popular, which is why it complements learning to program perfectly.

He’s right, too.

Several of you asked for a downloadable version of these cards when you saw the photographs from Picademy, so Craig has made them available on his website. Thanks so much Craig – we’re looking forward to seeing what comes next!

 

 

Upgrading the OpenWrt-Yun image on the Yún

via Arduino Blog

ArduinoYun_orizz

Today we released the upgraded version of the OpenWrt-Yun image on the Arduino Yún.
This version includes all the latest and greatest from stable OpenWrt, the latest (Python) Bridge (with a php contribution and fixes to the file module), we also added Mailbox support to REST api and other fixes to some open issues.

The new image contains also the fix to the well known Heartbleed bug, a big security issue that impacted on almost all websites of the world.

If you own an Arduino Yún we suggest you to follow the link and read the procedure to update the board.
You’ll need to download the zip file from the download page. Remember that updating the OpenWrt-Yun image will cause the loss of all files and configurations you previously saved on the flash memory of the Yún.
Enjoy!

Mudra: a Braille dicta-teacher

via Raspberry Pi

Sanskriti Dawle and Aman Srivastav are second-year students at the Birla Institute of Technology and Science in Goa. After a Raspberry Pi workshop they decided they wanted to do something more meaningful than just flash LEDs on and off, and set this month’s PyCon in Montreal as their deadline.

team-mudra1

Aman Srivastav and Sanskriti Dawle

They ended up producing something really special. Mudra means “sign” in Sanskrit: the Raspberry Pi-based device is a learning tool for visually impaired people, which teaches Braille by translating speech to Braille symbols. Braille literacy among blind people is poor even in the developed world: in India, it’s extremely low, and braille teachers are very, very few. So automating the teaching process – especially in an open and inexpensive way like this – is invaluable.

In its learning mode, Mudra uses Google’s speech API to translate single letters and numbers into Braille, so learners can go at their own speed. Exam modes and auto modes are also available. This whole video is well worth your time, but if you’re anxious to see the device in action, fast-forward to 1:30.

Sanskriti and Aman say:

Mudra is an excellent example of what even programming newbies can achieve using Python. It is built on a Raspi to make it as out-of-the-box as possible. We have close to zero coding experience, yet Python has empowered us enough to make a social impact with Mudra, the braille dicta-teacher, which just might be the future of Braille instruction and learning.

We think Mudra’s a real achievement, and a great example of clean and simple ideas which can have exceptional impact. You can see the Mudra repository on GitHub if you’d like a nose around how things work; we’re hoping that Sanskriti and Aman are able to productise their idea and make it widely available to people all over the world.

Learning Python with Raspberry Pi

via Raspberry Pi

If you’ve been round here for any length of time, you’ve probably heard mention of Alex Bradbury. Alex is currently polishing off his PhD thesis at the Computer Lab at the University of Cambridge, and he’s been involved with the Raspberry Pi project as a volunteer from our very early days, back when all we had was alpha development boards. Alex is responsible for building and releasing Raspberry Pi’s Raspbian OS images, and maintaining our Debian repository in his (limited) spare time.

He’s somehow also found the time to write a book with Linux Voice‘s Ben Everard.

Learning Python with Raspberry Pi doesn’t presuppose any computing knowledge, and takes you from a standing start through variables, loops and functions, 3D graphical programming, building games, networking, scripting, interfacing with hardware…and, of course, Minecraft. There’s much more besides: if you work your way through the whole book you’ll be building robots and alarm systems; manipulating sound and video; and learning how to test and debug the Bradbury and Everard way.

As well as what you’ll find in the book, Alex and Ben have made a large code repository available to complement the information and instructions in Learning Python with Raspberry Pi: you’ll be able to download what you need free of charge.

Alex says:

Ever since the introduction of the Raspberry Pi, Python has been touted (with good reason) as the language of choice for anyone wanting to program on the device. Reasonable people can disagree on the ultimate reasons for Python’s success, but I think we can all recognise what an asset its large and friendly community is, as well as the value of its extensive collection of high quality libraries for helping to solve almost any programming task.

Learning Python with Raspberry Pi aims to teach the reader the Python they need to make their Raspberry Pi project ideas a reality. We give lots of examples in the sort of areas likely to be of interest to the Pi community – including physical computing, audio and video, 3d graphics, Minecraft programming, and games.  Another important aspect for us is that every chapter ends with a whole host of ideas and pointers on what you’re now able to do given what you’ve just learnt. Python is the single most useful language to know for the Raspberry Pi, and I like to think that with Learning Python with Raspberry Pi, we’ve managed to produce an entertaining and educational introduction to it. Hopefully you agree!

Learning Python with Raspberry Pi is available from Amazon, and from a good book shop near you: we hope to be stocking it in the Swag Store soon too.

 

 

Raspberry Pi Projects: a big book by Andrew Robinson and Mike Cook

via Raspberry Pi

Ben here – Liz is currently non-functional due to her body having no idea what time it was when she arrived at the office this morning after landing back from San Francisco at the weekend.

Raspberry Pi Projects is a fantastic book from Wiley, the publishers of Eben and Gareth’s Raspberry Pi User Guide and Carrie Anne’s Adventures in Raspberry Pi. It’s written by two great Pioneers: Dr. Andrew Robinson (creator of PiFace) and Mike Cook (co-author of Raspberry Pi for Dummies and creator of many awesome hardware projects).

The book comprises of 16 practical software and hardware projects for the Raspberry Pi – all put together and documented by Andrew and Mike (with help) that are designed to help you better understand the system and become more confident in development of a range of projects. The projects are handily presented in rough order of difficulty, starting with the easier ones to get you going – and move on to more complex ones.

The book covers interactive text based games in Python, graphical games with PyGame, interactive game hardware, application with PiFace Digital, making a toy chicken send tweets, chaotic pendulum hamonographs, car racing and more – as well as a chapter on Minecraft by Sean McManus, and Home Automation by Jonathan Evans.

I wrote on here recently about things you can do with your Raspberry Pi – and this book is crammed full of amazing examples. Books like this and Carrie Anne’s will guide you through a given project and provide you with learning points along the way, which is a great way to learn about Linux, Python, hardware hacking or anything. Beginner or not you’ll learn lots by following the guide set out by experts such as these.

Here are some examples of the projects Mike put together:

PacMan made in Python PyGame:

Disco lights:

See more previews of the contents of the book on Mike’s blog!

Raspberry Pi Projects is available from Amazon and also as a two-part e-book from Wiley: Part 1 & Part 2

Graphic equaliser

via Raspberry Pi

Our good friends at Adafruit put this project on their Learning System earlier this month. It’s a beaut: you’ll learn something making it, and it looks fantastic when set up. Before we get into the nitty gritty, here’s some video:

This graphic equaliser (a spectrum analys/zer if you’re from the USA) is made from a RGB led strip, with everything down to the audio processing run on the Pi. Everything you see in the video is happening in real time. The setup runs Python, and is based on LightShowPi (which was originally designed to orchestrate Christmas lights), so you’ll be able add LightShowPi features like SMS control from your phone if you’re an advanced user.

Some soldering is required – but soldering is easy, and this is a good project to earn your soldering wings on if you haven’t already. There’s the usual full and helpful tutorial over at Adafruit, along with tips, a parts list, code and all that good stuff. I wish I’d had one of these for my student bedroom. Imagine the parties!

Embedded Scripting (Lua, Espruino, Micro Python)

via OSHUG

The thirty-second OSHUG meeting will take a look at the use of scripting languages with deeply embedded computing platforms, which have much more constrained resources than the platforms which were originally targeted by the languages.

Programming a microcontroller with Lua

eLua is a full version of the Lua programming language for microcontrollers, running on bare metal. Lua provides a modern high level dynamicaly typed language, with first class functions, coroutines and an API for interacting with C code, and yet which is very small and can run in a memory constrained environment. This talk will cover the Lua language and microcontroller environment, and show it running on-off-the-shelf ARM Cortex boards as well as the Mizar32, an open hardware design built especially for eLua.

Justin Cormack is a software developer based in London. He previously worked at a startup that built LED displays and retains a fondness for hardware. He organizes the London Lua User Group, which hosts talks on the Lua programming language.

Bringing JavaScript to Microcontrollers

This talk will discuss the benefits and challenges of running a modern scripting language on microcontrollers with extremely limited resources. In particular we will take a look at the Espruino JavaScript interpreter and how it addresses these challenges and manages to run in less than 8kB of RAM.

Gordon Williams has developed software for companies such as Altera, Nokia, Microsoft and Lloyds Register, but has been working on the Espruino JavaScript interpreter for the last 18 months. In his free time he enjoys making things - from little gadgets to whole cars.

Micro Python — Python for microcontrollers

Microcontrollers have recently become powerful enough to host high-level scripting languages and run meaningful programs written in them. In this talk we will explore the software and hardware of the Micro Python project, an open source implementation of Python 3 which aims to be as compatible as possible with CPython, whilst still fitting within the RAM and ROM constraints of a microcontroller. Many tricks are employed to put as much as possible within ROM, and to use the least RAM and minimal heap allocations as is feasible. The project was successfully funded via a Kickstarter campaign at the end of 2013, and the hardware is currently being manufactured at Jaltek Systems UK.

Damien George is a theoretical physicist who likes to write compilers and build robots in his spare time.

Note: Please aim to by 18:15 as the first talk will start at 18:30 prompt.

Sponsored by:

A pure Python interface for the camera module: meet picamera!

via Raspberry Pi

If you have a Raspberry Pi camera module, you’ve probably used raspistill and raspivid, which are command line tools for using the camera. Dave Jones, a Database Admin, software developer and SQL know-it-all based in Manchester has been working on an equivalent, feature complete implementation of these in Python. This means you can access the camera module directly from a Python script, without using os.system or executing a subprocess.

At Oggcamp I set up a big TV with a Pi and camera taped on top. I SSH’d in to the Pi from my laptop and entered commands in to iPython using picamera.

Speaking as an avid Pythonist, picamera’s implementation is beautiful and it really is a wonderful library to use. It works really well for demonstrations using the Pi camera, and for real world applications. Part of the appeal of the Raspberry Pi is that you can work on embedded electronics projects without needing to know low-level languages or have to program a microprocessor – instead you have the choice of a range of accessible high-level languages such as Python – and this is an extension of that kind of abstraction, which open up a world of possibilities to a wider diversity of makers.

Example usage:

import picamera
from time import sleep

camera = picamera.PiCamera()
camera.capture('image.jpg')

camera.start_preview()
camera.vflip = True
camera.hflip = True
camera.brightness = 60

camera.start_recording('video.h264')
sleep(5)
camera.stop_recording()

Also you can do things like this:

for i in range(100):
    camera.brightness = i
    sleep(0.1)

and watch the preview flow through the brightness levels.

The library has many configurations – you can change the brightness, contrast, saturation, image effects, exposure modes and such, as well as optionally show a live preview of the camera’s view. You can capture single images and sequences of images as well as video streams.

Here’s a presentation of picamera Dave gave at Manchester Raspberry Jam XVI – where he demonstrates the basic usage of the module by typing commands in to a Python prompt on his laptop, with a monitor displaying the camera output (unfortunately out of shot in the video):

Dave’s wife Holly works in the Palaeontology department at Manchester University (Interesting fact: when Dave and Holly got married, they picked a new surname to take (Dave was previously a Hughes) – so Holly could become Dr. Jones, and he would become Davy Jones) where they regularly capture images from microscopes. Rather than mount a huge camera on top of a microscope, Dave suggested attaching the Pi’s camera module to the lens.

An early version of the crudely mounted Picroscope

He ended up writing a web app to support its use. This allows the user to control camera configuration settings through a web page, and capture photographs at the click of a button, as well as archive pictures taken in to a database along with metadata and extra information entered in a web form.

The web app showing pictures taken (smaller field of view due to temporary mounting setup)

Single view of image taken through the web app, with metadata fields

Picroscopy configuration settings

Dave gave another presentation at the Manchester Jam, this time demonstrating a simple version of a Python web app for such an application (please excuse the numerous technical hiccups):

As Dave says in the video:

“This is where having a library is particularly useful. If we were doing this with, say, raspistill and raspivid, when you want to alter the brightness of your preview, you’d have to shut down the program, regenerate the command line, restart the program. Here we’re just saying “set a property”. This is why a library is better for an interactive application like this. There’s nothing wrong with raspistill and raspivid as far as they go, but they’re not ideal for building this sort of application. If you have interactivity, you want a library.”

See more videos from the Manchester Jam: Jam #16 Videos.

picamera has been available in pypi since October (v0.5), so it’s already in the wild – but now it’s hit the v1.0 milestone Dave considered feature complete, it’s packaged in the Raspbian archives so you install with apt-get (remember to run apt-get update first):

apt-get install python-picamera

or

apt-get install python3-picamera

depending on your taste.

Dave also mentioned to me that this is by far the most popular project he’s ever published – and he’s been impressed by how brilliant the feedback has been from the Pi community. He’s had a great response on the forums, detailed bug reports provided by users and plenty of help from James Hughes, the author of raspistill, and from Alex Bradbury in getting it packaged for Raspbian.

See the source for picamera and the picroscopy web app on github. Thanks to Dave for his hard work in building this library. Enjoy!

Wireless Encryption Between Galileo and a MSP430

via Hack a Day» hardware

[Mark] recently finished his latest project, where he encrypts wireless communications between the new Intel Galileo and a Texas Instruments MSP430. The wireless interfaces used are the very common nRF24L01+ 2.4GHz transceivers, that had a direct line of sight 15 feet range during [Mark]‘s tests. In his demonstration, the MSP430 sends an encrypted block of data representing the state of six of its pins configured as inputs. This message is then received by a sketch running on the Galileo and stored in shared memory. A python script then wakes up and is in charge of decrypting the message. The encryption is done using AES-128bits in Electronic Codebook mode (ECB) and semaphores are used to prevent simultaneous accesses to the received data. As it is the first project using an Intel Galileo we received, don’t hesitate to send us a tip if you found other ones.


Filed under: hardware, Microcontrollers

PyPy 2.1 beta released

via Raspberry Pi

Back in May, we mentioned that we’d been sponsoring the development of the ARM port of PyPy, the high-performance Python interpreter. Earlier today the team released a first beta of the upcoming 2.1 release, which for the first time adds ARM as an officially supported architecture.

You can see the announcement here, and download binaries for Raspbian here. Give it a spin and let us know what you think.

PyPy on Pi

via Raspberry Pi

While we love all programming languages equally here at the Foundation, we do love Python an awful lot. Most users run their code under the “default” CPython interpreter, but over the last few years the PyPy project has made great strides in producing an highly compatible alternative interpreter with an integrated tracing JIT compiler. On x86 platforms this can improve the performance of some workloads by a factor of ten or more, and the PyPy team are now bringing the same sort of boost to the ARM world.

You can download an Pi-compatible alpha release of PyPy for ARM and see some benchmarks here. We’re proud to have been able to contribute a small amount of funding to the latter stages of this project; over the next few weeks we’ll be running an irregular series highlighting some of the other open source projects that we’ve been contributing to.

Minecraft in the classroom?

via Raspberry Pi

Last week I ran a short session at Campus London with a roomful of students from local schools. Only one of the students had seen a Raspberry Pi before and only a couple had used a command line interface or seen a computer program. In just over an hour they learned how to set up the Raspberry Pi, did a bit of Linux and then hacked Minecraft using Python. Here’s what they thought of it:

“I used a raspberry pi and it showed me how exciting and useful new technology can be. Also learning simple coding was very useful and made me want to learn more. It made me more interested in technology and coding. It made me really consider my careers options involving technology.” —William

“This has pushed me to finish my game I am currently developing.” —Joseph

“It has made me interested about learning coding. I have realised coding isn’t as hard as I thought.” —Lara

“I want to learn more about programming, because it was really interesting.” —Ellie

“The most important thing I learned was how to use Raspberry Pi.” —Finley

Running minecraft from the command line

“The most important thing I learned was how to change the commands to Mine Craft.” —Harjoat

“We had a go using a device called a Raspberry Pi which let us hack into a game and let us give it commands. It was really fun and exciting to learn all these new things.” —Jasmine

Reading these comments makes me smile, it was a fantastic session and shows what you can learn in short amount of time. A few lessons jump out from the feedback:

  1. When given the opportunity, most young people find computing to be a powerful and exciting thing.
  2. Everyone gets something different out of learning how to tell a computer what to do.
  3. Play is a powerful way to learn and computers are a good way to play.

These lessons are hardly new—it’s where Logo, Scratch and Lego Mindstorms come from—but what has changed is the accessibility and opportunity. With a £30 computer and a free game you can learn computer science in a beautiful, constructionist sandbox. (“Why dig when you can code?” “Are you an Alpha or an Epsilon?” “Hack with your brain, not with your pickaxe.” And other rubbish aphorisms coming soon to a T-shirt near you.) Quite simply, you can teach yourself to think in powerful ways while messing about. I don’t know about you, but as a teacher I think that this is quite profound.

Hacking Pi Minecraft using the API and Python.

I’m going to blog more about Pi Minecraft in future; I think that its potential as a teaching and learning tool is huge.  I’ll be writing lesson plans for it and hopefully not just computing lessons: Martin O’Hanlon’s analogue clock for example would be a brilliant to teach trig and geometry in the constructionist stylee. If anyone out there—teachers, programmers, Notch, whoever—want to help then get in touch. The School of Minecraft has a nice ring to it don’t you think?

P.S. Campus is an amazing place: if you are a tech start-up or entrepreneur (or would like to be!) and can get down there, check it out. I love it.

PiUi – control your Pi with your phone

via Raspberry Pi

David Singleton has been laid up with a broken leg, and has taken the downtime to do some work on PiUi. PiUi enables you to add a mobile phone user interface to a Raspberry Pi project when a screen and keyboard aren’t a practical solution. It’s magic: PiUi makes your Pi behave like a wireless access point, and connecting your phone is as easy as…[restrains self from making obvious bad pun].

This is a really, really useful piece of software; I’ve already had about ten ideas for ways I can usefully deploy PiUi in the house. We’re finally replacing our wobbly green 1970s nightmare of a kitchen this year, and I’m hoping to have a Pi controlling some of the lighting, the coffee machine, the heating and some of the cooking hardware when we do. Using a phone rather than the touchscreen I’d been intending to mount on a wall is a no-brainer. You can find everything you need at GitHub, including lots of documentation. (Note to developers: we love it when you include lots of documentation.) David also has a post about the project on his blog.

This is something I expect we’re going to see a lot of people here using in future Pi projects; it’s simple, elegant and very nicely implemented. Do you have plans for PiUi? Let us know in the comments.