Hello friends, I hope you all are doing great. Today, I am going to share the 433 MHz RFM69 Sensor Gateway on Raspberry Pi 5 - Proteus Simulation, the seventy-second project of our IoT Projects series. If you have searched for an RFM69 Raspberry Pi gateway, how to read an RFM69HCW from Python, what RSSI and link margin mean, or a Proteus simulation of a 433 MHz sensor network, here is a complete one. A field node with a temperature sensor sends its readings over a small sub-GHz radio, and a Raspberry Pi 5 with the same radio is the gateway: it answers every packet, works out how healthy the link is and shows it on an OLED and a web dashboard.

Radio links are where many IoT projects fail, and they fail quietly: a packet that never arrives looks just like a sensor with nothing to say. So this gateway does more than print the readings. It measures the signal strength of every packet, compares it with what the receiver needs, turns the loss of the path into a distance, counts lost and repeated packets, and works out what each message costs the node's battery while the node turns its own power down. In this tutorial, we will go through the circuit, the RFM69 packet format, ACKs and retries, the link budget, path loss and the log-distance model, automatic transmission control, air time, duty cycle and battery charge, and then the Python program and the node's sketch. Then we run the simulation with the radios 100 m, 1 km and 2 km apart. At the end, you can download the project with both programs and every library file.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the 433 MHz RFM69 sensor gateway on Raspberry Pi 5 in Proteus simulation:

Figure: The RFM69 sensor gateway in a Proteus simulation: the gateway hears the node at -80 dBm.
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This RFM69 Gateway Do?

  • Hears the field node: an Arduino UNO with an RFM69HCW and an NTC thermistor sends its temperature, its message number and its transmit power every 2 seconds.
  • Talks RFM69 from Python: the Raspberry Pi 5 drives its own RFM69HCW over SPI with the same settings and packet format as the popular LowPowerLab library.
  • Answers every packet: an ACK within milliseconds, carrying the signal strength the gateway heard.
  • Lets the node save its battery: with that number the node turns its power down until the gateway hears -80 dBm, automatic transmission control.
  • Judges the link: the RSSI, the margin over the receiver's sensitivity, the path loss and the distance it means.
  • Counts what goes wrong: lost packets from gaps in the message numbers, repeats when the node missed an ACK, LINK WEAK, LINK LOST and LINK BACK.
  • Prices each message: the time on air, the duty cycle and the charge the node's radio takes from the battery.
  • Shows it all: a 0.96" OLED and a dashboard with an RSSI history picture on a laptop or a phone.

It is a great project for learning SPI register programming, a radio packet protocol and the physics of a radio link together. In the simulation, each RFM69HCW has its own pop-up with the link budget, the last packet decoded, the DISTANCE buttons and a set of test tools, so every number the Raspberry Pi works out can be checked against the radio model itself.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and the TEP Pi runtime.

The parts of the RFM69 sensor gateway and their library posts
PartProteus deviceLibrary postConnection
Raspberry Pi 5RASPBERRY PI 5Raspberry Pi 5 Library for ProteusPI1, rfm69_gateway.py, Ethernet 192.168.1.51
RFM69HCW radio (gateway)RFM69ADVTEPRFM69HCW Library for ProteusU1 on SPI0, DIO0 GPIO25, RST GPIO24
Arduino UNO (field node)ARDUINO UNO V4.0Arduino UNO Library for Proteus V4.0ARD1, RFM69_Field_Node.hex, serial monitor built in
RFM69HCW radio (node)RFM69ADVTEPRFM69HCW Library for ProteusU2: SCK D13, MISO D12, MOSI D11, NSS D10, RST D9, DIO0 D2
NTC thermistor 10k, B 3950NTCBEAD10KTEPNTC Thermistor Library for ProteusRT1 from A0 to GND
SMD resistor 10kRESISTORSMD1206TEPSMD Resistor LibraryR1 from +5V to A0
SSD1306 OLED 0.96" 128x64OLED12864WHITEADVTEPOLED SSD1306 Library for ProteusOLED1, I2C1 at 0x3C
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the RFM69 Gateway: the Circuit

