Tag Archives: Raspberry Pi Resources

Try our new free machine learning projects for Scratch

Post Syndicated from Daragh Broderick original https://www.raspberrypi.org/blog/free-machine-learning-projects-for-scratch/

Machine learning is everywhere. It’s used for image and voice recognition, predictions, and even those pesky adverts that always seem to know what you’re thinking about!

If you’ve ever wanted to know more about machine learning, or if you want to help you learners get started with machine learning, then our new free projects are for you!

The Terminator saying "My CPU is a neural net processor. A learning computer."

Spoiler alert: we won’t show you how to build your own Terminator. Trust us, it’s for the best.

Machine learning in education

When we hosted Scratch Conference Europe this summer, machine learning was the talk of the town: all of the machine learning talks and workshops were full with educators eager to learn more and find out how to teach machine learning. So this is the perfect time to bring some free machine learning resources to our projects site!

Smart classroom assistant

Smart classroom assistant is about creating your own virtual smart devices. You will create a machine learning model that recognises text commands, such as “fan on”, “Turn on my fan”, or my personal favourite, “It’s roasting in here!”.

animation of a fan running and a desk lamp turning on and off

In the project, you will be guided through setting up commands for a desk fan and lamp, but you could pick all sorts of virtual devices — and you can even try setting up a real one! What will you choose?

Journey to school

Journey to school lets you become a psychic! Well, not exactly — but you will be able to predict how your friends travel from A to B.

illustration of kids in school uniforms in front of a large street map

By doing a survey and collecting lots of information from your friends about how they travel around, you can train the computer to look for patterns in the numbers and predict how your friends travel between places. When you have perfected your machine learning model, you can try using it in Scratch too!

Alien language

Did you ever make up your own secret language that only you understood? Just me? Well, in the Alien language project you can teach your computer to understand your made-up words. You can record lots of examples to teach it to understand ‘left’ and ‘right’ and then use your model in Scratch to move a character with your voice!
animation of a cute alien creature on the surface of distant planet

Train your model to recognise as many sounds as you like, and then create games where the characters are voice-controlled!

Did you like it?

In the Did you like it? project, you create a character in Scratch that will recognise whether you enjoyed something or not, based on what you type. You will train your character by giving it some examples of positive and negative comments, then watch it determine how you are feeling. Once you have mastered that, you can train it to reply, or to recognise other types of messages too. Soon enough, you will have made your very own sentiment analysis tool!

illustration of kids with a computer, robot, and erlenmeyer flask

More machine learning resources

We’d like to extend a massive thank you to Dale from Machine Learning for Kids for his help with bringing these projects to our projects site. Machine Learning for Kids is a fantastic website for finding out more about machine learning, and it has loads more great projects for you to try, so make sure you check it out!

The post Try our new free machine learning projects for Scratch appeared first on Raspberry Pi.

A rather snazzy Raspberry Pi 4 wallpaper for your phone and computer

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/snazzy-raspberry-pi-4-wallpaper-phone-computer/

Fiacre took a rather snazzy photo of a Raspberry Pi 4, and he liked it so much that he set it as his iPhone’s wallpaper.

And we liked it so much that we asked him to produce size variants so we could share them with all of you.

You’ll find three variants of the image below: smartphone, 1920×1200, 4K. Just click on the appropriate image to be redirected to the full-resolution version.



Standard rules apply: these images are for personal use only and are not to be manipulated or sold.

Should we create more snazzy wallpapers of Raspberry Pi? Lets us know in the comments, and we’ll get Fiacre to work.

The post A rather snazzy Raspberry Pi 4 wallpaper for your phone and computer appeared first on Raspberry Pi.

Keynote speeches from Scratch Conference Europe 2019

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/keynote-speeches-scratch-conference-europe-2019/

This weekend, the Raspberry Pi Foundation hosted Scratch Conference Europe 2019 at Churchill College in Cambridge, UK.

Framing the busy weekend’s schedule were presentations from:

  • Massachusetts Institute of Technology (MIT) Media Lab’s Mitchel Resnick, co-inventor of Scratch himself
  • Science presenter Neil Monterio
  • Raspberry Pi favourite, the fire-loving Fran Scott

Since not everyone was able to travel to Cambridge to attend the conference, we wanted to make sure you’re not missing out, so we filmed their presentations, for you to watch at your leisure.

For the full Scratch Conference experience, we suggest gathering together a group of like-minded people to watch the videos and discuss your thoughts. Alternatively, use #ScratchEurope on Twitter to join in the conversation with the conference attendees online.

Enjoy!

Mitch Resnick presents at Scratch Conference Europe 2019

Mitch Resnick addresses the attendees of Scratch Conference Europe, hosted by the Raspberry Pi Foundation at Churchill College, Cambridge, UK on 24 August 2019.

Neil Monteiro presents at Scratch Conference Europe 2019

Neil Monteiro closes the show on day two of Scratch Conference Europe, hosted by the Raspberry Pi Foundation at Churchill College, Cambridge, UK on 24 August 2019. In this show, Neil takes the audience on a journey into a dangerous labyrinth…in code!

Fran Scott presents at Scratch Conference Europe 2019

Fran Scott closes the show on day three of Scratch Conference Europe, hosted by the Raspberry Pi Foundation at Churchill College, Cambridge, UK on 25 August 2019.

 

The post Keynote speeches from Scratch Conference Europe 2019 appeared first on Raspberry Pi.

Scratch 3 Desktop for Raspbian on Raspberry Pi

Post Syndicated from Martin O'Hanlon original https://www.raspberrypi.org/blog/scratch-3-desktop-for-raspbian-on-raspberry-pi/

You can now install and use Scratch 3 Desktop for Raspbian on your Raspberry Pi!

Scratch 3

Scratch 3 was released in January this year, and since then we and the Scratch team have put lots of work into creating an offline version for Raspberry Pi.

The new version of Scratch has a significantly improved interface and better functionality compared to previous versions. These improvements come at the cost of needing more processing power to run. Luckily, Raspberry Pi 4 has delivered just that, and with the software improvements in the newest version of Raspbian, Buster, we can now deliver a reliable Scratch 3 experience on our computer.

Which Raspberry Pi can I use?

Scratch 3 needs at least 1GB of RAM to run, and we recommend a Raspberry Pi 4 with 2GB+ RAM. While you can run Scratch 3 on a Raspberry Pi 2, 3, 3B+, or a Raspberry 4 with 1GB RAM, performance on these models is reduced, and depending on what other software you run at the same time, Scratch 3 may fail to start due to lack of memory.

The Scratch team is working to reduce the memory requirements of Scratch 3, so we will hopefully see improvements to this soon.

How to install Scratch 3

You can only install Scratch 3 on Raspbian Buster.

First, update Raspbian!

  • If you’ve yet to upgrade to Raspbian Buster, we recommend installing a fresh version of Buster onto your SD card instead of upgrading from your current version of Raspbian.
  • If you’re already using Raspbian Buster, but you’re not sure your running the latest version, update Buster by following this tutorial:

How to update Raspbian on your Raspberry Pi

How to update to the latest version of Raspbian on your Raspberry Pi.

Once you’re running the latest version of Buster, you can install Scratch 3 either using the Recommended Software application or apt on the terminal.

How to install Scratch 3 using the Recommended Software app

Open up the menu, click on Preferences > Recommended Software, and then select Scratch 3 and click on OK.

How to install Scratch 3 using the terminal

Open a terminal window, and type in and run the following commands:

sudo apt-get update
sudo apt-get install scratch3

What can I do with Scratch 3 and Raspberry Pi?

Scratch 3 Desktop for Raspbian comes with new extensions to allow you to control the GPIO pins and Sense HAT with Scratch code!

GPIO extension

GPIO extension is a replacement for the existing extension in Scratch 2. Its layout and functionality is very similar, so you can use it as a drop-in replacement.

The GPIO extension gives you the flexibility to connect and control a whole host of electronic devices.

Simple Electronics extension

If you are looking to add something simple, like an LED or button controller for a game, you should find the new Simple Electronics extension easier to use than the GPIO extension. The Simple Electronics extension is the first version of a beginner-friendly extension for interacting with Raspberry Pi’s GPIO pins. Taking lessons from the implementation of gpiozero for Python, this new extension provides a simpler way of using electronic components: currently buttons and LEDs.

