Hi, im having a trouble with printing data from the arduino to my phone, but somehow its very glitchy.
Its a test for my MPU6050 and i want to print my results on the phone
Heres some code and a picture of my problem
arduino code:
#include <MPU6050.h>
MPU6050 mpu;
#define EXPIRED                    true
#define stillTIMING                false
#define LEDon                      HIGH   
#define LEDoff                     LOW
#define PUSHED                     HIGH    
#define RELEASED                   LOW
#define CLOSED                     LOW   
#define OPEN                       HIGH
#define ENABLED                    true
#define DISABLED                   false
#define YES                        true
#define NO                         false
const float thresholdForce = 5.0;
const unsigned long resetInterval = 500;
static float peakForce = 0, lastPeakForce = 0;
static unsigned long lastPeakMs = 0;
//const int arraySize = 200; //array size
//float dataArray[arraySize]; // array for storing values
//byte currentIndex = 0; // current index of the array
struct makeTIMER
{
  unsigned long Time;           //when the TIMER started
  unsigned long Interval;       //delay time in ms which we are looking for
  bool          timerFlag;      //is the TIMER enabled ? ENABLED/DISABLED
  bool          Restart;        //restart this TIMER ? YES/NO
  //****************************************
  //fuction to check if the TIMER is enabled and check if the TIMER has expired
  bool checkTIMER()
  {
    //*********************
    //is this TIMER enabled and has this TIMER expired ?
    if (timerFlag == ENABLED && millis() - Time >= Interval)
    {
      //*********************
      //should this TIMER restart again?
      if (Restart == YES)
      {
        //restart this TIMER
        Time = millis();
      }
      //this TIMER is enabled and has expired
      return EXPIRED;
    }
    //this TIMER is disabled and/or has not expired
    return stillTIMING;
  } //END of   checkTime()
}; //END of   struct makeTIMER
makeTIMER forceChecker =
{
  0, 500ul, ENABLED, NO      //Time, Interval, timerFlag, Restart
};
makeTIMER delayValue =
{
  0, 25ul, ENABLED, NO      //Time, Interval, timerFlag, Restart
};
void setup() {
  Serial.begin(115200);
  Serial.begin(9600);
  
  Wire.begin();
  mpu.initialize();
  
  //measure range of mpu6050(±16g)
  mpu.setFullScaleAccelRange(3);
  delay(1000);
}
void loop(){
  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);
  
  // measuring accel
  float gForceX = (float(ax) / 32767.0) * 16.0;
  float gForceY = (float(ay) / 32767.0) * 16.0;
  float gForceZ = (float(az) / 32767.0) * 16.0;
  
  float accelX = gForceX * 9.81;
  float accelY = gForceY * 9.81;
  float accelZ = gForceZ * 9.81;
  float accelTotal = (sqrt(pow(accelX, 2) + pow(accelY, 2) + pow(accelZ, 2))) - 9.81;
  //accelTotal = 1+analogRead(A0)*4.0/1023; // simulate with A0 pot
  float myForce = accelTotal;
  if (myForce > thresholdForce && myForce > peakForce){
    peakForce = myForce;
    lastPeakForce = peakForce;
    lastPeakMs = millis();
    Serial.println(lastPeakForce);
    forceChecker.Time = millis();
    
  }
//  if(millis() - lastPeakMs > resetInterval && peakForce > 0){
  if(forceChecker.checkTIMER() && peakForce > 0){
    peakForce = 0;
    Serial.println(lastPeakForce); //print on phone
  }
}
Designer:
Picture of my problem:













 



