Skip to main content

Simple controller for waveshare raspberry hats based on sx126 radio transceivers

Project description

Raspberry waveshare sx1268 433Mhz controller + small tutorial

This guide is for people which are struggling to get WaveShare Raspberry hat with SX1268 (SX126X series) radio transceiver.

I will be using "HAT" as sx1268 waveshare rpi hat in the rest of this README

Instructions

Step 0: Prepare raspberry for waveshare hat

HAT is using GPIO 14 and GPIO 15 for UART communication.
With that in mind we have to free up this line from other devices.

Raspbian

/boot/config.txt should contain:

enable_uart=1

ArchlinuxARM

/boot/config.txt should contain: dtoverlay=uart0

config.txt can contain multiple dtoverlay definitions

# If you're struggling to install RPi.GPIO and you have GCC version > 10 use
export CFLAGS=-fcommon

pip install RPi.GPIO 
# or 
pip install waveshareSX126

Step 1: Installation

pip install waveshareSX126

Step 2: Examples!

Set HAT to 'monitor mode'

Listen for All messages on network 5 and print them to console

from waveshareSX126 import sx1268

# initialize hat with default parameters using ttyAMA0 serial
# by default hat will be set to:  
# address   : 0x0
# networkID : 0x0
# channel   : 0x0 
# mode      : configuration
controller = sx1268.Controller()
controller.initialize(serialPipe = "/dev/ttyAMA0")

# set HAT address to be broadcast & monitor 0xFFFF
controller.address = 0xFFFF

# set HAT to operate on networkID 0x5
controller.networkId = 0x5

# set controller mode to Transmission
controller.mode = sx1268.OperatingMode.Transmission

# listen and print any messages with will come
for message in controller.listen():
  print(message.decode())

Send P2P message

Send P2P message on address 0xB8, network 0x5 every 5 seconds

from waveshareSX126 import sx1268

import time

# initialize hat with default parameters using ttyAMA0 serial
# by default hat will be set to:  
# address   : 0x0
# networkID : 0x0
# channel   : 0x0 
# mode      : configuration
controller = sx1268.Controller()
controller.initialize(serialPipe = "/dev/ttyAMA0")

# set HAT address to 0xB8
controller.address = 0xB8

# set HAT to operate on networkID 0x5
controller.networkId = 0x5

# set controller mode to Transmission
controller.mode = sx1268.OperatingMode.Transmission

start_time = time.time()
i = 0

while True:

  if time.time() - start_time > 5:
    controller.sendMessage(f"This is message number: {i}")
    start_time = time.time()
    i += 1

Operate in Watch / WOR mode.

Send P2P message every 5 seconds, listen on incoming P2P messages

from waveshareSX126 import sx1268

import time

controller = sx1268.Controller()
controller.initialize()

# set HAT address to 0xB8
controller.address = 0xB8

# set HAT to operate on networkID 0x5
controller.networkId = 0x5

# set WOR mode to Sender (Send and Receive), and start operate in WOR mode
controller.worMode = sx1268.WORMode.Sender
controller.mode = sx1268.OperatingMode.Watch

start_time = time.time()
i = 0
while True:

  if controller.messageAvailable():
    for message in controller.readMessages():
      print(message.decode())

  if time.time() - start_time > 5:
    controller.sendMessage(f"This is message number: {i}")
    start_time = time.time()
    i += 1

  time.sleep(0.1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wssx126-0.0.5.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wssx126-0.0.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file wssx126-0.0.5.tar.gz.

File metadata

  • Download URL: wssx126-0.0.5.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for wssx126-0.0.5.tar.gz
Algorithm Hash digest
SHA256 bbdeb0328f2ba8e7bb048bcc0af23844fc68d597512bfc464af42dd538946c0f
MD5 b81e1e3045ddac60c4bc25bb35c687fe
BLAKE2b-256 f5183933483268e23474a7c618415e4266814a0b47c2be2f50570c8cd15cbe69

See more details on using hashes here.

File details

Details for the file wssx126-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: wssx126-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for wssx126-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9cb45895f2785cba82ca56568741a9b3c60f5482ba75d2929507be4a8c6ac244
MD5 b98aab85f6f752d5e141b38f4f0d4f0b
BLAKE2b-256 188d4af36ef0699163d74a3e9d43c068d879edb058f9e29e2a1db17b03b43a70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page