In this example, an LED connected to GPIO pin 17 is controlled by a button connected between pin 2 and GND.

Sense HAT extension

We’ve improved the Sense HAT extension to take advantage of new features in Scratch 3, and the updated version of the extension also introduces a number of new blocks to allow you to:

  • Sense tilting, shaking, and orientation
  • Use the joystick
  • Measure temperature, pressure, and humidity
  • Display text, characters, and patterns on the LED matrix

micro:bit and LEGO extensions

The micro:bit and LEGO extensions will become available later on Scratch 3 Desktop. This is because Scratch Link, the software which allows Scratch to talk to Bluetooth devices, is not yet available for Linux-type operating systems like Raspbian. A version of Scratch Link for Raspbian is part of our plans but, as yet, we don’t have a release date.

A round of thanks

It has been a long ambition of both the Scratch and Raspberry Pi teams to have Scratch 3 running on Raspberry Pi, and it’s amazing to see it released!

A big thank you to Raspberry Pi engineer Simon Long for building and packaging Scratch 3, and to the Scratch team for their support in getting over some of the problems we faced along the way.

The post Scratch 3 Desktop for Raspbian on Raspberry Pi appeared first on Raspberry Pi.

Build a Raspberry Pi music box with Sally Le Page

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/build-a-raspberry-pi-music-box-with-sally-le-page/

Connecting buttons to the GPIO pins of your Raspberry Pi instantly opens up your digital making to the world of clicky funtimes.

Sally Le Page

Our Music Box project teaches you how to connect several buttons to your Raspberry Pi and write code to make them trigger cool sound effects.

It’s fun. It’s easy. And we roped Sally Le Page into helping us show you how you can do it yourself, in your own home!

Here Sally is, and here’s the link to the updated online project for you to get stuck into.

Build a Raspberry Pi music box ft. Dr Sally Le Page

Subscribe to our YouTube channel: http://rpf.io/ytsub Help us reach a wider audience by translating our video content: http://rpf.io/yttranslate Buy a Raspberry Pi from one of our Approved Resellers: http://rpf.io/ytproducts Find out more about the #RaspberryPi Foundation: Raspberry Pi http://rpf.io/ytrpi Code Club UK http://rpf.io/ytccuk Code Club International http://rpf.io/ytcci CoderDojo http://rpf.io/ytcd Check out our free online training courses: http://rpf.io/ytfl Find your local Raspberry Jam event: http://rpf.io/ytjam Work through our free online projects: http://rpf.io/ytprojects Do you have a question about your Raspberry Pi?

The post Build a Raspberry Pi music box with Sally Le Page appeared first on Raspberry Pi.

Monitor air quality with a Raspberry Pi

Post Syndicated from Andrew Gregory original https://www.raspberrypi.org/blog/monitor-air-quality-with-a-raspberry-pi/

Add a sensor and some Python 3 to your Raspberry Pi to keep tabs on your local air pollution, in the project taken from Hackspace magazine issue 21.

Air is the very stuff we breathe. It’s about 78% nitrogen, 21% oxygen, and 1% argon, and then there’s the assorted ‘other’ bits and pieces – many of which have been spewed out by humans and our related machinery. Carbon dioxide is obviously an important polluter for climate change, but there are other bits we should be concerned about for our health, including particulate matter. This is just really small bits of stuff, like soot and smog. They’re grouped together based on their size – the most important, from a health perspective, are those that are smaller than 2.5 microns in width (known as PM2.5), and PM10, which are between 10 and 2.5 microns in width. This pollution is linked with respiratory illness, heart disease, and lung cancer.

Obviously, this is something that’s important to know about, but it’s something that – here in the UK – we have relatively little data on. While there are official sensors in most major towns and cities, the effects can be very localised around busy roads and trapped in valleys. How does the particular make-up of your area affect your air quality? We set out to monitor our environment to see how concerned we should be about our local air.

Getting started

We picked the SDS011 sensor for our project (see ‘Picking a sensor’ below for details on why). This sends output via a binary data format on a serial port. You can read this serial connection directly if you’re using a controller with a UART, but the sensors also usually come with a USB-to-serial connector, allowing you to plug it into any modern computer and read the data.

The USB-to-serial connector makes it easy to connect the sensor to a computer

The very simplest way of using this is to connect it to a computer. You can read the sensor values with software such as DustViewerSharp. If you’re just interested in reading data occasionally, this is a perfectly fine way of using the sensor, but we want a continuous monitoring station – and we didn’t want to leave our laptop in one place, running all the time. When it comes to small, low-power boards with USB ports, there’s one that always springs to mind – the Raspberry Pi.

First, you’ll need a Raspberry Pi (any version) that’s set up with the latest version of Raspbian, connected to your local network, and ideally with SSH enabled. If you’re unsure how to do this, there’s guidance on the Raspberry Pi website.

The wiring for this project is just about the simplest we’ll ever do: connect the SDS011 to the Raspberry Pi with the serial adapter, then plug the Raspberry Pi into a power source.

Before getting started on the code, we also need to set up a data repository. You can store your data wherever you like – on the SD card, or upload it to some cloud service. We’ve opted to upload it to Adafruit IO, an online service for storing data and making dashboards. You’ll need a free account, which you can sign up for on the Adafruit IO website – you’ll need to know your Adafruit username and Adafruit IO key in order to run the code below. If you’d rather use a different service, you’ll need to adjust the code to push your data there.

We’ll use Python 3 for our code, and we need two modules – one to read the data from the SDS011 and one to push it to Adafruit IO. You can install this by entering the following commands in a terminal:

pip3 install pyserial adafruit-io

You’ll now need to open a text editor and enter the following code:

This does a few things. First, it reads ten bytes of data over the serial port – exactly ten because that’s the format that the SDS011 sends data in – and sticks these data points together to form a list of bytes that we call data.

We’re interested in bytes 2 and 3 for PM2.5 and 4 and 5 for PM10. We convert these from bytes to integer numbers with the slightly confusing line:

pmtwofive = int.from_bytes(b’’.join(data[2:4]), byteorder=’little’) / 10

from_byte command takes a string of bytes and converts them into an integer. However, we don’t have a string of bytes, we have a list of two bytes, so we first need to convert this into a string. The b’’ creates an empty string of bytes. We then use the join method of this which takes a list and joins it together using this empty string as a separator. As the empty string contains nothing, this returns a byte string that just contains our two numbers. The byte_order flag is used to denote which way around the command should read the string. We divide the result by ten, because the SDS011 returns data in units of tens of grams per metre cubed and we want the result in that format aio.send is used to push data to Adafruit IO. The first command is the feed value you want the data to go to. We used kingswoodtwofive and kingswoodten, as the sensor is based in Kingswood. You might want to choose a more geographically relevant name. You can now run your sensor with:

python3 airquality.py

…assuming you called the Python file airquality.py
and it’s saved in the same directory the terminal’s in.

At this point, everything should work and you can set about running your sensor, but as one final point, let’s set it up to start automatically when you turn the Raspberry Pi on. Enter the command:

crontab -e

…and add this line to the file:

@reboot python3 /home/pi/airquality.py

With the code and electronic setup working, your sensor will need somewhere to live. If you want it outside, it’ll need a waterproof case (but include some way for air to get in). We used a Tupperware box with a hole cut in the bottom mounted on the wall, with a USB cable carrying power out via a window. How you do it, though, is up to you.

Now let’s democratise air quality data so we can make better decisions about the places we live.

Picking a sensor

There are a variety of particulate sensors on the market. We picked the SDS011 for a couple of reasons. Firstly, it’s cheap enough for many makers to be able to buy and build with. Secondly, it’s been reasonably well studied for accuracy. Both the hackAIR and InfluencAir projects have compared the readings from these sensors with more expensive, better-tested sensors, and the results have come back favourably. You can see more details at hsmag.cc/DiYPfg and hsmag.cc/Luhisr.

The one caveat is that the results are unreliable when the humidity is at the extremes (either very high or very low). The SDS011 is only rated to work up to 70% humidity. If you’re collecting data for a study, then you should discard any readings when the humidity is above this. HackAIR has a formula for attempting to correct for this, but it’s not reliable enough to neutralise the effect completely. See their website for more details: hsmag.cc/DhKaWZ.

