import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600,timeout=1)
abc= bytes("s","utf-8")
try:
while 1:
ser.write(abc);#写s字符
response = ser.readall();#用response读取端口的返回值
print (response);#进行打印
except:
ser.close();#抛出异常后关闭端口
](https://cdn.chandianzi.cn/wp-content/uploads/csstm/c1b56c1b84834a0ca870f85dea213c4b.bmp?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAejg0Mzc3NzYyOA==,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
![
int led = 13;
void setup(){
Serial.begin(9600); // 9600波特率
pinMode(led, OUTPUT);
}
void loop() {
if ( Serial.available())//判断串口缓存区有没有数据
{
if(‘s’ == Serial.read())//有数据就用read来读取并判断是不是s
// the setup routine runs once when you press reset:
// the loo
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
Serial.println("Hello Raspberry,I am jiayu's Arduino.");//是的话就向串口打印这串字符
}
}
](https://cdn.chandianzi.cn/wp-content/uploads/csstm/92682460b4a94e228cb0b3c386c1a529.bmp?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAejg0Mzc3NzYyOA==,size_19,color_FFFFFF,t_70,g_se,x_16#pic_center)
版权声明:本文为CSDN博主「z843777628」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z843777628/article/details/118718634
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600,timeout=1)
abc= bytes("s","utf-8")
try:
while 1:
ser.write(abc);#写s字符
response = ser.readall();#用response读取端口的返回值
print (response);#进行打印
except:
ser.close();#抛出异常后关闭端口
](https://cdn.chandianzi.cn/wp-content/uploads/csmcu/c1b56c1b84834a0ca870f85dea213c4b.bmp?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAejg0Mzc3NzYyOA==,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
![
int led = 13;
void setup(){
Serial.begin(9600); // 9600波特率
pinMode(led, OUTPUT);
}
void loop() {
if ( Serial.available())//判断串口缓存区有没有数据
{
if(‘s’ == Serial.read())//有数据就用read来读取并判断是不是s
// the setup routine runs once when you press reset:
// the loo
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
Serial.println("Hello Raspberry,I am jiayu's Arduino.");//是的话就向串口打印这串字符
}
}
](https://cdn.chandianzi.cn/wp-content/uploads/csmcu/92682460b4a94e228cb0b3c386c1a529.bmp?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAejg0Mzc3NzYyOA==,size_19,color_FFFFFF,t_70,g_se,x_16#pic_center)
版权声明:本文为CSDN博主「z843777628」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z843777628/article/details/118718634
暂无评论