When you recieve your Feather
board it will not have header pins
attached. You will need to solder the header pins to the Feather Board.
There are several ways to attach headers and they can be found
here.
Next up we need to make the Antennas. Depending on what frequency your
LoRa is designed for, in our case 900MHz, you will need a specifc
length. This can be calculated by Antenna length = 3*10^8(speed of
light) / 900*10^6 (desired frequency). For our 900MHZ our length turns
out to be 33.3cm. To make the length more reasonable we can make a half
qave or quarter wave antenna. To do so divide your length by 2 or 4
respectivly whichever you choose be sure it is the same for the
reciever and transmiitter. If you want more info about the Physics
involved it can be found
here.
So
now that we know the length to make a half wave antenna, 16.6cm, lets
cut the wire. You can use solid
core wire and cut it to length. Next we will solder it to the Ant. Pin.
The straighter the antenna the better results you will have. Repeat
this for as many Feathers as you need.
Now you Feathers are primed and ready to go.
Now that we have the Feather setup physically it is
time to tackle programming. Make sure you installed the libraries
mentiond above, SimpleDHT, RadioHead, LiquidCrystal, and
Adafruit_SleepDog. If not go back to
IDE setup.
We will first start with setting up the transmitter. For this you will
want to connect the Feather to your computer via USB. Now that it's
connected there are two things that need to be checked. First make sure
that under tools>Board>Adafruit Feathe M0 is selected. Second,
that under Tools>Port: COMx (Adafruit Feather M0) is showing up.
Your COM port number will vary. If you have trouble selecting the Board
refer back to step 1) of setting up the IDE.
Now that our Feather is connected we will move on to programming the
transmitter(TX).
Above of the setup() and loop() functions we have the headers and a few
variable definitions.
Of note here we have the header files that we installed and definitions
of TX pins that correspond with our pinout image.
Next we will program the setup() function.
Here we define the two pins that will be set to output. We also set the
frequency, start the serial communication and reset the LoRa module.
Lastly for the TX we will program the main loop().
Here we gather the humidity and temperature data from the DHT and send
it. Next we wait for a response from the reciever that will either
blink the succesful send or failed LED. We also assign the TX
identifying number, in this case 1.
If you want to sleep the module you will need to uncomment the two
sleep functions. The Watchdog.sleep() function will disable the serial
communication with a computer, as a result the Feather will not be
recognized via COM port. To fix this you will need to double press the
built in reset pin on the Feather chip. The 13 LED will breathe red and
you will be able to select a COM port for the Feather.
Reciever
We will next program the reciever that is capable of parsing data from
several transmitters. Starting off with the seutp above the main loop.
Here we define the pins for the LCD and delcare where we will store the
recieved data.
Moving on the the setup function.
Now we move on to the main loop that will gather the data from the
several transmitters. We accomplish this by using a switch case that
identifies which transmitter is sending and then updating the
appropriate temperature.
More cases in the switch statement can be added to increase the number
of transmitters accomidated.
Now that we have the incoming data stored in our variables we can do
things with it.
We first blink the onboard led to indicate message recived. Next we
update the LCD with the incoming temperatures. Then a response is sent
to out that reads "Data recieved", this is optional and depends on how
the Transmitter is setup. After this we print out the temperatures to
the Serial monitor in a comma delimted style to easily be parsed later.
Data Collection From Reciever
To record the reciever data from the serial monitor we will be using a
Python script. The environment I used wasy Spyder. The library that
enables serial communication with the Arduino is pyserial. To install
this librarys you can type "conda install pyserial" in the console
window. The library will then be installed.
How this script works is by accessing the data sent throught the serial
port the Feather is connected to on your computer. This data is then
decoded and written to a text file.
The data is encoded using utf-8
format, we decode it in line 19 to get it in the format of the serial
monitor. This script will run indefinately with this format. By
changing the while loop the duration can be controlled based on the
parameter you desire.
Data Relay
An alternative use of the Feathers is using them as relay stations
allowing for more remote data collection. The general idea is that one
Feather gathers the desired data and sends it to another Feather who's
purpose is to relay it to the reciever. Along the way, each station
could add its data to the packet heading to the reciever. The relay
pulls from the TX and RX we made before, incorperating bits of each.
We will start off with the code above the setup and loop
Here we define all we need for the push button and the LoRa module.
Next we will move on to the setup function.
Mostly the same as before with the additon of setting the buttonPin to
INPUT.
Now on to the main loop that runs. It has two actions that it preforms.
The first is using the push button to set the relay ID# if the button
is held down the LED will blink to indicate and increment the ID# of
that relay. This allows for setting up several realys with the same
code.
Second funcition is listening for the radio transmission from the
previous stage and sending that data along.
Here the signal is recieve, the data is copied with the addition of the
TXid and sent along. This send is recieved by both the previous and
next stage. For the previous stage it acts as the response that the
send was sucessful.
Conclusions
Throughout this tutorial we explored several configurations of M0
Feathers w/ LoRa being used to transmit data. Going forward, adapt what
you have learned here to the project of your choice. The world is your
burrito, choose your own fillings.