Safe levels

Once you’re monitoring your PM2.5 data, what should you look out for? The World Health Organisation air quality guideline stipulates that PM2.5 not exceed 10 µg/m3 annual mean, or 25 µg/m3 24-hour mean; and that PM10 not exceed 20 µg/m3 annual mean, or 50 µg/m3 24-hour mean. However, even these might not be safe. In 2013, a large survey published in The Lancet “found a 7% increase in mortality with each 5 micrograms per cubic metre increase in particulate matter with a diameter of 2.5 micrometres (PM2.5).”

Where to locate your sensor

Standard advice for locating your sensor is that it should be outside and four metres above ground level. That’s good advice for general environmental monitoring; however, we’re not necessarily interested in general environmental monitoring – we’re interested in knowing what we’re breathing in.

Locating your monitor near your workbench will give you an idea of what you’re actually inhaling – useless for any environmental study, but useful if you spend a lot of time in there. We found, for example, that the glue gun produced huge amounts of PM2.5, and we’ll be far more careful with ventilation when using this tool in the future.

Adafruit IO

You can use any data platform you like. We chose Adafruit IO because it’s easy to use, lets you share visualisations (in the form of dashboards) with others, and connects with IFTTT to perform actions based on values (ours tweets when the air pollution is above legal limits).

One thing to be aware of is that Adafruit IO only holds data for 30 days (on the free tier at least). If you want historical data, you’ll need to sign up for the Plus option (which stores data for 60 days), or use an alternative storage method. You can use multiple data stores if you like.

Checking accuracy

Now you’ve got your monitoring station up and running, how do you know that it’s running properly? Perhaps there’s an issue with the sensor, or perhaps there’s a problem with the code. The easiest method of calibration is to test it against an accurate sensor, and most cities here in the UK have monitoring stations as part of Defra’s Automatic Urban and Rural Monitoring Network. You can find your local station here. Many other countries have equivalent public networks. Unless there is no other option, we would caution against using crowdsourced data for calibration, as these sensors aren’t themselves calibrated.

With a USB battery pack, you can head to your local monitoring point and see if your monitor is getting similar results to the monitoring network.

HackSpace magazine #21 is out now

You can read the rest of this feature in HackSpace magazine issue 21, out today in Tesco, WHSmith, and all good independent UK newsagents.

Or you can buy HackSpace mag directly from us — worldwide delivery is available. And if you’d like to own a handy digital version of the magazine, you can also download a free PDF.

The post Monitor air quality with a Raspberry Pi appeared first on Raspberry Pi.

Hack your old Raspberry Pi case for the Raspberry Pi 4

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/hack-your-old-raspberry-pi-case-for-the-raspberry-pi-4/

Hack your existing Raspberry Pi case to fit the layout of your new Raspberry Pi 4, with this handy “How to hack your existing Raspberry Pi case to fit the layout of your new Raspberry Pi 4” video!

Hack your old Raspberry Pi case to fit your Raspberry Pi 4

Hack your existing official Raspberry Pi case to fit the new Raspberry Pi 4, or treat yourself to the new official Raspberry Pi 4 case. The decision is yours!

How to hack your official Raspberry Pi case

  1. Take your old Raspberry Pi out of its case.
  2. Spend a little time reminiscing about all the fun times you had together.
  3. Reassure your old Raspberry Pi that this isn’t the end, and that it’ll always have a special place in your heart.
  4. Remember that one particular time – you know the one; wipe a loving tear from your eye.
  5. Your old Raspberry Pi loves you. It’s always been there for you. Why are you doing this?
  6. Look at the case. Look at it. Look how well it fits your old Raspberry Pi. Those fine, smooth edges; that perfect white and red combination. The three of you – this case, your old Raspberry Pi, and you – you make such a perfect team. You’re brilliant.
  7. Look at your new Raspberry Pi 4. Yes, it’s new, and faster, and stronger, but this isn’t about all that. This is about all you’ve gone through with your old Raspberry Pi. You’re just not ready to say goodbye. Not yet.
  8. Put your buddy, the old Raspberry Pi, back in its case and set it aside. There are still projects you can work on together; this is not the end. No, not at all.
  9. In fact, why do you keep calling it your old Raspberry Pi? There’s nothing old about it. It still works; it still does the job. Sure, your Raspberry Pi 4 can do things that this one can’t, and you’re looking forward to trying them out, but that doesn’t make this one redundant. Heck, if we went around replacing older models with newer ones all the time, Grandma would be 24 years old and you’d not get any of her amazing Sunday dinners, and you do love her honey-glazed parsnips.
  10. Turn to your new Raspberry Pi 4 and introduce yourself. It’s not its fault that you’re having a temporary crisis. It hasn’t done anything wrong. So take some time to really get to know your new friend.
  11. New friendships take time, and fresh beginnings, dare we say it…deserve new cases.
  12. Locate your nearest Raspberry Pi Approved Reseller and purchase the new Raspberry Pi 4 case, designed especially to make your new Raspberry Pi comfortable and secure.
  13. Reflect that this small purchase of a new case will support the charitable work of the Raspberry Pi Foundation. Enjoy a little warm glow inside. You did good today.
  14. Turn to your old keyboard

The post Hack your old Raspberry Pi case for the Raspberry Pi 4 appeared first on Raspberry Pi.

How to build databases using Python and text files | Hello World #9

Post Syndicated from Mac Bowley original https://www.raspberrypi.org/blog/how-to-build-databases-using-python-and-text-files-hello-world-9/

In Hello World issue 9, Raspberry Pi’s own Mac Bowley shares a lesson that introduces students to databases using Python and text files.

In this lesson, students create a library app for their books. This will store information about their book collection and allow them to display, manipulate, and search their collection. You will show students how to use text files in their programs that act as a database.

The project will give your students practical examples of database terminology and hands-on experience working with persistent data. It gives opportunities for students to define and gain concrete experience with key database concepts using a language they are familiar with. The script that accompanies this activity can be adapted to suit your students’ experience and competency.

This ready-to-go software project can be used alongside approaches such as PRIMM or pair programming, or as a worked example to engage your students in programming with persistent data.

What makes a database?

Start by asking the students why we need databases and what they are: do they ever feel unorganised? Life can get complicated, and there is so much to keep track of, the raw data required can be overwhelming. How can we use computing to solve this problem? If only there was a way of organising and accessing data that would let us get it out of our head. Databases are a way of organising the data we care about, so that we can easily access it and use it to make our lives easier.

Then explain that in this lesson the students will create a database, using Python and a text file. The example I show students is a personal library app that keeps track of which books I own and where I keep them. I have also run this lesson and allowed the students pick their own items to keep track of — it just involves a little more planning time at the end. Split the class up into pairs; have each of them discuss and select five pieces of data about a book (or their own item) they would like to track in a database. They should also consider which type of data each of them is. Give them five minutes to discuss and select some data to track.

Databases are organised collections of data, and this allows them to be displayed, maintained, and searched easily. Our database will have one table — effectively just like a spreadsheet table. The headings on each of the columns are the fields: the individual pieces of data we want to store about the books in our collection. The information about a single book are called its attributes and are stored together in one record, which would be a single row in our database table. To make it easier to search and sort our database, we should also select a primary key: one field that will be unique for each book. Sometimes one of the fields we are already storing works for this purpose; if not, then the database will create an ID number that it uses to uniquely identify each record.

Create a library application

Pull the class back together and ask a few groups about the data they selected to track. Make sure they have chosen appropriate data types. Ask some if they can find any of the fields that would be a primary key; the answer will most likely be no. The ISBN could work, but for our simple application, having to type in a 10- or 13-digit number just to use for an ID would be overkill. In our database, we are going to generate our own IDs.

The requirements for our database are that it can do the following things: save data to a file, read data from that file, create new books, display our full database, allow the user to enter a search term, and display a list of relevant results based on that term. We can decompose the problem into the following steps:

  • Set up our structures
  • Create a record
  • Save the data to the database file
  • Read from the database file
  • Display the database to the user
  • Allow the user to search the database
  • Display the results

