I'm using a JY901 gyroscope sensor, talking to it with I2C. Works perfectly with a standard Uno (R3), and I (eventually) got it working with a NodeMCU 12e. but I can't seem to get it working with the target device, a Heltec Lora 32 board.
The device address is on 0x50 - and both boards seem to find it okay with a port scan.
Node MCU Output - Works
4 SDA
5 SCL
Start Scan
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
50 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
Scan Completed, 1 I2C Devices found.
Angle: Pitch -0.03 Roll 2.79 Yaw 98.65
Mag:236 -42 430
Angle: Pitch -0.03 Roll 2.79 Yaw 98.54
Mag:238 -40 430
Angle: Pitch -0.02 Roll 2.78 Yaw 98.62
Mag:241 -41 429
However, when I put this code on the Heltec, It finds the I2C port with the port scan (see below); it gets the CORRECT number of bytes to read when I poll the accelerometer but just returns zeros in the data fields.
Heltec Lora 32 (Fails)
21 SDA
22 SCL
Start Scan
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
50 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
Scan Completed, 1 I2C Devices found.
Angle: Pitch 0.00 Roll 0.00 Yaw 0.00
Mag:0 0 0
Angle: Pitch 0.00 Roll 0.00 Yaw 0.00
Mag:0 0 0
Angle: Pitch 0.00 Roll 0.00 Yaw 0.00
Mag:0 0 0
I should add that I've externalised the power supply so, the voltage & current is identical in both instances. I have pull up resistors (4.7k-Ohm) to VCC on both the SCL & SDA (but these are on the sensor circuit and are the same in both instances)
Things I've tried:
- Changing the I2C clock speed (100k, 400k)
- I've confirmed that the I2C bus is working on the Heltec (by talking to another board)
- Tried endTransmission(false) and endTransmission(true) (Just in case it made any difference - it doesn't)
- I have an oscilloscope that (theoretically) traces I2C but as soon as I attach the probes, the device stops sending anything.
I've turned everything else off on the Heltec (no OLED or Lora going - just the serial port to the USB monitor)
I've attached the source (bit rough because of all the fiddling) but this is the read I2C function
void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
{
Wire.beginTransmission(deviceAddr);
Wire.write(addressToRead);
uint8_t ec=Wire.endTransmission(false); //endTransmission but keep the connection active
Wire.requestFrom(deviceAddr, bytesToRead); //Ask for bytes, once done, bus is released by default
while(Wire.available() < bytesToRead); //Hang out until we get the # of bytes we expect
for(int x = 0 ; x < bytesToRead ; x++)
{
dest[x] = Wire.read();
}
}
Anyone got any idea what might be causing the problem?
jy910.ino (10.3 KB)