Figure: The complete circuit of the RFM69 sensor gateway on an A3 Proteus sheet.
The connections of the gateway and the field node
SignalRaspberry Pi 5 (gateway)Arduino UNO (node)
SCKGPIO11 (pin 23)D13
MISOGPIO9 (pin 21)D12
MOSIGPIO10 (pin 19)D11
NSS (chip select)CE0, GPIO8 (pin 24)D10
RST (active HIGH)GPIO24 (pin 18)D9
DIO0 (packet ready)GPIO25 (pin 22)D2
VCC / GND+3.3V / GND+3.3V / GND
SensorOLED: SDA pin 3, SCL pin 5A0: R1 10k to +5V, RT1 NTC to GND

Both radios are wired the same way: the SPI bus with a chip select, a reset line that is active HIGH on the RFM69, and DIO0, the pin the radio raises when a whole packet has arrived. Each radio's VCC is on a +3.3V supply terminal, because a real RFM69HCW must never see 5 V. The node's temperature comes from a divider on A0: 10k from +5V, then the NTC thermistor to ground, so the voltage falls as the thermistor warms. The OLED shares the Pi's I2C bus. In the simulation the two radios share one air, and the distance between them is chosen with the DISTANCE buttons on either pop-up.

How the RFM69 Sensor Network Works

The Radio and Its Packets

The RFM69HCW is a small module around the SX1231H, a sub-GHz transceiver that sends FSK: a 1 shifts the carrier up by 50 kHz and a 0 down by 50 kHz, at 55,555 bits a second, on 433.92 MHz. Every packet starts with 3 bytes of preamble, 10101010 for the receiver to lock on, then a 2-byte sync word, 0x2D and the network ID (100 here): a radio only listens to packets with its own sync word, which is how separate networks share a frequency. The LowPowerLab format then sends a length byte, the address it is for, the sender's address and a control byte, then up to 61 bytes of data, and the chip adds a 2-byte CRC so a damaged packet is thrown away. The gateway is node 1 and the field node is node 2.

ACKs, Retries and Repeats

A radio cannot know whether its packet arrived, so the node asks: bit 0x40 in the control byte means ACK requested. The gateway must answer with a short packet whose control byte has bit 0x80 set, and it must do so quickly, because the node waits only 30 ms before it sends the same packet again, up to two more times. Two things can go wrong. The packet can be lost, and then the gateway sees a gap in the message numbers. Or the packet arrives but the ACK is lost on its way back: the node then sends the same message again, and the gateway sees the same number twice, a repeat. Counting both tells you in which direction a link is failing.

The Link Budget

Whether a packet arrives is a matter of decibels. The transmitter sends a power, measured in dBm (0 dBm is 1 mW, +20 dBm is 100 mW); the path between the antennas takes away some decibels, the path loss; and what is left, the RSSI at the receiver, must be above the receiver's sensitivity. The sensitivity depends on the bit rate: the slower the bits, the longer each one lasts and the weaker the signal can be. At 55.5 kbps the SX1231H needs -103 dBm; at 4.8 kbps it hears -114 dBm. Worked example: the node at full power, +20 dBm, 100 m away with a path loss of 85 dB, arrives at 20 - 85 = -65 dBm. The margin over the sensitivity is -65 - (-103) = 38 dB: the signal could get 6,300 times weaker and still be heard. Real links need a margin of 10 dB or more, for fading, rain and people walking by, so the gateway flags LINK WEAK below 10 dB.

Path Loss and the Log-Distance Model

