Tuesday, May 29, 2018

Sense HAT & Sense Emulator = a perfect couple

If you're a Raspberry fan, chances are you already know about Sense HAT. It's an add-on board that provides an 8×8 RGB LED matrix, a five-button joystick and sensors: gyroscope, accelerometer, magnetometer, temperature, barometric pressure, humidity. A good thing is a "official" Python library supporting easy access to that hardware.

But a better thing is the Sense Emulator, an interactive application providing an interface for emulating the Sense HAT hardware. The idea is that you can develop a Python application intended to interact with the Sense HAT hardware without worrying about actually having such board at hand.

The way it works is that when working with the emulator within your Python application, you create a main class SenseHat giving accesss to all sensors, the LED pixel display, and the joystick. If you follow the recommendation of importing the library with the following idiom:
from sense_emu import SenseHat
then when you wish to deploy your code on an actual Sense HAT board the only change you need to make is to that line, changing it to:
from sense_hat import SenseHat
Fantastic! One line change it's all you need to move from sotfware emulation to actual hardware. Everything remains the same in your code.

No comments:

Post a Comment