raspberrypi bluetooth connection to arduino bluetooth shield using bluetoothctl
For those who frustated of bluez-simple-agent, this is the answer.
bluetoothctl
power on
agent on
scan on
--get <bdaddr>--
scan off
pair <bdaddr>
trust <bdaddr>
-paring done.-
CTRL+Z ( to see the console)
sudo rfcomm connect /dev/rfcomm1 20:XX:XX:XX:XX:XX 1 &
(sudo rfcomm <command> <dev> [bdaddr] [channel] (& is for background))
-checking-
ls -l /dev | grep rf
you should be able to see rfcomm1
Now, there is a connection. you might want to send a text.
sudo apt-get install python-serial (if you did not install)
make a script below, and save it as send_a.py
-----------------------------------------------------------------------------
#! /usr/bin/python
import serial
from time import sleep
bluetoothSerial = serial.Serial( "/dev/rfcomm1", baudrate=9600 )
bluetoothSerial.write(b'a')
------------------------------------------------------------------------------
sudo python3 ./send_a.py
If you had a connection, and reboot raspberry pi, then, you can follow below
bluetoothctl& (turn on PI's bluetooth and pairing)
sudo rfcomm connect /dev/rfcomm1 20:XX:XX:XX:XX:XX 1 &
sudo python3 send_a.py
Hope this helps.
댓글
댓글 쓰기