Hi, today we are going to do
GY-271 compass sensor module programming.
The GY-271 compass module uses a QMC5883L chip.
This compass sensor module uses the I2C protocol
to communicate with the raspberry pi.
On the Raspberry Pi RoverBot,
the compass sensor module is used to measure the angle
when the robot turns right or left.
Broadly speaking,
the process of accessing data from the QMC5883L compass sensor module
is register settings,
then reading the status register
if the data is ready to read,
if the data is ready
then the data will be converted
to an angle scale of 0-360 degrees.
Connection diagram between the raspberry pi
and the QMC5883L compass sensor module
as shown on the screen.
Then we take a look at the program.
First we will look at the register settings that I use.
We set the control register 2
with the address 0x0a with a value of 0x81.
0x81 means that we only give
a value of 1 in the 7th bit which is soft reset
and 0th bit which is to turn off the compass sensor module interrupt pin.
Next we set
the set/reset period register
which is 0x0b with a value of 0x01,
because the datasheet recommends giving a value of 0x01.
Then we set the control register 1
with the address 0x09 with a value of 0x11.
0x11 means
we give a value of 00 on OSR,
01 on RNG,
00 on ODR
and 01 on Mode.
Before reading the data,
first we read the status of the data, at the address
0x06.
If the data status is 0x04,
it means that DOR or data is not readable,
so the process of reading the data must be repeated again.
If the data status is 0x01,
it means that DRDY or data is ready to read,
then proceed to the next step.
The next step is to convert the raw data
x and y into the magnitude of the compass angle.
If the calculation result is negative,
then it must be added with 360 degrees and "declination",
the value of “declination” is different for each region.
The last process is to display the compass angle value.
During the testing process,
make sure the compass angle value that is read
does not change significantly.
Congratulations, now you can program
the GY-271 compass sensor on the Raspberry Pi RoverBot.
Thank you for watching this video,
dislike if you don't like it,
like if you like it
and subscribe for more videos in the future.