In empty space a radio wave spreads over a growing sphere, and the loss grows by 20 dB for every ten times the distance; at 433 MHz it is about 25 dB at 1 m. Near the ground, with trees, walls and the earth itself in the way, it grows faster. The log-distance model says loss = 25 dB + 10 x n x log10(distance in metres), with a path loss exponent n: 2 in free space, about 3 for a typical outdoor link near the ground, up to 4 or more indoors. With n = 3, which the RFM69 model uses: 55 dB at 10 m, 85 dB at 100 m, 115 dB at 1 km, 30 dB more for every ten times the distance. Turned around, the gateway can estimate the distance from the loss. Worked example: the node reports +5 dBm and the gateway hears -80 dBm, so the loss is 5 - (-80) = 85 dB, and the distance is 10 to the power of (85 - 25) / 30 = 10 to the power of 2 = 100 m. The same arithmetic shows how far this link can reach: at +20 dBm the loss may be 20 + 103 = 123 dB, which is 10 to the power of (123 - 25) / 30, about 1.8 km.

Automatic Transmission Control

If the gateway hears the node with 38 dB to spare, the node is wasting power, and the battery pays for it. The LowPowerLab RFM69_ATC class fixes that: the node sets bit 0x20 in its control byte to ask for the RSSI in the ACK, the gateway answers with that number as one extra byte, and the node moves its power one step at a time towards a target, here -80 dBm. After a packet without an ACK it steps up instead. Worked example: at 100 m the node starts at +20 dBm and is heard at -65 dBm; one step a message, it settles at +5 dBm, heard at 5 - 85 = -80 dBm, still with 23 dB of margin. When the path gets longer, the first packets are lost, every failed try pushes the power up, and the link comes back as soon as the margin is positive again. Turning the power down also means less interference for everyone else on the band, and in Europe 433 MHz devices may send only 10 mW, +10 dBm.

Air Time, Duty Cycle and the Battery

A packet costs the battery the radio's transmit current multiplied by the time on air. Worked example: the message N=12 T=24.8 P=5 is 15 bytes, and the whole frame is 3 + 2 + 1 + 3 + 15 + 2 = 26 bytes, 208 bits, which take 208 / 55,555 = 3.74 ms. At +20 dBm the RFM69HCW draws about 130 mA, so one message costs 130 mA x 3.74 ms = 487 microcoulombs; at +5 dBm it draws about 26 mA, 99 microcoulombs, 80 % less. The same air time gives the duty cycle, the share of time the node is on air: 3.74 ms every 2 s is 0.19 %, far under the 10 % that the European rules allow on 433 MHz. A real battery node sends far less often, once a minute or so, and sleeps between messages, so the radio's share of its battery is small; ATC still trims it, and keeps the band quiet.

The Python Program and the Node Sketch Explained

The gateway is rfm69_gateway.py, a Python program for the Raspberry Pi 5 that needs only lgpio, threading and http.server. It opens the radio on SPI0 at 4 MHz:

        self.h = lgpio.spi_open(0, 0, 4000000, 0)               # SPI0, CE0, 4 MHz, mode 0

Every register write is two bytes, the address with bit 7 set, then the value:

    def write(self, reg, v):
        lgpio.spi_xfer(self.h, bytes([reg | 0x80, v]))

When DIO0 goes high, the program reads the RSSI the radio held from the packet, then the length byte and the frame from the FIFO:

        rssi = -self.read(0x24) / 2.0                           # RSSIVALUE: -value / 2 dBm (held from the packet)
        n = min(self.xfer([0x00, 0])[1], 66)                    # the length byte

An ACK goes back before anything else, because the node waits only 30 ms:

                    if ctl & 0x40:                              # an ACK was asked for: answer first (the node waits 30 ms)

With the ATC request, the ACK carries the RSSI as one positive byte:

            self.send(to, 0x80 | 0x20, bytes([min(255, int(round(abs(rssi))))]))

Lost packets come from gaps in the message numbers:

        lost = 0 if first or repeat or n < s['n'] else n - s['n'] - 1

The distance from the path loss, with the log-distance model:

    return 10 ** ((loss - PL_1M) / (10 * EXPONENT))

And the time on air of a frame, byte by byte:

    return (3 + 2 + 1 + 3 + payload + 2) * 8 / BITRATE

