Trying to read an EV3 gyro on a BrickPi2

It works fine on an EV3. Plugged the gyro (& the same cable) to port S1 of my BrickPi2 & the following program gets the same constant value, no matter how I rotate the gyro, or even if its plugged in to S1. Any thoughts?

BrickPiSetup()
BrickPi.Sensor[PORT_1] = TYPE_SENSOR_EV3_GYRO_M0 #Angle mode
BrickPiSetupSensors() # Apply settings

while True:
result = BrickPiUpdateValues() # Get sensor data
if not result:
gyro_angle = BrickPi.Sensor[PORT_1]
print(f"Gyro Angle: {gyro_angle}")
time.sleep(1)

2 Likes

I don’t know anything about the BrickPi, but I have done some interesting things with a GPS module on the GoPiGo.

Since you are connecting it to the “S1” port, I am assuming it’s a serial device.

Though a serial interface is extremely simple, it’s also very picky about it’s signalling requirements and they have to match at both ends.

The first and most important thing is the operating/signal voltages. (Typically either +5 or +3) If they’re the same, you are golden. If not you should probably pick a different gyro. If they’re both Grove connectors, they’re probably +5.

Second thing is baud rate. Though 9600 baud is common, it can go as high as 15,000 baud. If the baud rate doesn’t match, you will get interesting results.

Third is the data wiring. TX on one end had to go to RX on the other side and vice versa.

Lastly, does it even work? You can test this by using a terminal emulator program like Putty on a PC and an FTD based serial-USB adapter. With that, you can see exactly what the data is.

Another thing:
Are you sure it’s serial? Many Grove connector interfaces are i2c interfaces.

The best thing is to get the data sheet or specification document for the module you are using. This will answer many questions.

Let us know what happens!

P.S.
Make sure the serial/USB adapter is based on the FTD serial interface chip as others have interesting side-effects that can be undesirable, especially if the device actively drives the serial buss.

P.S.
Looking at your code, I don’t see you setting baud rate in the configuration of the port.