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

Can I take solar panel's output as an input to Arduino
I cannot find UID of my Arduino
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

Categories

HOME
compiler-construction
image
wso2
heroku
single-sign-on
octobercms
youtube-dl
rsyslog
gis
binary-tree
portia
u-sql
quickbooks
windows-phone-7
dtrace
decomposition
libtiff
solaris-10
sms-gateway
zapier
riot.js
tokenize
accessor
h2db
semantic-analysis
phpfox
neo4j-spatial
ping
compatibility
kendo-datasource
unboundid
twilio-api
commit
rotational-matrices
amazon-kinesis-kpl
nssegmentedcontrol
sharefile
c11
android-fingerprint-api
opshub
midl
mime
heightmap
s
scorm
avconv
taffy
parentheses
prolog-setof
errordocument
hendrix
dandelion
mu
drupal-6
nativeapplication
capacity
specrun
nxt
android-textview
bonobo
skobbler-maps
nsfilemanager
paypal-express
storekit
moveit
packagist
yaws
oauth2client
jqgrid-formatter
tarjans-algorithm
microbenchmark
twirl
system.reflection
facebook-graph-api-v2.4
fscommand
block-device
phalanger
websocket4net
internet-connection
transcoding
resty-gwt
stxxl
dbconnection
gwt-rpc
drools-planner
clipper
frameset
onsubmit
bubble-chart
gnu-prolog
stage
external-accessory
hirefire
appender
self-extracting
netbeans-7.1
jmock
sortable-tables
gallio
jquery-ui-droppable
nhibernate.search
forums
ext3
virtual-functions
temporal-database
sustainable-pace
mediarss
genealogy
commodore

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App