AdSense
Friday, July 14, 2017
5 - Raspberry Pi and Sense Hat (II): IMU (Inertial Management Unit) with Accelerometer, Gyroscope and Magnetometer
RASPBERRY PI AND SENSE HAT(II): IMU (INERTIAL MANAGEMENT UNIT) WITH ACCELEROMETER, GYROSCOPE AND MAGNETOMETER
- Layout for this exercise:
1 - Introduction
- The Sense HAT has a movement sensor called an IMU (Inertial Management Unit) which can measure the type of movement it is experiencing:
https://www.raspberrypi.org/learning/astro-pi-guide/sensors/movement.md
- An IMU is an electronic device that measures and reports a body's specific force, angular rate, and sometimes the magnetic field surrounding the body, using a combination of accelerometers and gyroscopes, sometimes also magnetometers.
- An IMU is built basically with 3 sensors in one. The readings for these 3 sensors are combined to have an accurate orientation of the Sense HAT module:
a) gyroscope: measures momentum and rotation.
b) accelerometer: measures acceleration forces and can be used to find the direction of gravity.
c) magnetometer: measures the Earth's own magnetic field, so it's a bit like a compass.
- An IMU sensor is used on all manned and unmanned spacecraft to track movements and maintain an understanding of orientation.
- All objects in space have three axes around which they can rotate. The three axes are:
- Pitch, roll, yaw are terms used in aviation and airplane control to describe the movement around the 3 axes:
a) pitch: like a plane taking off
b) roll: the plane doing a victory roll
c) yaw: steering the plane like a car
- If you know how much rotation has happened on each axis, then you know which way the object is pointing.
- This image shows where these axes are in relation to the Sense HAT:
2 - Programming Raspberry Pi and Sense Hat to determine its orientation
- The next program offers accurate information about the orientation of the Raspberry Pi and Sense Hat module.
- The function set_imu_config(True,True,True) sets the magnetometer, gyroscope and accelerometer (in that order) to make measurements about the position (determined by the pitch, roll and yaw output parameters):
- Giving permissions of execution:
- The initial position of the Raspberry Pi and Sense Hat is flat on a table:
- Running the program:
- Tilting up the Raspberry Pi and the Sense Hat modules:
- After tilting up the module a variation for the pitch is detected while roll and yaw remain almost equal:
4 - Raspberry Pi and Sense Hat (I): measuring temperature, humidity and pressure
RASPBERRY PI AND SENSE HAT (I): MEASURING TEMPERATURE, HUMIDITY AND PRESSURE
- Layout for this exercise:
1 - Introduction
- The Sense HAT is an add-on board for Raspberry Pi made especially for the Astro Pi mission (it launched to the International Space Station in December 2015) and is now available to buy.
https://www.raspberrypi.org/products/sense-hat/
https://www.raspberrypi.org/education/programmes/astro-pi/
- The Sense HAT has an 8×8 RGB LED matrix, a five-button joystick and includes the following sensors:
- Accelerometer
- Magnetometer
- Temperature
- Barometric pressure
- Humidity
- Gyroscope
- Also, there is a Python library providing easy access to everything on the board:
http://pythonhosted.org/sense-hat/
- HAT stands for “Hardware attached on top”. It is a hardware specification for add-on modules for the Raspberry Pi:
https://www.raspberrypi.org/blog/introducing-raspberry-pi-hats/
- To install Sense Hat on Raspberry Pi:
2 - Displaying text
- A basic exercise to check whether Sense Hat is working correctly:
3 - Measuring temperature, humidity and pressure
- Sense HAT has got built-in sensors for temperature, humidity and pressure:
- Giving execution permissions:
- Running the Python script:
- About the temperature readings it is important to notice that the Sense HAT sensor gets a little extra warm because of the heat generated by the Raspberry Pi module.
3 - Raspberry Pi and ThingSpeak (II): channel for Sensor data
RASPBERRY PI AND THINGSPEAK (II): CHANNEL FOR SENSOR DATA
- Layout for this exercise:
1 - Creating a ThingSpeak Channel
- Once signed in the ThingSpeak account a New Channel can be created:
- ThingSpeak allows to collect and store data with the Channels tool:
- After creating the channel an API key is automatically available to be used for the communication between the Raspberry Pi module and the ThingSpeak web services:
2- Programming the sensor
- The Python program used in this exercise is an adapted version of this one:
https://github.com/simonmonk/raspberrypi_cookbook_ed2/blob/master/thingspeak_data.py
- Let's notice that the previously created API Key must be used in this program:
- The send_data function creates the web request providing the temperature to the field 1 (temp_c) of the channel, what will be display in the chart as the Y axis.
3 - Running the sensor
- Giving execution permissions to the Python script:
- Running the program, a series of of the Raspberry Pi CPU Temperature is generated:
- Let's notice that there is an increment of the CPU temperature (from 48.9 to 62.3 degrees) when a video is played on the Raspberry Pi:
https://www.youtube.com/watch?v=LNEEVsZt8vI
- The ThingSpeak channel shows a chart displaying the evolution of the Raspberry Pi CPU temperature along an interval of approximately 8 minutes:
2 - Raspberry Pi and ThingSpeak (I): sending notifications with ThingTweet
RASPBERRY PI AND THINGSPEAK(I): SENDING NOTIFICATIONS WITH THINGTWEET
- Layout for this exercise:
1 - ThingSpeak
- ThingSpeak is an open source Internet of Things (IoT) platform and API to store and retrieve data from things using the HTTP protocol over the Internet or via a Local Area Network.
https://thingspeak.com/
https://en.wikipedia.org/wiki/ThingSpeak
- An introduction to ThingSpeak:
https://www.codeproject.com/Articles/845538/An-Introduction-to-ThingSpeak
- ThingSpeak has integrated support from the numerical computing software Matlab from MathWorks, allowing ThingSpeak users to analyze and visualize uploaded data using Matlab without requiring the purchase of a Matlab license from Mathworks.
- ThingSpeak has a close relationship with Mathworks, Inc. In fact, all of the ThingSpeak documentation is incorporated into the Mathworks' Matlab documentation site and even enabling registered Mathworks user accounts as valid login credentials on the ThingSpeak website.
- Before signing up for ThinSpeak a MarthWorks account must be created:
- After providing some required information the profile of the MathWorks account is verified:
2 - ThingTweet
- ThingTweet is a web services wrapper around Twitter provided by ThingSpeak.
- ThingTweet allows to connect an IoT device (for instance a Raspberry Pi module) and send notifications to Twitter about different events.
- Once signed up to ThingSpeak the ThingTweet action must be selected:
- The ThingTweet application will be linked to a preexisting Tweeter account:
- Once the requested information is provided the Twitter account is linked to ThingSpeak:
- An API Key is automatically generated, what must be written down carefully for further usage:
3 - Sending notifications to Twitter about the Raspberry Pi CPU temperature
- The next Python program has been adapted from here:
https://github.com/simonmonk/raspberrypi_cookbook_ed2/blob/master/send_tweet.py
- The program sends web requests to ThingSpeak (using the ThingTweet action) to publish messages on Twitter every time a notification about the CPU temperature is made.
- Notice that the API key obtained before is introduced as a constant into the program:
- Giving permissions to the program to be run:
- Executing the program, every 1 minute a notification about the CPU Temperature is published:
- As a consequence of running the program, and due to the link between ThingSpeak and Twitter, a corresponding tweet is published:
Subscribe to:
Posts (Atom)