Gy-521 readings only giving me -1

Hi! I'm trying to use a Gy-521 and it's only giving me -1 in the serial monitor. I have no idea what I'm doing wrong and chatgpt wouldn't help me :/. Please help! This is my code:

#include<Wire.h>
int16_t GyX;

void setup() {
Wire.begin();
Wire.beginTransmission(0x68);
Wire.write(0x6b);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Wire.beginTransmission(0x68);
Wire.write(0x43);
Wire.endTransmission(false);
Wire.requestFrom(0x68,2,true);
GyX=Wire.read()<<8|Wire.read();
Serial.println(GyX);
delay(250);
}

I would suggest using one of the I2C scanner sketches to check that the device is detected first.

1 Like

Hi, @spoobsploot
Welcome to the forum.

Have you Googled;

Gy-521 arduino

There are many examples and tutorial as well as Libraries that would make you coding easier.

Can you please post a circuit diagram so we can see how you have connected everything?

Tom.... :smiley: :+1: :coffee: :australia:

Ok so I tried using a scanner and it said the device wasn't found. Here's a picture of the wiring (Teensy 4.0 and Gy-521):

If I can't find the problem, I might just use a different sensor :confused:

If you'd shown that photo 2 days ago you'd have gotten this answer back then:

You've hooked the sensor up to Wire1, not Wire.

2 Likes

Thanks so much :slight_smile: It works now

1 Like

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