Skip to content

Not available on rp2040 (raspberry pie Pico). #31

@xiezhoubin

Description

@xiezhoubin

Problem:
I use mpu6050 sensor and raspberry pie Pico development board. I can make sure the wiring is correct. However, the same code can run on Arduino uno and esp32, and can correctly read mpu6050 data. After the raspberry pie Pico runs, it cannot correctly read data.(Raspberry pie enables Pico to read normally using hardware IIC.)

arduino for rp2040:
https://github.com/earlephilhower/arduino-pico

Picture:
image
Raspberry pie Pico failed to read with software IIC:
image
Arduino uno successfully read with software IIC:
image

Code:

#include <SoftWire.h>
SoftWire Wire(12, 13); // Raspberry pie Pico(SDA=12,SCL=13) ,ARDUINO UNO(SDA=2,SCL=3)

const int MPU6050_addr = 0x68;
int16_t AccX, AccY, AccZ, Temp, GyroX, GyroY, GyroZ;
uint8_t swTxBuffer[32];
uint8_t swRxBuffer[32];

void setup() {
Wire.setTxBuffer(swTxBuffer, sizeof(swTxBuffer));
Wire.setRxBuffer(swRxBuffer, sizeof(swRxBuffer));
Wire.begin();
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}

void loop() {
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU6050_addr, 14, true);
AccX = Wire.read() << 8 | Wire.read();
AccY = Wire.read() << 8 | Wire.read();
AccZ = Wire.read() << 8 | Wire.read();
Temp = Wire.read() << 8 | Wire.read();
GyroX = Wire.read() << 8 | Wire.read();
GyroY = Wire.read() << 8 | Wire.read();
GyroZ = Wire.read() << 8 | Wire.read();

Serial.print("AccX = ");
Serial.print(AccX);
Serial.print(" || AccY = ");
Serial.print(AccY);
Serial.print(" || AccZ = ");
Serial.print(AccZ);
Serial.print(" || GyroX = ");
Serial.print(GyroX);
Serial.print(" || GyroY = ");
Serial.print(GyroY);
Serial.print(" || GyroZ = ");
Serial.print(GyroZ);
Serial.print(" || Temp = ");
Serial.println(Temp / 340.00 + 36.53);
delay(500);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions