Post Syndicated from David Honess original https://www.raspberrypi.org/blog/desktop-sense-hat-emulator/
Today, we’re announcing another Sense HAT emulator designed to run natively on your Raspberry Pi desktop, instead of inside a browser. Developed by Dave Jones, it’s intended for people who own a Raspberry Pi but not a Sense HAT. In the picture below, the sliders are used to change the values reported by the sensors while your code is running.
So, why do we need two versions?
- For offline use, possibly the most common way Raspberry Pis are used in the classroom.
- To accommodate the oldest 256 MB models of Raspberry Pi which cannot run the web version.
- To allow you to integrate your Sense HAT program with any available Python modules, or other Raspberry Pi features such as the Camera Module.
The emulator will come pre-installed in the next Raspbian release but, for now, you can just install it by typing the commands below into a terminal window:
sudo apt-get update sudo apt-get install python-sense-emu python3-sense-emu python-sense-emu-doc sense-emu-tools -y
You can then access it from the Desktop menu, under Programming.
The emulator closely simulates the Sense HAT hardware being attached to your Pi. You can read from the sensors or write to the LED matrix using multiple Python processes, for example.
Write your code in IDLE as before; there are also a number of examples that can be opened from the emulator’s built-in menu. If you then want to port your code to a physical Sense HAT, you just need to change
at the top of your program. Reverse this if you’re porting a physical Sense HAT program to the emulator, perhaps from one of our educational resources; this step isn’t required in the web version of the emulator.
There are a number of preferences that you can adjust to change the behaviour of the emulator, most notably sensor simulation, otherwise known as jitter. This costs some CPU time, and is disabled by default on the low-end Raspberry Pis, but it provides a realistic experience of how the hardware sensors would behave. You’ll see that the values being returned in your code drift according to the known error tolerances of the physical sensors used on the Sense HAT.
This emulator will allow more Raspberry Pi users to participate in future Astro Pi competitions without having to buy a Sense HAT: ideal for the classroom where 15 Sense HATs may be beyond the budget.
So, where do you start? If you’re new to the Sense HAT, you can just copy and paste many 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.
You can even install this emulator on other types of Linux desktop, such as Ubuntu! For more information on how to do this, please visit the emulator documentation pages here.