Programming with MicorPython: Wireless Radio

Import FutureBoard Library

Import the Library to make use of its functions.

from future import *

10: Wireless Radio

Import Radio Library

from radio import *

1. Initiate a Radio


Define an event trigger function and call it in the trigger parameter to automatically call the function on receiving message.

2. Set the radio channel

3. Read the channel feed

Returns the message.

4. Publish a message to channel


Sample Program 1

import time
from radio import *

r = Radio()
print('channel', = 12 

while True:
    a =
    if a:
        print('get', a)

Sample Program 2: Event Triggers

from radio import *

def onmsg(msg, mac):
    print('get', msg, 'from', mac)

r = Radio(onmsg)
print('channel', = 12
r.send("hello world")

Advanced Program: MESH with ESPNOW

# 1. WiFi
import network
w0 = network.WLAN(network.STA_IF)

# 2. MAC Address
mac = w0.config('mac')
>>> mac

# 3. import espnow
from esp import espnow
e = espnow.ESPNow()

# 4. Add peer MAC Address
# Note: Add the addess of the peer device

# 5. Event Trigger
def rxcb(mac, msg):
    print("Recv:", mac, msg)

# 6. Publish
e.send(b'\x8c\xaa\xb5\xb9\xf8\xf0', 'hello world')

# Seeable on receving end
# Recv: b'\xc4O3"\xdb\x89' b'hello world'