前面树莓派4B一本通(2)已经测试广播
名字是Go Bluetooth
MAC:E4 5F 01 4F 25 BB
这个本质是HCI0也就是PI自己的MAC
今天希望增加一个HCI使用外挂ESP32C3的办法
第一步
固件准备看这里 ESP32/ESP32C3开发环境说明_GKoSon的博客-CSDN博客
核心位置
XXX\build\bootloader\bootloader.bin
XXX\build\partition_table\partition-table.bin
XXX\build\hello-world.bin
————————————————
原始编译 C:\Users\Koson.Gong\Desktop\bin\c3
————————————————
修改硬件2个-1编译 C:\Users\Koson.Gong\Desktop\bin\c3-1
cp C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\controller_hci_uart_demo.bin C:\Users\Koson.Gong\Desktop\bin\c3
cp C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\bootloader\bootloader.bin C:\Users\Koson.Gong\Desktop\bin\c3
cp C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\partition_table\partition-table.bin C:\Users\Koson.Gong\Desktop\bin\c3
验证 c3-1
cp C:\Users\Koson.Gong\Desktop\bin\c3-1\controller_hci_uart_demo.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\controller_hci_uart_demo.bin
cp C:\Users\Koson.Gong\Desktop\bin\c3-1\bootloader.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\bootloader\bootloader.bin
cp C:\Users\Koson.Gong\Desktop\bin\c3-1\partition-table.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\partition_table\partition-table.bin
烧录
第二部
现在连接PI
绿色----IO4----PI 28 GPIO1
黄色----IO5----PI 27 GPIO0
蓝色--GND
ESP硬件uart两根线
C3 - 6 -RTS --- GPIO2
C3 - 7 -CTS --- GPIO3
三根线连接板子 或者5根线连接板子
第三步
挂起HCI
btattach -N -B /dev/ttyAMA1 -S 115200 & # without flow control
btattach -B /dev/ttyAMA1 -S 115200 & # with flow control
sudo hciconfig # check HCI interface, should have two hci interface, hci0 and hci1
+++++++++++++++++KAISHI
现在上面的指令 对我来说不是很好用 因为我的PI是原始的 没有修改
现在修改一下
注意:发现树莓派不能正确的话 是img有问题 上面2图是基于下面的img
crw-rw---- 1 root dialout 204, 64 Jan 26 03:03 ttyAMA0
dtoverlay=uart2
dtoverlay=disable-bt ----会把PI自己的蓝牙阉割 那样hciconfig就看不到PI自己的那个了
新出现这个!!!
在执行
btattach -N -B /dev/ttyAMA1 -S 115200 &
enable_uart=1 【加了这句话也不行】
最后我发现这个10月份的img不行!还是用5月份的img!
我现在是10月份的img+5月份的boot config.txt 这样是可以OK 的
一句话 开启UART2
+++++++++保持一下 可行的config.txt+++++++++
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
[all]
#dtoverlay=vc4-fkms-v3d
#dtoverlay=uart2
dtoverlay=uart2,ctsrts=on
++++++++++++++++++++++
具体看这个
树莓派4使用2-5号串口_wxtcstt的专栏-CSDN博客
+++++++++++++++++END
此时可以直接挂起
此时是本文开头的效果
现在准备切换
第一步 原始代码好像00全部是有问题的
修改
add一个函数
adapter_linux.go
func (a *Adapter) Address2() (string, error) {
if a.adapter == nil {
return "NO-MAC", errors.New("adapter not enabled")
}
return a.adapter.Properties.Address, nil
}
main
for {
address, _ := adapter.Address()
addressstring, _ := adapter.Address2()
println("Go Bluetooth /", address.MAC.String(), addressstring)
time.Sleep(time.Second)
}
}
现在开始奇幻
package main
import (
"fmt"
"time"
"tinygo.org/x/bluetooth"
"github.com/muka/go-bluetooth/api"
"github.com/muka/go-bluetooth/bluez/profile/adapter"
)
var madapter = bluetooth.DefaultAdapter
func main() {
//must("enable BLE stack", madapter.Enable())
println("GetDefaultAdapterID()", api.GetDefaultAdapterID())
adapter.SetDefaultAdapterID("hci1")
println("GetDefaultAdapterID()", api.GetDefaultAdapterID())
must("enable BLE stack", madapter.Enable())
adv := madapter.DefaultAdvertisement()
must("config adv", adv.Configure(bluetooth.AdvertisementOptions{
LocalName: "Go Bluetooth",
}))
must("start adv", adv.Start())
println("advertising...")
address, _ := madapter.Address()
addressstring, _ := madapter.Address2()
fmt.Println(madapter)
for {
println("Go Bluetooth /", address.MAC.String(), addressstring)
time.Sleep(time.Second)
}
}
func must(action string, err error) {
if err != nil {
panic("failed to " + action + ": " + err.Error())
}
}
// +build !baremetal
// Some documentation for the BlueZ D-Bus interface:
// https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc
package bluetooth
import (
"errors"
"github.com/muka/go-bluetooth/api"
"github.com/muka/go-bluetooth/bluez/profile/adapter"
)
type Adapter struct {
adapter *adapter.Adapter1
id string
cancelChan chan struct{}
defaultAdvertisement *Advertisement
connectHandler func(device Addresser, connected bool)
}
// DefaultAdapter is the default adapter on the system. On Linux, it is the
// first adapter available.
//
// Make sure to call Enable() before using it to initialize the adapter.
var DefaultAdapter = &Adapter{
connectHandler: func(device Addresser, connected bool) {
return
},
}
// Enable configures the BLE stack. It must be called before any
// Bluetooth-related calls (unless otherwise indicated).
func (a *Adapter) Enable() (err error) {
if a.id == "" {
//adapter.SetDefaultAdapterID("hci1")
a.adapter, err = api.GetDefaultAdapter()
if err != nil {
return
}
a.id, err = a.adapter.GetAdapterID() //github.com/muka/go-bluetooth/bluez/profile/adapter
}
return nil
}
func (a *Adapter) Address() (MACAddress, error) {
if a.adapter == nil {
return MACAddress{}, errors.New("adapter not enabled")
}
mac, err := ParseMAC(a.adapter.Properties.Address)
if err != nil {
return MACAddress{}, err
}
return MACAddress{MAC: mac}, nil
}
func (a *Adapter) Address2() (string, error) {
if a.adapter == nil {
return "NO-MAC", errors.New("adapter not enabled")
}
return a.adapter.Properties.Address, nil
}
追加测试一次复位
3根线不动
sudo apt-get install python-pip
sudo pip install esptool //MUST SUDO!!https://github.com/espressif/esptool/issues/343
esptool.py chip_id
卸载默认的py 安装py
sudo apt-get autoremove python2.7
https://blog.csdn.net/binbin846/article/details/103049168
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar zxvf Python-3.8.0.tgz
cd Python-3.8.0
sudo ./configure
sudo make
sudo make install
小结
核心位置
XXX\build\bootloader\bootloader.bin
XXX\build\partition_table\partition-table.bin
XXX\build\hello-world.bin
————————————————
原始编译 C:\Users\Koson.Gong\Desktop\bin\c3
————————————————
修改硬件2个-1编译 C:\Users\Koson.Gong\Desktop\bin\c3-1
cp C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\controller_hci_uart_demo.bin C:\Users\Koson.Gong\Desktop\bin\c3
cp C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\bootloader\bootloader.bin C:\Users\Koson.Gong\Desktop\bin\c3
cp C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\partition_table\partition-table.bin C:\Users\Koson.Gong\Desktop\bin\c3
验证 c3-1 + btattach -N -B /dev/ttyAMA1 -S 115200 & # without flow control
cp C:\Users\Koson.Gong\Desktop\bin\c3-1\controller_hci_uart_demo.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\controller_hci_uart_demo.bin
cp C:\Users\Koson.Gong\Desktop\bin\c3-1\bootloader.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\bootloader\bootloader.bin
cp C:\Users\Koson.Gong\Desktop\bin\c3-1\partition-table.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\partition_table\partition-table.bin
结论 是可以的
验证 C3 + btattach -B /dev/ttyAMA1 -S 115200 &
cp C:\Users\Koson.Gong\Desktop\bin\c3\controller_hci_uart_demo.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\controller_hci_uart_demo.bin
cp C:\Users\Koson.Gong\Desktop\bin\c3\bootloader.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\bootloader\bootloader.bin
cp C:\Users\Koson.Gong\Desktop\bin\c3\partition-table.bin C:\Users\Koson.Gong\Desktop\esp-idf\examples\bluetooth\hci\controller_hci_uart_esp32c3\build\partition_table\partition-table.bin
第一步上面的PI接线不动 只是修改ESP32C3的固件
发现 hciconfig hci1 reset 失败
第二部 复位 执行 btattach -B /dev/ttyAMA1 -S 115200 &
发现失败 无法up
连接2个硬件的线
C3 - 6 -RTS --- GPIO2
C3 - 7 -CTS --- GPIO3
测试成功
思路2:开源方案 目前master分支里面编译失败 需要切换分支再试试