Have the class log in and power up Python. If they are doing this locally, have them create a new folder to hold this project. We will be interacting with external files and so having them in the same folder avoids confusion with file locations and paths. They should then load up a new Python file. To start, download the starter file from the link provided. Each student should make a copy of this file. At first, I have them examine the code, and then get them to run it. Using concepts from PRIMM, I get them to print certain messages when a menu option is selected. This can be a great exemplar for making a menu in any application they are developing. This will be the skeleton of our database app: giving them a starter file can help ease some cognitive load from students.

Have them examine the variables and make guesses about what they are used for.

  • current_ID – a variable to count up as we create records, this will be our primary key
  • new_additions – a list to hold any new records we make while our code is running, before we save them to the file
  • filename – the name of the database file we will be using
  • fields – a list of our fields, so that our dictionaries can be aligned with our text file
  • data – a list that will hold all of the data from the database, so that we can search and display it without having to read the file every time

Create the first record

We are going to use dictionaries to store our records. They reference their elements using keys instead of indices, which fit our database fields nicely. We are going to generate our own IDs. Each of these must be unique, so a variable is needed that we can add to as we make our records. This is a user-focused application, so let’s make it so our user can input the data for the first book. The strings, in quotes, on the left of the colon, are the keys (the names of our fields) and the data on the right is the stored value, in our case whatever the user inputs in response to our appropriate prompts. We finish this part of by adding the record to the file, incrementing the current ID, and then displaying a useful feedback message to the user to say their record has been created successfully. Your students should now save their code and run it to make sure there aren’t any syntax errors.

You could make use of pair programming, with carefully selected pairs taking it in turns in the driver and navigator roles. You could also offer differing levels of scaffolding: providing some of the code and asking them to modify it based on given requirements.

How to use the code in your class

To complete the project, your students can add functionality to save their data to a CSV file, read from a database file, and allow users to search the database. The code for the whole project is available at helloworld.cc/database.

An example of the code

You may want to give your students the entire piece of code. They can investigate and modify it to their own purpose. You can also lead them through it, having them follow you as you demonstrate how an expert constructs a piece of software. I have done both to great effect. Let me know how your classes get on! Get in touch at [email protected]

Hello World issue 9

The brand-new issue of Hello World is out today, and available right now as a free PDF download from the Hello World website.



UK-based educators can also sign up to receive Hello World as printed magazine FOR FREE, direct to their door. And those outside the UK, educator or not, can subscribe to receive new digital issues of Hello World in their inbox on the day of release.

The post How to build databases using Python and text files | Hello World #9 appeared first on Raspberry Pi.

The NEW Official Raspberry Pi Beginner’s Guide: updated for Raspberry Pi 4

Post Syndicated from Phil King original https://www.raspberrypi.org/blog/the-new-official-raspberry-pi-beginners-guide-updated-for-raspberry-pi-4/

To coincide with the launch of Raspberry Pi 4, Raspberry Pi Press has created a new edition of The Official Raspberry Pi Beginner’s Guide book — as if this week wasn’t exciting enough! Weighing in at 252 pages, the book is even bigger than before, and it’s fully updated for Raspberry Pi 4 and the latest version of the Raspbian operating system, Buster.A picture of the front cover of the Raspberry Pi Beginner's Guide version two

The Official Raspberry Pi Beginner’s Guide

We’ve roped in Gareth Halfacree, full-time technology journalist and technical author, and the wonderful Sam Alder, illustrator of our incredible cartoons and animations, to put together the only guide you’ll ever need to get started with Raspberry Pi.



From setting up your Raspberry Pi on day one to taking your first steps into writing coding, digital making, and computing, The Official Raspberry Beginner’s Guide – 2nd Edition is great for users from age 7 to 107! It’s available now online from the Raspberry Pi Press store, with free international delivery, or from the real-life Raspberry Pi Store in Cambridge, UK.

As always, we have also released the guide as a free PDF, and you’ll soon be seeing physical copies on the shelves of Waterstones, Foyles, and other good bookshops.

The post The NEW Official Raspberry Pi Beginner’s Guide: updated for Raspberry Pi 4 appeared first on Raspberry Pi.

Make a retro console with RetroPie and a Raspberry Pi — part 2

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/retro-console-with-retropie-raspberry-pi-2/

Here’s part two of Lucy Hattersley’s wonderful retro games console tutorial. Part 1 of the tutorial lives here, for those of you who missed it.

Choose the network locale

RetroPie boots into EmulationStation, which is your starter interface. It’s currently displaying just the one option, RetroPie, which is used to set up the emulation options. As you add games to RetroPie, other systems will appear in EmulationStation.

With RetroPie selected, press the A button on the gamepad to open the configuration window. Use the D-pad to move down the options and select WiFi. You will see a warning message: ‘You don’t currently have your WiFi country set…’. Press the D-pad left to choose Yes, and press A. The interface will open raspi-config. At this point, it’s handy to switch to the keyboard and use that instead.

Choose 4 Localisation Options, and press the right arrow key on the keyboard to highlight Select, then press Enter.

Now choose 4 Change Wi-fi Country and pick your country from the list. We used GB Britain (UK). Highlight OK and press Enter to select it.

Now move right twice to choose Finish and press Enter. This will reboot the system.

Connect to wireless LAN

If you have a Raspberry Pi with an Ethernet connection, you can use an Ethernet cable to connect directly to your router/modem or network.

More likely, you’ll connect the Raspberry Pi to a wireless LAN network so you can access it when it’s beneath your television.

Head back into RetroPie from EmulationStation and down to the WiFi setting; choose Connect to WiFi network.

The window will display a list of nearby wireless LAN networks. Choose your network and use the keyboard to enter the wireless LAN password. Press Enter when you’re done. Choose the Exit option to return to the RetroPie interface.

Configuration tools

Now choose RetroPie Setup and then Configuration Tools. Here, in the Choose an option window, you’ll find a range of useful tools. As we’re using a USB gamepad, we don’t need the Bluetooth settings, but it’s worth noting they’re here.

We want to turn on Samba so we can share files from our computer directly to RetroPie. Choose Samba and Install RetroPie Samba shares, then select OK.

Now choose Cancel to back up to the Choose an option window, and then Back to return to the RetroPie-Setup script.

Run the setup script

Choose Update RetroPie-Setup script and press Enter. After the script has updated, press Enter again and you’ll be back at the Notice: window. Press Enter and choose Basic install; press Enter, choose Yes, and press Enter again to begin the setup and run the configuration script.

When the script has finished, choose Perform a reboot and Yes.

Turn on Samba in Windows

We’re going to use Samba to copy a ROM file (a video game image) from our computer to RetroPie.

Samba used to be installed by default in Windows, but it has recently become an optional installation. In Windows 10, click on the Search bar and type ‘Control Panel’. Click on Control Panel in the search results.

Now click Programs and Turn Windows features on or off. Scroll down to find SMB 1.0/CIFS File Sharing Support and click the + expand icon to reveal its options. Place a check in the box marked SMB 1.0/CIFS Client. Click OK. This will enable Samba client support on your Windows 10 PC so it can access the Raspberry Pi.

We’ve got more information on how Samba works on The MagPi’s website.

Get the game

On your Windows PC or Mac, open a web browser, and visit the Blade Buster website. This is a homebrew video game designed by High Level Challenge for old NES systems. The developer’s website is in Japanese — just click BLADE BUSTER Download to save the ROM file to your Downloads folder.

Open a File Explorer (or Finder) window and locate the BB_20120301.zip file in your Downloads folder. Don’t unzip the file.

Click on Network and you’ll see a RETROPIE share. Open it and locate the roms folder. Double-click roms and you’ll see folders for many classic systems. Drag and drop the BB_20120301.zip file and place it inside the nes folder.

Play the game

Press the Start button on your gamepad to bring up the Main Menu. Choose Quit and Restart EmulationStation. You’ll now see a Nintendo Entertainment System option with 1 Games Available below it. Click it and you’ll see BB_20120301 — this is Blade Buster. Press A to start the game. Have fun shooting aliens. Press Start and Analog (or whatever you’ve set as your hotkey) together when you’re finished; this will take you back to the game selection in EmulationStation.

