Raspberry Pi Blog

This is the official Raspberry Pi blog for news and updates from the Raspberry Pi Foundation, education initiatives, community projects and more!

Build your own Raspberry Pi night vision camera

A Raspberry Pi Zero W, Pimoroni HyperPixel screen, and Raspberry Pi IR Camera Module are all you need to build this homemade night vision camera.

How to build a night vision camera

How to build a night vision camera, video showing the process and problems that I came across when building this camera

Raspberry Pi night vison camera

Built into the body of an old camera flash, Dan’s Raspberry Pi night vision camera is a homage to a childhood spent sneaking around the levels of Splinter Cell. Says Dan:

The iconic image from the game is the night vision goggles that Sam Fisher wears. I have always been fascinated by the idea that you can see in the dark and this formed the foundation of my idea to build a portable hand-held night vision piece of equipment.

The camera, running on Raspbian, boasts several handy functions, including touchscreen controls courtesy of the Pimoroni HyperPixel, realtime video and image capture, and a viewing distance of two to five metres.

It’s okay to FAIL

Embracing the FAIL (First Attempt In Learning) principle, Dan goes into detail about the issues he had to overcome while building the camera, which is another reason why we really enjoyed this project. It’s okay to fail when trying your hand at digital making, because you learn from your mistakes! Dan’s explanations of the struggles he faced and how he overcame them are 👌.

For a full rundown of the project and tips on building your own, check out its Hackster.io page.

4 Comments

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 at least 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.

23 Comments

Code your own 2D shooting gallery in Python | Wireframe issue 20

Raspberry Pi’s own Rik Cross shows you how to hit enemies with your mouse pointer as they move around the screen.

Duck Hunt made effective use of the NES Zapper, and made a star of its sniggering dog, who’d pop up to heckle you between stages.

Clicky Clicky Bang Bang

Shooting galleries have always been a part of gaming, from the Seeburg Ray-O-Lite in the 1930s to the light gun video games of the past 40 years. Nintendo’s Duck Hunt — played with the NES Zapper — was a popular console shooting game in the early eighties, while titles such as Time Crisis and The House of the Dead kept the genre alive in the 1990s and 2000s.

Here, I’ll show you how to use a mouse to fire bullets at moving targets. Code written to instead make use of a light gun and a CRT TV (as with Duck Hunt) would look very different. In these games, pressing the light gun’s trigger would cause the entire screen to go black and an enemy sprite to become bright white. A light sensor at the end of the gun would then check whether the gun is pointed at the white sprite, and if so, would register a hit. If more than one enemy was on the screen when the trigger was pressed, each enemy would flash white for one frame in turn, so that the gun would know which enemy had been hit.

Our simple shooting gallery in Python. You could try adding randomly spawning ducks, a scoreboard, and more.

Pygame Zero

I’ve used two Pygame Zero event hooks for dealing with mouse input. Firstly, the on_mouse_move() function updates the position of the crosshair sprite whenever the mouse is moved. The on_mouse_down() function reacts to mouse button presses, with the left button being pressed to fire a bullet (if numberofbullets > 0) and the right button to reload (setting numberofbullets to MAXBULLETS).

Each time a bullet is fired, a check is made to see whether any enemy sprites are colliding with the crosshair — a collision means that an enemy has been hit. Luckily, Pygame Zero has a colliderect() function to tell us whether the rectangular boundary around two sprites intersects.

If this helper function wasn’t available, we’d instead need to use sprites’ x and y coordinates, along with width and height data (w and h below) to check whether the two sprites intersect both horizontally and vertically. This is achieved by coding the following algorithm:

  • Is the left-hand edge of sprite 1 further left than the right-hand edge of sprite 2 (x1 < x2+w2)?
  • Is the right-hand edge of sprite 1 further right than the left-hand edge of sprite 2 (x1+w1 > x2)?
  • Is the top edge of sprite 1 higher up than the bottom edge of sprite 2 (y1 < y2+h2)?
  • Is the bottom edge of sprite 1 lower down than the top edge of sprite 2 (y1+h1 > y2)?

If the answer to the four questions above is True, then the two sprites intersect (see Figure 1). To give visual feedback, hit enemies briefly remain on the screen (in this case, 50 frames). This is achieved by setting a hit variable to True, and then decrementing a timer once this variable has been set. The enemy’s deleted when the timer reaches 0.

Figure 1: A visual representation of a collision algorithm, which checks whether two sprites intersect.

As well as showing an enemy for a short time after being hit, successful shots are also shown. A problem that needs to be overcome is how to modify an enemy sprite to show bullet holes. A hits list for each enemy stores bullet sprites, which are then drawn over enemy sprites.

Storing hits against an enemy allows us to easily stop drawing these hits once the enemy is removed. In the example code, an enemy stops moving once it has been hit.

