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 project 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 Pico. The transceiver features two PiicoDev 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 PiicoDev 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. If your Pico is going to be communicating with another type of Dev board, check the guide for help with setting up that other Dev board. It's best to have at least two transceivers, two Dev boards, and hardware to connect everything together. 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 Dev board with two transceivers.

Plug your Pico into your expansion board, making sure the USB connector is on the same side as the two pin battery connector. Connect your PiicoDev cable to the PiicoDev socket and click the other end to your transceiver. If your second transceiver setup uses the same Dev board, then set it up in exactly the same way. Or, if you're using a different Dev board for your second transceiver setup, check the guide for instructions specific to that Dev board.

Alright I have my two transceivers set up now, before we connect these to our computer we'll change some settings in Thonny to make life a bit easier. Open Thonny go to Tools > Options and in the General tab make sure you uncheck the "Allow only single Thonny instance" option. When we uncheck that, this means that we can open two Thonny windows and have one window per device. We have a note to restart Thonny after changing, so I'll press OK and will restart Thonny.

Now I can connect my first Pico, click Stop/Start and we have a Pico connected. Now I'll launch another instance of Thonny and connect my second Pico, click Stop/Start and the shell gives us a warning we have Picos detected on COM9 and COM11. Go to Run > Select Interpreter and I'll select the highest COM port number 11. And now I'm connected to my second Pico.

So you can see it's helpful to connect to one Pico at a time so that we know which is which. Now things might get a little bit confusing working with two separate Thonny windows, 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).

We need to download some driver files next. Find the Download/Install PiicoDev Modules section, right click PiicoDev unified and click "Save Link As" and I'll save that to a PiicoDev directory in my documents. And do the same with PiicoDev Transceiver.py , save link as and I'll save it to that same directory.

In both the Thonny windows we can see the File pane, I've navigated to that directory in Funny. For my transmitter I'll select both those files and upload them and we can see them appear on my transmitting Pico. And for my receiver I'll do the same.

We have prepared these Picots ready for programming, it's time to transmit and receive some data. Find the Transmit/Receive section and click Transmit. itself isn't very useful so let's look at how we can send more complex data

There's a little documentation about how to use the send and receive methods in the article. For now, scroll down to the example to transmit and receive data. You can see there are two code listings for this example; on the left we have the transmitter code and on the right the receiver code. Copy all that code for the transmitter and paste it into a new script in Funny. Take all the receiver code and copy that into a new script for your receiver.

First, run the receiver code and save it if prompted. My receiver is running the code and there's nothing being printed to the Shell because we're not transmitting anything yet. Next, run the transmitter code and save if prompted. Very interesting! Let's take a closer look at what's just happened. When we ran the transmitter code, the receiver has immediately printed four messages. We have the message "Hello World", another message which looks like a number, and then a couple of more complex messages.

Let's take a closer look at these example scripts. We'll start with the transmitter. We set up the transmitter code much like every other PicaDev project by importing the device driver and a delay function. Next, we initialize the transceiver and we're calling that radio. So, every time you see the word radio in the transmitter script, we're referring to this PicaDev transceiver. Next, we send a simple string. We use the send method to send the string "Hello World" and that's exactly what we saw on the receiving end. Look at that; we get capitals, we get lowercase, and we even get some punctuation like commas and that exclamation point. After a short delay, we send a number. Here, we're sending just a value 123. This could be an integer or a floating point number with a decimal point and you can see on the receiver we got that 123. Now, sending just a number by itself isn't very useful, so let's look at how we can send more complex data.

Itself can be a little bit confusing, especially if we want to send different types of data and we don't want to mix up those different types of data.

So, the next two lines are some labelled values. Here, we create a variable called named data and we're assigning that a tuple. This tuple contains a string which is the label, in this case temperature °C, and then after a comma we have the value, in this case 25.0. We call radio.send named data and on the receiver end that tuple comes back out. We have 25.0 with the label temperature °C and we do something similar with humidity percent and 60.0.

So, you can see this labelled data can be useful if we want to separate our data so it doesn't get mixed up. You can imagine this being used for say a weather station where we wouldn't want to mix up the two different types of data that we're sending.

Those are the three ways that we can use send. We can send a simple string, we can send a value all by itself, or we can send a value with a label in the form of a tuple.

So, what's the receiver doing? We initialize it in exactly the same way with the same three setup lines and the receiver is running an infinite loop. We call if radio.receive which will return true if a new message has been received. We can access the contents of that message by reading from the radio.message attribute. So, we read that into a variable called simply message and finally we print message. We're running this on a pretty fast loop which means that this is constantly polling the radio to see if a new message has been received. This polling rate is faster than the rate at which we're sending messages and that's pretty important if you don't want to miss any messages.

Okay, so we can send and receive simple messages. Let's actually control some real hardware using... the receiver we can just check if the message is equal to LED on then we can turn the LED on and if the message is equal to LED off then we can turn the LED off

These messages you might recall that the PiicoDev transceiver has a user controllable LED on it. This LED more or less behaves like a power LED; it always turns on when the device gets power, but you can turn it on and off if you wish.

Let's remix this example code to create a simple remote controller. We'll have our transmitter periodically send on/off commands. The receiver will listen for these commands and turn its LED on or off depending on what message it gets.

Let's start with the transmitter. Starting at the bottom, I'll delete all of this code up to "send hello world". I know that I want an infinite loop, so I'll create a while true loop and I'll put all of that code inside the loop. Let's create a command to send. I propose that we send "LED: on" to turn the LED on and "LED: off" to turn the LED off (radio.send("LED: off")).

Now we have to decide which of these messages to send. We'll just continuously send "on/off, on/off" over and over again. For that, I'll need a state and we'll set that to false to begin with. Then, every loop, we can check if state is equal to false; then we want to turn the LED on, so we send the command for "on". We can also check if state is equal to true and that's when we want to turn the LED off, so we send the "off" command. Then, at the end of our loop, we can say "state is equal to not state" that will turn true to false and false to true. And we can delay (sleep) ms 1000.

So what we have just done is write an infinite loop that loop will continuously send on/off commands every one second. I'm just going to run this code before working on the receiver. Now, since my receiver was still running from the example, I can actually see those commands are coming in on the receiver. That's pretty cool! So we're periodically getting "LED on"/"LED off" now.

Let's do something with that. This part's pretty easy. In the receiver, we can just check if the message is equal to "LED on" then we can turn the LED on and if the message is equal to "LED off" then we can turn the LED off.

We can just check the contents of the message variable after we print the message. We can just insert a couple of if statements: if message is LED on then we want to turn the LED on the board on and that is Radio dot LED equals true. Likewise, if message is equal to LED off then radio dot LED equals false and that's it.

If we run this code again, we're getting our messages printed to the Shell as before and we can also see that that LED is blinking at exactly the same time. Very cool, we can control Hardware over the air. This is a very simple example but from here you can do whatever you like.

Now 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 picnic 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.

To add a second transceiver to the PK Dev bus, 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 PK Dev 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 and 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!

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.