Connecting MPU6050 with cayenne

hi all!

I am new to IOT, I am doing this DIY project (fall detector) in which i have to connect my (accelerometer+gyroscope) MPU6050 sensor with cayenne so that whenever a fall occurs mpu6050 generates trigger and i get a notification. but the problem is I am unable to find it under listed sensors. I have even tried generating my own generic sensor widget/device using digital/analogue input but seems like i am unable to go to the next steps of adding it. I am using NodeMcu esp8266 12E and mpu6050 only.

Have you got the MPU6050 working with nodemcu without cayenne code? can you share the code you are using for it.

I have used mpu6050 with Arduino Nano and bluetooth module it works fine .

#include <MPU6050.h>

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <ESP8266WiFi.h>

#include <Wire.h>

MPU6050 mpu;

boolean freefallDetected = false;

//char token = “”; //fill the token of cayenne
char ssid = “"; //fill with wifi ssid
char pwd[*] = "
”; //fill with wifi password
char username = “2d4";
char password[] = "c24
d8";
char clientID[] = "
******”;

void setup()
{
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, pwd);
Serial.println(“Initialize MPU6050”);

while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))
{
Serial.println(“Could not find a valid MPU6050 sensor, check wiring!”);
delay(500);
}

mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);

mpu.setIntFreeFallEnabled(true);
mpu.setIntZeroMotionEnabled(false);
mpu.setIntMotionEnabled(false);

mpu.setDHPFMode(MPU6050_DHPF_5HZ);

mpu.setFreeFallDetectionThreshold(17);
mpu.setFreeFallDetectionDuration(2);

checkSettings();

attachInterrupt(12, doInt, RISING);
}

void doInt()
{
freefallDetected = true;
}

void checkSettings()
{
Serial.println();

Serial.print(" * Sleep Mode: ");
Serial.println(mpu.getSleepEnabled() ? “Enabled” : “Disabled”);

Serial.print(" * Motion Interrupt: ");
Serial.println(mpu.getIntMotionEnabled() ? “Enabled” : “Disabled”);

Serial.print(" * Zero Motion Interrupt: ");
Serial.println(mpu.getIntZeroMotionEnabled() ? “Enabled” : “Disabled”);

Serial.print(" * Free Fall Interrupt: ");
Serial.println(mpu.getIntFreeFallEnabled() ? “Enabled” : “Disabled”);

Serial.print(" * Free Fal Threshold: ");
Serial.println(mpu.getFreeFallDetectionThreshold());

Serial.print(" * Free FallDuration: ");
Serial.println(mpu.getFreeFallDetectionDuration());

Serial.print(" * Clock Source: ");
switch (mpu.getClockSource())
{
case MPU6050_CLOCK_KEEP_RESET: Serial.println(“Stops the clock and keeps the timing generator in reset”); break;
case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println(“PLL with external 19.2MHz reference”); break;
case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println(“PLL with external 32.768kHz reference”); break;
case MPU6050_CLOCK_PLL_ZGYRO: Serial.println(“PLL with Z axis gyroscope reference”); break;
case MPU6050_CLOCK_PLL_YGYRO: Serial.println(“PLL with Y axis gyroscope reference”); break;
case MPU6050_CLOCK_PLL_XGYRO: Serial.println(“PLL with X axis gyroscope reference”); break;
case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println(“Internal 8MHz oscillator”); break;
}

Serial.print(" * Accelerometer: “);
switch (mpu.getRange())
{
case MPU6050_RANGE_16G: Serial.println(”+/- 16 g"); break;
case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break;
case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break;
case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break;
}

Serial.print(" * Accelerometer offsets: “);
Serial.print(mpu.getAccelOffsetX());
Serial.print(” / “);
Serial.print(mpu.getAccelOffsetY());
Serial.print(” / ");
Serial.println(mpu.getAccelOffsetZ());

Serial.print(" * Accelerometer power delay: ");
switch (mpu.getAccelPowerOnDelay())
{
case MPU6050_DELAY_3MS: Serial.println(“3ms”); break;
case MPU6050_DELAY_2MS: Serial.println(“2ms”); break;
case MPU6050_DELAY_1MS: Serial.println(“1ms”); break;
case MPU6050_NO_DELAY: Serial.println(“0ms”); break;
}

Serial.println();
}

void loop()
{
Cayenne.run();
}

CAYENNE_OUT(V8)
{
Vector rawAccel = mpu.readRawAccel();
Activites act = mpu.readActivites();

if (freefallDetected)
{
Cayenne.virtualWrite(V8, act.isFreeFall); //virtual pin
delay(100);
}
}

what does this line does?

i have taken above code from online source as my coding is not good. but it works fine with nodemcu and MPU6050. I can see data on serial monitor changing. I am unable to add any widget that can read data and send to cayenne. Issue is the code cayenne gives me to burn on my device inorder to create a widget is not working . I am having errors regarding libraries. Whenever I solve one error it gives another . all are regarding libraries of cayenne.

share the error you are getting, will be helpful to solve.

I have downloaded the libraries using arduino .

try deleting and adding the library from guthub https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino

Same error is popping up.

try uploading this code and share the entire error.


try this code.

Your code is working now how may I display the data I am getting from my code.

Just add the MPU6050 code in the above code.

while changing this:

CAYENNE_OUT(V8)
{
Vector rawAccel = mpu.readRawAccel();
Activites act = mpu.readActivites();

if (freefallDetected)
{
Cayenne.virtualWrite(V8, 1, "digital_sensor", "d"); //virtual pin
delay(100);
}
}
1 Like

Love you man! you are a life savior. It is working.

1 Like

great to hear that, would be great if you can share your project with the community.

It isn’t my project, I am new to IOT so I was doing an already done project to learn things. I can not call it my project but I can share its link.

But believe me it was quite difficult without your guidance. Thanks again.

2 Likes