Wireless communication, here we come! With a couple of PiicoDev Transceivers we'll create a simple messaging system and control some real hardware. This guide will cover connecting your PiicoDev Transceivers to a dev. board and how to send control messages. From here the sky is the limit - gather data from remote sensors or control distant hardware. It's up to you!

Transcript

Wireless connectivity is a staple of modern technology. We use the radio spectrum to transmit and receive all kinds of data for entertainment, communications, and telemetry. The PiicoDev Transceiver is a data radio you can use in your projects to send and receive simple messages. Use it to create a wireless messaging system, maybe control some distant hardware, or transmit data from a remote weather station.

In this guide, we'll set up two transceivers and send data between them. This video will go over connecting the transceiver to a Raspberry Pi. The transceiver features two PicaDev connectors for daisy-chaining with other hardware, a transmit and receive indicator, a user controllable LED, and ID switches to allow daisy-chaining with other PicaDev smart modules. Make sure all the ID switches are off for now.

The transceiver is compatible with different dev boards too and enables different dev boards to wirelessly communicate with each other. This is all the hardware you need to connect a PicaDev transceiver to a Raspberry Pi. To follow along, it's best to have two complete dev boards each set up with their own transceiver. Now, instead of getting set up using two Raspberry Pies, I'm going to use a Raspberry Pi Pico for my second device. It's a very cost effective dev board and once we're working in the Thonny programming environment, the code that we write for the Pi and the Pico looks the same.

If you've got two Pies and you want to set both of them up for this, then absolutely go for it. Likewise, if your second device isn't a Pico, check the guide for specific advice on setting up that dev board with the transceiver. If you only have one dev board, don't worry. There's a demo at the end of this guide where we can prototype a project on a single board with two transceivers set up. The Pi can be connected by following the instructions in the guide.

The PiicoDev adapter connects to the GPIO header on our Raspberry Pi 4. There's an arrow pointing towards the Ethernet connector. Connect your PiicoDev cable to one of the ports on the adapter and connect the other end to your transceiver.

I've booted up my Pi connected to the internet and we'll just do a few housekeeping things before running some examples. First, go to the Pi menu then Preferences > Raspberry Pi Configuration. Under the Interfaces tab, make sure that I2C is enabled. If you change this, you may need to restart your Pi.

Next, go to Programming and make sure you have PiicoDev installed. Go to Tools > Manage Packages and search for PiicoDev and install or upgrade as necessary. One last thing to do in Thonny, go to Tools > Options and uncheck “Allow only single Thonny instance”. This will make life a little bit easier later on and you can see a note here that we need to restart Thonny after changing this option. Restart Thonny.

We're allowing multiple instances of Thonny for the case where you're using another Dev board plugged into your Pi. So, one window we will be writing scripts for our Pi and in the other window we'll be writing scripts for our other Dev board. Now, you can connect your other Dev board to your Pi with USB. This USB cable will be for programming only; all messages are going to be sent wirelessly between the two transceivers.

If you have drivers set up for this Raspberry Pi, we just need to install them onto the other Dev board. In the guide for this article, find the download section and select whatever Dev board you're using, if not a second Raspberry Pi. I'm using a Raspberry Pi Picker, so I'll select that tab. Then, right click each.

I'll save the link to a PiicoDev directory I made in my home directory and repeat for Pikadev transceiver. Save the link as and save to that same directory. Now things might get a little bit confusing working with two separate funny Windows. My left window will be for my Pi and my right window will be for my Pico, so that we don't get lost. I'm going to color the transmitter window teal (T for transmitter) and I'll color the receiver window red (R for receiver).

In the right hand window, go to run configure interpreter and instead of running the local Python 3 interpreter, we want to connect to a Dev board. I'm using a Raspberry Pi picker and we can detach the port automatically and we can see that we're connected to the Pico. Select both those files that you downloaded, right click and upload to great. We now have PiicoDev installed on the Pi using funny and we've uploaded the PiicoDev driver files to the other Dev board. Now we're ready to run some example code.

Return to the article for this tutorial and find the first example transmit and receive. There's some documentation about how to use the transmit and receive message, but if you like you can jump straight to the code. On the left we have the transmitter code, copy all of that code and paste it into the instance of Thigh for your Pi. I'll save this file as transmitter.py. On the right hand side of the screen we have the receiver code, copy and paste all of that code onto your other device.

We have our Pi acting as a transmitter and our Pico as a receiver. First run the receiver code and save if prompted. There's nothing being printed to the Shell just yet, this receiver is just idling waiting for new messages. Return to your transmitter and run that script and immediately in the shell for the receiver we can see some messages. transmitter and receiver must be running at the same time

Come through, how cool is that? We have "Hello World" we have a number and then we have some more complex looking messages. Let's take a closer look at the code. Looking at the transmitter code, first we begin by importing the PiicoDev modules to run the transceiver and then we initialize the transceiver and call it radio. So, for the transmitter code, anytime you see the word radio we're referring to this physical transceiver device. And then quite simply, we can begin sending messages with the send method. So, we call radio.send and we can just send a string "Hello World" and of course that's what came out on the other end on our receiver. There's a short delay then we can radio.send a value. Here we're sending an integer, but this could also be a float.

What about this more complex data? Here we have a value 25.0 and some kind of name. This is what we're calling labelled values. In the transmitter code, we create a tuple called named data and in that tuple is a string that's the label, a comma, and then the value. And then we do the same thing with another type of labelled data. This is really useful so we don't get our data mixed up. We can send data that has different meanings and we can make sure that our receiver can receive that data and sort it appropriately.

Turning now to the receiver code, we have exactly the same three setup lines. That means that when you see the word radio in the receiver code, we're referring to the physical radio connected to the receiver. We have a simple infinite loop in which we check the radio.receive method. This will return true if there's a new message received. The message is held in the message attribute and so we can just read radio.message into a variable called message. We can print that message and then there's a short loop delay. It's important to note that the transmitter and receiver must be running at the same time.

Receiver code is checking for messages much more frequently than the transmitter is sending them. Here we have a very short delay between checks and the transmitter is taking its time between transmissions. This is important if you want to make sure you don't drop or miss any messages.

What else can we do with these radios though? I propose we remix this code and create a remote controller. Recall that the PiicoDev transceiver has a user controllable LED on board. I propose that our transmitter sent continuous messages to instruct the receiver to turn its LED on or off. Here's what that might look like: I'll leave the receiver code running because that's a nice debug tool and will focus on the code for the transmitter first. I'll first delete all of the code below "Hello World". I know we want this to run forever so I'll create a while true loop and we'll put that radio send inside. Let's send our first command which is to turn the LED on. I'll just use something like "LED: On" or copy that. And our command to turn the LED off could just be "LED Off" quite simply. We can insert a short delay and this is it. This is all we need to send two control messages forever.

I'll click run on the transmitter script and you ought to see in your receiver that it is now receiving these LED on/off control messages. So what can we do with these messages on the other end? Well right after the print message statement we can just put in a couple of if statements. If message is equal to "LED On" then we want to turn the LED on and for that we use the dot LED property: radio.LED equals true. That will turn the onboard LED on. And if message is equal to "LED Off" we can turn the LED off: radio.LED equals false.

If I rerun the receiver code everything looks about the same. We still have the same messages coming in on the shell.

The LED on your receiving device is continuously flashing and is synchronized with the messages coming through from our transmitter. This is a very simple example, but from here you can do whatever you like. For projects with many transceivers, you may want to manage radio traffic using addresses and groups. This will allow you to send messages that are only received by the intended recipients. Transceivers can be configured with a radio address, by default this is zero but it can be any whole number up to 127. To send a private message to a specific transceiver, include the address argument when using the send command. When the address argument is not included, send just broadcasts to address zero which all transceivers listen to. So you can broadcast to everyone with address 0, but then if you want to send a private message you use the address of that receiver.

A group is a collection of PiicoDev transceivers that may communicate. The PiicoDev transceiver will only ever send and receive messages within its own group. The group parameter is set at initialization and is a number between 0 and 255. The default is zero. Now it's also possible to run multiple transceivers on the same PiicoDev bus. You might want to do this if you're experimenting and you only have one Dev board, or to create a bridge between two transceiver groups. Recall that we're already working with a transceiver that has all its ID switches off. To add a second transceiver, you first need to set a unique ID. Do this by setting the first ID switch on and then the rest can remain off. Then daisy-chain the new transceiver onto the PiicoDev bus. Now in the code we can initialize the two different transceivers. The first instance...

I'm calling transmitter and it's the unit with all the ID switches off so I've included the ID argument with four zeros for the second instance called receiver. The first switch is on so there is a one in the first place of the ID argument. The remaining three switches are off so there are three zeros that follow.

When I run the code, the transmitter will continuously transmit new values and the receiver will receive the values and print them to the shell. And so there you have it, getting started with the PiicoDev transceiver.

I hope you're as excited by this as me. This is a really powerful tool we can send simple text messages from one device to another and you could use that to create some kind of remote control system or remote data Gathering system. You can do a lot by transmitting data over the air. I can't wait to see what you make with your PiicoDev transceiver.

If you make anything cool or you just have some questions, let us know on our forums. We're full-time makers and happy to help. Until next time, happy making! Oh...

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.