rfm69_check.py
1 # SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 Wiring Check, Pi Radio w/RFM69 7 8 Learn Guide: https://learn.adafruit.com/lora-and-lorawan-for-raspberry-pi 9 Author: Brent Rubell for Adafruit Industries 10 """ 11 import time 12 import busio 13 from digitalio import DigitalInOut, Direction, Pull 14 import board 15 # Import the SSD1306 module. 16 import adafruit_ssd1306 17 # Import the RFM69 radio module. 18 import adafruit_rfm69 19 20 # Button A 21 btnA = DigitalInOut(board.D5) 22 btnA.direction = Direction.INPUT 23 btnA.pull = Pull.UP 24 25 # Button B 26 btnB = DigitalInOut(board.D6) 27 btnB.direction = Direction.INPUT 28 btnB.pull = Pull.UP 29 30 # Button C 31 btnC = DigitalInOut(board.D12) 32 btnC.direction = Direction.INPUT 33 btnC.pull = Pull.UP 34 35 # Create the I2C interface. 36 i2c = busio.I2C(board.SCL, board.SDA) 37 38 # 128x32 OLED Display 39 reset_pin = DigitalInOut(board.D4) 40 display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin) 41 # Clear the display. 42 display.fill(0) 43 display.show() 44 width = display.width 45 height = display.height 46 47 48 # RFM69 Configuration 49 CS = DigitalInOut(board.CE1) 50 RESET = DigitalInOut(board.D25) 51 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 52 53 while True: 54 # Draw a black filled box to clear the image. 55 display.fill(0) 56 57 # Attempt to set up the RFM69 Module 58 try: 59 rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 915.0) 60 display.text('RFM69: Detected', 0, 0, 1) 61 except RuntimeError as error: 62 # Thrown on version mismatch 63 display.text('RFM69: ERROR', 0, 0, 1) 64 print('RFM69 Error: ', error) 65 66 # Check buttons 67 if not btnA.value: 68 # Button A Pressed 69 display.text('Ada', width-85, height-7, 1) 70 display.show() 71 time.sleep(0.1) 72 if not btnB.value: 73 # Button B Pressed 74 display.text('Fruit', width-75, height-7, 1) 75 display.show() 76 time.sleep(0.1) 77 if not btnC.value: 78 # Button C Pressed 79 display.text('Radio', width-65, height-7, 1) 80 display.show() 81 time.sleep(0.1) 82 83 display.show() 84 time.sleep(0.1)