Set up Sense HAT inputs in Scratch 3
Linux Format|September 2021
Les Pounder shows how to obtain data and control sprites using the Sense HAT add-on board with Scratch 3.
Les Pounder

YOU NEED

  • Raspberry Pi 3B+ or better

  • Sense HAT

  • Latest Raspbian release

  • Code: https:// github.com/ lesp/ LXF280Sense-Bats/ archive/ refs/heads/ main.zip

This month we’ll use the scientific powerhouse Sense HAT board with Scratch 3 to create four quick projects to demonstrate the power of Scratch 3 and the Sense HAT.

The Sense HAT is a remarkable board. Released in 2015, it works with Python, Node-RED and for this tutorial it works with Scratch 3 thanks to a special palette of blocks that enable anyone to use the sensors, display and joystick with very little coding knowledge.

With the power off, connect the Sense HAT to all 40 pins of the GPIO, ensuring that the board fits neatly over the Pi. Use the brass standoff, provided with the Sense HAT to fix the board firmly in place. Connect your peripherals and then power up the Raspberry Pi to the desktop.

Scratch 3 should come pre-installed on your Raspberry Pi OS image, but just in case it’s missing it can be installed from the main menu, under Preferences>Recommended Software. Scratch 3 is found in the Programming category: place a tick in the box and click Apply to install. Once installed, Scratch 3 can be found in the main menu under Programming.

Open Scratch 3 (on first start Scratch may take a little while to open). We’re going to assume that you have an understanding of how to code with Scratch, but if not we covered the basics in previous issues. Before we write any new code we need to click the blue folder icon in the bottom left of the screen to load the Extensions menu. From there select Raspberry Pi Sense HAT and a palette of new blocks are added to our code.

Project 1: Spin me right round

The Sense HAT has a sensor that can detect our orientation using an accelerometer. This sensor can measure our pitch, yaw and roll, in other words if we pick up the Raspberry Pi and tilt it backwards, forwards, left or right it can measure the orientation. We’re going to use the pitch value to spin a sprite. Click the New Sprite icon (blue cat icon in the bottom right) and select the Bat. Then delete the Cat icon using the trashcan icon next to it. From Events, drag When Green Flag Clicked into the coding area.

Continue reading your story on the app

Continue reading your story in the magazine

MORE STORIES FROM LINUX FORMATView All

Improve Your Shots Using Optical Filters

Mike Bedford looks at the benefits of photographic filters and how to emulate them – but some effects can only be achieved optically.

10+ mins read
Linux Format
November 2021

Create efficient backups

Backups aren’t just a safety net for Trekkies such as Shashank Sharma, but a way of life. But they can take up quite a lot of space if not done right…

6 mins read
Linux Format
November 2021

Build your own custom Ubuntu distro

Why settle for what the existing distributions have to offer? Michael Reed looks at Cubic, a tool for creating your own custom respin based on Ubuntu.

10+ mins read
Linux Format
November 2021

Controlling the Pi's GPIO with Scratch

Les Pounder shows how we can use Scratch with simple electronics.

7 mins read
Linux Format
November 2021

American Truck Simulator

Management is firm: no new pay rises. So they’re terrified that Andy Kelly is planning to retrain as a highly paid truck driver.

5 mins read
Linux Format
November 2021

LINUX WINDOWS

Old rivalries have been forgotten and ancient boundaries blurred. Jonni Bidwell investigates this new Redmond-Penguin harmony.

10+ mins read
Linux Format
November 2021

Network-share files quickly and easily

Nick Peers reveals how to share files over your local network without getting bogged down in networking protocols.

7 mins read
Linux Format
November 2021

Asus Tinker Board 2S

This is the little board that couldn’t, says a disappointed Les Pounder as he tries a board that’s definitely no Raspberry Pi.

3 mins read
Linux Format
November 2021

Pinhole photography with the HQ Camera

Interchangeable lenses enable us to experiment with that historical curiosity, the pinhole camera, Mike Bedford shows you how.

10+ mins read
Linux Format
October 2021

Linux Mint 20.2

Jonni Bidwell is running low on mint metaphors and time, but the promise of some budget mojito mix expedited this review.

6 mins read
Linux Format
October 2021
RELATED STORIES

MacBooks

The most powerful Pro lineup ever created

8 mins read
AppleMagazine
October 22, 2021

CHINA CRACKDOWN ON APPLE STORE HITS HOLY BOOK APPS, AUDIBLE

Amazon’s audiobook service Audible and phone apps for reading the holy books of Islam and Christianity have disappeared from the Apple store in mainland China, the latest examples of the impact of the country’s tightened rules for internet firms.

3 mins read
AppleMagazine
October 22, 2021

Camera Set

The iPhone 13’s leaps forward for photo & video

6 mins read
AppleMagazine
AppleMagazine #520

Down to Their Last Dollar

Businesses fail every day, from world-beaters (like TWA and Lehman Brothers) to sexy high-fliers (DeLorean, Enron) to Steady Eddie, old-school icons (Toys “R” Us, Sears). Sometimes, of course, market conditions simply turn Sisyphean. But often, when that boulder starts to roll backward, a leader’s grit, imagination, resourcefulness, and ability to conjure a little luck can mean the difference between a brave new chapter and, well, Chapter 11. Here, four businesses that went from nearly bust to total gangbusters.

3 mins read
Inc.
October 2021

SPATIAL AUDIO RELATIONS

Ears-on with Apple Music’s new Atmos offerings

10+ mins read
Sound & Vision
October - November 2021

Logitech Ergo K860

This ergonomic “split” keyboard helps reduce wrist–strain

2 mins read
Mac Life
November 2021

Vissles V84 (2.0) Mechanical Keyboard

A Mac–friendly typing experience — and then some

2 mins read
Mac Life
November 2021

Steve Jobs

10 years without the genius behind apple

7 mins read
AppleMagazine
Ocotber 08, 2021

iPad mini- Packing its punch in the palm of your hand

Although all eyes were on the Apple Watch Series 7 and iPhone 13 range at this year’s California Streaming event, the unexpected announcement of a refreshed iPad mini also got people talking. Bringing Apple’s smallest tablet in line with the iPad Pro and Air has helped to give consumers more choice, whilst a refreshed entry-level iPad remains a sensible buy.

7 mins read
AppleMagazine
October 01, 2021

Steve Jobs and the GTN

Why the ubiquitous works

5 mins read
Flying
October 2021