Pyb Microcontroller BLE Communication with OLED Display
main.py -- put your code here!
Import necessary modules
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()
Create LED Object
led1 = LED(1)
Turn on LED1
led1.on()
Loop indefinitely
while True: # Turn off LED1 led1.off() delay(500)
# Turn on LED1
led1.on()
delay(500)
# Send 'Hello World' message through BLE
ble.write('Hello World\n')
delay(500)
原文地址: https://www.cveoy.top/t/topic/o4Py 著作权归作者所有。请勿转载和采集!