If you’ve been setting up RetroPie on your monitor, now is the time to move it across to your main television. The RetroPie console will boot automatically and connect to the network, and then you can move ROM files over to it from your PC or Mac. At this point, you may notice black borders around the screen; if so, see the Fix the borders tip.

Enjoy your gaming system!

More top tips from Lucy

Change the resolution

Some games were designed for a much lower resolution, and scaling them up can look blocky on modern televisions. If you’d prefer to alter the resolution, choose ‘RetroPie setup’. Open raspi-config, Advanced Options, and Resolution. Here you’ll find a range of other resolution options to choose from.

Fix the borders

These are caused by overscan. Choose RetroPie from EmulationStation and raspi-config. Now select Advanced Options > Overscan and select No on the ‘Would you like to enable compensation for displays with overscan?’ window. Choose OK and then Finish. Choose Yes on the Reboot Now window. When the system has rebooted, you will see the borders are gone.

The MagPi magazine issue 81

This article is from the latest issue of The MagPi magazine, which is out today and can be purchased online, at the Raspberry Pi Store, or from many newsagents and bookshops, such as WHSmith and Barnes & Noble.

The MagPi magazine issue 81

You can also download issue 81 for free from The MagPi website, where you’ll also find information on subscription options, and the complete MagPi catalogue, including Essentials guides and books, all available to download for free.

the MagPi subscription

The post Make a retro console with RetroPie and a Raspberry Pi — part 2 appeared first on Raspberry Pi.

Make a retro console with RetroPie and a Raspberry Pi — part 1

Post Syndicated from Lucy Hattersley original https://www.raspberrypi.org/blog/retro-console-with-retropie-raspberry-pi-1/

Discover classic gaming on the Raspberry Pi and play homebrew ROMs, with this two-part tutorial from The MagPi Editor Lucy Hattersley.

Raspberry Pi retro games console

Turning a Raspberry Pi device into a retro games console is a fun project, and it’s one of the first things many a new Pi owner turns their hand to.

The appeal is obvious. Retro games are fun, and from a programming perspective, they’re a lot easier to understand than modern 3D powerhouses. The Raspberry Pi board’s small form factor, low power usage, HDMI connection, and wireless networking make it a perfect micro-console that can sit under your television.

RetroPie

There are a bunch of different emulators around for Raspberry Pi. In this tutorial, we’re going to look at RetroPie.

RetroPie combines Raspbian, EmulationStation, and RetroArch into one handy image. With RetroPie you can emulate arcade games, as well as titles originally released on a host of 8-bit, 16-bit, and even 32- and 64-bit systems. You can hook up a joypad; we’re going to use the Wireless USB Game Controller, but most other USB game controllers will work.

You can also use Bluetooth to connect a controller from most video games consoles. RetroPie has an interface that will be very familiar to anyone who has used a modern games console, and because it is open-source, it is constantly being improved.

You can look online for classic games, but we prefer homebrew and modern releases coded for classic systems. In this tutorial, we will walk you through the process of setting up RetroPie, configuring a gamepad, and running a homebrew game called Blade Buster.

Get your microSD card ready

RetroPie is built on top of Raspbian (the operating system for Raspberry Pi). While it is possible to install RetroPie from the desktop interface, it’s far easier to format a microSD card† and copy a new RetroPie image to the blank card. This ensures all the settings are correct and makes setup much easier. Our favourite method of wiping microSD cards on a PC or Apple Mac is to use SD Memory Card Formatter.

Attach the microSD card to your Windows or Mac computer and open SD Card Formatter. Ensure the card is highlighted in the Select card section, then click Format.

Download RetroPie

Download the RetroPie image. It’ll be downloaded as a gzip file; the best way to expand this on Windows is using 7-Zip (7-zip.org).

With 7-Zip installed, right-click the retropie-4.4-rpi2_rpi3.img.gz file and choose 7-Zip > Extract here. Extract GZ files on a Mac or Linux PC using gunzip -k <filename.gz> (the -k option keeps the original GZ file).

gunzip -k retropie-4.4-rpi2_rpi3.img.gz

Flash the image

We’re going to use Etcher to copy the retropie-4.4-rpi2_rpi3.img file to our freshly formatted microSD card. Download Etcher. Open Etcher and click Select Image, then choose the retropie-4.4-rpi2_rpi3.img image file and click Open.

Etcher should have already located the microSD card; remove and replace it if you see a Select Drive button. Click Flash! to copy the RetroPie image to the microSD card.

See our guide for more information on how to use Etcher to flash SD cards.

Set up the Raspberry Pi

Insert the flashed microSD card to your Raspberry Pi. Now attach the Raspberry Pi to a TV or monitor using the HDMI cable. Connect the USB dongle from the Wireless USB Game Controller to the Raspberry Pi. Also attach a keyboard (you’ll need this for the setup process).

Insert the batteries in the Wireless USB Game Controller and set the power switch (on the back of the device) to On. Once everything is connected, attach a power supply to the Raspberry Pi.

See our quickstart guide for more detailed information on setting up a Raspberry Pi.

Configure the gamepad

When RetroPie starts, you should see Welcome screen displaying the message ‘1 gamepad detected’. Press and hold one of the buttons on the pad, and you will see the Configuring screen with a list of gamepad buttons and directions.

Tap the D-pad (the four-way directional control pad on the far left) up on the controller and ‘HAT 0 UP’ will appear. Now tap the D-pad down.
Map the A, B, X, Y buttons to:

A: red circle
B: blue cross
X: green triangle
Y: purple square

The Left and Right Shoulder buttons refer to the topmost buttons on the rear of the controller, while the Triggers are the larger lower buttons.

Push the left and right analogue sticks in for the Left and Right Thumbs. Click OK when you’re done.

Top tips from Lucy

Install Raspbian desktop

RetroPie is built on top of the Raspbian operating system. You might be tempted to install RetroPie on top of the Raspbian with Desktop interface, but it’s actually much easier to do it the other way around. Open RetroPie from EmulationStation and choose RetroPie setup. Select Configuration tools and Raspbian tools. Then choose Install Pixel desktop environment and Yes.

When it’s finished, choose Quit and Restart EmulationStation. When restarted, EmulationStation will display a Ports option. Select it and choose Desktop to boot into the Raspbian desktop interface.

Username and password

If RetroPie asks you for the username and password during boot, the defaults are pi and raspberry.

The MagPi magazine issue 81

The rest of this article can be found in the latest issue of The MagPi magazine, which is out now and can be purchased online, at the Raspberry Pi Store, or from many independent bookshops, such as WHSmith and Barnes & Noble. We’ll also post the second half on the blog tomorrow!

The MagPi magazine issue 81

You can also download issue 81 for free from The MagPi website, where you’ll find information on subscription options, and the complete MagPi catalogue, including Essentials guides and books, all available to download for free.

the MagPi subscription

The post Make a retro console with RetroPie and a Raspberry Pi — part 1 appeared first on Raspberry Pi.

Meet us at Maker Faire Bay Area 2019

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/maker-faire-bay-area-2019/

We’ll be attending Maker Faire Bay Area this month and we’d love to see as many of you there as we can, so be sure to swing by the Raspberry Pi stand and say hi!

Our North America team will be on-hand and hands-on all weekend to show you the wonders of the Raspberry Pi, with some great tech experiments for you to try. Do you like outer space? Of course, why wouldn’t you? So come try out the Sense HAT, our multi-sensor add-on board that we created especially for our two Astro Pi units aboard the International Space Station!

We’ll also have stickers, leaflets, and a vast array of information to share about the Raspberry Pi, our clubs and programmes, and how you can get more involved in the Raspberry Pi community.

And that’s not all!

Onstage talks!

Matt Richardson, Executive Director of the Raspberry Pi Foundation North America and all-round incredible person, will be making an appearance on the Make: Electronics by Digi-Key stage at 3pm Saturday 18 May to talk about Making Art with Raspberry Pi.

Matt Richardson

Hi, Matt!

And I’m presenting too! On the Sunday, I’ll be on the DIY Content Creators Stage at 12:30pm with special guests Joel “3D Printing Nerd” Telling and Estefannie Explains it All for a live recording of my podcast to discuss the importance of community for makers and brands.

