Arduino和Raspberry pi 4之间的蓝牙通信

2024-05-13 14:24:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接Arduino(带4.0蓝牙模块)和Raspberry pi 4(带蓝牙模块)。 我只想让锉刀收到一根线,永远不要发送,这就是arduino的草图:

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3);

void setup() {
  bluetooth.begin(9600);
}

void loop() {
  delay(500);
  bluetooth.println("string");
}

现在,如果我尝试将我的智能手机连接到蓝牙终端,它可以正常工作,但当我在树莓上尝试同样的操作时,它不会收到任何字节。 以下是我尝试过的:

import serial
bluetoothSerial = serial.Serial("/dev/rfcomm0", baudrate=9600)
print(bluetoothSerial.readline())
bluetoothSerial.close()

尽管这两个设备是成对连接的,但在几秒钟没有收到任何信息后,它会给我一个错误,即"The Host is down"

这些是bluetoothctl的截图 screenshot1

enter image description here


Tags: 模块includesetupserialpiraspberryarduinobluetooth