Sense HAT Emulator Upgrade

Last year, we partnered with Trinket to develop a web-based emulator for the Sense HAT, the multipurpose add-on board for the Raspberry Pi. Today, we are proud to announce an exciting new upgrade to the emulator. We hope this will make it even easier for you to design amazing experiments with the Sense HAT!

What’s new?

The original release of the emulator didn’t fully support all of the Sense HAT features. Specifically, the movement sensors were not emulated. Thanks to funding from the UK Space Agency, we are delighted to announce that a new round of development has just been completed. From today, the movement sensors are fully supported. The emulator also comes with a shiny new 3D interface, Astro Pi skin mode, and Pygame event handling. Click the ▶︎ button below to see what’s new!

Upgraded sensors

On a physical Sense HAT, real sensors react to changes in environmental conditions like fluctuations in temperature or humidity. The emulator has sliders which are designed to simulate this. However, emulating the movement sensor is a bit more complicated. The upgrade introduces a 3D slider, which is essentially a model of the Sense HAT that you can move with your mouse. Moving the model affects the readings provided by the accelerometer, gyroscope, and magnetometer sensors.

Code written in this emulator is directly portable to a physical Raspberry Pi and Sense HAT without modification. This means you can now develop and test programs using the movement sensors from any internet-connected computer, anywhere in the world.

Astro Pi mode

Astro Pi is our series of competitions offering students the chance to have their code run in space! The code is run on two space-hardened Raspberry Pi units, with attached Sense HATs, on the International Space Station.

Image of Astro Pi unit Sense HAT emulator upgrade

Astro Pi skin mode

There are a number of practical things that can catch you out when you are porting your Sense HAT code to an Astro Pi unit, though, such as the orientation of the screen and joystick. Just as having a 3D-printed Astro Pi case enables you to discover and overcome these, so does the Astro Pi skin mode in this emulator. In the bottom right-hand panel, there is an Astro Pi button which enables the mode: click it again to go back to the Sense HAT.

The joystick and push buttons are operated by pressing your keyboard keys: use the cursor keys and Enter for the joystick, and U, D, L, R, A, and B for the buttons.

Sense Hat resources for Code Clubs

Image of gallery of Code Club Sense HAT projects Sense HAT emulator upgrade

Click the image to visit the Code Club projects page

We also have a new range of Code Club resources which are based on the emulator. Of these, three use the environmental sensors and two use the movement sensors. The resources are an ideal way for any Code Club to get into physical computing.

The technology

The 3D models in the emulator are represented entirely with HTML and CSS. “This project pushed the Trinket team, and the 3D web, to its limit,” says Elliott Hauser, CEO of Trinket. “Our first step was to test whether pure 3D HTML/CSS was feasible, using Julian Garnier’s Tridiv.”

Sense HAT 3D image mockup Sense HAT emulator upgrade

The Trinket team’s preliminary 3D model of the Sense HAT

“We added JavaScript rotation logic and the proof of concept worked!” Elliot continues. “Countless iterations, SVG textures, and pixel-pushing tweaks later, the finished emulator is far more than the sum of its parts.”

Sense HAT emulator 3d image final version Sense HAT emulator upgrade

The finished Sense HAT model: doesn’t it look amazing?

Check out this blog post from Trinket for more on the technology and mathematics behind the models.

One of the compromises we’ve had to make is browser support. Unfortunately, browsers like Firefox and Microsoft Edge don’t fully support this technology yet. Instead, we recommend that you use Chrome, Safari, or Opera to access the emulator.

Where do I start?

If you’re new to the Sense HAT, you can simply copy and paste many of the code examples from our educational resources, like this one. Alternatively, you can check out our Sense HAT Essentials e-book. For a complete list of all the functions you can use, have a look at the Sense HAT API reference here.

8 comments

Peter avatar

Hii, at first great work. It’s super handy tool for experimenting with sensor data.
After testing a little bit I noticed some problems. I was trying to get gyroscope raw data which. But I couldn’t notice a significant changing in the values by turning the hat, only noise. Accelerometer works fine apparently.

Besides the function set_imu_config() seems not to work properly since I still get raw values.

I’m using Chrome 57.0.2987.133 (64-bit) and my code looks like this:
from sense_hat import SenseHat
from time import sleep

sense = SenseHat()
sense.set_imu_config(False, True, False)

while(True):
gyro_raw = sense.get_gyroscope_raw()
print(“x: {x}, y: {y}, z: {z}”.format(**gyro_raw))
sleep(1)

Kind regards
Peter

David Honess avatar

Yes, I think you’re right. The gyroscope should show angular momentum while the model is being turned, so if it’s always showing simulated noise then it’s not the correct behaviour. I’ve raised this as an issue here so we can track it. Thanks for letting us know.

David Honess avatar

We have a fix for this now, should be deployed to production by the end of today.

Frans Stoffel avatar

Sense Hat is a nice extension of my Pi Zero’s.
Born long for the invasion of home comuters in a time that you need a heavy power supply for a computer it is nice playing with such small computers. One Pi Zero W has a mediawiki website, another Pi Zero has a Kodi OpenElec media player. Another Pi Zero has a Lighttpd webserver and the last Pi Zero has an Sense Hat. I have started with Pi’s when the Pi 3B+ has born! After the P3 B+ came the wonderfull Pi Zero’s

With my granddaughter of 8 year its possible to build up a story of two Kobold figures named Olvin and Alvin. A lighttpd webser on the Pi Zero is used. On the android phone of my daughter my granddaughter types in the next adventure of our story. Then its my turn on this story.

Thanks for the posibility of buying a Pi.

bsimmo avatar

Shame it’s not on EDGE as that is what our school use,
I’ve submitted a bug to the Feedback Hub with Microsoft

Vote and/or add information if you can
https://aka.ms/F8nbni (link to Feedback hub report etc.)

David Honess avatar

Thanks for letting us know. You should still be able to use the emulator on Microsoft Edge but with a fall back 3D mode where you just have a flat object that you can move. I’ve noticed a problem with the emulator home page which I’m tracking here, but if you go directly to a shared trinket URL then it should work. Try this one for example.

David Honess avatar

A fix for this has been deployed.

knick avatar

I have an issue. Sense hat LED is light when the OS booting. But when the booted the LED is not off. Normal the LED is off when the booted. Please help check the issue whether board issue or software issue. Thanks!

Comments are closed