Arduino nano 数据点缺失

Arduino nano data points missing

感谢您帮助我解决了我之前的问题。 我现在可以使用腻子将数据从 arduino 获取到 PC,FSR 连接到鞋底并检测压力。

我现在面临的唯一问题是,它似乎时不时缺少脚跟撞击和脚趾离地的情况。(附图片)Plot of data

蓝线代表脚跟 FSR 的数据,红线代表脚趾 FSR 从图中可以看出,arduino 在蓝色峰值 3 处缺少脚跟撞击,在红色峰值 5 处缺少脚趾离地瞬间。

任何人都可以告诉我为什么经常发生这种情况.. 我正在使用波特率 9600 和 2 FSR 的 arduino nano ..将波特率增加到 38400 以上时,丢失似乎更频繁地发生

/** 代码使用来自 FSR 的数据查找脚趾离地和脚后跟撞击的实例*/

    void setup()
    {

      /*************************************************SERIAL**************************************************/
      Serial.begin(9600);


    }

    /*Variables for FSRS*/
    //A0= Toe,A1=Heel
    int  sum_toe_max = 0,sum_toe_min = 0, sum_heel_max = 0, sum_heel_min = 0  ,toe, heel, temp,diff_toe,diff_heel,data_heel=0, data_toe=0,              data_toe2, data_heel2 ;
    int heel_max[5] = {0, 0, 0, 0, 0}, toe_max[5] = {0, 0, 0, 0, 0}; /*These arrays holds the top 5 maximas upto the time of calibration*/
    int heel_min[5]= {100,100,100,100,100}, toe_min[5]={100,100,100,100,100};/*These arrays holds the top 5 maximas upto the time of            calibration*/
    float avg_heel_max,avg_heel_min,avg_toe_max,avg_toe_min;/*variables to hold the averages of the valus of max and min arrays*/
    float UL=0.80,LL=0.05;/* Setting the Limiters*/
    int counter_toe_max = 0, counter_heel_max = 0,counter_toe_min = 0, counter_heel_min = 0;//counter for the number of H and T occured 
    int cal_limit = 10;/*time for which calibration should go on*/
    int timer = 0;/*stores the time elapsed*/

    void loop()
    {

      read_FSR();//Call The FSR function
      //read_acc();


    }


    /*********************************************FSR_TOE***********************************************/
                      /*Function to read the FSR_TOE data and save to SD*/
                      void read_FSR()
                      {


                          data_toe = analogRead(A0);
                          data_heel = analogRead(A1);
                          timer = millis() / 1000;

                          Serial.print(millis());
                          Serial.print(" ");                             
                          Serial.print(data_toe);
                          Serial.print(" ");
                          Serial.println(data_heel);     






                          /*Calibration and finding the maxima uptil cal_limit seconds.*/
                          if (timer < cal_limit)
                          {


                            /*TOE calibration*/

                            /*To find the top 5 max pressures*/
                            if (data_toe > toe_max[counter_toe_max])
                            {
                              toe_max[counter_toe_max] =data_toe;                                                                                                   
                              counter_toe_max = counter_toe_max + 1;


                            }
                            if (counter_toe_max >= 5)
                            {
                              counter_toe_max = 0;
                            }



                            /*To find the top 5 min pressures*/
                            if (data_toe < toe_max[counter_toe_min])
                            {
                              toe_min[counter_toe_min] = data_toe;                                  
                              counter_toe_min = counter_toe_min + 1;

                            }
                            if (counter_toe_min >= 5)
                            {
                              counter_toe_min = 0;
                            }

                            /*HEEL FSR calibration*/
                            /*To find the top 5 max pressures*/

                            if (data_heel > heel_max[counter_heel_max])
                            {
                              heel_max[counter_heel_max] =data_heel;                                                                                                          
                              counter_heel_max = counter_heel_max + 1;

                            }
                            if (counter_heel_max >= 5)
                            {
                              counter_heel_max = 0;
                            }


                            /*To find the top 5 min pressures*/
                            if (data_heel < heel_min[counter_heel_min])
                            {
                              heel_min[counter_heel_min]=data_heel; =                                                                           
                              counter_heel_min = counter_heel_min + 1;

                            }
                            if (counter_heel_min >= 5)
                            {
                              counter_heel_min = 0;
                            }


                          }




                          /*Displaying the maximum and minimum valus array and finding the averages for both the FSR's*/
                          if (timer == cal_limit && temp == 0)
                          {


                            /*Finding sum of the array elements*/
                            for (int i = 0; i < 5; i++)
                            {
                              sum_toe_max = sum_toe_max + toe_max[i];
                              sum_toe_min = sum_toe_min + toe_min[i];


                            }

                            for (int i = 0; i < 5; i++)
                            {
                              sum_heel_max = sum_heel_max + heel_max[i];
                              sum_heel_min = sum_heel_min + heel_min[i];


                            }

                            avg_toe_max = sum_toe_max / 5;/*dividing by 5 to get the avg of the 5 values*/
                            avg_toe_min = sum_toe_min / 5;


                            avg_heel_max = sum_heel_max / 5;
                            avg_heel_min = sum_heel_min / 5;

                            diff_toe = avg_toe_max-avg_toe_min;/*difference between maximas and minimas*/
                            diff_heel = avg_heel_max-avg_heel_min ;




                            Serial.println();
                            Serial.print(F("Avg ToePress max "));
                            Serial.println(avg_toe_max);
                            Serial.print(F("Avg ToePress min "));
                            Serial.println(avg_toe_min);
                            Serial.print(F("Avg HeelPress max "));
                            Serial.println(avg_heel_max);
                            Serial.print(F("Avg HeelPress min "));
                            Serial.println(avg_heel_min);
                            Serial.print(F("Diff in avg toe press:"));
                            Serial.println(diff_toe);
                            Serial.print(F("Diff in avg heel press:"));
                            Serial.println(diff_heel);
                            Serial.print(F("Target HeelPress "));
                            Serial.println(UL*(avg_heel_max-avg_heel_min));
                            Serial.print(F("Target ToePress "));
                            Serial.println(LL*(avg_toe_max-avg_toe_min));


                            temp = temp + 1;
                          }
                          /*Done with calibration( when timer =10s)*/




                          /*Checking the oncoming data for a condition of Toe Off
                            Consider it as a toe off if the normalised value of data_toe i.e (data_toe-avg_toe_min)/diff_toe
                            at the previous instant is greater than LL(Lower Limit) i.e 0.2 times the differnce between the                         averages of max and min of toe FSR 
                            and the normalised value of data_toe2 at the current instant is lesser than the same*/

                          if (timer > cal_limit && (data_toe-avg_toe_min)/diff_toe > LL)
                          {
                            data_toe2 = analogRead(A0);/*Data toe at the current instant*/

                            if ((data_toe2-avg_toe_min)/diff_toe < LL)
                            {

    //                                      
                                  Serial.print(timer*1000);
                                  Serial.print(" ");
                                  Serial.print(("f t T "));
                                  Serial.print(data_toe);
                                  Serial.print("Avg min ");
                                  Serial.print(avg_toe_min);
                                  Serial.print("Diff ");
                                  Serial.print(diff_toe);
                                  Serial.println(" TOE");




                            }


                          }

                          /*Checking the oncoming data for a condition of Heel Stike
                            Consider it as a Heel Strike if the normalised value of data_heel i.e (data_heel2-avg_heel_max)/diff_heel
                            at the previous instant is lesser than UL(Lower Limit) i.e 0.8 times the differnce between the                          averages of max and min of heel FSR 
                            and the normalised value of data_heel2 at the current instant is greater than the same*/

                        if(timer>cal_limit && (data_heel-avg_heel_min)/diff_heel<=UL)
                          {

                            data_heel2=analogRead(A1);/*Data heel at the current instant*/
                            if((data_heel2-avg_heel_min)/diff_heel>=UL)
                            {


                                Serial.print(timer*1000);
                                Serial.print(" ");
                                Serial.print(("f t H "));
                                Serial.print(data_heel);
                                Serial.print(" HEEL");
                                Serial.println(UL);
                                Serial.flush();





                            }

                          }





                      }

您定义了 String arr[2][2]={{""}}; 但稍后使用 arr[SD_savr][3]="TO";arr[SD_savr][4]=Y[0];arr[SD_savr][3]="HS"; 访问它,这是越界并导致 未定义的行为,这可能是您重置的原因。

当你删除 SD 使用时,你能否也删除 #include 这会影响您的内存要求吗? (甚至是不良行为?) 冻结而不是重置通常是相同的原因,只是命中了其他地址。 ;)

我看不到当前代码有任何数组越界问题,但那是我要 double/triple 检查的地方...

其他问题:

  • I2C (Wire):您请求 14 个字节,但只读取了其中的 2 个? ...
  • start 是一个浮点数? dt应该是0.0,我猜