绘制使用mpchart获取的60hz数据信号

时间:2017-11-22 12:20:14

标签: android graph bluetooth signal-processing mpandroidchart

Hy先生,我通过arduino的adc获取60hz信号并向我的应用发送浮动缓冲区。当我将数据从arduino导出到csv文件时一切正常,波形的形状非常好,但是当我尝试使用mpchart libs在我的应用程序中绘制缓冲区时,它会变得有点破碎。有谁能帮我解决这个问题? Bellow遵循我的代码和图表的图像

Arduino的代码:

array = inputarray[:]

蓝牙接收功能

#include "SoftwareSerial.h"
#define sensorPin A1


#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void setup() {
  //configure pins 14,15 of arduino mega to serial TX/RX respectively
  SoftwareSerial bluetooth(14, 15);


  //configure AD pins for 9600 hz;
  sbi(ADCSRA, ADPS2);
  sbi(ADCSRA, ADPS1);
  sbi(ADCSRA, ADPS0);
  Serial1.begin(9600);
}

void loop() {
  while (1) {
    float vector[400];
    int i = 0;
    for (int i = 0; i < 400; i++) {
      vector[i] = floatMap(analogRead(sensorPin), 0, 1023, 0, 5);
    }
    for (int i = 0; i < 400; i = i++) {
      Serial1.print('#');
      Serial1.print(vector[i],2);
      delay(30);
    }
  }
}


float floatMap(float x, float inMin, float inMax, float outMin, float outMax) {
  return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}

int procura_inic(int vector[]) {
  for (int i = 0; i < 319; i++) {
    if (vector[i] == 0 && (vector[i + 1] > vector[i])) {
      return i;
      break;
    }
  }
}

跟踪功能

 public void run() {
                byte[] buffer = new byte[1024];  // buffer store for the stream
                int bytes = 0;
                int begin = 0;// bytes returned from read()
                while (true) {
                    try {

                        bytes += mmInStream.read(buffer, bytes, buffer.length - bytes);
                        //This loop is responsible for  message sending.
                        for(int i = begin; i < bytes; i++) {
                                mHandler.obtainMessage(
                                        MESSAGE_READ, begin, i, buffer).sendToTarget();
                                begin = i + 1;
                                if(i == bytes - 1) {
                                    bytes = 0;
                                    begin = 0;
                                }
                        }

                    } catch (IOException e) {
                        break;
                    }
                }
            }

enter image description here

0 个答案:

没有答案