Accelerometer Programming in Photon

Hi there,

I am hoping to program an accelerometer with my photon and there doesn’t seem to be a reference in the library on particle build. I am very new to the programming world and would really appreciate any direction as to how to program this device for my photon.

This following is the link to the Accelerometer I purchased.

Thanks!

The library seems to have three examples which you can take a look at. https://build.particle.io/libs/5689c0b84ceb31271d0001ab/tab/example-mpu-dump-to-serial.cpp
Without more specific questions, I’m not sure if there’s much we can tell you right now.

Also a search in the forum for keywords like MPU6050 might bring up some info to checkout before re-asking already answered questions
https://community.particle.io/search?q=mpu6050

@Lyter, I also have a port of a MPU6050 library in my github here.

1 Like

I meant to add that I will be using it to determine wave height attached to something like a boat bumper. Thanks very much for the references, I will take a further look into them!!

With regards to more information I am hoping to use the MPU-6050 with my photon to determine wave height. Not sure if you have any further recommendations for me?

Thank you for the link, and your input!

Recieving Null Values

Has anyone been able to send values to the particle cloud? I have GY88 that works just fine with my ESP8266 and my Arduino however I get zero's when I send it to Particle.

Can you get correct values over Serial?

Also the code you’re using to send the data would be good to see.
There are loads of ways to do that and at least as many to do it wrong.

As per BKM (Best known method provided in the documentation)

Here I create the accelerometer class:
// MPU variables:
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

int16_t prev_ax, prev_ay, prev_az;
int16_t prev_gx, prev_gy, prev_gz;

Then I just have a function that is called intermittently to get the data and push it to particle. Here is a basic example.

void reportAccelerometerData()
{
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    Particle.publish("ACY", String(int(ay)));
}

Unfortunately I can’t get the ATOM ide to play too nicely with my Linux box so getting serial data is a bit of a challenge. Could it be that it’s not getting properly converted to a string from an int16?

This might be the easy (to document) method, but it's not BKM :wink:

This is neither, but it's definetly better

  char data[64];
  snprintf(data, sizeof(data), "%4d / %4d / %4d", ax, ay, az);
  Particle.publish("Acc", data, PRIVATE);
  // optional to obey the rate limit
  // delay(1000);

Ah thanks!! :wink:

I’m much more of a Python dev so pushing data into a character buffer/array always is something that I forget about. I’ll give that a try!

How do I read the temperature values of MPU6050 with particle photon.
Here is a video of reading temperature with arduino and MPU6050.

You’ve got a video and code for Arduino, as well as the library.
You’ve got a library for that chip on Particle as well. Have you taken a look at it?