After looking around and seeing not much on the accelerometer widget I though I would ask, all I want it todo is display the position of the phone in x,y,z however I can only get the value to change from 0 when I move the phone rapidly. Is there anything I am doing wrong or is this not what the accelerometer is intended for in Blynk
• Arduino with HM-10 Bluetooth module
• iPhone X with iOS 11.2 also tested on an iPod touch 6th generation
• local server
• Blynk Library version
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "----";
SoftwareSerial SerialBLE(2,3); // RX, TX
const int ledPin = 5;
int ledState = LOW;
void setup()
{
// Debug console
Serial.begin(9600);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
Serial.println("Waiting for connections...");
}
BLYNK_WRITE(V0) {
int x = param[0].asFloat();
int y = param[1].asFloat();
int z = param[2].asFloat();
Serial.println(x);
Serial.println(y);
Serial.println(z);
}
BLYNK_WRITE(V2) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
Well, the accelerometer returns the accelerations, not the positions. That’s why when you moved fast you saw a big value, because you gave your phone a big acceleration.
In theory you could double-integrate the acceleration to get the position, but the bias on the accelerations will make the estimation of the velocity (one integration) and position to drift. The velocity will drift linearly. The position will drift quadratically.
How would I go about doing that?, I was wanting to use the accelerometer to control a robot so tilting the phone forward will move the robot forward etc, is there a widget I can achieve that with or is this something out with blynks functionality
So you don’t need the position of the phone, but it’s attitude.
With accelerometers + gyroscopes + mag you’d be able to implement an attitude estimation filter, but there are only accelerometers in blynk.
With accelerometers only you can implement a very rough attitude estimation, knowing that the actual acceleration (if not moving the phone fast) is only due to the gravity. Then comparing the acceleration vector with the gravity vector you can estimate an orientation of the phone except the rotation around the gravity vector, because that is a symmetry for the system.
So the only way to do what I am trying todo is use the MPU6050 or create my own app to access these functions in my phone?
The only problem with trying that is I am unable to get any value out of the phone with out moving it fast so I could only move my robot with fast movements
If you need only roll and pitch movements, for example to go forward backward and left right you might be able to do it.
BTW you should get a value around 9.81 also when the phone is still. Isn’t it? Can you post the println of your file and put the frequency of the accelerometer the highest you can on the app?
On the app you cannot configure the frequency of the accelerometer.
This is what I get from my serial monitor when the phone is flat
[0]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.1 on Arduino Uno
[82] Connecting...
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
-1
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
-1
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
0
x value is
0
y value is
0
z value is
-1
x value is
0
y value is
0
z value is
-1