兴趣之余,利用晚上的时间,做一些个人兴趣方面的开发. 之前没接触过 arduino, 无意之中买了个开发板做一些小开发, 这里利用python 读取 mpu9250 数据实时绘图.
下位机代码 C++
void Serial_SendDataPython( int16_t *sendData, uint8_t lens )
{
uint8_t tmpData[32] = {0}; //tmpData lens >= 2 * lens + 4
uint8_t *ptrData =tmpData;
uint8_t dataBytes= lens << 1;
uint8_t dataLens= dataBytes + 4;
uint8_t count= 0;
uint16_t tmpSum= 0;
tmpData[0] = 'S';while(count > 1]);//tmpData[count+2] = Byte8L(sendData[count >> 1]);
tmpData[count+1] = (sendData[count >> 1])>>8;
tmpData[count+2] = (sendData[count >> 1])&0x00ff; ;
count= count + 2;
}for(uint8_t i = 0; i < dataBytes; i++)
tmpSum+= tmpData[i+1];
tmpData[dataLens- 3] = (uint8_t)(tmpSum & 0x00FF);
tmpData[dataLens- 2] = '\r';
tmpData[dataLens- 1] = '\n';do{//Serial_SendByte(*ptrData++);
Serial.write(*ptrData++);
}while(--dataLens);
}
....................................
IMU_Buf[0] = testLostRate++;
MU_Buf[1] = ax/2;
IMU_Buf[2] = ay/2;
IMU_Buf[3] = az/2;
IMU_Buf[4] = gx/2;
IMU_Buf[5] = gy/2;
IMU_Buf[6] = gz/2;
IMU_Buf[7] =