The node is RFM69_Field_Node.ino for the Arduino UNO, with the RFM69 library by LowPowerLab. One line turns on automatic transmission control:

  radio.enableAutoPower(ATC_RSSI);

Every 2 seconds it builds its message and sends it with up to two retries, 30 ms apart:

  snprintf(msg, sizeof(msg), "N=%u T=%s P=%d", counter, num, p);
  bool ok = radio.sendWithRetry(GATEWAYID, msg, strlen(msg), 2, 30);

Its transmit power in dBm from the library's power level, and its temperature from the NTC with the B equation:

  return level < 16 ? level - 2 : level < 20 ? level - 4 : level - 3;
  float t = 1.0 / (1.0 / 298.15 + log(r / R25) / BETA);

The OLED gets a new frame every half second: the link state, the RSSI, the margin, the node's power, the path loss and distance, the temperature, the packet counts and the seconds since the last packet. Each packet prints a line on the Pi's terminal, and every event (LINK UP, PACKETS LOST, REPEAT, LINK WEAK, LINK LOST, LINK BACK) gets its own line. The pages are / (the dashboard), /rssi.bmp (the RSSI history) and /data (JSON).

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files (the steps are under the download button).
  2. Open Pi-5-RFM69-Gateway.pdsprj from the Proteus Simulation folder. Keep rfm69_gateway.py, RFM69_Field_Node.hex and the DLL files next to it.
  3. Press Play. The two radio pop-ups and the UNO's serial monitor open; the radios start 100 m apart, and the node turns its power down.
  4. On a radio's pop-up press 1 km, then 2 km, then 100 m again.
  5. Open the Laptop or the Mobile WiFi Monitor and press Go for the dashboard.

Simulation Results: the RFM69 Gateway in Proteus

We ran the whole story in one simulation: the radios 100 m apart, then 1 km, then 2 km, then back to 100 m. The distance was set on the gateway radio's pop-up, and the node's own setting stayed at 10 m, so the larger one counts. At the start the node sends at full power:

Figure: The RFM69 gateway simulation at the start: the node at full power.
   1.6 s  LINK UP - node 2, RSSI -65.0 dBm, its power +20 dBm
   1.6 s  [2] N=1 T=25.0 C  RSSI -65.0 dBm  margin 38.0 dB  node +20 dBm  loss 85.0 dB  ~100 m  3.74 ms 487 uC

Every number is the worked example: -65 dBm, a margin of 38 dB, a path loss of 85 dB and 100 m, a frame of 3.74 ms and 487 microcoulombs. The gateway radio's pop-up shows the same link from the radio's side, and the node's pop-up counts its ACKs and shows ATC at work:

Figure: The gateway radio: listening, every ACK sent back with the RSSI.
Figure: The node radio: the ACKs come back, and ATC turns the power down.
Figure: The node's serial monitor: one step down after every ACK.