There will also be a whole host of incredible creations by makers from across the globe, and a wide variety of talks and presentations throughout the weekend. So if you’re a fan of creative contraptions and beastly builds, you’ll be blown away at this year’s Maker Faire.

Showcasing your projects

If you’re planning to attend Maker Faire to showcase your project, we want to hear from you. Leave a comment below with information on your build so we can come and find you on the day. Our trusty videographer Fiacre and I will be scouting for our next favourite Raspberry Pi make, and we’ll also have Andrew with us, who is eager to fill the pages of HackSpace magazine with any cool, creative wonders we find — Pi-related or otherwise!

Discounted tickets!

Maker Fair Bay Area 2019 will be running at the San Mateo County Event Center from Friday 17 to Sunday 19 May.

If you’re in the area and would like to attend Maker Fair Bay Area, make use of  our 15% community discount on tickets. Wooh!

For more information on Maker Faire, check out the Maker Faire website, or follow Maker Faire on Twitter.

See you there!

The post Meet us at Maker Faire Bay Area 2019 appeared first on Raspberry Pi.

An Introduction to C & GUI Programming – the new book from Raspberry Pi Press

Post Syndicated from Simon Long original https://www.raspberrypi.org/blog/an-introduction-to-c-gui-programming-the-new-book-from-raspberry-pi-press/

The latest book from Raspberry Pi Press, An Introduction to C & GUI Programming, is now available. Author Simon Long explains how it came to be written…

An Introduction to C and GUI programming by Simon Long

Learning C

I remember my first day in a ‘proper’ job very well. I’d just left university, and was delighted to have been taken on by a world-renowned consultancy firm as a software engineer. I was told that most of my work would be in C, which I had never used, so the first order of business was to learn it.

My manager handed me a copy of Kernighan & Ritchie’s The C Programming Language, pointed to a terminal in the corner, said ‘That’s got a compiler. Off you go!’, and left me to it. So, I started reading the book, which is affectionately known to most software engineers as ‘K&R‘.

I didn’t get very far. K&R is basically the specification of the C language. Dennis Ritchie, the eponymous ‘R’, invented C, and while the book he helped write is an excellent reference guide, it is not a great introduction for a beginner. Like most people who know their subject inside out, the authors tend to assume that you know more than you do, so reading the book when you don’t know anything about the language at all is a little frustrating. I do know people who have learned C from K&R, and they have my undying respect!

I ended up learning C on the job as I went along; I looked at other people’s code, hacked stuff together, worked out why things didn’t work, asked for help from my colleagues, made a lot of mistakes, and gradually got the hang of it. I found only one book that was helpful for a beginner: it was called C For Yourself, and was actually one of the manuals for the long-extinct Microsoft QuickC compiler. That book is now impossible to find, so I’ve always had to tell people that the best book for learning C as a beginner is ‘C For Yourself, but you won’t be able to find a copy!’

Writing An Introduction to C & GUI Programming

When I embarked on this project, the editor of The MagPi and I were discussing possible series for the magazine, and we thought about creating a guide to writing GUI applications in C — that’s what I do in my day job at Raspberry Pi, so it seemed a logical place to start. We realised that the reader would need to know C to benefit from the series, and they wouldn’t be able to find a copy of C For Yourself. We decided that I ought to solve that problem first, so I wrote the original beginners’ guide to C series for The MagPi.

(At this point, I should stress that the series is aimed at absolute beginners. I freely admit that I have simplified parts of the language so that the reader does not have to absorb as much in one go. So yes, I do know about returning a success/fail code from a program, but beginners really don’t need to learn about that in the first chapter — especially when many will never need to write a program which does it. That’s why it isn’t explained until Chapter 9.)

An Introduction to C and GUI programming by Simon Long published by Raspberry Pi Press

So, the beginners’ guide to C came first, and I have now got round to writing the second part, which was what I’d planned to write all along. The section on GUIs describes how to write applications using the GTK toolkit, which is used for most of the Raspberry Pi Desktop and its associated applications. GTK is very powerful, and allows you to write rich graphical user interfaces with relatively few lines of code, but it’s not the most intuitive for beginners. (Much like C itself!) The book walks you through the basics of creating a window, putting widgets on it, and making the widgets do useful things, and gets you to the point where you know enough to be able to write an application like the ones I have written for the Raspberry Pi Desktop.

An Introduction to C and GUI programming by Simon Long published by Raspberry Pi Press

It then seemed logical to bring the two parts together in a single volume, so that someone with no experience of C has enough information to go from a standing start to writing useful desktop applications.

I hope that I’ve achieved that and if nothing else, I hope that I’ve written a book which is a bit more approachable for beginners than K&R!

Get An Introduction to C & GUI Programming today!

An Introduction to C & GUI Programming is available today from the Raspberry Pi Press online store, or as a free download here. You can also pick up a copy from the Raspberry Pi Store in Cambridge, or ask your local bookstore if they have it in stock or can order it in for you.

Alex interjects to state the obvious: Basically, what we’re saying here is that there’s no reason for you not to read Simon’s book. Oh, and it feels really nice too.

The post An Introduction to C & GUI Programming – the new book from Raspberry Pi Press appeared first on Raspberry Pi.

New Wolfram Mathematica free resources for your Raspberry Pi

Post Syndicated from Philip Harney original https://www.raspberrypi.org/blog/new-wolfram-mathematica-resources-2019/

We’ve worked alongside the team at Wolfram Mathematica to create ten new free resources for our projects site, perfect to use at home, or in your classroom, Code Club, or CoderDojo.

Try out the Wolfram Language today, available as a free download for your Raspberry Pi (download details are below).

The Wolfram Language

The Wolfram language is particularly good at retrieving and working with data, like natural language and geographic information, and at producing visual representations with an impressively small amount of code. The language does a lot of the heavy lifting for you and is a great way to let young learners in particular work with data to quickly produce real results.

If you’d like to learn more about the Wolfram Language on the Raspberry Pi, check out this great blog post written by Lucy, Editor of The MagPi magazine!

Weather dashboard

Wolfram Mathematica Raspberry Pi Weather Dashboard

My favourite of the new projects is the weather dashboard which, in a few quick steps, teaches you to create this shiny-looking widget that takes the user’s location, finds their nearest major city, and gets current weather data for it. I tried this out with my own CoderDojo club and it got a very positive reception, even if Dublin weather usually does report rain!

Coin and dice

Wolfram Mathematica Raspberry Pi Coin and Dice

The coin and dice project shows you how to create a coin toss and dice roller that you can use to move your favourite board game into the digital age. It also introduces you to creating interfaces and controls for your projects, choosing random outcomes, and displaying images with the Wolfram Language.

Day and night

In the day and night tracker project, you create a program that gives you a real-time view of where the sun is up right now and lets you check whether it’s day or night time in a particular country. This is not only a pretty cool way to learn about things like time zones, but also shows you how to use geographic data and create an interactive experience in the Wolfram Language.

Sentimental 8-ball

Wolfram Mathematica Raspberry Pi 8-ball

In Sentimental 8-Ball, you create a Magic 8-Ball that picks its answers based on how positive or negative the mood of the user’s question seems. In doing so, you learn to work with lists and use the power of sentiment analysis in the Wolfram Language.

Face swap

Wolfram Mathematica Raspberry Pi face swap

This fun project lets you take a photo of you and your friend and have the Wolfram Language identify and swap your faces! Perfect for updating your profile photo, and also a great way to learn about functions and lists!

More Wolfram Mathematica projects

That’s only half of the selection of great new projects we’ve got for you! Go check them out, along with all the other Wolfram Language projects on our projects site.

Download the Wolfram Language and Mathematica to your Raspberry Pi

Mathematica and the Wolfram Language are included as part of NOOBS, or you can download them to Raspbian on your Raspberry Pi for free by entering the following commands into a terminal window and pressing Enter after each:

sudo apt-get update
sudo apt-get install wolfram-engine

The post New Wolfram Mathematica free resources for your Raspberry Pi appeared first on Raspberry Pi.

Build a Raspberry Pi robot buggy

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/build-a-raspberry-pi-robot-buggy/

Need a project for the week? We’ve got one for you. Learn to build a Raspberry Pi robot buggy and control it via voice, smart device or homemade controller with our free online resources.

