arduino-uno


Need explanations about a code relative to MPU6050


Can anybody please explain me these code. I don't understand how I2C protocol is working.
#include<Wire.h>
const int MPU=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; //int16_t is a 16bit integer. uint16_t is an unsigned 16bit integer
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
The code opens a I2C connection to the device, transmits an address to read from, and then reads 14 bytes from the device, reassemblying them back into 7 16 bit integers.
I would recommend reading the documentation.

Related Links

Arduino Program Reset Bug
arduino uno R3 input pins with gsm shield
Light weight machine to machine communication with Arduino
Interfacing RM5 evolution coin acceptor with arduino
Arduino-ESP8266 Sending URL from a client browser connected to the esp8266 AP and receiving the entered URL in the arduino board
Need explanations about a code relative to MPU6050
Arduino Programmer only works after unlugging and plugging back in
How do I communicate between Arduino board and Intel Edison Arduino board using XBee S2?
I cannot solve my arduino program error
2.4 inch TFT LCD SPFD5408 with Arduino Uno - touch not working
DAC0808 doesn't want tranfer to analog
Trouble in programming arduino with esp8266
How to control a servo motor with Windows Remote Arduino?
Set baud rate to esp8266 at 9600
Arduino AC Dimmer - serial communication lost due to interrupt
connection error with arduino etherent shield and apache localhost

Categories

HOME
jdo
bluetooth
gitlab
magnific-popup
ngrx
angular-material
comparison
hp-exstream
raspberry-pi
dot
cplex
rubygems
twitter-bootstrap-4
pivotal-cloud-foundry
android-youtube-api
iggrid
spring-xd
modelica
jplayer
vb.net-2010
windows-phone-7
percona
vaadin7
django-simple-history
opentracing
after-effects
progressive-web-apps
autocad-plugin
abi
csrf-protection
css-animations
crystal-reports-2010
pingfederate
jaxb2
nat
yadcf
preg-match-all
grails-3.1
azure-sql-database
geopositioning
language-concepts
serve
hockeyapp
ssjs
angularjs-factory
janrain
auto-update
user-accounts
komodoedit
worksheet
colorama
r-forge
azure-sdk
fuzzy-search
clang-static-analyzer
pagerank
rhino-servicebus
ptrace
xpath-1.0
javax.sound.midi
varargs
graph-drawing
proj4js
inmobi
coldbox
tt-news
id3v2
issuu
xojo
typeof
xceed-datagrid
dealloc
algebraic-data-types
access-rights
html4
mylyn
enterprisedb
android-hardware
simba
gdata-api
newtonscript
amazon-appstore
mod-auth
sudzc
subviews
gamequery
revisions
dbal
libs
caching-application-block

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App