The node lowered its power one step after every ACK, and the gateway heard it fall: -66, -67, -68 dBm and so on. (The library's power levels have one oddity: level 15 is +13 dBm but level 16 is +12 dBm, so +12 and +13 swap places once on the way down.) After 16 messages it reached the target:

  33.6 s  [2] N=17 T=25.3 C  RSSI -80.0 dBm  margin 23.0 dB  node +5 dBm  loss 85.0 dB  ~100 m  3.74 ms 99 uC
Figure: The RFM69 gateway simulation: the gateway hears -80 dBm.

Now the node sends at +5 dBm and each message costs 99 microcoulombs instead of 487, 80 % less, with 23 dB of margin still in hand. The path loss is still 85 dB, so the distance estimate is still 100 m, because it does not depend on the power. The OLED and the dashboard show the settled link, and the dashboard's picture shows the RSSI bars stepping down while the orange dots of the node's power fall:

Figure: The OLED: RSSI -80 dBm, the node at +5 dBm.
Figure: The dashboard on the Laptop WiFi Monitor: ATC in the RSSI history.

Then we pressed 1 km on the gateway radio's pop-up, at 44.2 seconds. At +5 dBm the node now arrives at 5 - 115 = -110 dBm, far below the -103 dBm the receiver needs. The node's monitor shows what happens next: no ACK, the power one step up after each failed try, three tries a message, until a packet gets through:

Figure: The node's monitor at 1 km: no ACK, the power up, then the link back.
  49.7 s  3 PACKETS LOST (message 25 after 21)
  49.7 s  LINK WEAK - margin 2.0 dB (RSSI -101.0 dBm at +12 dBm)

Three messages were lost, and the first one through came with a margin of only 2 dB. That packet's distance estimate, 858 m, is a little short, and for an instructive reason: the message reports the power it started with (+12 dBm), but the try that arrived had already been stepped up to +14 dBm. From then on, ATC raised the power one step per ACK until it reached the top:

  59.6 s  [2] N=30 T=25.3 C  RSSI -95.0 dBm  margin 8.0 dB  node +20 dBm  loss 115.0 dB  ~1000 m  3.89 ms 505 uC
Figure: The RFM69 gateway simulation at 1 km.
Figure: The gateway radio at 1 km: -95 dBm, 8 dB of margin.

At full power the link holds at -95 dBm with 8 dB of margin. The path loss of 115 dB gives exactly 1,000 m, and the radio's own verdict agrees: OK by 8.2 dB, with the 7 too-weak packets and 4 CRC errors of the transition counted. The gateway keeps LINK WEAK on the OLED and the dashboard, because a real link with 8 dB of margin would drop out in the first rain shower:

Figure: The OLED at 1 km: LINK WEAK.
Figure: The dashboard at 1 km: the bars turn red under 10 dB of margin.

Next we pressed 2 km, at 70.5 seconds. At full power the node now arrives at 20 - 124 = -104 dBm, 1 dB short of the sensitivity, and no amount of retrying helps. Ten seconds after the last packet the gateway gave up:

  79.6 s  LINK LOST - no packet for 10 s (the last: RSSI -95.0 dBm at +20 dBm)
Figure: The RFM69 gateway simulation at 2 km: the link lost.
Figure: The gateway radio at 2 km: too weak by 0.8 dB.
Figure: The dashboard: LINK LOST.

This is where a lower bit rate would save the link: at 4.8 kbps the receiver needs only -114 dBm, and -104 dBm would have 10 dB to spare. Finally we pressed 100 m again, at 87.2 seconds. The node was still at full power after all its failed tries, so the first packet arrived very strong:

  87.6 s  LINK BACK after 18.0 s - RSSI -65.0 dBm, the node at +20 dBm, 8 packets lost
Figure: The RFM69 gateway simulation: the node back at 100 m.

The gap in the message numbers tells the gateway exactly how many packets the outage cost, 8, and ATC immediately started to turn the node down again: +19, +18, +17 dBm and on. The dashboard's RSSI history tells the whole story in one picture, the slope down at 100 m, the red bars at 1 km, the gap at 2 km and the climb back:

Figure: The dashboard at the end: the RSSI history of the run.
Figure: The same dashboard on the Mobile WiFi Monitor.
Figure: The Raspberry Pi 5 terminal: a line for every packet and every event.

The run covered 103 seconds of simulation in 590 seconds on our PC, with no repeats at all: every ACK left the gateway within a few milliseconds. In our first test run the gateway wrote its whole OLED frame, 1 KB over I2C, in one go, and ACKs waiting behind it came too late. The node then retried most messages and ATC never got going, which is why the program now writes the OLED one small transfer at a time between radio checks. It is the same advice as in the real hardware section: keep long jobs out of the loop that has to answer the radio.

Download the Project Files

Click the button below to download RFM69-433MHz-Sensor-Gateway-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 15 MB, without the source code of the models):

