How do I link my MPU6050 to cayenne?

I have a MPU6050 3 axis accel/ 3 axis gyro (has an onboard ADC) that I have working on python and wanted to use this with cayenne.

How would I set up cayenne to allow communication?
I currently have the MPU6050 wired to sda (pin 3) and scl (pin5)

Hi again @hoang.tony.p,

Good to see you around! Unfortunately, it is not possible right now. We will be releasing Arduino integration soon, then we will work on giving users the ability to bring on any device for Raspberry Pi. This way, you are not waiting on the Cayenne team to integrate devices into the system. Hope this helps!

-B

Is there an ETA for arduino integration? Thanks

This upcoming week :slight_smile:

-B

Hi, I know this is an old post but interested if you found a solution to get the MPU6050 to communicate with Cayenne? Thanks.

which device are you using to connect to cayenne. we can try together to send MPU6050 value to cayenne.

Thank you for responding! I’m using an ESP 8266. I am able to connect to Cayenne with this board and am sending temp and humidity data.

can you share the code and a link to the ESP8266 board.

link to board:
https://hiletgo.com/products/hiletgo-new-version-esp8266-nodemcu-lua-cp2102-esp-12e-internet-wifi-development-board-open-source-serial-wireless-module-works-great-with-arduino-ide-micropython

//this is the code I’m using to connect to Cayenne to send temp and humidity ( I removed wifi and Cayenne authentication info)

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <DHT.h>

// WiFi network info.
char ssid = “”;
char wifiPassword = “”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “”;
char password = “”;
char clientID = “”;

DHT dht(D2, DHT11);

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
float temp = dht.readTemperature(true); //Fahrenheit
float hum = dht.readHumidity();
Cayenne.virtualWrite(1, temp, TYPE_TEMPERATURE, UNIT_FAHRENHEIT);
Cayenne.virtualWrite(2, hum, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
}

I tried editing the code I found here at this Cayenne Community link to use with the board I’m using including revising code to MQTT format.

were you succesfull at it?

no, I could not make that code work.

can you post the code. before that try connecting MPU6050 to nodemcu and code without cayenne lines. just to check whether you are getting reading from MPU6050.

the following is a stripped down version of the sketch file I was editing. I removed the math calculations from the code. I was basically trying to edit the code down enough just to get board to connect to Cayenne. I am a beginner to all of this (less than 2 weeks) so I’m sure there are coding errors and omissions in this example. I left the dht11 temp/humidity code in the sketch but I don’t really need it. My main goal is to get the x/y/z data to the Cayenne dashboard via wifi board.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <DHT.h>
#include <Wire.h>
#include <Math.h>
#include <I2Cdev.h>
#include <MPU6050.h>

//#define VIRTUAL_PINX V2
const int VIRTUAL_PINX = 3;
//#define VIRTUAL_PINY V3   
const int VIRTUAL_PINY = 4;

MPU6050 accelerometer;


// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

DHT dht(D2, DHT11);

void setup() {
		Serial.begin(9600);
    Wire.begin();
  
	  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
    
    accelerometer.initialize(); 
}

void loop() {
	Cayenne.loop();
 float temp = dht.readTemperature(true); //Fahrenheit
 float hum = dht.readHumidity();
 Cayenne.virtualWrite(1, temp, TYPE_TEMPERATURE, UNIT_FAHRENHEIT);
 Cayenne.virtualWrite(2, hum, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);

 float angle_x = accelerometer.getAcceleration();
 Cayenne.virtualWrite(3, angle_x);
// Cayenne.virtualWrite(4, angle_y);
}

these are the errors from the Audrino IDE;

Arduino: 1.8.5 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

C:\Users\Documents\Arduino\MyESP8266ODHT11AXIS\MyESP8266OfficeDHT11MPU6050\MyESP8266OfficeDHT11MPU6050.ino: In function ‘void loop()’:

MyESP8266OfficeDHT11MPU6050:48: error: no matching function for call to ‘MPU6050::getAcceleration()’

float angle_x = accelerometer.getAcceleration();

                                            ^

