Hi, I am using python to get data from the sensors using MegaPi.
All the other sensors work (ultrasonic sensor and the line following sensor), but when it comes to the gyro sensor, it’s returning as 0.0. It works in mBlock and also when I use Arduino IDE, but for some reason its not working in Python. My code is attached below:
from megapi_python3 import *
import time
def ultrasonicRead(v):
print(f"distance: {round(v, 2)} cm")
def gyroRead(w):
print(w)
def lineRead(x):
print(int(x))
if name == ‘main’:
bot = MegaPi()
bot.start(‘COM6’)
while True:
# bot.ultrasonicSensorRead(8, ultrasonicRead)
# bot.lineFollowerRead(7, lineRead)
bot.gyroRead(6, 3, gyroRead)
time.sleep(1)