Build your robot buggy

To build a basic Raspberry Pi-powered robot buggy, you’ll need to start with a Raspberry Pi. For our free tutorial, the team uses a Raspberry Pi 3B+, though you should be good with most models.

You’ll also need some wheels, 12v DC motors, and a motor controller board, along with a few other peripherals such as jumper wires and batteries.

Our project resource will talk you through the whole set up, from setting up your tech and assembling your buggy, to writing code that will allow you to control your buggy with Python.

Control your robot buggy

Our follow-up resource will then show you how to set up your Android smartphone or Google AIY kit as a remote control for your robot. Or, for the more homebrew approach, you can find out how to build your own controller using a breadboard and tactile buttons.

Make your robot buggy do cool things

And, lastly, you can show off your coding skills, and the wonder of your new robot by programming it to do some pretty neat tricks, such as line following. Our last tutorial in the Buggy Robot trio will show you how to use sensors and write a line-following algorithm.

Do you want your robot to do more? Of course you do. Check out our How to build a competition-ready Raspberry Pi robot guide for more.

Pi Wars 2019

The William Gates Building in Cambridge will this weekend be home to Pi Wars, the “two-day family-friendly event in which teams compete for prestige and prizes on non-destructive challenge courses”. As the name suggests, all robots competing in the Pi Wars events have Raspberry Pi innards, and we love seeing the crazy creations made by members of the community.

If you can make it to the event, tickets are available here – a lot of us will be there, both as spectators and as judges (we’re not really allowed to participate, bums bums). And if you can’t, follow #PiWars on Twitter for updates throughout the event.

The post Build a Raspberry Pi robot buggy appeared first on Raspberry Pi.

Laser-engraved Raspberry Pi hologram

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/laser-engraved-raspberry-pi-hologram/

Inspired by an old episode of Pimoroni’s Bilge Tank, and with easy access to the laser cutter at the Raspberry Pi Foundation office, I thought it would be fun to create a light-up multi-layered hologram using a Raspberry Pi and the Pimoroni Unicorn pHAT.

Raspberry Pi layered light

Read more –

Break it to make it

First, I broke down the Raspberry Pi logo into three separate images — the black outline, the green leaves, and the red berry.

RASPBERRY PI HOLOGRAM
RASPBERRY PI HOLOGRAM
RASPBERRY PI HOLOGRAM

Fun fact: did you know that Pimoroni’s Paul Beech designed this logo as part of the ‘design us a logo’ contest we ran all the way back in August 2011?

Once I had the three separate files, I laser-engraved them onto 4cm-wide pieces of 3mm-thick clear acrylic. As there are four lines of LEDs on the Unicorn pHAT, I cut the fourth piece to illuminate the background.

RASPBERRY PI HOLOGRAM

To keep the engraved acrylic pieces together, I cut out a pair of acrylic brackets (see above) with four 3mm indentations. Then, after a bit of fiddling with the Unicorn pHAT library, I was able to light the pHAT’s rows of LEDs in white, red, green, and white.

RASPBERRY PI HOLOGRAM

The final result looks pretty spectacular, especially in the dark, and you can build on this basic idea to create fun animations — especially if you use a HAT with more rows of LEDs.

Iterations

This is just a prototype. I plan on building a sturdier frame for the pieces that securely fits a Raspberry Pi Zero W and lets users replace layers easily. As with many projects, I’m sure this will grow and grow as each interaction inspires a new add-on.

How would you build upon this basic principle?

Oh…

…we also laser-engraved this Cadbury’s Creme Egg.

The post Laser-engraved Raspberry Pi hologram appeared first on Raspberry Pi.

Make our light-up Raspberry Pi box for #MonthOfMaking

Post Syndicated from Alex Bate original https://www.raspberrypi.org/blog/light-raspberry-pi-box-monthofmaking/

On Tuesday, Rob at The MagPi magazine tweeted this:

The MagPi magazine on Twitter

Hey @Raspberry_Pi, wanna join us in making some stuff for #MonthOfMaking? Rob has some cosplay to do this week and other plans for the rest of the month…

And we said YES!

At this point in time, Alex was hiding in the Raspberry Pi Foundation makerspace, creating thingamabobs and whatsit with the laser cutter, and an idea came into her mind.

(Is it weird that I’m referring to myself in the third person? It is. I’ll stop.)

The idea started with this:

Raspberry Pi laser cut box #MonthOfMaking

Oddly satisfying, right?

And ended like this:

Raspberry Pi laser cut box #MonthOfMaking

Raspberry Crepe Cake?

With a little bit of this in between:

Raspberry Pi laser cut box #MonthOfMaking

For hiding treasures

And thanks to some cheap battery-powered lights and magnets from Poundland…

#MonthOfMaking

Whosits and whatsits galore

…it lights up too!

Raspberry Pi laser cut box #MonthOfMaking

Photograph taken inside my rucksack for ambience

Make your own

So, do you want to make your own? Of course you do.

Ideally, you need access to a laser cutter, but if you don’t have one, you can just cut out the layers from some thick cardboard using a craft knife.

You’ll need these four files:

Raspberry Pi laser cut box
Raspberry Pi laser cut box
Raspberry Pi laser cut box
Raspberry Pi laser cut box

These are slightly different to the ones I used, so the acrylic should press-fit without the need for the backing frame you see in the image above.

Feel free to resize the files and change the box design to better fit whatever you want to put inside, but remember: making these boxes to sell, or diverging from our brand guidelines when using the Raspberry Pi logo, is against our trademark rules.

#MonthOfMaking

Join Raspberry Pi and The MagPi magazine in the #MonthOfMaking by using the hashtag in your social posts sharing your makes online. And, just as you can see from my light-up box, your make doesn’t have to use any digital technology. Bake a cake, stitch loop art, restore a car — whatever you plan on making this month, make sure we see your creation! Have fun!

The post Make our light-up Raspberry Pi box for #MonthOfMaking appeared first on Raspberry Pi.

What we are learning about learning

Post Syndicated from Oliver Quinlan original https://www.raspberrypi.org/blog/what-we-are-learning-about-learning/

Across Code Clubs, CoderDojos, Raspberry Jams, and all our other education programmes, we’re working with hundreds of thousands of young people. They are all making different projects and learning different things while they are making. The research team at the Raspberry Pi Foundation does lots of work to help us understand what exactly these young people learn, and how the adults and peers who mentor them share their skills with them.

Coolest Projects International 2018

Senior Research Manager Oliver Quinlan chats to participants at Coolest Projects 2018

We do our research work by:

  • Visiting clubs, Dojos, and events, seeing how they run, and talking to the adults and young people involved
  • Running surveys to get feedback on how people are helping young people learn
  • Testing new approaches and resources with groups of clubs and Dojos to try different ways which might help to engage more young people or help them learn more effectively

Over the last few months, we’ve been running lots of research projects and gained some fascinating insights into how young people are engaging with digital making. As well as using these findings to shape our education work, we also publish what we find, for free, over on our research page.

How do children tackle digital making projects?

We found that making ambitious digital projects is a careful balance between ideas, technology, and skills. Using this new understanding, we will help children and the adults that support them plan a process for exploring open-ended projects.

Coolest Projects USA 2018

Coolest Projects USA 2018

For this piece of research, we interviewed children and young people at last year’s Coolest Projects International and Coolest Projects UK , asking questions about the kinds of projects they made and how they created them. We found that the challenge they face is finding a balance between three things: the ideas and problems they want to address, the technologies they have access to, and their skills. Different children approached their projects in different ways, some starting with the technology they had access to, others starting with an idea or with a problem they wanted to solve.

Achieving big ambitions with the technology you have to hand while also learning the skills you need can be tricky. We’re planning to develop more resources to help young people with this.

Coolest Projects International 2018

Research Assistant Lucia Florianova learns about Rebel Girls at Coolest Projects International 2018

We also found out a lot about the power of seeing other children’s projects, what children learn, and the confidence they develop in presenting their projects at these events. Alongside our analysis, we’ve put together some case studies of the teams we interviewed, so people can read in-depth about their projects and the stories of how they created them.

Who comes to Code Club?