If you don’t want this behaviour, then you’ll also need to update the position of the bullets in an enemy’s hits list to match the enemy movement pattern.

When decrementing the number of bullets, the max() function is used to ensure that the bullet count never falls below 0. The max() function returns the highest of the numbers passed to it, and as the maximum of 0 and any negative number is 0, the number of bullets always stays within range.

There are a couple of ways in which the example code could be improved. Currently, a hit is registered when the crosshair intersects with an enemy — even if they are barely touching. This means that often part of the bullet is drawn outside of the enemy sprite boundary. This could be solved by creating a clipping mask around an enemy before drawing a bullet. More visual feedback could also be given by drawing missed shots, stored in a separate list.

Here’s Rik’s code, which lets you hit enemies with your mouse pointer. To get it running on your system, you’ll first need to install Pygame Zero. And to download the full code, go here.

Get your copy of Wireframe issue 20

You can read more features like this one in Wireframe issue 20, available now at Tesco, WHSmith, and all good independent UK newsagents.

Or you can buy Wireframe directly from Raspberry Pi Press — delivery is available worldwide. And if you’d like a handy digital version of the magazine, you can also download issue 20 for free in PDF format.

Make sure to follow Wireframe on Twitter and Facebook for updates and exclusive offers and giveaways. Subscribe on the Wireframe website to save up to 49% compared to newsstand pricing!

1 Comment

10,000 sticker pack giveaway

UPDATE: all 10,000 sticker packs have now been claimed. We honestly didn’t think these would go so quickly. If you’re in a different time zone to us and reading this later during your day, we’re sorry you missed out. We’ll see whether we can run another giveaway in the future at a time that’s better suited for community members in other time zones.

Would you like a Raspberry Pi sticker pack? We’re giving away a whopping 10,000 sticker packs to the first 10,000 people who fill in the form at the bottom of this post.

But before you do that, please read the following guidelines.

Giveaway guidelines

Please:

  • Only fill in the form once, to give as many people as possible the chance to get their hands on a sticker pack. We will ignore duplicate entries.
  • Fill in all the boxes, otherwise we may not be able to get your sticker pack to you.
  • Include your email address so we can follow up with you if we encounter issues with postage. We won’t use your email address for any other reason.
  • Include a postal address you will have access to for at least the next two months, since it may take up to two months for the sticker pack to reach you.
  • All entries must be submitted by 1 September 2019.

We’ll only use your details for this giveaway. All data you enter into the form will be permanently deleted after two months.

It may take until 15 October for your sticker pack to reach you. Please do not contact us before that date to enquire about your stickers.

102 Comments

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?

No Comments

Real-time train station departure board

All across the UK, you’ll find train departure boards on station platforms that look like this:

They’ve looked this way for as long as I can remember (before they were digital dot-matrix displays, they were made from those flappy bits of plastic with letters of the alphabet and numbers printed on them, which whirled round like a Rolodex; they still look very similar). If you’re a frequent train traveller in the UK, you probably have a weird emotional response to seeing one of these. Mine is largely one of panic about being late.

Some people have a more…benign relationship with trains than I do, like Chris Crocker-White, who has adapted a build tweeted by Chris Hutchinson to make a miniature departure board for his desk. Here’s the tweet that started it all:

Chris Hutchinson on Twitter

Pretty hyped about my most recent @Raspberry_Pi project – a realistic, real-time, train departure board I’ve open sourced the software over at: https://t.co/vGQzagsSpi Next step: find a case and make it a permanent fixture! https://t.co/HEXgzdH8TS

Chris C-W’s build is similar, but has a couple of very neat upgrades, including some back-end software work (his build runs in Docker on balenaCloud, to make configuration easier), and some work on the display, which he’s tweaked to use 1:1 pixel mapping of the fonts and avoid any scaling, so the tiny board looks more like the dot-matrix LED displays you’ll see when you visit the station. You can see the difference in the image below:

 

Chris seems to be using his board as a piece of desktop furniture, where it looks terrific, but model train or narrow-gauge enthusiasts should be all over this project too; it’s a lovely way to inject some realism into a miniature setup. You can find a very complete guide to making your own here.

Now, if you’ll excuse me, I have a train to catch.

 

 

5 Comments

Use PlayStation Buzz! controllers with a Raspberry Pi

Buzz! was a favourite amongst my university housemates and me. With popular culture questions asked by an animated Jason Donovan, answered using real-life quiz controllers with a big red button, what’s not to like?

But, as with most of the tech available in the early 2000s, my Buzz! controllers now sit in a box somewhere, dusty and forgotten.

That’s why it is so goshdarn delightful to see PiMyLifeUp breathe new life into these awesome-looking games controllers.

Bringing Buzz! back

The tutorial uses the hidapi library to communicate with the controllers, allowing them to control functions through the Raspberry Pi, and the Raspberry Pi to control the LED within the big red button.