C:\Users\Documents\Arduino\MyESP8266ODHT11AXIS\MyESP8266OfficeDHT11MPU6050\MyESP8266OfficeDHT11MPU6050.ino:48:48: note: candidate is:

In file included from C:\Users\Documents\Arduino\MyESP8266ODHT11AXIS\MyESP8266OfficeDHT11MPU6050\MyESP8266OfficeDHT11MPU6050.ino:11:0:

C:\Users\Documents\Arduino\libraries\MPU6050/MPU6050.h:625:14: note: void MPU6050::getAcceleration(int16_t*, int16_t*, int16_t*)

     void getAcceleration(int16_t* x, int16_t* y, int16_t* z);

          ^

C:\Users\Documents\Arduino\libraries\MPU6050/MPU6050.h:625:14: note: candidate expects 3 arguments, 0 provided

Multiple libraries were found for “CayenneMQTTESP8266.h”
Used: C:\Users\Documents\Arduino\libraries\CayenneMQTT
Not used: C:\Users\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Not used: C:\Users\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Not used: C:\Users\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Not used: C:\Users\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master
Multiple libraries were found for “Adafruit_Sensor.h”
Used: C:\Users\Documents\Arduino\libraries\Adafruit_Sensor-master
Not used: C:\Users\Documents\Arduino\libraries\Adafruit_Unified_Sensor
exit status 1
no matching function for call to ‘MPU6050::getAcceleration()’

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

try this code and see if you get reading. check your serial monitor for reading.

#include "Wire.h"
#include "Math.h"
#include "I2Cdev.h"
#include "MPU6050.h"
 
MPU6050 accelerometer;

const float pi = 3.141592;
const int avg_max = 100;
int16_t ax, ay, az;
float x, y, z;
int avg_count;
float _angle_x, angle_x, _angle_y, angle_y;
long ax_avg, ay_avg, az_avg;

void setup() {

    Serial.begin(9600);   
    Wire.begin();  
    accelerometer.initialize();    
    if (accelerometer.testConnection()) {
        Serial.println("Accelerometer Connected...");  
    }
}
 
void loop() {
    //read accelerometer
    accelerometer.getAcceleration(&ax, &ay, &az);  

    //accumulate averages
    ax_avg = ax_avg + ax;
    ay_avg = ay_avg + ay;
    az_avg = az_avg + az;
    avg_count++;

    //got all the sample?
    if (avg_count == avg_max)
    {
     //calculate averages
     x = ax_avg/avg_max;
     y = ay_avg/avg_max
     z = az_avg/avg_max

     //compute angles
     angle_x = atan2(x, sqrt(square(y) + square(z))      )/(pi/180);
     angle_y = atan2(y, sqrt(square(x) + square(z))      )/(pi/180);

     //initialize for next pass
     avg_count = 0;
     ax_p = 0;
     ay_p = 0;
     az_p = 0;   

    //print results
    Serial.print(angle_x);
    Serial.print("\t"); 
    Serial.println(angle_y);

    }   
}

this line of code
angle_x = atan2(x, sqrt(square(y) + square(z)) )/(pi/180);

got this error when compiling

Arduino: 1.8.5 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

C:\Users\Documents\Arduino\MyESP8266ODHT11AXIS\sketch_may07a\sketch_may07a.ino: In function ‘void loop()’:

sketch_may07a:45: error: ‘square’ was not declared in this scope

  angle_x = atan2(x, sqrt(square(y) + square(z))      )/(pi/180);

                                  ^

sketch_may07a:50: error: ‘ax_p’ was not declared in this scope

  ax_p = 0;

  ^

sketch_may07a:51: error: ‘ay_p’ was not declared in this scope

  ay_p = 0;

  ^

sketch_may07a:52: error: ‘az_p’ was not declared in this scope

  az_p = 0;   

  ^

exit status 1
‘square’ was not declared in this scope

do some google search and find ways to connect MPU6050 to nodemcu.

have a look at this MPU6050 Interfacing with NodeMCU | NodeMCU