In another research project, we found that Code Clubs in schools are often diverse and cater well for the communities the schools serve; Code Club is not an exclusive club, but something for everyone.

Code Club Athens

Code Clubs are run by volunteers in all sorts of schools, libraries, and other venues across the world; we know a lot about the spaces the clubs take place in and the volunteers who run them, but less about the children who choose to take part. We’ve started to explore this through structured visits to clubs in a sample of schools across the West Midlands in England, interviewing teachers about the groups of children in their club. We knew Code Clubs were reaching schools that cater for a whole range of communities, and the evidence of this project suggests that the children who attend the Code Club in those schools come from a range of backgrounds themselves.

Scouts Raspberry Pi

Photo c/o Dave Bird — thanks, Dave!

We found that in these primary schools, children were motivated to join Code Club more because the club is fun rather than because the children see themselves as people who are programmers. This is partly because adults set up Code Clubs with an emphasis on fun: although children are learning, they are not perceiving Code Club as an academic activity linked with school work. Our project also showed us how Code Clubs fit in with the other after-school clubs in schools, and that children often choose Code Club as part of a menu of after-school clubs.

Raspberry Jam

Visitors to Pi Towers Raspberry Jam get hands-on with coding

In the last few months we’ve also published insights into how Raspberry Pi Certified Educators are using their training in schools, and into how schools are using Raspberry Pi computers. You can find our reports on all of these topics over at our research page.

Thanks to all the volunteers, educators, and young people who are finding time to help us with their research. If you’re involved in any of our education programmes and want to take part in a research project, or if you are doing your own research into computing education and want to start a conversation, then reach out to us via [email protected].

The post What we are learning about learning appeared first on Raspberry Pi.

GPIO Zero v1.5 is here!

Post Syndicated from Ben Nuttall original https://www.raspberrypi.org/blog/gpio-zero-v1-5/

GPIO Zero is a zero-boilerplate Python library that makes physical computing with Python more accessible and helps people progress from zero to hero.

Today, I’m pleased to announce the release of GPIO Zero v1.5.0. It’s packed full of updates, including new features, bug fixes, and lots of improvements to the documentation.

Guido, the creator of Python, happened across the library recently, and he seemed to like it:

Guido van Rossum on Twitter

GPIOzero I love you! https://t.co/w3CnUGx3yO

Pin factories – take your pick

GPIO Zero started out as a friendly API on top of the RPi.GPIO library, but later we extended it to allow other pin libraries to be used. The pigpio library is supported, and that includes the ability to remotely control GPIO pins over the network, or on a Pi Zero over USB.

This also gave us the opportunity to create a “mock” pin factory, so that we could emulate the effect of pin changes without using real Raspberry Pi hardware. This is useful for prototyping without hardware, and for testing. Try it yourself!

As well as the pin factories we provide with the library (RPi.GPIO, pigpio, RPIO, and native), it’s also possible to write your own. So far, I’m aware of only one custom pin factory, and that has been written by the AIY team at Google, who created their own pin factory for the pins on the AIY Vision Kit. This means that you can connect devices to these pins, and use GPIO Zero to program them, despite the fact they’re not connected to the Pi’s own pins.

If you have lots of experience with RPi.GPIO, you might find this guide on migrating from RPi.GPIO to GPIO Zero handy.

Ultrasonic distance sensor

We had identified some issues with the results from the DistanceSensor class, and we dealt with them in two ways. Firstly, GPIO Zero co-author Dave Jones did some work under the hood of the pins API to use timing information provided by underlying drivers, so that timing events from pins will be considerably more accurate (see #655). Secondly, Dave found that RPi.GPIO would often miss edges during callbacks, which threw off the timing, so we now drop missed edges and get better accuracy as a result (see #719).

The best DistanceSensor results come when using pigpio as your pin factory, so we recommend changing to this if you want more accuracy, especially if you’re using (or deploying to) a Pi 1 or Pi Zero.

Connecting devices

A really neat feature of GPIO Zero is the ability to connect devices together easily. One way to do this is to use callback functions:

button.when_pressed = led.on
button.when_released = led.off

Another way is to set the source of one device to the values of another device:

led.source = button.values

In GPIO Zero v1.5, we’ve made connecting devices even easier. You can now use the following method to pair devices together:

led.source = button

Read more about this declarative style of programming in the source/values page in the docs. There are plenty of great examples of how you can create projects with these simple connections:

Testing

An important part of software development is automated testing. You write tests to check your code does what you want it to do, especially checking the edge cases. Then you write the code to implement the features you’ve written tests for. Then after every change you make, you run your old tests to make sure nothing got broken. We have tools for automating this (thanks pytest, tox, coverage, and Travis CI).

But how do you test a GPIO library? Well, most of the GPIO parts of our test suite use the mock pins interface, so we can test our API works as intended, abstracted from how the pins behave. And while Travis CI only runs tests with mock pins, we also do real testing on Raspberry Pi: there are additional tests that ensure the pins do what they’re supposed to. See the docs chapter on development to learn more about this process, and try it for yourself.

pinout

You may remember that the last major GPIO Zero release introduced the pinout command line tool. We’ve added some new art for the Pi 3A+ and 3B+:

pinout also now supports the -x (or --xyz) option, which opens the website pinout.xyz in your web browser.

Zero boilerplate for hardware

The goal of all this is to remove obstacles to physical computing, and Rachel Rayns has designed a wonderful board that makes a great companion to GPIO Zero for people who are learning. Available from The Pi Hut, the PLAY board provides croc-clip connectors for four GPIO pins, GND, and 3V3, along with a set of compatible components:

Since the board simply breaks out GPIO pins, there’s no special software required. You can use Scratch or Python (or anything else).

New contributors

This release welcomed seven new contributors to the project, including Claire Pollard from PiBorg and ModMyPi, who provided implementations for TonalBuzzer, PumpkinPi, and the JamHat. We also passed 1000 commits!

Watch your tone

As part of the work Claire did to add support for the Jam HAT, she created a new class for working with its buzzer, which works by setting the PWM frequency to emit a particular tone. I took what Claire provided and added some maths to it, then Dave created a whole Tones module to provide a musical API. You can play buzzy jingles, or you can build a theremin:

GPIO Zero theremin

from gpiozero import TonalBuzzer, DistanceSensor buzzer = TonalBuzzer(20) ds = DistanceSensor(14, 26) buzzer.source = ds

…or you can make a siren:

GPIO Zero TonalBuzzer sine wave

from gpiozero import TonalBuzzer from gpiozero.tools import sin_values buzzer = TonalBuzzer(20) buzzer.source = sin_values()

The Tones API is a really neat way of creating particular buzzer sounds and chaining them together to make tunes, using a variety of musical notations:

>>> from gpiozero.tones import Tone
>>> Tone(440.0)
>>> Tone(69)
>>> Tone('A4')

We all make mistakes

One of the important things about writing a library to help beginners is knowing when to expect mistakes, and providing help when you can. For example, if a user mistypes an attribute or just gets it wrong – for example, if they type button.pressed = foo instead of button.when_pressed = foo – they wouldn’t usually get an error; it would just set a new attribute. In GPIO Zero, though, we prevent new attributes from being created, so you’d get an error if you tried doing this. We provide an FAQ about this, and explain how to get around it if you really need to.

Similarly, it’s common to see people type button.when_pressed = foo() and actually call the function, which isn’t correct, and will usually have the effect of unsetting the callback (as the function returns None). Because this is valid, the user won’t get an error to call their attention to the mistake.

In this release, we’ve added a warning that you’ll see if you set a callback to None when it was previously None. Hopefully that will be useful to people who make this mistake, helping them quickly notice and rectify it.

Update now

Update your Raspberry Pi now to get the latest and greatest GPIO Zero goodness in your (operating) system:

sudo apt update
sudo apt install python3-gpiozero python-gpiozero

Note: it’s currently syncing with the Raspbian repo, so if it’s not available for you yet, it will be soon.

What’s next?

We have plenty more suggestions to be working on. This year we’ll be working on SPI and I2C interfaces, including I2C expander chips. If you’d like to make more suggestions, or contribute yourself, find us over on GitHub.

The post GPIO Zero v1.5 is here! appeared first on Raspberry Pi.