Arduino Uno - Incorrect/Scrambled 串行数据

Arduino Uno - Incorrect/Scrambled Serial Data

我一直在努力编写一个非常简单的 Arduino 程序,将地址引脚递增到 EPROM,然后通过其他引脚读取数据。当我无法做一些像递增布尔值数组这样简单的事情时(两个值的 MSB 也几乎总是停留在 1),我的假设是我的代码一定是搞砸了,但随后它开始发送两次应该有很多字符(Serial.println(char);),这在发送字符串时没有发生。然后更糟糕的事情开始发生,例如在编译期间没有发现错误时设备完全没有响应。所以我需要知道的是,是我的代码坏了还是我的 Arduino 坏了?我在所有波特率下都试过了,这是我得到的一些输出。请注意,我在我的代码中插入了延迟以减慢速度,但没有做出任何改变。我不得不拍下这个屏幕,因为字符不会粘贴在片段中。

这是我的半生不熟的代码,您会注意到它充满了一次发送单个字符的循环(因为这避免了一些疯狂的行为)。

/**
 * EEPROM Reader/Dumper for EPROMS or EEPROMS.
 * 
 * @version 1.0.0.0
 * @author  Bit Fracture
 * @date    2015.05.23
 */

//Defining the address lines (four additional pins are manual)
int     a_pins[10]  = {2,3,4,5,6,7,8,9,10,11};

//Defining the 8-bit data pins
int     d_pins[8]   = {12,13,14,15,16,17,18,19};

//Store our current address (start at binary 0)
boolean address[10] = {0,0,0,0,0,0,0,0,0,0};

//Store our serial output data (start at binary 0)
boolean data[8]     = {0,0,0,0,0,0,0,0};

void setup()
{
  //Start communication with the computer
  Serial.begin(115200);
  delay(100);

  //Set address pins to output
  for (int i=0; i < sizeof(a_pins); i += 1)
  {
      pinMode(a_pins[i], OUTPUT);

      //Tell Serial this pin's status
      Serial.println("PO: " + (a_pins[i]));
      delay(100);
  }

  //Set data pins as input
  for (int i=0; i < sizeof(d_pins); i += 1)
  {
      pinMode(d_pins[i], INPUT);

      //Tell Serial this pin's status
      Serial.println("PI: " + (d_pins[i]));
      delay(100);
  }

  //Warn start
  Serial.println("BEGINNING TRANSMISSION");
}

void loop()
{
  //Calculate new binary address
  boolean carry = 1; //Start with a carry to initiate increment process
  for (int i=0; i < sizeof(address); i += 1)
  {
    boolean _temp = ((address[i] || carry) && (!address[i] || !carry));
    carry         = (address[i] && carry);
    address[i]    = _temp;
  }

  //Set output pins to new values
  for (int i=0; i < sizeof(a_pins); i += 1)
  {
    digitalWrite(a_pins[i], address[i]);
  }

  //Allow for the changes to propagate through the EPROM circuitry
  delay(250);

  //Read the inputs
  for (int i=0; i < sizeof(d_pins); i += 1)
  {
    data[i] = digitalRead(d_pins[i]);
  }

  //Output the address
  for (int i = sizeof(address); i > 0; i--)
  {
    if (address[i] == 1)
      Serial.print("1");
    else
      Serial.print("0");
  }
  Serial.print(": ");

  //Output the value
  for (int j = sizeof(data); j > 0; j--)
  {
    if (data[j] == 1)
      Serial.print("1");
    else
      Serial.print("0");
  }
  Serial.println();

  //Keep things from going too fast for now
  delay(1000);
}

简而言之:我需要理解为什么一开始的串行数据看起来像跑到程序内存中而不是发送它应该发送的字符串,以及为什么我似乎不能做这么简单的事情作为递增二进制数并将其输出到串行!

谢谢大家

您正在将二进制数发送到串行端口而不是将它们转换为 ascii,通过将二进制数转换为 ascii 对您的设置代码做这个小改动,

char my_buffer_ax[10];
char my_buffer[200];


  memset(my_buffer, 0, 200);
  strcat(my_buffer, "PO: "); 
  //Set address pins to output
  for (int i=0; i < sizeof(a_pins); i += 1)
  {
      pinMode(a_pins[i], OUTPUT);

      //Tell Serial this pin's status
      memset(my_buffer_ax, 0, 10);
      itoa(a_pins[i], my_buffer_ax, 10); 
      strncat(my_buffer, my_buffer_ax, strlen(my_buffer_ax)); 
      delay(100);
  }
  Serial.println(my_buffer);

  memset(my_buffer, 0, 200);
  strcat(my_buffer, "PI: "); 
  //Set data pins as input
  for (int i=0; i < sizeof(d_pins); i += 1)
  {
      pinMode(d_pins[i], INPUT);

      //Tell Serial this pin's status
      memset(my_buffer_ax, 0, 10);
      itoa(d_pins[i], my_buffer_ax, 10); 
      strncat(my_buffer, my_buffer_ax, strlen(my_buffer_ax)); 
      delay(100);
  }
  Serial.println(my_buffer);