Sense HAT emulator

Over the last few months, we’ve been working with US-based startup Trinket to develop a web-based emulator for the Sense HAT, the multipurpose add-on board for the Raspberry Pi which is also the core component of the Astro Pi units on the International Space Station. We wanted to provide a unique, free learning resource that brings the excitement of programming our space-qualified hardware to students, teachers, and others all over the world.

We’re delighted to announce its release today, and you can try it for yourself right now. Click the Run button below and see what happens!

trinket-logo

The emulator will allow more people to participate in future Astro Pi competitions – you’ll be able to join in without needing to own a Raspberry Pi computer or a Sense HAT.

British ESA Astronaut Tim Peake with an Astro Pi unit on the International Space Station

British ESA Astronaut Tim Peake with the Astro Pi. Image credit ESA

The new emulator builds on Trinket’s existing Python-in-browser platform, and provides the following features:

  • Virtual Sense HAT with environmental controls and joystick input
  • Full Python syntax highlighting
  • Contextual auto-complete
  • Intuitive error reporting and highlighting
  • Image upload
  • HTML page embedding
  • Social media integration
  • Project sharing via direct URL
  • Project download as zip (for moving to Raspberry Pi)
  • All major browsers supported

sense_hat_emu

The Sense HAT has temperature, pressure and humidity sensors, and can change its behaviour according to the values they report. The Sense HAT emulator has sliders you can move to change these values, so you can test how your code responds to environmental variables.

Part of a screenshot of the Astro Pi emulator, showing three silders with buttons that can be dragged to change the temperature, pressure and humidity that the virtual Sense HAT's sensors are reporting

You can move the sliders to change what the sensors are reporting

Code written in this emulator is directly portable to a physical Raspberry Pi with a Sense HAT without modification. This means any code you write can be run by the Astro Pi units on board the ISS! It is our hope that, within the next 12 months, code that has been written in the emulator will run in space. Look out for news on this, coming soon on the Astro Pi site!

We owe huge thanks to Trinket, who have been wonderful partners in this project. The development work has been completed in just over two months, and has been a huge collaborative effort from the start. The software relies heavily on open-source technology and a global community of developers who are committed to making the power of code more accessible to students.

A closed group of beta testers, made up of previous Astro Pi participants and Code Club champions, has been putting the emulator through its paces over recent weeks. We’re proud to say that we’ve just had a bug-free open beta over the weekend, and now we’re looking forward to seeing it used as widely as possible.

So, where do you start? If you’re new to the Sense HAT, you can just copy and paste a lot of the code examples from our educational resources like this one. You can also check out our e-book Sense HAT Essentials. For a complete list of all the functions you can use, have a look at the Sense HAT API reference here; please note that the IMU (movement-sensing) functions will be supported in a future update. Head over to the main Sense HAT emulator site to see loads of other cool examples of what’s possible. Flappy LED, anyone?

Don’t forget to share your projects!

19 comments

Alex Bate

Flappy LED is my life now.

Avatar

Elliot at Trinket told me his highest score is 150! The game gets faster every 20 columns :)

Avatar

Wow I only got to 84 and my eyes started blurring! This is cool that you can emulate the sense hat in the browser though. Has anyone seen if it runs okay in a browser on an rpi?

Avatar

Yes it will work however the JavaScript support in Epiphany is a bit poor so we had to disable the python syntax highlighting to make it work. It will just be a basic text box with line numbers.

Avatar

code please.

Avatar

Awesome++

One can now try a Pi before you buy.

Does this mean that, technically speaking, TrinketPi (to coin a name) is now cheaper than even the Pi Zero to “own” and use (assuming one already has access to a computer somewhere)?

Avatar

Hi Colin, well – it’s not a full Raspberry Pi which is being emulated here. It’s only really the Sense HAT itself. So I don’t think we could claim this :)

Avatar

nice, a “minimal” game writing system you can write online games for (and other stuff). And you can convert from “virtual” into real too. So you can show off what you made to others “offline”.

Hope a lot of stuff gets written for it, and added to the emulator site to try out!

Avatar

Awesome work, this is really neat and very useful! The Raspberry Pi ecosystem keeps getting better and better with so much cool toys on both hardware and software fronts lately.

But even more useful, by chance would anyone be able to get access to all the necessary files to host our own virtual Pi locally on …our real Pi? (is that a head spinner or what)

Avatar

I believe this is possible but we also have another version of this emulator, written in pure Python, which will fulfil what you need. Mainly intended for offline teaching environments which is how a lot of Pis are used.

Avatar

Hmmm. Not working for me on Windows 8.1 and Firefox 48.0. When I click the RUN icon, the whole browser locks up until I kill the process in Task Manager. Demo works OK in Internet Explorer on the same machine.

Avatar

Okay right, can you go here and raise an issue please?
https://github.com/astro-pi/beta-testing/issues

Avatar

Done! (I’ve also mentioned the fact that, although the emulator does run in IE11 on that laptop, the SenseHAT graphic is shrunken and shifted half-way under the top side of the embed window. I included a screen shot of that).

Avatar

With blocky I have made a some new blocks for the SenseHat.
Not only can I visually program, but now I can test out the Python program in one browser. A real treat

New SenseHat Blockly blocks
https://github.com/niceprogram/blocky_raspberry_pi_sensehat

Avatar

Would it run on a Raspberry Pi browser? My only computer is the Raspberry Pi and I do not own the Sense HAT.

Avatar

Yes it will work however the JavaScript support in Epiphany is a bit poor so we had to disable the python syntax highlighting to make it work. So you just get a basic text box with line numbers.

Avatar

Pretty cool!!

Avatar

What is the price?

Avatar

bonjour

Leave a Comment

Comments are closed