-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrfm69_tx.py
57 lines (50 loc) · 1.44 KB
/
rfm69_tx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# RFM69 radio bonnet transmitter test
import time
import busio
import board
import adafruit_ssd1306
import adafruit_rfm69
from digitalio import DigitalInOut, Direction, Pull
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# 128x32 OLED Display
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height
# RFM69 Configuration
packet = None
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 433.0)
rfm69.encryption_key = None
while True:
# initialization
packetRX = None
packetTX = None
display.fill(0)
display.text('RFM69: init', 0, 0, 1)
display.show()
count = 0
packetTX = bytes("Hello World!", "utf-8")
rfm69.send(packetTX)
display.fill(0)
display.text('Packet sent', 0, 0, 1)
display.show()
while((packetRX == None) & (count < 10)):
display.fill(0)
display.text('Listening for ack packet...', 0, 0, 1)
display.show()
packetRX = rfm69.receive()
count = count + 1
if not packetRX is None:
display.fill(0)
packet = packetRX
displayPacket = str(packet, "utf-8")
display.text('ACK Packet = ', 0, 0, 1)
display.text(displayPacket, 25, 10, 1)
display.show()
time.sleep(3)