繁体   English   中英

Arduino USB 到 Raspberry Pi (Rasbian) 的串行连接未初始化

[英]Arduino USB serial connection to Raspberry Pi (Rasbian) not initializing

我有一个 Arduino Nano 33 iot,它通过串行以 38400 波特输出数据,通过 USB 连接。 安装程序从 Serial.Begin 开始。 运行 Raspian buster 的 Raspberry Pi 4 设置为接收数据。 它可以看到正确的端口 /dev/ttyACM0,但什么也没有。

我什至在树莓派上安装了正确的 Arduino IDE 和 SAMD 板 package。 直到 IDE 上传替换草图并重置 CPU 后,它仍然找不到它。 IDE 可以获取序列号和板类型。 然后我可以退出 IDE 并且 Arduino 仍在向 Raspberry Pi 输出串行。

使其工作的唯一其他方法是每次在 Raspberry Pi 上重新启动时按下 Arduino 上的重置按钮。 串行在 Pi 上使用屏幕进行了测试。

这些选项都不方便。 我错过了什么?

 /*
Connects via I2C to a CMPS14, outputs NMEA0183 HDM sentences via Serial (38400 baud)
   By James Henderson, 2014, adapted to output NMEA sentences by Ian Van Schaick
*/
#include <Keyboard.h>
#include <Wire.h>

#define CMPS14_ADDRESS 0x60  // Address of CMPS14 shifted right one bit for arduino wire library
#define ANGLE_8  1           // Register to read 8bit angle from


unsigned char high_byte, low_byte, angle8;
signed char pitch, roll;
float angle16;
int fine;
float bearingH; // Holds whole degrees of bearing
float bearingL; // Holds decimal digits of bearing
int bearing;
char nbsp;
char mystring[25];
char mystring2[25];
char mystring3[25];
int software;
int cal;
unsigned int _last_status;

uint8_t checksum(char *s)
{
  uint8_t c = 0;

  while (*s)
    c ^= *s++;
  return c;
}

void CMPS14_eraseProfil()
{
  Wire.beginTransmission(CMPS14_ADDRESS);
  Wire.write(0x00);
  Wire.write(0xE0);
  _last_status = Wire.endTransmission();

  delay(20); //  20ms delay after each of the three bytes send
  Wire.beginTransmission(CMPS14_ADDRESS);
  Wire.write(0x00);
  Wire.write(0xE5);
  _last_status = Wire.endTransmission();

  delay(20); //  20ms delay after each of the three bytes send
  Wire.beginTransmission(CMPS14_ADDRESS);
  Wire.write(0x00);
  Wire.write(0xE2);
  _last_status = Wire.endTransmission();

  delay(20); //  20ms delay after each of the three bytes send
}

//Correct heading for known deviation
int DeviationCorrect(int Head)
{
   return 0;
}

void setup() {
  Serial.begin(38400);  // Start serial port
  Wire.begin();
  nbsp = 32;
  //  CMPS14_eraseProfil();
}

void loop() {
  Wire.beginTransmission(CMPS14_ADDRESS);  //starts communication with CMPS14
  Wire.write(ANGLE_8);                     //Sends the register we wish to start reading from
  Wire.endTransmission();

  // Request 5 bytes from the CMPS14
  // this will give us the 8 bit bearing,
  // both bytes of the 16 bit bearing, pitch and roll
  Wire.requestFrom(CMPS14_ADDRESS, 26);

  while (Wire.available() < 26);       // Wait for all bytes to come back
  //  software = Wire.read();
  //  Serial.print("Version: ");
  //  Serial.println(software);
  angle8 = Wire.read();               // Read back the 5 bytes
  high_byte = Wire.read();
  low_byte = Wire.read();
  pitch = Wire.read();
  roll = Wire.read();

  //  int i = 6;
  //  while (i <= 25) {
  //    Wire.read();
  //    i++;
  //  }
  //
  //  cal = Wire.read();
  //  Serial.print("Cal: ");
  //  Serial.println(cal);

  bearing = ((high_byte << 8) + low_byte) / 10;
  fine = ((high_byte << 8) + low_byte) % 10;
  byte data[128] = "$HCHDM,";
  data[8] = bearing;
  //  int deviation = 0;
  //DeviationCorrect(bearing);
  //  bearing = bearing;
  //+ deviation;

  //Print out NMEA 0183 string HDM
  snprintf(mystring, sizeof(mystring), "$HCHDM,%d.%d,M", bearing , fine);
  uint8_t crc = checksum(mystring + 1);
  Serial.print(mystring);
  Serial.print("*");
  if (crc < 16) Serial.print("0");
  Serial.println(crc, HEX);

    //Print out NMEA 0183 string XDR for Pitch
    snprintf(mystring2, sizeof(mystring2), "$HCXDR,A,%d,D,PITCH", pitch);
    uint8_t crc2 = checksum(mystring2 + 1);
    Serial.print(mystring2);
    Serial.print("*");
    if(crc2 < 16) Serial.print("0");
    Serial.println(crc2, HEX);
  
    //Print out NMEA 0183 string XDR for Roll/Heel
    snprintf(mystring3, sizeof(mystring3), "$HCXDR,A,%d,D,ROLL", roll);
    uint8_t crc3 = checksum(mystring3 + 1);
    Serial.print(mystring3);
    Serial.print("*");
    if(crc3 < 16) Serial.print("0");
    Serial.println(crc3, HEX);
  delay(100);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM