Git Product home page Git Product logo

zetarf's Introduction

ZetaRF Version 2.0.0

Written by: Benjamin Balga. Copyright: 2020, Benjamin Balga, released under BSD license.

Supported (tested) Platforms: (should be compatible with any platform supporting SPI at 1MHz)
Basic Arduino Teensy 2 upto 4.1 including LC Raspberry Pi

--

ZetaRf got updated to v2! Check your code, this is a breaking update from v1. See 'SimpleRxTx' example for a migration guide and the notes below.

--

About

ZetaRf is an Arduino library for ZETA modules from RF Solutions, which implements a Silicon Labs Si4455 Low Current Sub-GHz Transceiver, and for Dorji DRF4463F modules which implements a Silicon Labs Si4463 Low Current Sub-GHz Transceiver.

Currently the 2 modules are not cross-compatible.

RF Solutions does not provide ready to use sample code in C/C++ to use their ZETA modules directly, but either PIC ASM code or Arduino library if you interface your module with their CODEC chip. This library enables you to communicate directly with the ZETA module without the CODEC chip. Same for Doji modules.

Beware: The new ZetaPlus modules from RF Solutions are not compatible! They use AT commands over UART or SPI via an intermediate microcontroller and the radio IC SPI bus is not accessible.

ZETA modules communicates over high-speed SPI (up to 10MHz) and 2 gpio.

This library is based on code examples from Silicon Labs Wireless Development Suite, largely modified.

ZetaRf library is optimized for very low latency (a few milliseconds). That costs a bit of reliability, packets may be dropped. You can expect about 4ms of latency for a 8-byte packet.

--

ZetaRf version 2

ZetaRf version 2 has breaking changes from the v1, as well as bug fixes and various improvements like the support for multiple radio configurations simultaneously.

Please report any issue you find! :)

This library may not be directly compatible with any board implementing Si4455 chip! Currently it was only tested with the ZETA-868-SO and ZETA-433-SO modules from RF Solutions, and DRF4463F modules (868 and 433 MHz) from Dorji.

ZETA module datasheet: https://www.rfsolutions.co.uk/downloads/1456219226DS-ZETA.pdf

Data Packets

You have two options for packet sizing: either fixed length or variable length. The option is choosen when you create the ZetaRf object (suffix _VL)

All packets are transmitted with a 16-bit CRC (IBM-16) and checked at reception.

Fixed size packets:

All packets are transmitted and received with a fixed size. Receiving a wrongly sized packet will mostly result in CRC errors, but you could receive bad messages that happened to make it through.

Default packet size is usually 8 bytes (configured in the radio config files), but you can specify the size you want by using beginWithPacketLengthOf(<packet length in bytes>). Max is 64 bytes.

Receive and sending methods use this packet length by default unless you change it by calling setPacketLength(<new length>)

Variable length packets:

Variable length packets allows for a more efficient use of the RF space when dealing with various messages of different sizes. A size byte is included in the packet and the RX modem automatically handles it.

Receive and sending methods handle the variable part mostly by themselves. Use beginWithPacketLengthOf(<max packet length in bytes>) to limit the maximum packet size at RX.

At this time you cannot peek the packet size before read.

Usage

Power Supply

Zeta modules only supports 1.8V to 3.6V operation, and malfunction issues have been reported with 5V-level signals (e.g. 5V Arduino with 3.3V Zeta). Do not use voltage levels greater than VDD. If you can, power everything with 3.3V or use level shifters (voltage divider or else).

Create the radio object

The library uses templates to be very clear about which config and GPIO you use:

ZetaRf868<ZetaRf::nSEL<10>, ZetaRf::SDN<9>, ZetaRf::nIRQ<8>> zeta; // Pin D10 for NSEL, pin D9 for SDN, etc

ZetaRf868 denotes the radio configuration. Several configurations are available, and you can use your own if needed.

  • ZetaRf868 : RF Solution's ZETA module in 868MHz
  • ZetaRf433 : RF Solution's ZETA module in 433MHz
  • ZetaRf868_VL : RF Solution's ZETA module in 868MHz in variable length packet mode
  • ZetaRf433_VL : RF Solution's ZETA module in 433MHz in variable length packet mode
  • ZetaRf_DRF4463F_868 : Dorji DRF4463F module in 868MHz
  • ZetaRf_DRF4463F_433 : Dorji DRF4463F module in 433MHz
  • ZetaRf_DRF4463F_868_VL : Dorji DRF4463F module in 868MHz in variable length packet mode (COMING SOON)
  • ZetaRf_DRF4463F_433_VL : Dorji DRF4463F module in 868MHz in variable length packet mode (COMING SOON)

Begin

Must be called before any other method.

To use the default radio config packet settings:

zeta.begin()

To specify the packet length (fixed length) or the max packet length (variable length, VL):

zeta.beginWithPacketLengthOf(<packet length>)
zeta.beginWithMaxPacketLengthOf(<max packet length>) // For VL

Event loop

You must poll the lib for new messages or any event that occured:

ZetaRf::Events const ev = zeta.checkForEvent(); // Check default events

Or check for specific events:

Events checkForAnyEventOf(Events filter) // e.g. checkForAnyEventOf(ZetaRf::Event::PacketReceived | ZetaRf::Event::PacketTransmitted)
Events checkForAllEventsOf(Events filter) // Waits for all given events at once

ZetaRf::Events evaluates to true if any event occured, you can then check for any particular event, e.g.:

if (ev & ZetaRf::Event::PacketReceived) { ... }

Events are cleared and do not persist unless they are not "checked" by the above methods.

You can get current events with events() and clear events using clearEvents() or clearEvents(<events>).

Note: PacketReceived will be cleared even if data is left in the FIFO after read (if you don't read it all). Loop on available() or hasDataAvailable() to read everything.

Events available (Default event = checked by checkForEvent()):

Event Default event Description
PacketTransmitted x Packet transmit completed
PacketReceived x Valid packet received and waiting in FIFO. Don't forget to restart listening if you listened for a single packet!
CrcError x CRC Error detected on the received packet (FIFO is reset, packet lost)
TxFifoAlmostEmpty x Tx FIFO almost empty
RxFifoAlmostFull x Rx FIFO almost full
InvalidSync Invalid Sync frame detected (RF modem)
InvalidPreamble Invalid Preamble detected (RF modem)
DetectedPreamble Preamble detected (RF modem)
DetectedSync Sync frame detected (RF modem)
LatchedRssi x RSSI value latched on packet receive (read with latchedRssiValue(), value is reset when restarting RX )
FifoUnderflowOrOverflowError x Underflow or overflow on the FIFO (FIFO is reset)
StateChange Radio state changed
ChipReady Chip ready to accept commands (after power up)
DeviceBusy x The chip didn't respond to a command (sign of comm errors)

*Notes:

  • You should restart listening on any error if you listened for a single packet.
  • DeviceBusy can be considered a "fatal error", it is recommended to call begin to reset the chip upon getting this error.*

Send data

Transmit a packet, for both fixed or variable length configs:

bool sendPacketOnChannel(uint8_t channel, uint8_t const* data, uint8_t dataSize, unsigned long timeoutForReady_ms = 100)

For fixed length packets only:

bool sendFixedLengthPacketOnChannel(uint8_t channel, uint8_t const* data, unsigned long timeoutForReady_ms = 100)

For variable length packets only:

bool sendVariableLengthPacketOnChannel(uint8_t channel, uint8_t const* data, uint8_t dataSize, unsigned long timeoutForReady_ms = 100)

Max data size is 64 bytes. Returns true if the transmission started (it doesn't wait for completion), false on error (timeout or comm error).

A PacketTransmitted event will be raised when the packet transmit completed. The chip will automatically return to the active mode before the transmit.

Receive data

Switch to receive mode

Start listening packets on a channel, and automatically return to RX after packet reception:

bool startListeningOnChannel(uint8_t newChannel)

To listen for only one packet (needed to read the packet's RSSI value):

bool startListeningSinglePacketOnChannel(uint8_t newChannel)

To restart listening on the same channel as previously:

bool restartListeningSinglePacket()

Read data

Use available() or hasDataAvailable() while data is available to read.

Common method to read either a fixed or variable length packet (max data size is the packet length, or for VL configs it is the max packet length set with beginWithMaxPacketLengthOf or setMaxRxPacketLength):

ZetaRf::ReadPacketResult readPacketTo(uint8_t* data)

To specifically read a fixed length packet:

ZetaRf::ReadPacketResult readFixedLengthPacketTo(uint8_t* data, uint8_t packetLength)

To specifically read a variable length packet (optional, use the rxPacketDataLength pointer to get the received packet length (which is also in ReadPacketResult) )

ZetaRf::ReadPacketResult readVariableLengthPacketTo(uint8_t* data, uint8_t* rxPacketDataLength) // Max data size is the max packet length set via beginWithMaxPacketLengthOf or setMaxRxPacketLength.
ZetaRf::ReadPacketResult readVariableLengthPacketTo(uint8_t* data, uint8_t maxDataSize, uint8_t* rxPacketDataLength)

Notes: Reads directly from FIFO. FIFO has a capacity of 64 bytes.

All methods returns an object that evaluates to true if no error occured, or false on error. It contains the error value if any, and the received packet size (receivedPacketSize()).

Simple way:

if (zeta.readPacketTo(data)) { /* Valid packet */ }

Or to check error values:

ZetaRf::ReadPacketResult const result = zeta.readPacketTo(data);
if (result != ZetaRf::ReadPacketResult::Success) { /* Error */ }

// or

switch (result.value()) {
case ZetaRf::ReadPacketResult::PacketSizeLargerThanBuffer:
	// do something?
	... etc
}
Error Values Description
Success Packet received and valid
PacketSizeLargerThanBuffer VL mode, received packet is bigger than the given data buffer (use receivedPacketSize() to get the size)
InvalidPacketSize VL mode, the size byte of the received packet is invalid (either null or bigger than the FIFO capacity)
RequestFailed Comm error with the chip
InvalidArgument Invalid argument(s) passed to the method
NotEnoughDataInFifo The FIFO doesn't contain the amout of data you requested
Timeout Comm timeout

Examples

See code examples for more details. (TODO: add more examples)

To build the Raspberry Pi examples, run cmake . followed by make from the root directory. The binaries will be located in the new build folder.

Installation

Arduino

Copy the library folder to your Arduino library folder.

Raspberry Pi

Copy the library folder to your project folder. Add ZetaRF to your CMakeLists.txt file with

add_subdirectory(ZetaRF)

add_compile_definitions(WIRINGPI)
include_directories(ZetaRF/src)

add_executable(MyProject ${SOURCES})
target_link_libraries(MyProject zetarf)

Pin connections

ZETA Pin # ZETA Module Arduino Pi Description
1 ANT - - Antenna (small wire for tests works great (86mm long for 868MHz))
2 GND GND GND Power Ground
3 SDN GPIO GPIO Shutdown (active high)
4 VDD VDD 3v3 Power (1.8V to 3.6V)
5 nIRQ GPIO GPIO IRQ (active low)
6 NC - - Not Connected
7 GPIO1 - - Not Used or Hardware CTS for DRF4463F modules (active low)
8 GPIO2 - - Not Used
9 SCLK SCLK SCLK SPI Clock
10 SDI COPI COPI Zeta SPI In to Arduino SPI Out (Controller Out, Peripheral In)
11 SDO CIPO CIPO Zeta SPI Out to Arduino SPI In (Controller In, Peripheral Out)
12 nSEL CS GPIO Chip Select (active low)

Configuration files

The project contains WDS XML configuration files, used to generate configuration files, if you want to change some settings. Be careful, it might brake things if you don't know what you're doing.

Note: FRR are used and enforced by the library to read module state and interrupt registers. Changing the FRR configuration will break the library.

Credits

All contributions are welcome! Open an issue or make a Pull Request to contribute.

@adamfowleruk - 433MHz configurations

@hallgchris - Raspberry Pi port

Todo List

  • More examples
  • Frequency selection with enum instead of define
  • Configurable auto-return to listening mode
  • Sleep/Active status commands

License

See LICENSE file.

zetarf's People

Contributors

adamfowleruk avatar gipda avatar hallgchris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zetarf's Issues

ZetaRF library working slow

Yesterday I had a problem. Zeta.begin was working for about 5 sec on arduino mega. Today I tried with the same code, everything was the same but now zeta.begin worked for just 1.4 sec. That was strange...
After testing with arduino mega I tried uno and nano and I got much better results. Arduino nano from the powering to message sent 0.9 sec, arduino uno 0.9 sec, arduino mega 2.4 sec. Arduino nano and uno were Chinese versions while mega was original. After this test I tried using Chinese arduino mega, but with no success. It was keep looping void setup () even with 2 sec delays added.
Then I tried using baud 4800 as suggested by beinnlora (before I used baud 115200 as a default in this library). And I was surprised to get just 0.16s from power up to message sent (I was using arduino nano). So its 5.6 times faster than with baud 115200 and 15 times faster than arduino mega.
Test http://prntscr.com/mtwnqq
So I guess arduino mega should be avoided while testing and for better speed baud 4800 is a good choice. I will try to improve speed further, however why did my arduino mega worked 3 times slower yesterday than today with the same connections, same computer, same code?

Raspberry Pi support

Hey GIPdA!

I've recently been working on porting your v2 branch to run on a raspberry pi for my own use. I was wondering, is this something you'd be interested in having in your project?

You can find my work so far here if you're interested. It seems to be working, although so far it's still a WIP. Wasn't sure whether to make a PR or to just gauge interest first as I'm new to open source and not really familiar with etiquette... But if you're interested, I'll tidy it up and make a PR :)

Keen on hearing your thoughts!
Chris

VariableLength Code transmitting but not receiving

Hi, I uploaded the example code for Simple RxTx on two transceivers for 915 MHz, one is connected to an Arduino nano and the other one to UNO using a logic level converter. Everything works properly with the fixed length example code, however when I try the variable length code, I am able to transmit from one transceiver but nothing is seen on the other end.
I also tried to activate the debug mode on one end but I don't receive any additional information regarding the receiving part.

I put a serial print right after the zeta.available() function, but it never goes past it. I'm not able to understand why there is such a difference from the fixed data package to the variable one.

P.S. I am testing the two transceivers without antennas as of now, it's not meant to but I just wanted to get everything right before soldering an antenna.

CleanShot 2023-06-15 at 15 36 11@2x

Problems with 434Mhz

Hi!
First, thank you for share!
you did a wonderfull work!

Can you help me with a issue?
For some reason the project don´t work with 434Mhz!!
I have a RF stick (EZRadio 4455Cled-434) in 434 Mhz and like to test it with your Project and my zeta (ZETA-1 ver B).

I read this info from ZETA:
Read IT status:
Chip rev: 17 , Part : 21828 , PBuild : 0 , ID : 3328, Customer: 0, Rom ID : 3 , Bond : 0, Rev Ext : 3 , Rev Branch: 0 , Rev Int : 13, Patch : 0, Func : 1 , SVN Flags : 0 , SVN Rev : 3540385792

I believe it´s about config file.... can you help?
I attached the config file to this post.

Thanks in advance.
Besta regards,
Regis

radio_config_fixed_434.zip

Qn: Wiring diagram for this library...

Hello,

Thanks for writing this library - I wasn't looking forward to hand cranking it myself. It doesn't seem to work for me though. I assume I've not wired my Arduino Pro Mini to the Zeta chip correctly, or it's because I've got the 433 MHz chip.

Could you please add to your repository anything that may help me. E.g. photo of a correctly wired up module to an Arduino, wiring diagram, or guidance around 433 MHz settings.

I'm working on a data radio project for a youth group I work with.

Thanks very much in advance.

Investigate packet reception loss in variable length mode

In variable length mode, in any RX mode, waiting for a packet might cause the RX to stall and the radio module stops receiving any packet. Less likely in single packet RX than in continuous RX. Not seen happening in fixed packet length mode.
Apparently, not recoverable without a hard reset.
Detection doesn't seems possible without a radio state change (to TX or maybe READY, will cause a comm error).

Recurring routine to change state could impact RX, but there is probably no other way around it.

Possible data corruption when sending way too fast (Teensy 4)

Sending multiple packets without delay (500us-1ms) might lead to data corruption. The lib is supposed to wait before sending to avoid that, so tests are needed. See ZetaRf::waitUntilOutOfTx.
Seen on Teensy 4. These being so fast, might need to add a small delay before or after.
Workaround: add a 1ms delay after or before sending. No less than 500us.

TX not working with Teensy 4

Somehow bad behaviour on SPI bus it seems, RX works but TX doesn't (doesn't report error but no packet received on the other end).
Seen on Teensy 4.0, possibly on 4.1 too, with DRF4463F. Not tested with Zeta.
Will investigate soon.

Arduino Due Support

Attempting to get this to work for an Arduino Due, but these are ARM based. Any ideas on what needs to change?

Questions about other possibilities of zeta library

Hello again.
I'm new at github so I'm not sure if this is a good place for the following questions.

  1. I tested zeta 433 mHz modules with this library and I got this data https://prnt.sc/mtn3nu My code worked for 0.8 s, zeta.begin 4.5 sec, 0.3 sec for sending a message. I want to use these modules as a switch so 4.5 sec becomes a problem. Is it possible to reduce that time? If yes, how much? Range doesn't matter that much.
  2. Is it possible to use Si4455 without external mcu? For example it would be wonderful by raising GPIO1/2 to high and making it to send preinstalled messages.

Issues with Teensy/433Mhz - begin(...) returning false

Hello! Thank you for making thing fantastic project :) I have been trying to run your library on a Teensy LC and 3.6 with the 433 MHz version of the Zeta. Unfortunately I've been unable to get anything to send yet - although I strongly suspect user error.

