Skip to content

Commit

Permalink
Make the driver wait for the nRF to be ready on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmo committed Jan 9, 2018
1 parent 2249c8b commit a274a43
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
34 changes: 34 additions & 0 deletions py/main.py
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 14 additions & 1 deletion py/quokka_radio.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a274a43

Please # to comment.