433 MHz RFM69 Sensor Gateway on Raspberry Pi 5 - Proteus Simulation V1.0
  • Proteus Simulation: Pi-5-RFM69-Gateway.pdsprj, rfm69_gateway.py, RFM69_Field_Node.hex and copies of the models.
  • Python Code: rfm69_gateway.py, the gateway program.
  • Arduino Code: RFM69_Field_Node.ino, the node sketch.
  • Proteus Library Files: the LIB files of the Raspberry Pi 5, the RFM69HCW, the Arduino UNO, the NTC thermistor, the SMD resistor, the OLED and the two WiFi Monitors.
  • Proteus Model Files: the DLL models and the TEPPi folder, the Python runtime of the Raspberry Pi 5.
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy everything in Proteus Model Files, the DLL files and the TEPPi folder, into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

The gateway program is plain Python: edit rfm69_gateway.py next to the project and press Play again. The sensitivity, the path loss model, the LINK WEAK and LINK LOST limits and the radio's registers are at the top. The node sketch needs the RFM69 library by LowPowerLab from the Arduino Library Manager; compile it for the Arduino UNO, export the compiled binary and set ARD1's PROGRAM property to the new HEX file. NODEID, NETWORKID, ATC_RSSI and the time between messages are at the top of the sketch.

Ideas to Extend the Project

  • Add more nodes: each with its own NODEID, and the gateway keeping a table of their links.
  • Turn on AES encryption on both sides with the same 16-character key, and see what a wrong key does.
  • Let the gateway switch both sides to 4.8 kbps when a link stays weak: 11 dB more sensitivity, more than twice the range.
  • Put the node to sleep between messages and work out a real battery life from the sleep current and the message charge.
  • Forward the readings to MQTT or a database, and plot the RSSI over a day.
  • Fit the path loss exponent from readings at two known distances instead of assuming 3.

From Simulation to Real Hardware

  • 3.3 V only: the RFM69HCW is not 5 V tolerant; on an Arduino UNO use a level shifter or a breakout with one, and a 3.3 V regulator that gives 130 mA.
  • An antenna, always: a straight quarter-wave wire, 16.4 cm at 433 MHz, on the ANT pad; never transmit at +20 dBm without one.
  • Stay legal: use the frequencies and powers allowed where you live; in Europe 433 MHz devices may send 10 mW with up to 10 % duty cycle.
  • Mind the ACK time: on a busy Raspberry Pi, use an interrupt on DIO0 or a dedicated thread so the ACK leaves within 30 ms.
  • Expect fading: a real RSSI jumps by several dB from packet to packet; average it before you judge a link, and keep 10 dB or more of margin.

Troubleshooting

  • RFM69 not responding: check the SPI labels, RST on GPIO24 and the radio's +3.3V terminal.
  • No packets at all: both sides need the same frequency, bit rate and network ID; the pop-up's Registers page shows what each side wrote.
  • The node prints no ACK although the gateway sees the packets: the ACK came too late; keep long waits out of the gateway's loop.
  • The temperature reads -99: the divider on A0 is open; R1 goes to +5V and the NTC to GND.
  • The OLED stays blank: SDA / SCL on GPIO2 / GPIO3, address 0x3C, VCC on 3.3 V.

Limitations of the Simulation

  • The radio link is the RFM69 library's model: a log-distance path loss with exponent 3 and the SX1231H's sensitivity at each bit rate, without fading or noise, so the RSSI is steady from packet to packet.
  • The link uses the larger of the two radios' DISTANCE settings, and both directions see the same loss.
  • The transmit currents are the datasheet's typical values; a real module and its supply differ.
  • The network to the laptop and the phone is simulated inside Proteus.
  • Raspberry Pi is a trademark of Raspberry Pi Ltd and Arduino a trademark of Arduino SA; this project is not made or endorsed by them or by Labcenter.

So, that was all about the 433 MHz RFM69 Sensor Gateway on Raspberry Pi 5 - Proteus Simulation. I hope it helps you understand how an RFM69 is driven from Python, how ACKs and retries keep a link honest, what the RSSI, the margin and the path loss tell you, how automatic transmission control saves a node's battery and what each message costs, all tested in a simulation before you put radios in a field. More IoT projects with the ESP32 and the Raspberry Pi 5 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!