Arduino UART在某些点不工作的问题
我正在连接一个与Arduino具有相同代码框架的Arduino。他们之间的通信在大多数情况下工作正常,但我注意到在某些时候Arduino无法向Spark Core发送消息。Arduino从火花核心接收到的信息很好。我不明白是什么导致UART出现问题,即使代码很简单 在这种情况下,我有一个连接到Arduino的按钮,每当用户按下它时,它会向Spark Core发送“高”信号,Spark Core会打开LED,当他们松开时,它会发送“低”信号以关闭LED。有人能帮我理解为什么UART有时会冻结或什么吗?如何检测问题并修复它 Arduino代码: Spark核心代码:Arduino UART在某些点不工作的问题,arduino,embedded,microcontroller,uart,sparkcore,Arduino,Embedded,Microcontroller,Uart,Sparkcore,我正在连接一个与Arduino具有相同代码框架的Arduino。他们之间的通信在大多数情况下工作正常,但我注意到在某些时候Arduino无法向Spark Core发送消息。Arduino从火花核心接收到的信息很好。我不明白是什么导致UART出现问题,即使代码很简单 在这种情况下,我有一个连接到Arduino的按钮,每当用户按下它时,它会向Spark Core发送“高”信号,Spark Core会打开LED,当他们松开时,它会发送“低”信号以关闭LED。有人能帮我理解为什么UART有时会冻结或什么
按钮的端口输入引脚上是否有偏置电阻,或者只是让它开路?在这种情况下,它可能会浮动。我想我发现了问题,我将7个传感器连接到Arduino,所有传感器都需要5V电压。我删除了其中一些,UART似乎工作正常。我的问题可能与电压有关,但我不明白它是如何具体影响UART的。我现在只连接3个传感器。可能是影响了一个12伏的驱动器。我也有类似的问题。检查以确保它们具有相同的TTL逻辑电压,因为您可能需要一个电平转换器。接下来使用示波器检查过压/欠压情况。祝你好运
#define buttonPin 7
int buttonState = 0; // variable for reading the pushbutton status
int sendonce = 0;
void setup() {
Serial.begin(9600);
// Serial.print("BEGIN\n");
}
void loop() {
isButtonPressed();
}
void isButtonPressed () {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
if (sendonce == 0)
{
Serial.print("High\n");
// ser.write('1');
sendonce = 1;
}
}
else if (buttonState == LOW && sendonce == 1) {
sendonce = 0;
Serial.print("Low\n");
}
}
#include "Serial2/Serial2.h"
// name the pins
int led1 = D7;
int led2 = D1;
String txtMsg = "";
char s;
char lightStatus[20] ;
// This routine runs only once upon reset
void setup()
{
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
//Serial1.begin(9600);
Serial2.begin(9600);
//Serial2.println("Hello From Spark");
}
// This routine loops forever
void loop()
{
while (Serial2.available() > 0) {
s=(char)Serial2.read();
if (s == '\n') {
if(txtMsg=="High") {
digitalWrite(led1, 1);
strcpy(lightStatus, "Light On");
}
if(txtMsg=="Low") {
digitalWrite(led1, 0);
strcpy(lightStatus, "Light Off");
}
// Serial.println(txtMsg);
txtMsg = "";
} else {
txtMsg +=s;
}
}
}