diff --git a/py/main.py b/py/main.py new file mode 100644 index 0000000..d25ce7c --- /dev/null +++ b/py/main.py @@ -0,0 +1,34 @@ +import machine + +spi = machine.SPI('Y', baudrate=10000000) + + +import ssd1306 +disp_slave_select = machine.Pin('Y5', machine.Pin.OUT) +disp_slave_select.value(1) +d = ssd1306.SSD1306_SPI(128, 64, spi, machine.Pin('X11'), machine.Pin('X22'), disp_slave_select) + +import quokka_radio +nrf_slave_select = machine.Pin('Y4', machine.Pin.OUT) +nrf_slave_select.value(1) +r = quokka_radio.Radio(nrf_slave_select, spi) + +d.fill(1) +d.text('radio', 5, 5, 0) +d.show() + +r.enable() +print('version:', r.version()) +print('version:', r.version()) + +import pyb +pyb.LED(2).on() + +r.set_channel(22) + +while True: + msg = r.receive() + if msg: + d.fill(1) + d.text(msg, 5, 5, 0) + d.show() diff --git a/py/quokka_radio.py b/py/quokka_radio.py index 183db19..b7fc4f8 100644 --- a/py/quokka_radio.py +++ b/py/quokka_radio.py @@ -1,7 +1,7 @@ # boot.py -- run on boot-up # can run arbitrary Python, but best to keep it minimal -from pyb import delay, udelay +from pyb import delay, udelay, millis from machine import Pin, SPI # States @@ -57,6 +57,19 @@ def __init__(self, slave_select, spi): self.slave_select = slave_select self.spi = spi + # Wait for up to a second for the nRF to be ready + time = millis() + 1000 + success = False + while millis() < time: + try: + self.version() + except RuntimeError: + continue + success = True + break + if success == False: + raise RuntimeError("Unable to communicate with radio") + def version(self): """ Return version string