Created
June 2, 2016 19:31
-
-
Save ubi-gists/a51ab0cae7b4a224d54d0f9a5d74d566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MPU-6050 Short Example Sketch | |
// By Arduino User JohnChi | |
// Modified by Mateo Vélez - Metavix | |
#include <ubidots_arduinoYUN.h> | |
#include <Process.h> | |
#include<Wire.h> | |
const int MPU=0x68; //dirección I2C del MPU-6050 | |
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; | |
String api = "5ca9ba0038a49e0492c6794f9043a0918ddcbd26"; //tu API key | |
String idvari = "53badbd77625a25f8665d11b"; //tu ID de la variable a modificar | |
Ubidots ubiclient(api); | |
int reset = 0; | |
void setup(){ | |
Bridge.begin(); | |
Console.begin(); | |
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); | |
while (!Console); //se espera a que se establezca la conexión wireless | |
Console.println("Ubidots client"); | |
ubiclient.ubitoken(api); //se hace una petición de token a la API | |
reset = 0; | |
} | |
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) | |
Console.print("AcX = "); Console.print(AcX); | |
Console.print(" | AcY = "); Console.print(AcY); | |
Console.print(" | AcZ = "); Console.print(AcZ); | |
ubiclient.save3_values("54299d5b7625425c68294d5b",String(AcX),"54299d667625425a05c44e68",String(AcY),"54299d727625425a8d471bce",String(AcZ)); | |
reset++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment