Uncategorized

PiVirtualWire

VirtualWire support for Raspberry Pi Feb 25, 2016

https://quadmeup.com/virtualwire-support-for-raspberry-pi/

FS1000A and XY-MK-5V 433MHz RF modules are very often first choice for cheap and dirty Do It Yourself wireless communication. Pair of those , allowing one way radio communication, const less than 3 dollars or euros. So they are really cheap. Limited range and transmission speed limits their real life usage, but simple assembly and extremely easy programming are additional advantage over more complex solutions. Specially in Arduino world, with VirtualWire library. I will not write about it right now, there is enough on the internet already.

FS1000A and XY-MK-5V 433MHz RF modules for Raspberry Pi

Unfortunately, problems starts when you want to do cross platform communication based on those modules and VirtualWire library. For example with Arduino and Raspberry Pi. I have found exactly one working implementation of VirtualWire library that is written in Python and works well with Raspberry Pi. And it was hidden. So, with some effort I allowed myself to wrap this code into small python library and this is how piVirtualWire was created.

It depends on pigpio library and requires it installed on Raspberry Pi:

wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
make install
`

And running always in the background sudo /home/pi/PIGPIO/pigpiod

Then, all you need is code.

Transmitter module python code example

This code snippet assumes that FS1000A TX module ADAT (DATA) line is connected to GPIO 4 and uses 1000 baud rate. piVirtualWire library is located in piVirtualWire subfolder.

`import piVirtualWire.piVirtualWire as piVirtualWire
import time
import pigpio

if __name__ == "__main__":

    pi = pigpio.pi()
    tx = virtualwire.tx(pi, 4, 1000) # Set pigpio instance, TX module GPIO pin and baud rate

    msg = 42

    tx.put(msg)
    tx.waitForReady()

    tx.cancel()
    pi.stop()
`

Receiver module python code example

This code snippet assumes that XY-MK-5V is connected to GPIO 18 and uses 1000 baud rate.

`import piVirtualWire.piVirtualWire as piVirtualWire
import time
import pigpio if name == "main": pi = pigpio.pi() rx = piVirtualWire.rx(pi, 18, 1000) # Set pigpio instance, TX module GPIO pin and baud rate while True: while rx.ready(): print(rx.get()) time.sleep(0.5) rx.cancel() pi.stop() Happy Arduino to Raspberry Pi radio transmissions with FS1000A and XY-MK-5V! Tagged as: #Arduino #Electronics #FS1000A and XY-MK-5V #Radio #Raspberry Pi .END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.