Skip to content

Input Devices

This week’s assignment is to measure something: add a sensor to a microcontroller board that you have designed and read it

I’m trying to use a MPU6050 gyroscope with the XIAO and read something.

Individual Assignment

Here’s what I’ve done for this assignment.

  1. Obtained a MPU6050 3-axis gyroscope link

  2. I installed the MPU6050 adafruit library in the Arduino IDE and attempted to get the sensor to work. It was unsucessful.

  3. I used a multimeter to verify the connections and realized that the SDA and SCL pins were mislabeled (backwards) on the FabXIAO diagram when comparing the pinout and schematics, so I switched the SDA and SCL wires and tried again. No luck.

  4. Mr Dubick informed us that there appears to be an issue with the SeeedXIAO RP2040 and the I2C protocol, so I decided to test the sensor by connecting it to an Arduino UNO and running the same code. It worked, so the sensor is operational and the issue is with the communication between the XIAO and the sensor. When I uploaded and ran the code it returned an error that the MPU6050 chip initialization failed.

  5. I consulted about the issue with ChatGPT and made mild progress. It generated the following code.

#include <Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU6050

void setup() {
  Wire.begin();  // initialize the Wire library for I2C communication
  Serial.begin(9600);  // initialize the Serial communication for debugging purposes
  Wire.beginTransmission(MPU_addr);  // start communication with the MPU6050
  Wire.write(0x6B);  // select the PWR_MGMT_1 register
  Wire.write(0);     // write a zero to the PWR_MGMT_1 register to wake up the MPU6050
  Wire.endTransmission(true);  // end the communication with the MPU6050
}

void loop() {
  Wire.beginTransmission(MPU_addr);  // start communication with the MPU6050
  Wire.write(0x3B);  // select the starting register for the 14 registers we want to read
  Wire.endTransmission(false);  // end the transmission with the MPU6050, but don't release the I2C bus
  Wire.requestFrom(MPU_addr,14,true);  // request 14 bytes of data from the MPU6050, and release the I2C bus when done

  int16_t AcX=Wire.read()<<8|Wire.read();  // read the accelerometer X value
  int16_t AcY=Wire.read()<<8|Wire.read();  // read the accelerometer Y value
  int16_t AcZ=Wire.read()<<8|Wire.read();  // read the accelerometer Z value
  int16_t Tmp=Wire.read()<<8|Wire.read();  // read the temperature value
  int16_t GyX=Wire.read()<<8|Wire.read();  // read the gyroscope X value
  int16_t GyY=Wire.read()<<8|Wire.read();  // read the gyroscope Y value
  int16_t GyZ=Wire.read()<<8|Wire.read();  // read the gyroscope Z value

  Serial.print("AcX = "); Serial.print(AcX);  // print the accelerometer X value
  Serial.print(" | AcY = "); Serial.print(AcY);  // print the accelerometer Y value
  Serial.print(" | AcZ = "); Serial.print(AcZ);  // print the accelerometer Z value
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  // print the temperature value in degrees Celsius
  Serial.print(" | GyX = "); Serial.print(GyX);  // print the gyroscope X value
  Serial.print(" | GyY = "); Serial.print(GyY);  // print the gyroscope Y value
  Serial.print(" | GyZ = "); Serial.println(GyZ);  // print the gyroscope Z value
  delay(1000);  // wait for 1 second before reading the next set of values
}
  1. Using the above code, produced output from the sensor, and I was initially excited, but then quickly realized that it was bad data. Back to work.

  2. I had concerns that that sensor was defective, so I tested the sensor with an Arduino Uno. I used the tutorial at this link from LastMinuteEngineers. It worked, so I’m left with trying to decide what to do next. The sensor is good, so wondering if it’s a problem with the XIAO.

  3. To test this theory, I’m going to see if I can get the sensor to so work with Python in Thonny. I used the following tutorials to test out the sensor.

  4. Seeed Studio XIAO RP2040 with MicroPython to connect and load MicroPython on the Seeed Xiao.
  5. How to Connect the MPU6050 to the XIAO RP2040

I first followed the above tutorials with a SeeedXIAO with headers and the MPU6050 sensor connected with jumper wires. It worked with no issues, so I moved on to the development board I had milled earlier. I followed the same protocol, and it too worked, so the problem must be with the SeeedXIAO RP2040 and Arduino protocols.

Group Assignment

Here is a link to our group assignment