pyupm_rf22 module

class pyupm_rf22.RF22(spiBus=0, slaveSelectPin=10, interruptPin=2)[source]

Bases: object

API for the RF22 Transceiver Module.

ID: rf22

Name: ISM Band Radio Transceiver

Other Names: RFM22B

Category: wifi

Manufacturer: sparkfun

Link:https://www.sparkfun.com/products/12030

Connection: spi This base class provides basic functions for sending and receiving unaddressable, unreliable datagrams of arbitrary length to 255 octets per packet.

Subclasses may use this class to implement reliable, addressed datagrams and streams, mesh routers, repeaters, translators etc.

On transmission, the TO and FROM addresses default to 0x00, unless changed by a subclass. On reception the TO addressed is checked against the node address (defaults to 0x00) or the broadcast address (which is 0xff). The ID and FLAGS are set to 0, and not checked by this class. This permits use of the this base RF22 class as an unaddressable, unreliable datagram service. Subclasses are expected to change this behavior to add node address, ids, retransmission etc.

Naturally, for any 2 radios to communicate that must be configured to use the same frequency and modulation scheme.

RF22 Sensor image provided by SparkFun* underCC BY-NC-SA-3.0.

C++ includes: rf22.hpp

FSK_PN9_Rb2Fd5 = 1
FSK_Rb125Fd125 = 9
FSK_Rb19_2Fd9_6 = 6
FSK_Rb2Fd5 = 2
FSK_Rb2_4Fd36 = 3
FSK_Rb38_4Fd19_6 = 7
FSK_Rb4_8Fd45 = 4
FSK_Rb57_6Fd28_8 = 8
FSK_Rb9_6Fd45 = 5
GFSK_Rb125Fd125 = 17
GFSK_Rb19_2Fd9_6 = 14
GFSK_Rb2Fd5 = 10
GFSK_Rb2_4Fd36 = 11
GFSK_Rb38_4Fd19_6 = 15
GFSK_Rb4_8Fd45 = 12
GFSK_Rb57_6Fd28_8 = 16
GFSK_Rb9_6Fd45 = 13
OOK_Rb19_2Bw335 = 22
OOK_Rb1_2Bw75 = 18
OOK_Rb2_4Bw335 = 19
OOK_Rb38_4Bw335 = 23
OOK_Rb40Bw335 = 24
OOK_Rb4_8Bw335 = 20
OOK_Rb9_6Bw335 = 21
UnmodulatedCarrier = 0
adcRead(adcsel=0, adcref=0, adcgain=0, adcoffs=0)[source]

uint8_t adcRead(uint8_t adcsel=RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR, uint8_t adcref=RF22_ADCREF_BANDGAP_VOLTAGE, uint8_t adcgain=0, uint8_t adcoffs=0)

Reads a value from the on-chip analog-digital converter

adcsel: Selects the ADC input to measure. One of RF22_ADCSEL_*. Defaults to the internal temperature sensor

adcref: Specifies the reference voltage to use. One of RF22_ADCREF_*. Defaults to the internal bandgap voltage.

adcgain: Amplifier gain selection.

adcoffs: Amplifier offset (0 to 15).

The analog value. 0 to 255.

available()[source]

uint8_t available()

Starts the receiver and checks whether a received message is available. This can be called multiple times in a timeout loop true if a complete, valid message has been received and is able to be retrieved by recv()

ezmacStatusRead()[source]

uint8_t ezmacStatusRead()

Reads and returns the current EZMAC value from register RF22_REG_31_EZMAC_STATUS The current EZMAC value

headerFlags()[source]

uint8_t headerFlags()

Returns the FLAGS header of the last received message The FLAGS header

headerFrom()[source]

uint8_t headerFrom()

Returns the FROM header of the last received message The FROM header

headerId()[source]

uint8_t headerId()

Returns the ID header of the last received message The ID header

headerTo()[source]

uint8_t headerTo()

Returns the TO header of the last received message The TO header

init()[source]

uint8_t init()

Initializes this instance and the radio module connected to it. The following steps are taken: Software reset the RF22 module

Checks the connected RF22 module is either a RF22_DEVICE_TYPE_RX_TRX or a RF22_DEVICE_TYPE_TX

Configures the RF22 module

Sets the frequency to 434.0 MHz

Sets the modem data rate to FSK_Rb2_4Fd36 true if everything was successful

lastRssi()[source]

uint8_t lastRssi()

Returns the RSSI (Receiver Signal Strength Indicator) of the last received message. This measurement is taken when the preamble has been received. It is a (non-linear) measure of the received signal strength. The RSSI

mode()[source]

uint8_t mode()

Returns the operating mode of the library. the current mode, one of RF22_MODE_*

static printBuffer()
recv(buf, len)[source]

uint8_t recv(uint8_t *buf, uint8_t *len)

Turns the receiver on if it not already on. If there is a valid message available, copy it to buf and return true else return false. If a message is copied, *len is set to the length (Caution, 0 length messages are permitted). You should be sure to call this function frequently enough to not miss any messages It is recommended that you call it in your main loop.

buf: Location to copy the received message

len: Pointer to available space in buf. Set to the actual number of octets copied.

true if a valid message was copied to buf

reset()[source]

void reset()

Issues a software reset to the RF22 module. Blocks for 1ms to ensure the reset is complete.

rssiRead()[source]

uint8_t rssiRead()

Reads and returns the current RSSI value from register RF22_REG_26_RSSI. If you want to find the RSSI of the last received message, use lastRssi() instead. The current RSSI value

send(data, len)[source]

uint8_t send(const uint8_t *data, uint8_t len)

Waits until any previous transmit packet is finished being transmitted with waitPacketSent(). Then loads a message into the transmitter and starts the transmitter. Note that a message length of 0 is NOT permitted.

data: Array of data to be sent

len: Number of bytes of data to send (> 0)

true if the message length was valid and it was correctly queued for transmit

setFHChannel(fhch)[source]

uint8_t setFHChannel(uint8_t fhch)

Sets the frequency hopping channel. Adds fhch * fhs to center frequency

fhch: The channel number

true if the selected frequency center + (fhch * fhs) is within range

setFHStepSize(fhs)[source]

uint8_t setFHStepSize(uint8_t fhs)

Sets the frequency hopping step size.

fhs: Frequency Hopping step size in 10kHz increments

true if center + (fhch * fhs) is within limits

setFrequency(center, afcPullInRange=0.05)[source]

uint8_t setFrequency(float center, float afcPullInRange=0.05)

Sets the transmitter and receiver center frequency

center: Frequency in MHz. 240.0 to 960.0. Caution, some versions of RF22 and derivatives implemented more restricted frequency ranges.

afcPullInRange: Sets the AF Pull In Range in MHz. Defaults to 0.05MHz (50kHz). Range is 0.0 to 0.159375 for frequencies 240.0 to 480MHz, and 0.0 to 0.318750MHz for frequencies 480.0 to 960MHz,

true if the selected frequency center + (fhch * fhs) is within range and the afcPullInRange is within range

setMode(mode)[source]

void setMode(uint8_t mode)

Sets the parameters for the RF22 Idle mode in register RF22_REG_07_OPERATING_MODE. Idle mode is the mode the RF22 will be in when not transmitting or receiving. The default idle mode is RF22_XTON i.e. READY mode.

mode: Mask of mode bits, using RF22_SWRES, RF22_ENLBD, RF22_ENWT, RF22_X32KSEL, RF22_PLLON, RF22_XTON.

setModeIdle()[source]

void setModeIdle()

If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, disables them.

setModeRx()[source]

void setModeRx()

If current mode is Tx or Idle, changes it to Rx. Starts the receiver in the RF22.

setModeTx()[source]

void setModeTx()

If current mode is Rx or Idle, changes it to Rx. Starts the transmitter in the RF22.

setModemConfig(index)[source]

uint8_t setModemConfig(ModemConfigChoice index)

Select one of the predefined modem configurations. If you need a modem configuration not provided here, use setModemRegisters() with your own ModemConfig.

index: The configuration choice.

true if index is a valid choice.

setModemRegisters(config)[source]

void setModemRegisters(const ModemConfig *config)

Sets all the registered required to configure the data modem in the RF22, including the data rate, bandwidths etc. You can use this to configure the modem with custom configurations if none of the canned configurations in ModemConfigChoice suit you.

config: A ModemConfig structure containing values for the modem configuration registers.

setPreambleLength(nibbles)[source]

void setPreambleLength(uint8_t nibbles)

