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.

댓글

이 블로그의 인기 게시물

공유기 2개 쓰는데 동일 네트워크 구성하기 ASUS 공유기 + iptime 공유기, LAN, WIFI 연결

OneDrive가 바꾼 문서, 사진, 바탕화면 기본 폴더 복구하기(레지스트리 사용안하고 복구)

갤럭시북 이온 노트북 소음 잡기