Python gyroRead for Z value not working properly



Does someone who uses the Ultimate Robot with Python could tell me if the function gyroRead(0,3,onRead) to read the z value. If its working properly?

Currently it starts for me with a random value between 180 and -180 and then starts to decrease the value. Rotation changes the value but its still wrong. Read x and y work normally.

The code im testing is:
from megapi import *

def onRead(level):
print(“Gyro Value:%f” %level);

if name == ‘main’:
bot = MegaPi()
while 1:


There have been many previous reports on the gyro z -axis and drifting

My problem in a past life

I am working on a python - mbot problem for oscar. I will then pull out my gyro and try it.


This code worked for me:

from megapi import *
angle = 123

def onRead(level):
global angle
angle = level

bot = MegaPi()

print (“start test”)

while 1:

bot.gyroRead(P,A, onRead) where P is port sensor is plugged into, A is axis 1, 2 , 3

iangle = int(angle)
print (iangle)


Thank you, dr-roboto.

The code bot.gyroRead (P, A, onRead) works for me but P has to be set to 0 and the gyro sensor has to be connected to port 6 of the RJ25 Shield.

The z-axis drifting is probably caused by the power supply.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.