How to code the Sense HAT for Raspberry Pi in your web browser


You can now code the Sense HAT for Raspberry Pi in an emulator in your web browser, without any hardware.

You may be familiar with the Sense HAT, an expansion board for the Raspberry Pi that was specially designed for a space mission with ESA British astronaut Tim Peake for Astro pi. It is a great material, very handy for data logging, science experiments, environmental analysis, games and more. It comes with a Python library which makes it up and running immediately. (See Exploring the Raspberry Pi Sense HAT and Experimenting with the Raspberry Pi Sense HAT).

Enter the emulator

The Raspberry Pi Foundation has partnered with Trinket, which make brilliant online resources for learning Python (and more) in the browser. Trinket builds a Sense HAT emulator which lets you run the same Python code that you use on a real Sense HAT on a Raspberry Pi, and it emulates the behavior of the hardware in a virtual on-screen graphic.

The virtual Sense HAT has temperature, pressure and humidity sensors, and can change its behavior based on the values ​​they report. The Sense HAT emulator has sliders that you can move to change these values, so you can test your code’s response to environmental variables.

The emulator includes:

  • LED display
  • Environmental controls
  • Joystick control (on screen or keyboard)
  • Complete Python syntax highlighting
  • Contextual autofill
  • Intuitive error reporting and highlighting

You can also upload images, embed knickknacks on your own website, share your project with a direct URL, or download your project as a ZIP archive so you can easily move it to your Raspberry Pi.

Previously, joystick access was limited to using a third-party library like pygame or evdev, but since library access is limited to what is implemented in Trinket, we decided to go ahead. with an idea we’re considering anyway: to implement a native joystick interface within the Sense HAT library. The latest version of Python code offers this, and it has also been implemented in Trinket. You can now access sense.stick to process events and assign reminders to actions. (To see the joystick documentation for more information.)

Astro pi

At the end of 2015, we sent two Raspberry Pis to the International Space Station with Tim Peake. Tim has completed his six month assignment and successfully executed student code on the Astro Pi units. The Pis are still aboard the space station and we now have access to them on the ground! This means that we can upgrade the library and upload more programs to it in the future. We intend to have more competitions on a larger scale next year, and we thought this would be a great way to encourage more engagement, as you no longer need to access the material. to participate.

Tim Peake in the International Space Station

Detect the HAT in the classroom

The Sense HAT emulator is perfect for classroom use with a small number of Raspberry Pis with Sense HAT. In a PC suite, anyone can write code for their virtual Sense HAT and take turns executing their code on a real one.

The emulator is also useful for testing code under extreme or unlikely conditions. If something is supposed to happen when the temperature is particularly high or low, it is difficult to test its operation. The emulator allows you to simulate these conditions without taking your Pi to the beach or the North Pole!

Check out some Sense HAT resources on the Astro Pi website, and be sure to pay attention to other science and coding competitions for the chance to run your code in space!


About Author

Comments are closed.