The Sense HAT has an 8 × 8 RGB LED matrix, a five – button joystick and includes the following sensors:
As you can see, the Sense HAT comes equipped with six types of sensors. Let’s try to acquire some data using these sensors!
Atmospheric Pressure · Temperature · Humidity
First, let’s start with pressure, temperature and humidity sensors! These sensors are located on the right side of the Sense HAT. The humidity sensor is labeled “HUMIDITY” and below it is the atmospheric pressure sensor, labeled “PRESSURE”. The temperature seems to be read from the humidity sensor.
There’s a function for each sensor so the values can be acquired very easily!
There wouldn’t be a problem even if you remove it from the command line, but if you forcibly terminate it while it’s running the LED display may stay on. (It does not turn off automatically; the state at the moment of termination is maintained). It’s recommended that you write a program that does not become an infinite loop or remove it from IDLE.
As shown in the above video, a character string “Temperature = 33.4, Pressure = 1010.8, Humidity = 33.8” is displayed on the LED matrix. These are the result I obtained: Temperature 33.4 °C; atmospheric pressure 1010.8 hPa; humidity 33.8%.
The temperature exceeded 30 degrees due to the heat generated by the Raspberry Pi. Although it’s quite different from the actual temperature, it seems to be useful for countermeasures against thermal runaway (as a measure of the main body temperature).
The code above warns you of abnormal temperature on the International Space Station. The temperature value will show in green background when there is no problem (18.3 to 26.7 ° C) and red background in case of abnormality. In the video above, the temperature sensor indicates the value of 34.2 degrees so it’s shown in the red background.
Gyroscope · Acceleration sensor · Magnetic sensor
Next to the humidity and pressure sensors there is an “Inertial Measurement Unit (IMU: Accelerometer, Gyroscope, Magnetometer)”.
A gyroscope is a spinning wheel or disc in which the axis of rotation is free to assume any orientation by itself. (It’s an instrument or device that detects the angle (attitude), angular velocity or angular acceleration of an object.)
An accelerometer is a device that measures proper acceleration. (A compact accelerometer (acceleration sensor) is fabricated using MEMS technology. MEMS accelerometers are used for automotive airbags, car navigation inclinometers, game controllers, etc.)
Acceleration, in physics, is the rate of change of velocity of an object with respect to time. An object’s acceleration is the net result of any and all forces acting on the object, as described by Newton’s Second Law. Accelerations are vector quantities (they have magnitude and direction).
A magnetometer is an instrument that measures magnetism—either magnetization of magnetic material like a ferromagnet, or the direction, strength, or the relative change of a magnetic field at a particular location.
I find angular velocity, angular acceleration, and acceleration pretty difficult concepts to grasp. The angular velocity describes the speed of rotation; the angular acceleration is the rate of change of the rotation speed (angular velocity); and the acceleration is the rate of change of the speed with direction (velocity).
In regards to the magnetic field, let’s look at how a compass works in the Sense HAT. For now, I have no idea how it is used but let’s try running a sample code.
First, I will use the gyroscope to acquire the orientation of the Raspberry Pi. To handle this sensor you need to understand the following three terms: Pitch, Roll, and Yaw.
An aircraft in flight is free to rotate in three dimensions: pitch, nose up or down about an axis running from wing to wing; yaw, nose left or right about an axis running up and down; and roll, rotation about an axis running from nose to tail.
Although the code becomes longer, it’s more easier to understand what’s going on, even for Python beginners.
from sense_hat import SenseHat
print("p: %s, r: %s, y: %s"%(p,r,y))
I tried to tilt the Raspberry Pi in various directions while outputting the values of Pitch, Roll and Yaw at 1 second intervals. You can see that the values are changing as shown in the video above. If you rotate the Raspberry Pi side to side to turn it over, the value of Pitch changes. If you turn it upside down, the value of Roll will change, and if you rotate it horizontally, Yaw will change.
I’ve noticed that the value change slightly even if I’m not moving the Pi. Maybe it’s due to something in the surrounding that’s causing the values changing…?
There’s another way to get x, y, z values, as shown in the above example code. It looks like it’s utilizing an acquisition method using the accelerometer. You can see a change in values when tilting the Raspberry Pi in the video above.
I can understand that the orientation can be acquired with a gyroscope, but the orientation can also be acquired with an accelerometer?
Accelerometer also detects the acceleration in the direction of the ground due to gravity, and the acceleration that can be obtained from the acceleration sensor is always the resultant force of acceleration applied to the device by the user and gravitational acceleration.
Acceleration detected by the accelerometer can be acquired as a component of each spatial axis in a three-dimensional space centered on the device as shown below.
Calls set_imu_config to disable the gyroscope and accelerometer then gets the direction of North from the magnetometer in degrees.
Figure 5 shows the values obtained at 1-second intervals. I was able to obtain those values but what on earth do these numbers mean?! Even though there was a change in the direction, I did not see much change in the numbers. Maybe something nearby is interfering with the sensor? (If you were successful in obtaining the data, please share with us how you did!)
Please check out the above link for more details on how to make the case. The required parts, connection method, and assembly method are explained in detail.
Here is the case I made! First, I printed SECTION_2 and SECTION_3 to put together the main body. It did not fit snugly without using the screws, as you can see the little gaps…
At first, I thought the case was huge, but it actually fits the main body and the Sense HAT quite nicely. There was also a space to attach the buttons. Oh, you can also place the camera, of course!
Next, I printed SECTION_1 and SECTION_4. I changed the color of the lid and the heat sink for better presentation. There was a minor error in 3D printing and I was not able to perfectly align/assemble the case…
Figure 8 The assembled flight unit / @Raspberry Pi
Just make sure you follow the steps as described on the official website. You’ll be able to put together a nice looking flight case as shown in Figure 8. Also, make sure to use the right material for the case to minimize any distortions.
We were able to acquire values from Sense HAT’s six onboard sensors!
As for the temperature sensor, if you connect the Raspberry Pi body and Sense HAT separately, it looks like it’s possible to avoid the heat problem we discussed above (i.e. heat from the main body affecting the real data).
Next time we’ll go over how to use Sense HAT joystick as inputs!