main.py -- put your code here!

from pyb import Pin, LED, UART, OLED, delay

Create OLED Object

oled = OLED()

Clear OLED

oled.fill(0) oled.show()

Create BLE Object

ble = UART('BLE')

Initialize BLE

ble.init(57600, bits=8, parity=None, stop=1, timeout=100)

Set to AT Mode

ble.write('+++a') ble.read(10)

Get BLE MAC

ble.write('AT+MAC? ') mac = ble.read(100)[7:19]

Set to Transparent Mode

ble.write('AT+Z ') ble.read(100)

OLED Show MAC

oled.text('MAC:', 0, 0, 1) oled.text(mac, 0, 12, 1) oled.show()

led1 = LED(1) led1.on()

while True: led1.off() delay(500) led1.on() delay(500) ble.write('Hello World\n') delay(500)

该代码初始化并配置了一个 OLED 显示屏和一个 BLE(蓝牙低功耗)模块。

然后它获取 BLE 模块的 MAC 地址,并将其显示在 OLED 显示屏上。

之后,它会持续闪烁一个 LED,并每 500 毫秒通过 BLE 发送字符串“Hello World”。

Pycom 微控制器:使用 OLED 显示 BLE MAC 地址并发送消息

原文地址: https://www.cveoy.top/t/topic/o4PB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录