LoRa - Long-Range Radio for IoT | Arduino, ESP32, RPI Pico

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we'll be working with Laura you'll see how this amazing radio system works and how we can use inexpensive Laura modules with an Arduino Uno Raspberry Pi Pico and esp32 we'll also build a remote data Gathering system with a remarkable range or go in the distance today so welcome to the workshop [Music] well hello and welcome to the workshop and today we're going to be working with an absolutely amazing radio technology called Laura now Laura is a low-cost low power technology that uses an unlicensed band to send small bits of data over very large distances with Lori you don't necessarily need to measure the distances between devices using meters or yards you can use kilometers or miles is that good now today I am going to show you how you can use some very inexpensive Laura modules with some common microcontrollers and we'll be using an Arduino Uno we'll be using a Raspberry Pi Pico and we'll also be using an esp32 we'll be programming those microcontrollers using both C plus plus and micro python so you can see how versatile it is to work with Laura so let me begin today today's video by telling you a little story about why you would want to use Laura instead of Wi-Fi or Bluetooth in your next iot project now let's say that you're an experimenter and you live in a nice orange house right beside an ice green tree and you decide to wire iot sensors into your house you use Wi-Fi and connect the number of iot devices throughout your house and it works pretty well although on some of the remote regions of your house the signal is a bit weak you then decide to add some sensors to the outside of your house and the ones that you place near your home still get a reasonable signal however the sensors you have out by the nice green tree don't get enough signal at all now if our experimenter was to switch their system to using Laura instead of Wi-Fi they'd find that they get a full signal throughout their home as well as outside including outside by the nice big green tree but that Laura signal can travel even further it can travel out to the nice Red Barn and Beyond the nice Red Barn into the field and in addition the Laura devices consume so little power that they can use alternate energy sources such as solar energy Laura is a low-powered long-range radio system it uses Fred Specter modulation and this makes it resilient to noise and interference because of this Laura systems can have a range of 15 kilometers or nine miles in rural areas but the range can be much further than that in fact the world record for Laura at the moment is 832 kilometers or 517 miles it was set in the Netherlands using a balloon Laura has very low power consumption the data rate of Laura is only 300 to 50 000 bits per second and this rate can be dynamically adjusted Laura is best suited for small bursts of low bandwidth data Laura has built-in encryption so your data is safe one of the best features of Laura is that it uses an unlicensed Radio band the industrial scientific and medical or ISM band The Frequency allocation for the ism band is different in different parts of the world and you could have to make certain that you're using the correct frequencies for your area in addition the 2.4 gigahertz band can be used worldwide within each of these frequency bands there are a number of different channels allocated for both uplinks and down links here is the channel allocated for the North American frequency band of 902 to 928 megahertz this is commonly referred to as the 915 megahertz band the spread Spectrum technology used by Laura allocates its entire bandwidth so nothing is wasted this makes it exceptionally resistant to noise and multi-path Distortion multi-path Distortion occurs when a signal bounces off of something and arrives at a different time if you remember the old analog television this was perceived as ghosts in your picture Laura makes use of CSS or chirp spread Spectrum modulation CSS uses curb signals for data transmission a chirp is a signal that changes frequency rapidly it embeds information Within These kirps the illustration over here shows a shirt with a frequency increase and this is called an upshurp in this illustration we see a chirp with a frequency decrease and this is called a down chirp the duration and bandwidth of a chirp are unique and distinct because they are unique they are very distinguishable below the noise floor and this is what gives Laura its incredible distance capabilities multiple Laurent devices will use different chirp variations to distinguish themselves Laura also adjusts the spreading factor and the number of Terps used when discussing Laura the topic of Laura Wan will inevitably come up it's important to realize the distinction between the two Lara describes the physical layer of the transmission it describes things such as the hardware as well as the software used to directly interact with that Hardware Laura Wan describes a communication protocol and network architecture that uses this Hardware we can use a standard data diagram to illustrate the relationship between Lauren and Laura in this diagram the application layer is on the very top below the application layer sits the Mac layer and this is the layer that is serviced by Laura Wan below the Mac layer is the physical layer and the physical layer is what is serviced by Laura in a typical lorawan setup the Laura devices are called nodes and these nodes can be connected to other devices called gateways a node can connect to more than one Gateway and you can have more than one node connection to a gateway all the connections between the end nodes and the gateways are performed using lower radio signals now the gateways are connected to a network server and that Network server in turn is connected to a number of application servers these application servers can drive the various applications that the end nodes are servicing note that the connection on this side is all done by tcpip and is a standard internet connection that can either be wired or Wireless but we don't need to concern ourselves with all that at the moment because today we're just going to focus on Laura we're going to do some very basic experiments using two different nodes or devices we'll also do an experiment using a controller and multiple devices as well we'll be making use of a couple of very inexpensive Laura modules and will also be using some very common microcontrollers so now let's get started with Laura now the experiments that we're going to be doing today are all based around really the same module the rfm95 module by hope RF I've got that module in a couple of different forms over here now here's the Hope RF module itself and you can get these things on eBay and Amazon they're really inexpensive and they're very common now the one thing you'll notice first off about this module is how tiny it is in fact if I place this row of standard header pins against it you can see that it's even tinier than the standard headers so you can't just solder on pins onto this and expect to use it on a subtle as breadboard so there's a couple of solutions for that the first one is to jury rig it yourself and that's what I did over here this is basically just a piece of perf board and I've soldered it onto the perf board and on the back of the perf board you can see I've got all the wires over here from The Hope RF module to a bunch of pins and this actually works pretty well I've got a wire antenna on it and I'm going to be using this in one of my demonstrations today but a nicer way of doing it is to use this now this is a little board that I picked up on digikey it's actually made by pie Maroni and this board allows you just to put the module on top of the board and as it has castellated pins you can just solder it and you end up with something that looks like this and this is a much nicer module to use than the homemade one that I had and it's got all the pins labeled out for you and everything so that's a really easy way to use that now I understand SparkFun also makes these with the module already soldered onto a board I wasn't able to obtain those but you might be able to now the other solution I'm using is from Adafruit and it's actually the same module but they've got the module on a breadboard compatible board over here although when I say breadboard compatible take it with a grain of salt it's very wide over here but I'll show you some solutions for using it with a subtle as breadboard because it's not going to fit on a standard breadboard properly now this module has a couple of advantages the first one as I said is that the pins are spaced 0.1 of an inch so it's more compatible with the stuff that we're using but also it has a regulator on it a 3.3 volt regulator so it can be used with anything from three to six volts whereas The Hope RF module over here can only be used with 3.3 volts another thing about it is it has logic level converters so it's uh compatible with any type of logic and that's really handy now you'll notice it doesn't have any pins on it you have the solder the pins you also have to figure out the antenna connection which is over here and there's a couple of things you can do for that you can solder a little antenna connector onto it and I've got one down here that I've done you can take a look at my handiwork over here I soldered one of those on another thing you can do is what I did with the other module and just put a piece of wire onto it so you can handle that either way and the modules are essentially interchangeable except of course for the voltage thing on the Adafruit module so you want to pay attention to that now there are other common modules out there that you can probably use with the same code if they have an SPI interface chances are they will probably work as well now one very important consideration in any Lora installation is the antenna that you're going to use it can really make a difference in the range that you're going to get now it is imperative that you do use an antenna even if it's just a piece of wire you should never run a Lora module without an antenna connected to it you can actually damage the module I've got a few here that you can choose from this is a pretty standard type of Allura antenna you'll find a lot of these things are available in a lot of places including Amazon and sometimes they're even included with the adapters and they're very tiny they have an SMA connector on them and you can extend this type of a thing with a piece of SMA coax and that's very readily available as well if you want to mount the antenna distance from the receiver this is another very tiny antenna it's meant to go into a very tiny case that I'll be showing you in a few moments but it certainly is not that big at all and this of course is the module we used earlier the Adafruit module and as you can see I've got a piece of wire on it and that's quite sufficient as an antenna but it can't just be any length of wire the length of the wire you use is dependent upon the frequency that you're using and so as I'm using 915 megahertz my wire is just a little bit over three inches and you can see from this chart what length of wire you would need to use depending on the operating frequency of your Laura now if you want to go full flood you can take a look at an antenna like this this is an outdoor antenna that comes with a big piece of coax over here it even comes with mounting brackets and this is of course the thing that you would use if you're setting up some sort of a repeater or some sort of a metropolitan area network or something or just want to experiment as I do with using a fancy antenna with Laura so as you can see there's a wide variety of antennas make certain though that at least you use a piece of wire don't ever run these devices without an antenna now I want to show you another Laura radio module it's not one that we're going to be using in our experiments today it's one that you'll see in a future episode of the dronebot workshop when we discuss Laura Wan and this is from Seed Studio it's called the Laura E5 and it's actually a very nice little module it's supposed to outperform the Hope RF module although in the tests I'm doing they really both performed as great now this has a couple of differences in the Hope RF module one thing you can see is that you don't need the solder this module it uses what they call The Grove connection system and that's something that Seed Studio uses for a lot of its products in fact I've got a system set up over here right now with a little development board it's got a cduino show on it and the development board has an OLED display and it's connected with a few Grove connectors one to our Laura module and the other one to a temperature and humidity module and this is running on something called the things Network which I'll explain to you a little bit more in depth when we talk about Laura Wan another difference in this module is that it basically is treated like a modem it uses a Serial interface and our other module is serial of course it's SPI but this one uses a uart interface and it actually is treated like a modem you just use the at command set to control this module so it's a really neat little device and you'll be seeing this again in a future episode of the dronebot workshop and one last piece of equipment that we're going to be using in a future episode of dronebot Workshop this is a bit different than everything else we've seen so far because this is not just a Laura radial module it's actually a microcontroller that has Laura built into it this is the hell Tech esp32 Laura board and as you can see it's actually a very nice little assembly with a built-in OLED display it uses USBC which is very nice and if you turn it over down here you'll see there's a little connector that is for a lipo battery a 3.7 volt lipo that you can power the board off of and it also will recharge through the USBC so it's really nice all-in-one solution and for a real all-in-one solution you can also order it with this little case and with this case you can put the board into here it's got a place on the bottom here so you can get at the Lipo and at all the gpio pins it uses that really a tiny little antenna that I showed you earlier it's got a top on it with a bezel and this will attach to the two buttons on the board so you've got a complete Laura on the go kind of setup over here so that's a very nice option right here you can see it running right now it's running something called meshtastic and again I will explain what meshtastic is in a future episode but it's got this little antenna connected to it and a very visible OLED display so it's a really nice module and you'll be seeing more of this in a future episode of the dronebot workshop so now that we have the fundamentals of Laura down and we've looked at a few Laura devices it's time to begin working with this amazing technology we're going to take two of the Adafruit modules as well as a couple of Arduino Unos and do some basic Lora experiments we'll be programming with the Arduino IDE using C plus plus and we'll be making use of a really amazing Library the Laura Library which makes working with Laura about as easy as writing to the serial monitor now the Laura Library by Sandeep mystery is available on GitHub and is also available within the Arduino IDE Library manager here we are on the GitHub page and you can see the components of the library you can also take a look at the compatible hardware and you can see that it works with a number of different lore boards and so not just the one that we're using today so this is a pretty good library for many of your Laura experiments now if you want to find out how to use the library go into the API dot MD and that shows you how you include the library at the beginning pretty simple and how we do a begin with the frequency that we have to set up in this in the setup and how we set the pins that we're using for our Laura module and now this tells you how to send data so you can begin a packet over here with begin packet or begin packet with an implicit number how we write data to the packet and how we end data from the packet also there are some callbacks some transmit and receive callbacks as well as some packet parsing we can do so there's a lot of good information up over here so let's get that Library installed and start using it with our Arduino IDE now before we can start working with any of our experiments we're going to need to install the Laura Library into our Arduino IDE so go into your library manager and simply type Laura into the filter and you'll come back with a number of different libraries now if you scroll a little bit over here you'll find the one we want Laura by Sandeep mystery and this one has already been installed on mine if you haven't installed it of course you'll click the install button and then you'll have the library and the library comes with a number of sample files you can look at as well we'll be basing our first Laura experiments on the Adafruit rfm9 modules now if you want 868 or 915 megahertz you'll want an rfm95 and if you'd like 433 megahertz you'll need an rfm96 otherwise the connections and the operation are identical now these are frequency shift keying packet radios they have a power output of up to 100 milliwatts and they consume anywhere between 50 and 150 milliamps for a transmission they'll also consume 30 milliamps during a receive they use an SPI connection and these modules can operate from anywhere from 3.3 to 6 volt DC and they'll take 150 milliamps of current they're also both 3.3 and 5 volt logic safe so this is an ideal module to use with 5 volt logic devices like we're going to be using today we're going to be pairing our module with an Arduino Uno we're also going to require a push button switch this is just a normally open momentary contact switch we'll need an LED any color of LED will do and a dropping resistor for the LED now if you're using the original UNO this can be any value from 150 to 470 ohms but if you're using the new R4 Uno you'll want to keep it at 330 ohms or higher we'll Begin by connecting the five volts from the Uno to the v in pin on the module we'll connect the ground connection from the Uno to a ground connection on the module pin 3 of the Arduino Uno will be connected to the G zero output this is the interrupt output of the module pin 13 will be connected to sck pin 12 to miso and pin 11 to MOSI we'll connect pin 4 to the Cs or clip select lead and pin 2 of the Arduino Uno will be connected to the reset pin on the Lora module we'll connect pin 8 of the Arduino Uno to one side of our push button switch the other side of the push buttons which will be connected to ground Arduino Uno pin 5 will be connected to one side of our dropping resistor and we'll connect the other side of the dropping resistor to the anode of our LED we'll connect the cathode of the led to the ground and one very important connection is an antenna you should never use the module without an antenna so you'll need to hook up an appropriate antenna to your module now remember you're going to need to build two of these circuits to follow our experiments so build them both and now we'll look at some code we can use to exchange messages between them using Laura now we're going to begin our Laura experiments with a very simple demonstration that just sends data packets between one device and another you're going to have to designate one of your arduinos as being the sender and the other one is being the receiver and here's the code you're going to run on the sender now it's actually pretty simple we're going to start off by including the required libraries and we need the SPI Library which is built into your Arduino IDE and the Laura Library which we just installed next we need to define a couple of the connections that we're using to the Laura module because they aren't the standard connections as far as the library is concerned and then we Define a byte that we call the message count and we're just going to use this as a counter now in setup we'll set up our serial Monitor and then we'll go and we'll do a setup for Aura and this is where we use set pins and apply those pins that we gave it here earlier and over here is where we begin Laura and this is where you're going to have to make certain you've got the right number in over here this is the value you'd use for North American frequencies for 915 megahertz but if you're in a different part of the world you're going to need to use a different value for this so make certain that you use the correct one for your area after that we go into the loop the Loop's pretty simple we print the serial Monitor and then we send our Laura packet look how simple it is to do that we just begin the packet and a Laura print prints out to Laura so this prints out the contents of the packet and then we end the packet it's as simple as that we increment the message counter put in a five second delay because we don't want to send these messages too often and repeat the process so it's pretty simple we'll load this up to the first Arduino and now we'll look at the sketch that we're going to need on the receiver side now on the receive side the sketch is almost as simple as the transmit one was we start off by including the same libraries and defining the pins to the Laura module our setup is pretty well identical we start the serial monitor we set the pins on the Lora module over here we do a begin and so once again make certain that you have the correct value for your location over here and then we move on to the loop now in the loop we are receiving and we're trying to parse a packet so we take a look at the packet size over here if the packet size is greater than zero then we do indeed have a packet and so we begin here we'll print that we've received the packet and then while the packets available we're going to print the actual data within the packet and we do that right over here and then we print the RSSI which is a signal strength and then we end the loop and keep doing it so this is again a very simple sketch that we can use to demonstrate how we can do simple Transmissions with Laura so load this up to the second Arduino and we'll go and demonstrate it and so here's our Laura demonstration now in this demonstration the unit with the green subtle spreadboard is my sender unit and the one with the red solid spreadboard is the receiver unit and you'll notice I used two of these little mini breadboards put together in order to hold the module because that module is very wide and it won't fit on a standard breadboard I'll be showing you another subtlest breadboard a little later on that you can also use with these modules and as you can see from the serial monitor it seems to be working we're sending packets out of one side and we're receiving them on the other side with a very strong signal strength but that makes perfect sense as our modules are literally just a few centimeters apart I'm going to try to cut the signal strength down a little bit maybe put this little piece of Steel in between the two not sure if that's going to help or not and it did reduce it by a little bit maybe if I went this way oh yeah it reduced the RSSI a bit by doing that so I'm blocking some of the signal nonetheless a lot of signal is getting through and of course this demonstration would probably be a lot more interesting if I could separate these two units by a bit but it does serve to prove that it's quite easy to send Laura packets using the Arduino Uno so now that we proved that we can indeed send data between our two arduinos using Laura let's expand upon that and control the LED with a push button we're going to use the push button on the transmitter to control the LED on the receiver and this is a one-way conversation at the moment so our sketch on the sender side is going to start off the same as we always have with the two included libraries and by defining our pins we're going to Define our message counter we've got a couple of other variables over here and this is for the push button the button pin which is the actual pin we're physically connected to and the button State the state of the push button whether it's been pressed or not pressed in setup it's almost the same way of the addition of the push button so we have to put a pin mode in there and we're using the internal pull-up so we didn't have to use a pull-up resistor after that it's essentially the same as before once again remember to always have the correct frequency over here then we go into the Loop and then the loop we're going to take a look at the state of the push button to see if it's been pressed and so the button state is just going to be a digital read on the button pin itself now if the button is pressed that will go low so if it is low we know the push button has been pressed and we'll send the packet and their packet is really simple again we're going to do a begin packet we're going to do a print and this is the contents of the packet the packet's just going to say button pressed we're going to literally send that text out and then we're going to end the packet we're going to increment our message counter and print out the message count and then we're going to add a half a second delay and that's to debounce the push button and we'll go back and do it again in the loop so we're only sending packets out if we happen to press the push button so it's a pretty simple sketch load this one up to the transmitter and now we'll take a look at the one for the receiver and now we come to the receive side of our push button control and so we start off this sketch the usual way with the two libraries and by defining our pins we have some additional variables here we have an integer that represents the LED pin that we've got our LED connected to we have a string called contents which is an empty string to start and that's the contents of our received message a string called button press and it's literally the text button pressed because that's what we're looking for for the transmitter so if you decide to change your transmit sketch to send something else you'll need to modify this part as well and then a Boolean that is the receive button State and this will tell us whether the button on the other end is indicating an off or an on now in setup we go pretty well basically the same thing the only difference is we have to set a pin mode for the LED pin which is of course an output the rest of this is the same as we've seen before again we have to make certain we have the same rate frequency over here here and then we'll go into the loop and for the loop you'll notice a lot of this is the same as our previous receive sketch we take a look to see if we can parse a packet and if we do get a packet we'll print out that we received it and we'll read the packet and we'll print out the packet and the RSSI values to our serial Monitor and now we come down to the button Now button state is going to indicate whether the LED is on or off and so we're going to toggle it every time we receive one of these signals so we're going to make the button State the inverse of what it is right now so it's high we're going to make it low if it's low we're going to make it high and then with that we're going to drive the LED we'll take a look at the button State and if it is indeed High then we're going to drive the led by turning that pin high and printing to the serial monitor that it is on otherwise we'll turn the pin low and print that it is off and we finished everything by clearing out the contents and then we do it all over again so once again it's a pretty simple sketch load it up to the receive side and let's see if we can control our LED with the remote transmitter all right so here's a demonstration of the Laura remote control now this device over here is the sender device and this is the receiver device over here and I've also got the serial monitors open for both devices so if I press the button on the sender you can see the serial monitor says it's sent to packet the other end says it received the packet the button was pressed and the LED is on which indeed it is and if I press it again it'll toggle everything off and I can continue to do so and we can continue to observe it on both the LED and the serial monitor so this is a pretty simple little circuit and a pretty simple sketch but it is the basis for a basic remote control and of course instead of controlling an LED you could control anything really that you could turn on and off with a microcontroller using Laura now the two experiments that we've done so far have sent data just in one direction from a transmitter to a receiver but of course we can send Laura data in both directions and that's why I've got push buttons and LEDs on each of the arduinos will be able to control the other arduino's LED with our push button by sending data in both directions now we're going to make use in our sketch of something called a callback function and we've seen this in other Radio Systems before a callback is something that is initiated whenever data is received it's kind of like an interrupt and in fact we're going to treat it just like an interrupt if you recall the connection from the module to the Arduino there was a connection from an i o pin on the module that went to a pin on the Arduino that had to be interrupt capable and that's because the library treats this callback as an interrupt and so we'll write code for it the same way we'll write a function that needs to get executed every time we receive data and attach it to that callback so let's go and take a look at the code now that we're going to use to send data two ways between our arduinos using Laura now for our two-way Communications demonstration we're going to run the same sketch on both devices although there is a small change that you can make to each device and I'll show you that in a moment we start the sketch off the usual way with the same libraries and defining our pins we Define a number of variables many of what you'll recognize from the previous sketches that we do alt messages are outbound message uh down over here is where you might want to do some modifications now we're going to define the local address that's our address and we'll Define the address of the destination now in this case I've placed FF in here and FF is a broadcast address so if you broadcast this it'll go to any destination but you can change this and what you would do is you would have opposite parameters in the two devices so let's say you change this to CC on the other end you would make this CC and this BB if that makes any sense to you the rest of these are the same variables we've seen before now in this setup we do do a lot of the usual things we have an input pull up for a push button and the LED is an output we'll begin the serial monitor we'll start off Laura we'll set the pins and of course we'll set the correct frequency over here now here's where we do something different and you remember we just discussed the Callback function well here's where we bind it we do on receive what do we do we call the on receive function we just happen to have named our function the same thing and so this is like joining an interrupt to a function we're attacking the on receive to this function which we'll look at in a few moments every time we receive data that function will be activated now we place Laura into a receive mode so we're constantly receiving and we printed the serial monitor that we've initialized successfully now the loop is actually pretty simple and that's because the loop uses a couple of functions so let's go and take a look at the functions first first of all we've got a function to actually send the message so rather than build up the packet inside the loop we're going to call a separate function to do it you can see there's a lot more in our packet now we're going to write the destination address now remember right now the destination is equal to FF so it's a broadcast address but if we want to specifically aim it at the other computer we have to put in its unique address here we'll also write the sender's address this is our own address into the packet the message count we'll write the length of the packet in there and that's because we use this as error checking on the other end to make certain we've received it correctly and then we print the outgoing remember the outgoing variable is actually the contents of our message and then we end the packet and increment the message count so that's to send messages function now here's the function we're going to activate every time we get a callback every time we receive data it looks very similar to what we saw in our other receipt we take a look to see if the packet actually is there and has data in it if it does have data we read some of these things like the recipient descender the incoming message ID and the length from the packet and we set our strength to blank to start off over here we go through and check a number of things first of all we see can we actually get the bytes do we do we'll read them one of the time we'll see if the incoming message length is the same as the message length and better than the packet if it isn't then we know the packet is corrupted and will return over here we'll dump out of the phone out of the function we also want to make sure we're the correct recipient so it has to either be us or FF if it isn't we'll jump out but assuming we made it this far this packet is for us so we'll print all the details of it to the serial Monitor and then we go through the button toggle function to see if we need to actually toggle our LED on or off like we did before so all of these functions are called from the loop so in the loop we just set the push button State as we did before and if the puts button has been pressed we will compose an out message and send the message and put a delay for debouncing it and then we put Laura back into a receive mode because otherwise we just want to be receiving so it's actually a pretty simple sketch load this up to both devices remember after you use it you can play with those addresses and we'll see if we can control our LEDs in either direction now and so here's our demonstration of the two-way Communications between R2 Laura enabled devices and so if I press the yellow push button you will see the yellow LED on the other device illuminate and the blue push button will illuminate the blue one and both push buttons will toggle their respective LEDs and it seems to work pretty well of course I've only got them separated by a few centimeters but you can separate these by large distances and achieve the same results with your simple Laura two-way switch now up until this point all of the work that we've done with Laura has been with the Arduino IDE and C plus plus but of course you can work with Laura using other programming languages so what we're going to do next is take out a couple of Raspberry Pi picots install The micropython Interpreter on them and we'll program for Laura using micropython we're going to take a Laura library that we can get from GitHub that already has some sample code and it'll show you how easy it is to use Laura with micropython it's essentially as easy as it was using osc plus plus so let's get out our picots and install The micropython Interpreter onto them we're going to need to install micropython onto our Raspberry Pi Pico and here's how we do it to start with don't connect the Pico up to your computer use your computer to go to the micropython website and download the latest firmware release of micropython for the Raspberry Pi Pico once you have the file downloaded press and hold the boot cell key on your pico now connect the USB cable from your computer to the Raspberry Pi Pico you should see a drive appear on your computer screen once you see that you can release the boot cell key now copy the file that you downloaded over to that drive once the file has been copied the drive will disappear you can now disconnect the Raspberry Pi Pico and put it on the subtle as breadboard so that we can wire it up once again we're going to be using the Adafruit rfm 9x module we'll Begin by connecting the VN pin on the module to the 3.3 volt output of the Raspberry Pi Pico we'll connect the module's ground to the Picos ground module pin g0 will be connected to picopin gp28 sck pin will be connected to Pico pin gp6 miso will go to gp4 MOSI will go to gp7 the Cs or clip select pin will be connected to gp5 on the Raspberry Pi Pico and finally we'll connect the reset pin to dp27 once again make certain that you've got an antenna connected to your module and now we're ready to begin working with Laura in micropython now for our micropython experiments we're going to be using a library that we can grab on GitHub and it's the ulura library by Martin wheeler now download the library and you will find there are three relevant files and it'll show you them here there's a eulora pi file and that file needs to be copied to both of the Raspberry Pi picots then when you go into examples you'll find there are two files client.py and server.py on one of the Picos you're going to place client py along with the ulura library on the other one you'll place server.py so you'll have one machine with the client in the ulura library and the other machine with the server and the ulura library don't make a subdirectory put both of the files into the same directory if you're looking for an easy way to copy files onto the Raspberry Pi Pico just simply use the thawny IDE open the file up from your computer and then save the file onto the Raspberry Pi Pico now here's the script that we're going to be using on the server side now remember we've copied both server.py and you laura.py which is a library to our Raspberry Pi Pico and so this is server.py we started off by importing sleep from the time library and that's pretty common when we want to put a delay in our program we also import from that you Laura library that we loaded and we import a couple of different functions we'll be looking at this one in a moment then we have a callback function now if you recall from our C plus plus script we used a callback the Callback being activated every time we receive data and the same concept is true in micro python so our callback function is just going to do a number of prints it's going to say who it's from the address which in this case will be the client address received which is the received data so it's going to do the payload message it's also going to print the RSSI and SNR which is the signal strength and the signal to noise ratio now over over here we have the Laura parameters and these are the parameters for hooking up the Laura module and these are the pin outs that we're using for the lower module now this line over here is where we need to take a look at the library it says the SPI bus and it gives the SPI bus connections as this so if we go into the library we'll see that's all defined under SPI config so rp20 defines these four different pins over here so if you're using a different processor you're going to want to take a look at that or if you want to and you want to use different PIN numbers you could always add a statement into here although I don't really know why you'd want to do that underneath here is another thing you're going to need to configure though and that's the frequency in fact if you take this out of the box it's actually set for the European frequency I've got it set for 915 because I'm in North America so I use 915 megahertz so make absolutely certain that you've changed this to the correct value for your location now down here we're going to initialize the Laura radial and then we're going to set our call back the Callback function we saw up over here we'll just establish what it is down here we continuously listen so we put everything into continuous listen mode and then we do a little Loop while true will sleep for a tenth of a second then this that just lets us do things over and over and over so we're just going to continually listen and if the Callback is activated the Callback function will print out on the display so that's a pretty simple application in micropython that we can use to use as our Laura server and so now we move over to the client script and this is even simpler than the server script was it starts off identically we do the two Library Imports that we did before from the time in the ulura library we set up the Laura module parameters exactly the same way that we did in the earlier sketch and we initialized the radio the same as we did in the earlier sketch in fact the only different thing that we're doing is we're creating a loop down over here a while true Loop and we're doing a send and look how easy it is to send data is Laura send to wait and then you send the data and the address you're sending the data to so that's pretty simple then we will just print out sent to let us know that we've sent something and we're going to go to sleep for 10 seconds so every 10 seconds we're going to send out this message to the server side so it's a very simple script and it illustrates this how simple it is to use micropython with Laura let's load all this up and take a look at it working now here's my Raspberry Pi Pico along with the Adafruit Laura adapter and I want you to take note of the subtlest breadboard that I've got them on this is styled a bit differently than a lot of breadboards in that the power rail goes down the center and then you have the common connection rails on the other sides of it and this allows me to stagger the Adafruit module which as we saw earlier was too wide for a conventional breadboard and get connections to it quite easily and it's also really good for those large esp32 and esp8266 modules as well so you might look into getting a breadboard like this also now I've got the Pico and the Laura module hooked up and as you can see the Laura module is just using the wire antenna again and if we go over to take a look at the IDE I can look in the shell and you can see that I'm getting some data and the data is coming from the client side this is the server side the client-side data is not too and interesting to look at in the Shell it just basically says sent scent scent and every 10 seconds it's going to send me a message the message is this is a test message and on this side I can see I received a byte and it tells me that the bite is this is a test message that's the contents of the message the RSSI is the signal strength and the SNR is a signal to noise ratio and so every 10 seconds I get this now the transmit end right now is in my office which is on the other end of the basement so it's not that far away but it's not here in the workshop and so as you can see we can also use micro python instead of C plus plus to program and work with Laura and so now it's time for that data Gathering project that I alluded to earlier we're going to take the two Arduino Unos that we already have wired up and we're going to add a dht22 temperature and humidity sensor to each one of them then we will take an esp32 we'll attach Lora module to it I'm going to use that Laura module that I hand wired the whole bar f one but you could use that or the Arduino module it doesn't matter and we're also going to hook an OLED up to the esp32 to display our temperature and humidity now by itself this is actually a pretty useful device but what I really want you to get out of this is how it works because this is the basis for any data Gathering project using Laura our esp32 is going to pull the two different sensors and they're going to return data to it and you could use this for any type of sensor and any type of data Gathering so let's begin by looking at the wiring we're going to need for this project and then we'll look at how the code works we're going to be using a different Laura module for our main station it's the Hope RF rm95w module that I showed you earlier this is a very popular Laura modem module it has a power output of up to 100 milliwatts and it's sensitive down to negative 148 dbm this module consumes 10 milliamps when it's receiving it has an SPI connection as well as a number of gpio pins now this is the 3.3 volt DC device and it can only accept 3.3 volts and it consumes 120 milliamps it's only a 3.3 volt logic device so do not apply any 5 volt logic directly to it and one thing about this module is it is not subtle as breadboard friendly as the pins are spaced too closely together so you're going to have to come up with some method of wiring it up now if you wish you can use the Adafruit module that we've been using for our previous experiments it is completely compatible and the only difference is the labeling on a few of the pins is Illustrated here with whatever module you decide to use we're going to be using an esp32 now you can use any esp32 board that you happen to have you don't need to use the same one I'm using we'll also be using an OLED display with an i squared C connection we'll Begin by connecting the 3v3 or 3.3 volt output of the esp32 to the 3.3 volt connection on the rfm95w module we'll connect the esp32's ground to the module's ground we'll connect the modules di0 pin to gpio pin 2 on the esp32 the sck connection will be going to gpio pin 18 miso goes to gpio 19 MOSI goes to gpio 23 the NSS pin will go to gpio pin 5 on the esp32 and will connect the reset pin to gpio pin 14. now on our OLED we will connect the ground to the ground of the esp32 and will connect VCC to the 3.3 volt connection we'll also connect the scl line to gpio pin 22 and the SDA to gpio pin 21. and as always make certain that you have an antenna connected to the module before you proceed for our remote temperature sensors we're going to reuse the Arduino Uno circuits that we wired up earlier our new circuits will not require the push button but you can leave it on your board I'm just going to remove it from the diagram for clarity we're going to be adding a DHT 22 temperature and humidity sensor this is also known as an am2302 we'll connect the 5 volt pin of the dht22 to the Arduino Unos 5 volt output the data pin of the dht22 will be connected to pin 9 of the Arduino Uno and we'll connect the ground pin of the dht22 to the Uno's ground note that the third pin on the dht-22 has no connection to it and remember you're going to have to have two of these Arduino Uno circuits to complete our project now let's take a look at the way that our controller and sensors are going to work we have the controller which is maced around an esp32 and our two sensors which are based upon an Arduino Uno the controller will send out a data request to sensor number one and sensor number one will reply with its temperature and humidity data sensor number one will then apply a two second timeout for the dht-22 sensor the controller will then request data from sensor number two and it will return data as well and also apply its own two-second timeout now if we were to request data while the timeout is still active the sensor is just going to ignore it that way the data that we get is always good because we've applied the two second timeout now let's take a look at the remote sensor side and there are two things we want to examine the first being the receive callback the receive callback is very simple as a callback should be we received the Laura message and decide whether it is for us if it isn't for us we'll just exit but if it is for us we're going to update the message variable the message variable is the packet number from the controller it changes with every transmission to let us know that the controller is requesting new data and then we're going to exit now on the loop side we're going to check the message variable coming in that message variable will just simply be a number and we want to see if it's a new one if it is then we've got a new request from the controller we'll read our DHT sensor and we'll send out the Laura message with the sensor values we'll then apply a two second delay before we go back and check the message variable again on the controller side I receive callback is also pretty simple we'll receive the message and decide if it's for us if it is we'll identify the sender is it sensor 1 or sensor 2. once we've identified the sender we'll update the sensor values and also a timestamp variable that determines whether the data is fresh or not and then we will exit on the loop side we'll read those sensor in time variables we'll use the time variable to decide if this is a recent value or if it's an old one if it's an old one we're going to format the display as being missing data because that means that our receiver has not been responding however if it's new we're going to update the data with the first pattern and that pattern has the data from sensor 1 and large letters and from Sensor 2 and small letters we'll apply a three second delay after which we'll make a request to sensor one for data then we'll update the display pattern with Pattern 2 where Sensor 2 has the larger text and sensor 1 is smaller and after a three second delay we'll make a request to sensor to for some more data then we'll go and turn around and do it all over again so by looking at this flowchart you should be able to understand how our system works now let's go and take a look at some code we can use to make it work now here's a sketch that we're going to be using on both of the remote units the Arduino Unos and the sketch requires you to install another library in addition to the Laura library and that's the DHT lib Library by Rob tiller now this is not the normal DHT library and you can find that easily in your library manager this filter by DHT lib and here it is over here so you can install that into your IDE so I'm going to include those libraries and we're going to define a PIN to connect our dht22 sensor to and of course the LED that we still have is connected to pin 5. we'll create a sensor object for the d8t as well then we'll Define the pins used by the Laura module as we've done before we'll Define a message variable for the outgoing message called out message and one for the ingoing message as well and we'll also have the previous value of the incoming message because the incoming message is this going to be basically the sequence number of the packet we want to make sure that it has changed so we're going to we're going to record both the Old and the new one and a message counter as well now here's the only section of the code that you may need to modify in fact you will need to modify it for one of the units this has address AA we're going to be using a a and BB for our two remote sensors and those are just arbitrary choices so you'll need to set one of these to a a and the other one when you compile it before you do set it to BB so we'll have different addresses now here's the Callback function that we're going to be calling up every time we receive a packet we're going to do the normal checks to make certain the packet is okay and will come all the way down over here when the packet is fine we're just going to take the in message variable and update it with the incoming data okay and there's another function we have over here for sending the message and we basically just provide it with the outcome solving string and we do what we've seen before with Laura begin and lower right to send out a packet okay in the setup but it's quite simple we'll set up the serial monitor set the LED up as an output and we'll set up the Laura module we've seen all this before we'll set the Laura module for the correct frequency make certain that you do that we'll attach the Callback function to on receive and we'll place the Laura module in receive mode now in the loop what we're going to do is check to make certain that the message coming in is different from the previous one so we know we're dealing with a new new request and not the old one if we are we're going to read the DHT 22 sensor and get its values we're going to print the results in the serial monitor just for fun we're going to format the outgoing message string and we're going to send that string as the Laura packet so we're going to send that out to the controller print some stuff again on the serial monitor we'll update the old message variable to be the current one we'll Place Laura again receive mode and then we're going to put it into a two second delay and the optional bit is if you're not using the LED you can just put one big long delay here but otherwise we're going to turn the LED on during the two second delay and what that does is this gives you a visual indication that the remote unit is actually working so that's the code loaded up to the remote units make sure to change one of them to BB and we'll now look at the controller code and here's the sketch that we're going to be using on the controller side the side that has the esp32 now we're going to start by including the required libraries in one set of libraries you'll need to get her the Adafruit gfx and the SSD 1306 libraries and those are for the OLED displays you may already have them because they're pretty popular libraries but if not you can just download them through the library manager starting off again with the pins used by the Laura module and the source and sensor addresses now our local address is 0 1 and the two sensors sensor address one is AA and address two is BB and you'll remember that from the code we use for the remote sensors now we have a few parameters for the OLED display and we also Define the display itself over here we set up a couple of temperature and humidity variables for our remote data and we format them like this because this will display on the screen and if we see this we know that we haven't yet got any sensors data because it'll get replaced by actual sensor data now we've got a couple of variables for the sensor data the remote temperature and remote humidity for both one and two we also have some time variables because we're going to try to do a timeout and make certain our data is fresh if we go too long without getting data then we know there's something wrong with the remote sensor so we've got two timeouts for the two different sensors and we set them to Millis which is the current value in milliseconds since the processor was booted up and so these are both set to the same thing we also set an interval in milliseconds and I'm setting mine for 12 and a half seconds you can change this if you like but basically if I don't see data from the other end for 12 and a half seconds and then I probably have not going to get any data there's something wrong with that remote sensor and I'm going to display an error on the display to indicate that and again you can change that time delay if you wish and the message hydraulic we've used before now we have a couple of functions now here's our first function called new display and this is for driving the OLED display it takes the temperature and humidities in from both of them and then display order which is an integer that can be either zero or one in one order you're going to have sensor one as the main display with Sensor 2 in tiny letters and the other order it'll be the opposite and so basically we just do a couple of display header stuff first that's common for both of them and then we check to see that last bit if it's a one or a zero if it's one we're going to set up the display with a remote Sensor 2 data in it first and if it's a zero we'll do the same thing with remote Sensor One data so this is basically just a link to display commands now the next function is to get the value and that just extracts the values from the delimited string because remember we're getting a delimited string in with the temperature and humidity values and so this can just end of individually distract extract either the temperature or the humidity okay the on receive function is of course our callback function which we're getting used to right now we go through the normal stuff at the beginning to make certain that it's a valid packet and it's meant for us and if it is we'll get uh we'll see if it comes from sensor one or two and we'll take a look at the sensor address if it's remote sensor one then the incoming data is remote data one and the Millis value is assigned to the current active so in other words we're refreshing that timer from remote sensor one otherwise we do the same thing for remote sensor two now there's another function called send message we've seen this before it's identical we're just going to send the message out as a Laura packet and this function get values gets the temperature and humidity values from the data variables so basically we've got the variable coming in we also have the time variable and we want to make certain that we got fresh data and then we're going to display it so we're going to get the current time we're going to see if the time limit has been expired for sensor one if the data is good then we're just going to use our get data function to get the temperature and humidity data and assign it to remote temp 1 and remote humid one otherwise we're going to put question marks as the value for those and that's because we've exceeded their timeout we do the same thing for cents or two over here now in the setup it's pretty simple we're going to set up the serial monitor we'll set up our SSD 1306 OLED display we're going to clear our display buffer and refresh the OLED with a bunch of x's which you'll just see when you first boot up uh the Laura mod dual is set up the same way we did before again make certain that you're using the correct frequency for your area we'll set Laura into on receive now in the loop we're going to get the latest data values with that get values function we showed earlier and we'll print them to the screen we'll update our OLED with those latest values and we'll delay three seconds to hold the display in the first mode so the first mode we have a zero over here that gives us sensor one is big letters and Sensor 2 is small we'll hold that for three seconds then we'll send a remote message one a message to the remote Sensor One excuse me just to get some Val get some new values then we'll go into receive mode again we're going to refresh the display again with the new values this time we're going to put Sensor 2 on top because we have a 1 in the back here do the same thing wait three seconds and send a message out to remote too so this way we're staggering the message as we send out to the remote sensors by about three seconds instantly have no conflicts over there and we also flip our display back and forth so that's the code uploaded to the esp32 and along with the remote sensors you can check it out and should have a working temperature and humidity sensor and here's our remote temperature and humidity sensor system all three units we've got the controller up over here and the two remote units down here and the controller you'll notice is built on that same subtlest breadboard that I used earlier that is wide enough to accommodate both the esp32 module that I used and my homemade Laura module which is down here and is working just fine now I'm going to separate the sensors to a more remote location after all that's what it's for but I wanted to show you this just to show you the two LEDs on the sensor notice how they flash on and off in sequence now remember these LEDs are illuminated every time that the sensor goes into a delay period to delay for two seconds to allow its dht-22 to reset and so you'll notice that what is happening here is that the controller is pulling one of them and then it goes into its delay and afterwards the controller pulls the other one and it goes into its DeLay So now that we seen that let's go and separate our sensors a little bit and so now I've moved my remote temperature and humidity sensors to two different areas and I'm displaying them right now by the way that little rolling thing you see on the display that's just an artifact of the video in real life that's not happening now you'll notice that one of them has a pretty reasonable temperature that's the sensor that's here in the worktop at 25.5 degrees Celsius the other one looks very cold negative 11.5 degrees Celsius and no that is not outside even though I live in Canada it is August and it doesn't get that cold in August it will in the winter the second sensor is in my deep freeze in the basement and this is proving out a couple of things first of all it shows how the display handles negative temperatures it has no problem with that it also shows what happens when the display needs an extra digit and it has no problem with that and it also demonstrates that the Laura transmission is capable of working even when the transmitter is inside a freezer which of course has a metal case on it so that's pretty impressive and this system could be used for anything not just temperature and humidity you could use a similar system to gather data from remote sensors and bring it into a central spot and so this is a great application for Laura now one thing I didn't do in today's video was a Laura distance test I live in a suburban area so the distances I could get with my setup probably wouldn't really pertain to the distances that you could get nonetheless I was curious as to how far we were transmitting with some of the experiments we were doing today so I took a USB power bank and hooked it up to the esp32 and took it out for a walk to see how far I could get the signal now I had no problem getting the signal anywhere in my home including the signal that was coming out of my freezer in the basement so I went outside and I was absolutely amazed I walked the full two blocks before the signal from the freezer in my basement started to drop off and the signal from the workshop in the basement was still going as strong as ever and that's really incredible when you're considering I'm just using little wire antennas so this is a really neat technology and you're going to be seeing more of it here in the dronebot workshop in fact I'm working on another video video that covers Laura Wan which is also a very important aspect of working and networking with Laura now if you want some more information about Laura there's an article that accompanies this video you'll find a link right below the video and you can grab all of the code that I use today for the experiments in that article while you're on the dronebot workshop website you're reading the article you can also sign up for the newsletter if you haven't already it's not a sales letter it's just my way of letting you know now and then what's going on here in the workshop if you'd like to discuss Laura of course the best place to go for that would be the dronebot workshop Forum where you'll find a whole bunch of like-minded individuals who'd be happy to help you with your projects and probably would love to discuss Laura and finally if you haven't please subscribe to the YouTube channel I make videos about things not only Laura but microcontroller and electronics related and I'm sure you'll enjoy them if you enjoyed this video all you need to do to subscribe is hit that red subscribe button and if you can also hit that Bell notification you'll get notified every time that I make a new video assuming of course that you've got notifications enabled in your web browser so until we meet again the next time please take good care of yourself stay safe out there and I will see you soon here in the dronebot workshop goodbye for now [Music] um
Info
Channel: DroneBot Workshop
Views: 102,677
Rating: undefined out of 5
Keywords: lora, lora esp32, lora rpi pico, arduino lora, lora tutorial
Id: YQ7aLHCTeeE
Channel Id: undefined
Length: 67min 57sec (4077 seconds)
Published: Mon Sep 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.