Lab 11: Sensors and Data Processing Using MPU-6050
In this lab, students will work with the MPU-6050 sensor to detect gestures and tilts using the accelerometer and gyroscope. The content covers the working principles of the MPU-6050, reading accelerometer and gyroscope data, and sample code implementation. Dive into the world of embedded systems and sensor applications with Prof. Chung-Ta King at National Tsing Hua University in Taiwan.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CS4101 Introduction to Embedded Systems Lab 11: Sensors Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan National Tsing Hua University
Introduction In this lab , we will learn To use accelerometer of NuMarker to detect gestures To use gyroscope of NuMarker to detect tilts 1 National Tsing Hua University
MPU-6050 3-axis accelerometer 3-axis gyroscope 2 National Tsing Hua University
MPU-6050: Accelerometer Two bytes (high and low) to present each axis Read_MPU6050_AccY(void): LowByte =MPU6050_ReadByte(MPU6050_ACCEL_YOUT_L); HighByte =MPU6050_ReadByte(MPU6050_ACCEL_YOUT_H); AccY = (HighByte<<8) | LowByte ; 3 National Tsing Hua University
MPU6050 - Gyroscope Similar to the accelerometer Read_MPU6050_GyroX(void): LowByte = MPU6050_ReadByte(MPU6050_GYRO_XOUT_L); HighByte = MPU6050_ReadByte(MPU6050_GYRO_XOUT_H); GyroX = (HighByte<<8) | LowByte ; 4 National Tsing Hua University
MPU6050.h/.c (Library/NuMakerLib/Include,Source) #define MPU6050_I2C_SLA 0xD0 #define MPU6050_I2C_PORT I2C1 void MPU6050_WriteByte(uint8_t MPU6050_reg, uint8_t MPU6050_data) { uint8_t data[1]; data[0]=MPU6050_data; I2C_writeBytes(MPU6050_I2C_PORT, MPU6050_I2C_SLA, MPU6050_reg, 1, data); } uint8_t MPU6050_ReadByte(uint8_t MPU6050_reg){ uint8_t data[1]; I2C_readBytes(MPU6050_I2C_PORT, MPU6050_I2C_SLA, MPU6050_reg, 1, data); return(data[0]); } 5 National Tsing Hua University
smpl_I2C_MPU6050 (SampleCode/NuMaker-TRIO) int32_t main(){ int16_t accX, accY, accZ; int16_t gyroX, gyroY, gyroZ; SYS_Init(); I2C_Open(I2C1, I2C1_CLOCK_FREQUENCY); while(1) { accX = Read_MPU6050_AccX(); accY = Read_MPU6050_AccY(); accZ = Read_MPU6050_AccZ(); printf("Acc: %6d, %6d, %6d, ", accX,accY,accZ); gyroX = Read_MPU6050_GyroX(); gyroY = Read_MPU6050_GyroY(); gyroZ = Read_MPU6050_GyroZ(); printf("Gyro: %6d, %6d, %6d", gyroX,gyroY,gyroZ); } } Init_MPU6050(); 6 National Tsing Hua University
Lab: Basic 1 Use your NuMaker to cast lots ( ) Shake your NuMarker left and right very hard for preparation. Then, make a sudden up-down move to cast the lots. Print the cast lot on the display, which is a word from Bad , Good , and Great , depending on the intensity of the left-right shake: If the intensity is low, print Bad . If the intensity is medium, print Good . If the intensity is high, print Great . 7 National Tsing Hua University
Lab: Basic 2 Game of ball rolling There is a ball and a destination flag on the display. The player has to control the ball by tilting the device (right, left, up, down) to move close to the flag. If the ball touches the destination flag, the game is won. A new game is then started with the ball and the flag at new random locations. You have to protect the ball from going through the screen boundaries by setting proper conditions. Sample 8 National Tsing Hua University
Lab: Bonus Enhance Basic 2 to add obstacles. You have to make sure that there is at least one path from the starting position of the ball to the destination flag. National Tsing Hua University