Arduino Gyroscope Protocol

This protocol sends MPU6050 gyroscope data in timed cycles to the user. You can set the type of data you need and the cycle time. Defaultly it sends these data: acceleration including gravity, actual angle and temperature) in every second.

The default settings are the following:
  • accelerometer: +/- 2g (all setttings: 2, 4, 8, 16)
  • gyroscope: +/- 250 degrees/sec (all setttings: 250, 500, 1000, 2000)
  • Defaultly sets clock source to X Gyro, which is slightly better than the internal clock source.

How to build a test circuit with an MPU6050 and an Arduino Mega?
Arduino codes are included.

I. "welcome" event from microcontroller

Example

c=welcome&id=XnaiK3&type=OzGyroControllerMPU6050&pos=2&t=3

Parameters

Parameter Type Range Functionality
c String "welcome" Identifies the welcome message.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
type String "OzGyroscopeSensor" Determines the type of the device.
pos Byte 0-255 Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position.
t Byte 0-255 Counts the number of responses and events sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.



II. Commands to microcontroller

"auto_conf" command

Measures the offsets of your newly connected MPU6050 and calibrates it, this can take a minute, just lay it on a horizontal surface and do NOT touch it, just sit back and relax. This is important for the MPU6050 to work properly.

The MPU6050 automatically saves the calibration so you do not need to recalibrate it everytime.

Example

//the measurement sample size is 1100:
c=auto_conf&sample_size=1100&id=XnaiK3&t=0
Parameter Type Range Functionality
c String "auto_conf" Identifies the command.
sample_size unsigned int 0-65535 Optional parameter, default value: 1000. The size of the measurement sample during the calibration. The longer the sample size the more time the calibration will take.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.

Response

//it lets you know when the offset configuration is ready
c=auto_conf_resp&sample_size=1100&id=XnaiK3&t=3
Parameter Type Range Functionality
c String "auto_conf_resp" Identifies the command.
sample_size unsigned int 0-65535 The size of the measurement sample during the calibration.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of responses and events sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.

"set" command

Sets the acceleration range, gyroscope speed range and the clock source.

    The default settings are the following:
  • accelerometer: +/- 2g (all setttings: 2, 4, 8, 16)
    The smaller the range the more precise is the measurement, because all axis (x,y,z) is measured on 16 bits.
  • gyroscope: +/- 250 degrees/sec (all setttings: 250, 500, 1000, 2000)
  • Sets the clock source to use the X Gyro for reference, which is slightly better than the default internal clock source.
    (If you use a gyro or an external clock source then you will get an improved stability.)

Example

//this example sets the accel range to +/- 16g
//the speed range to +/- 2000 degrees/sec
//and the clk source to internal oscillator
c=set&acc_range=16&gyro_range=2000&clk_source=0&id=XnaiK3&t=1

Parameters

Parameter Type Range Functionality
c String "set" Identifies the command.
acc_range specific bytes 2, 4, 8, 16 Sets the +/- g range of the accelerometer.
gyro_range specific ints 250, 500, 1000, 2000 Sets the gyroscope's +/- degrees/s speed range
clk_source specific bytes 0,1,2,3,4,5,6,7 0: Internal oscillator 8 MHz
1: PLL with X Gyro reference 8 MHz
2: PLL with Y Gyro reference 8 MHz
3: PLL with Z Gyro reference 8 MHz
4: PLL with external 32.768kHz reference
5: PLL with external 19.2MHz reference
6: Reserved
7: Stops the clock and keeps the timing generator in reset
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.

Response

c=set_resp&acc_range=16&gyro_range=2000&clk_source=0&id=XnaiK3&t=4

Parameters

Parameter Type Range Functionality
c String "set_resp" Identifies the response.
acc_range specific bytes 2, 4, 8, 16 The +/- g range of the accelerometer is set.
gyro_range specific ints 250, 500, 1000, 2000 The gyroscope to +/- degrees/s speed range is set.
clk_source specific bytes 0,1,2,3,4,5,6,7 0: Internal oscillator 8 MHz
1: PLL with X Gyro reference 8 MHz
2: PLL with Y Gyro reference 8 MHz
3: PLL with Z Gyro reference 8 MHz
4: PLL with external 32.768kHz reference
5: PLL with external 19.2MHz reference
6: Reserved
7: Stops the clock and keeps the timing generator in reset
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of responses and events sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.



"getvalue" command

Ask sensor values from MPU6050 in real time. You will receive acceleration, gyroscope, angle and temperature values in the response.

Example

c=getvalue&id=XnaiK3&t=2
Parameter Type Range Functionality
c String "getvalue" Identifies the command.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of commands sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.

Response

Receive acceleration, gyroscope, angle and temperature values in the response. You can see more specified information of each measurement below the table.

//MPU6050 layed on a flat surface and turned 1240 degrees clockwise with 756 degrees/s
//Clockwise and counterclockwise depends on which side of the MPU6050 is faced upwards
c=getvalue_resp
    &accx=0.03&accy=0.02&accz=9.84 //acceleration including gravity
    &rotx=0.19&roty=0.02&rotz=756.00 //rotation speed (gyroscope)
    &angx=-0.18&angy=0.19&angz=-1240.00 //current angles
    &temp=24.91&id=XnaiK3&t=5
Parameter Type Range Functionality
c String "getvalue_resp" Identifies the command.
accx Double -156.80 to 156.80
(case of 16g =>
16 * 9.80 = 156.80)
Shows the acceleration including gravity in x direction.
accy Double -156.80 to 156.80 Shows the acceleration including gravity in y direction.
accz Double -156.80 to 156.80 Shows the acceleration including gravity in z direction.
rotx Double -2000 to 2000 degrees/s (if set in the highest range) Show the current rotation speed in X direction of the MPU chip.
roty Double -2000 to 2000 degrees/s Show the current rotation speed in Y direction of the MPU chip.
rotz Double -2000 to 2000 degrees/s Show the current rotation speed in Z direction of the MPU chip.
angx Double -90.00 to +90.00 Degrees. The current angle in X direction of the MPU chip. It is relative to the calibrated ("auto_conf" command) angle which is 0.
angy Double -90.00 to +90.00 Degrees. The current angle in Y direction of the MPU chip. It is relative to the calibrated ("auto_conf" command) angle which is 0.
angz Double Full Double range Degrees. The current angle in Z direction of the MPU chip. It is relative to the bootup angle which is 0.
temp Double -40.00 to 85.00 Shows the current temperature in celsius. It can mistake +/- 1%
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of responses and events sent combined. Counts from 0 to 255 then from 0 again. Be aware that the t of the commands differs from the t of the responses and events.

Extra information to 'getvalue_resp'

Acceleration information

Shows the acceleration component of the forces effecting the MPU6050. When layed on surface it shows the gravity (9.80 m/s2).

Default range: +/- 2g (1g = 9.80 m/s2) (The lower the range, the more precise is the measurement.)
Other ranges: +/- 4, 8, 16 g


Rotation information

Shows the actual rotation speed in degrees/sec of the MPU6050 chip.

Default range: +/- 250 degrees/s (The lower the range, the more precise will the measurement be.)
Other ranges: +/- 500, 1000, 2000 degrees/s


Angle information

Shows the actual angles of the MPU6050 chip.

TOP VIEW. THE ORIGO IS THE MPU6050 CENTERPOINT:

top view in bottom view z angle grows in clockwise
Figure 1 - Top view (in bottom view Z angle grows in clockwise)

More information