Here's serial output I get from running the example code in this repository (with #define ZETARF_FREQUENCY_433MHZ 1 added before the ZetaRF include). I've also defined ZETARF_DEBUG_VERBOSE_ON.

21:27:42.221 -> Starting Zeta TxRx...
21:27:42.320 -> Read IT status
21:27:42.320 -> Invalid Preamble
21:27:42.320 -> CMD Error
21:27:42.320 -> Read IT status
21:27:42.320 -> Invalid Preamble
21:27:42.320 -> Read IT status
21:27:42.320 -> Invalid Preamble
21:27:42.320 -> FIFO Under/Overflow Error
21:27:42.486 -> Read IT status
21:27:42.486 -> FIFO Almost Empty
21:27:42.486 -> Invalid Preamble
21:27:42.486 -> FIFO Under/Overflow Error
21:27:42.486 -> CMD Error
21:27:42.486 -> Read IT status
21:27:42.486 -> FIFO Almost Empty
21:27:42.486 -> Invalid Preamble
21:27:42.486 -> Read IT status
21:27:42.486 -> Invalid Preamble
21:27:42.486 -> FIFO Under/Overflow Error
< Cropped output, continues like this for a while >
21:27:43.778 -> Read IT status
21:27:43.778 -> FIFO Almost Empty
21:27:43.778 -> Invalid Preamble
21:27:43.778 -> FIFO Under/Overflow Error
21:27:43.778 -> CMD Error
21:27:43.778 -> Read IT status
21:27:43.778 -> FIFO Almost Empty
21:27:43.778 -> Invalid Preamble
21:27:43.778 -> Read IT status
21:27:43.778 -> Invalid Preamble
21:27:43.778 -> FIFO Under/Overflow Error
21:27:43.778 -> ----------
21:27:43.778 -> Chip rev: 34
21:27:43.778 -> Part    : 85
21:27:43.778 -> PBuild  : 134
21:27:43.778 -> ID      : 1536
21:27:43.778 -> Customer: 0
21:27:43.778 -> Rom ID  : 0
21:27:43.778 -> Bond    : 0
21:27:43.778 -> 
21:27:43.778 -> Rev Ext   : 6
21:27:43.778 -> Rev Branch: 0
21:27:43.778 -> Rev Int   : 2
21:27:43.778 -> Patch     : 256
21:27:43.778 -> Func      : 0
21:27:43.778 -> SVN Flags : 69
21:27:43.778 -> SVN Rev   : 12285568
21:27:43.778 -> ----------
21:27:43.778 -> Read IT status
21:27:43.778 -> FIFO Almost Empty
21:27:43.778 -> Invalid Preamble
21:27:43.778 -> FIFO Under/Overflow Error
21:27:43.778 -> Init done.