Sets the length of the preamble in 4-bit nibbles. Caution: this should be set to the same value on all nodes in your network. Default is 8. Sets the message preamble length in RF22_REG_34_PREAMBLE_LENGTH

nibbles: Preamble length in nibbles of 4 bits each.

setPromiscuous(promiscuous)[source]

void setPromiscuous(uint8_t promiscuous)

Tells the receiver to accept messages with any TO address, not just messages addressed to this node or the broadcast address

promiscuous: true if you wish to receive messages with any TO address

setSyncWords(syncWords, len)[source]

void setSyncWords(const uint8_t *syncWords, uint8_t len)

Sets the sync words for transmit and receive in registers RF22_REG_36_SYNC_WORD3 to RF22_REG_39_SYNC_WORD0 Caution: this should be set to the same value on all nodes in your network. Default is { 0x2d, 0xd4 }

syncWords: Array of sync words

len: Number of sync words to set

setTxPower(power)[source]

void setTxPower(uint8_t power)

Sets the transmitter power output level in register RF22_REG_6D_TX_POWER. Be a good neighbor and set the lowest power level you need. After init(), the power will be set to RF22_TXPOW_8DBM. Caution: In some countries you may only select RF22_TXPOW_17DBM if you are also using frequency hopping.

power: Transmitter power level, one of RF22_TXPOW_*

setWutPeriod(wtm, wtr=0, wtd=0)[source]

void setWutPeriod(uint16_t wtm, uint8_t wtr=0, uint8_t wtd=0)

Sets the wakeup timer period registers RF22_REG_14_WAKEUP_TIMER_PERIOD1, RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RF22_R<EG_16_WAKEUP_TIMER_PERIOD3

wtm: Wakeup timer mantissa value

wtr: Wakeup timer exponent R value

wtd: Wakeup timer exponent D value

spiBurstRead(reg, dest, len)[source]

void spiBurstRead(uint8_t reg, uint8_t *dest, uint8_t len)

Reads a number of consecutive registers from the RF22 using burst read mode

reg: Register number of the first register, one of RF22_REG_*

dest: Array to write the register values to. Must be at least len bytes

len: Number of bytes to read

spiBurstWrite(reg, src, len)[source]

void spiBurstWrite(uint8_t reg, const uint8_t *src, uint8_t len)

Write a number of consecutive registers using burst write mode

reg: Register number of the first register, one of RF22_REG_*

src: Array of new register values to write. Must be at least len bytes

len: Number of bytes to write

spiRead(reg)[source]

uint8_t spiRead(uint8_t reg)

Reads a single register from the RF22

reg: Register number, one of RF22_REG_*

The value of the register

spiWrite(reg, val)[source]

void spiWrite(uint8_t reg, uint8_t val)

Writes a single byte to the RF22

reg: Register number, one of RF22_REG_*

val: The value to write

statusRead()[source]

uint8_t statusRead()

Reads and returns the device status register RF22_REG_02_DEVICE_STATUS The value of the device status register

temperatureRead(tsrange=0, tvoffs=0)[source]

uint8_t temperatureRead(uint8_t tsrange=RF22_TSRANGE_M64_64C, uint8_t tvoffs=0)

Reads the on-chip temperature sensor

tsrange: Specifies the temperature range to use. One of RF22_TSRANGE_*

tvoffs: Specifies the temperature value offset. This is actually signed value added to the measured temperature value

The measured temperature.

waitAvailable()[source]

void waitAvailable()

Starts the receiver and blocks until a valid received message is available.

waitAvailableTimeout(timeout)[source]

bool waitAvailableTimeout(unsigned long timeout)

Starts the receiver and blocks until a received message is available or a timeout

timeout: Maximum time to wait in milliseconds.

true if a message is available

waitPacketSent()[source]

void waitPacketSent()

Blocks until the RF22 is not in mode RF22_MODE_TX (i.e. until the RF22 is not transmitting). This effectively waits until any previous transmit packet is finished being transmitted.

wutRead()[source]

uint16_t wutRead()

Reads the wakeup timer value in registers RF22_REG_17_WAKEUP_TIMER_VALUE1 and RF22_REG_18_WAKEUP_TIMER_VALUE2 The wakeup timer value

class pyupm_rf22.uint8Array(nelements)[source]

Bases: object

cast()[source]
static frompointer()