By the end of this tutorial, you will have learned how to read information about all your USB devices, learned how to read data that the devices are sending back and also how to write a library that will act as a simple wrapper to dealing with the device.

Aside from the Buzz! controllers, available on eBay or similar for a few pounds, you only need a Raspberry Pi and its essential peripherals to get started, as the controllers connect directly via USB — thanks, Buzz!

PiMyLifeUp’s tutorial is wonderfully detailed, explaining the hows and whys of the lines of code needed to turn your old Buzz! controllers into a quiz game written in Python that uses the coloured buttons to answer multiple-choice questions.

Guitar Hero, dance mats, Donkey Kong Bongos — what other gaming peripherals would you like to bring back to life?

2 Comments

We asked our engineers your Raspberry Pi 4 questions…

We collected some of the most common Raspberry Pi 4 questions asked by you, our community, and sat down with Eben Upton, James Adams, and Gordon Hollingworth to get some answers.

Raspberry Pi 4 Q&A

We grilled our engineers with your Raspberry Pi 4 questions 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?

Do you have more questions about our new board or accessories? Leave them in the comments of our YouTube video, or in the comments below, and we’ll collect some of the most commonly asked questions together for another Q&A session further down the line.

39 Comments

Pulling shower thoughts from Reddit for a Raspberry Pi e-paper display

The Reddit users among you may already be aware of the Shower Thoughts subreddit. For those of you who aren’t, Shower Thoughts is where people go to post the random epiphanies they’ve had about life, the universe, and everything. For example:

YouTuber ACROBOTIC is a fan of the Shower Thoughts subreddit. So much so that they decided to program their Raspberry Pi to update an e-paper HAT with the subreddit’s top posts from the last hour.

Raspberry Pi 4 Scrape JSON Data w/ Python And Display It On e-Paper | reddit /r/showerthoughts

$2 for PCB prototype (any color): https://jlcpcb.com/ ========== * Your support helps me post videos more frequently: https://www.patreon.com/acrobotic https://www.paypal.me/acrobotic https://buymeacoff.ee/acrobotic BTC: 1ZpLvgETofMuzCaKoq5XJZKSwe5UNkwLM ========== * Find me on: https://twitter.com/acrobotic https://facebook.com/acrobotic https://instagram.com/acrobotic ========== * Parts & supplies: https://acrobotic.com/shop https://amazon.com/shops/acrobotic ========== In another video we setup a Raspberry Pi to control an e-Paper/e-Ink HAT and running demo code.

For their build, they used a three-colour e-paper display, but you can use any e-paper add-on for Raspberry Pi to recreate the project. They also used Raspberry Pi 4, but again, this project will work with other models — even Raspberry Pi Zero W.

ACROBOTIC created an image to frame the Shower Thoughts posts, which they uploaded to their Raspberry Pi as a .bmp file. They altered prewritten code for using the e-paper display to display this frame image and the various posts.

Adding .json to the URL of the appropriate Shower Thoughts page allows access to the posts in JSON format. Then a request can be set up to pull the data from this URL.

ACROBOTIC goes into far more detail in their video, and it’s a great resource if you’re looking to try out working with JSON files or to learn how to pull data from Reddit.

Find more projects using e-paper displays for you to recreate in our handy guide.

5 Comments

Raspberry Pi Sense HAT impact recorder for your car

Let the accelerometer and gyroscope of your Raspberry Pi Sense HAT measure and record impact sustained in a car collision.

Raspberry Pi Sense HAT

The Raspberry Pi Sense HAT was originally designed for the European Astro Pi Challenge, inviting schoolchildren to code their own experiments for two Raspberry Pi units currently orbiting the Earth upon the International Space Station.

The Sense HAT is kitted out with an 8×8 RGB LED matrix and a five-button joystick, and it houses an array of useful sensors, including an accelerometer and gyroscope.

And it’s these two sensors that Instructables user Ashu_d has used for their Impact Recorder for Vehicles.

Impact Recorder for Vehicles

“Impact Recorder is designed to record impact sustained to a vehicle while driving or stationary,” Ashu_d explains. Alongside the Raspberry Pi and Sense HAT, the build also uses a Raspberry Pi Camera Module to record footage, saving video and/or picture files to the SD card for you to examine after a collision. “The impacts are stored in the database in the form of readings as well as video/picture.”

By following Ashu_d’s Instructables tutorial, you’re essentially building yourself a black box for your car, recording impact data as the Sense HAT records outside the standard parameters of your daily commute.

“Upon impact, remote users can be verified in real time,” they continue, “and remote users can then watch the saved video or take remote access to the Pi Camera Module and watch events accordingly.”

Ashu_d goes into great detail on how to use Node-RED and MQTT to complete the project, how you can view video in real time using VLC, and how each element works to create the final build over at Instructables.

1 Comment