Hello everyone, in today’s blog we are moving further to the last part of the series of Gyroscope sensor of the stm32 board. In this blog, we are going to get the readings from the Gyroscope sensor of the stm32 board, the delay, and the core peripherals. We are then going to use them to run the mini-project to get the readings from the stm32 Gyroscope sensor.
If you are new here then I suggest you please read the previous parts of the series in which I have already explained the working of the sensor and why we use this Gyroscope Sensor. You can read those from here PART1, PART2.
So we are going to generate the Gyroscope sensor readings in three-axis x, y, and z before that let’s discuss what these readings are used for or what we do with these readings?

Why use Gyroscope?
A gyroscope is a device that uses Earth’s gravity to help determine orientation. Its design consists of a freely-rotating disk called a rotor, mounted onto a spinning axis in the center of a larger and more stable wheel. As the axis turns, the rotor remains stationary to indicate the central gravitational pull, and thus which way is “down.”
History of Gyroscope Sensor
Gyroscopes were first invented and named in the 19th century by French physicist Jean-Bernard-Léon Foucault. It wasn’t until 1908 that German inventor H. Anschütz-Kaempfe developed the first workable gyrocompass, according to Encyclopedia Britannica. It was created to be used in a submersible. Then, in 1909, it was used to create the first auto-pilot.
Where you can see gyroscope working?



A gyroscope in your phone enables it to sense the linear orientation of the phone to auto-rotate your screen. While the gyroscope takes care of the rotational orientation, it is the accelerometer that senses the linear changes relative to the frame of reference of the device.
Read the Sensor and provide the readings
Now we are going to get the data from the Gyroscope sensor and for that, we need to use the
gyro: I16x3 which is going to help us in receiving the readings of the Sensor and using this gyro structure we will get the Gyroscope measurements.
We are going to use the no_main and no_std code to work on the hardware you can go through the reasons why we are doing this.
This is the code we are going to implement to get the readings successfully
#![no_main] #![no_std] use cortex_m::asm; use stm32f3_Gyroscope::config::initialization::*; use stm32f3_discovery::stm32f3xx_hal::hal::blocking::delay::DelayMs; /// This program is going to print the Gyroscope sensor readings(x, y, z-axis) on the itm-dump console with /// 1 sec of delay. /// /// #Arguments /// None /// /// #Return /// This is a no_std no_main code which will neither return nor stop. #[entry] fn main() -> ! { let (mut delay, mut itm, gyro) = initialization(); loop { let x_axis= gyro.gyro.x; let y_axis = gyro.gyro.y; let z_axis= gyro.gyro.z; iprintln!( &mut itm.stim[0], "Readings \n x= {:?} y= {:?} z= {:?}", x_axis, y_axis, z_axis ); delay.delay_ms(1000u16); } }
We are using the gyro to get the readings from all the three-axis x, y, and z and then using the gyro. (axis) we get the particular axis value.
Then we store all the three-axis values in x_axis, y_axis, and z_axis variables.
After this, we use the iprintln! macro to print the output we receive from the Gyroscope sensor on the itm console. We do this process with some delay and for that, we are using the delay.
Using this we will receive the Gyroscope data successfully.
You can also use this link to check the working code of the same using this repository.
Thanks for reading, we are going to work on something more interesting in coming blogs till then keep reading.
If you want to read more content like this? Subscribe to Rust Times Newsletter and receive insights and latest updates, bi-weekly, straight into your inbox. Subscribe to Rust Times Newsletter: https://bit.ly/2Vdlld7.