zeta.systemError() returns false, but zeta.begin(...) is also returning false.

Any ideas what might be causing this? Thanks for your help :)
Chris

Problems with receiving zeta433d rf

Hello, I'm using 2 zeta 433D-rf, 1 arduino uno and 1 arduino nano as microcontrollers. I made sure to connect everything as mentioned in the table below this library, but the problem is that I can't receive messages. I'm using examples from this library, sending messages via serial monitor, both rf modules have 433 mHz antennas. It seems that transmitting process works fine. Rf modules powered by 3.3 V, also I added line #define ZETARF_FREQUENCY_433MHZ 1
Am I missing something?

ZetaPLUS 868MHz - UART wiring and code

Hello,

I was wondering if the library supports the ZetaPLUS module using UART communications? I successfully made 2 modules work at 868MHz using SPI; however, when I send the data (using the SimpleRxTx example) from my Board1 (Elegoo UNO R3),

11:33:24.616 -> TX >values
11:33:24.616 -> <
11:33:24.654 -> Packet transmitted

I receive this on Board2 (Kuman UNO R3):

11:33:24.655 -> Packet received with RSSI: 216
11:33:24.655 -> RX >��������<
11:33:24.655 -> HEX >
11:33:24.655 -> FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF<
11:33:24.655 -> Error: Device Busy! Restarting...

When I switch their roles,

Board2:

11:36:58.871 -> TX >Hello 
11:36:58.871 -> <
11:36:58.871 -> Error: Device Busy! Restarting...

And nothing is received on Board1.

I tried using a Leonardo instead of the problematic board (same pins), I get the same issue using the TM4C123 board:

11:47:38.699 -> Starting Zeta TxRx...
11:47:38.929 -> Failed to initialize the radio module!
11:47:38.929 -> ZetaRf begin failed. Check wiring?

Second part of my question:

Does the library support UART communication, and do you have any code examples to make it work?

Thanks a lot because I've been struggling for too long using 868MHz RF modules such as Zeta or MRF89.

(I can give you links if wanted :)
Kylian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.