Hi all !
Hope everyone is well and safe.
Before and a bit after Christmas, was time to test LoRa to LoRa communication using the two Arduinos MKR 1300 WAN from the kit.
One of the Arduinos will be connected to the Adafruit's high temperature sensor and the other one to the computer. The Adafruit's high temperature sensor is immersed in the pool water.
Hardware
- 2x Arduino MKR 1300 WAN
- 1x 4.7K ohm resistor
- 1x DS18B20 high temperature sensor
- 2x AA bateries
Note: Although in the picture, the Arduino is powered by USB (powerbank), the final try and the working prototype was being powered by two AA bateries.
Here's the schematics for it:
Code
The code is straight forward. I will be using the LoRa sender example from the Arduino examples sending the temperature value (using OneWire's and DallasTemperature libraries) .
Here's the code for LoRa sending the temperature
#include <SPI.h> #include <LoRa.h> #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); float celcius = 0; void setup() { //Serial.begin(9600); sensors.begin(); //while (!Serial && millis() < 50000); //need this because it was waiting on serial //Serial.println("LoRa Sender"); if (!LoRa.begin(866E6)) { //Serial.println("Starting LoRa failed!"); while (1); } } void loop() { sensors.requestTemperatures(); celcius = sensors.getTempCByIndex(0); //Serial.print("Sending temperature: "); //Serial.println(celcius); // send packet LoRa.beginPacket(); LoRa.print(celcius); //LoRa.print(counter); LoRa.endPacket(); delay(5000); }
The code is easy to understand, but if you look closely, you'll see (among others) the following line commented out:
//while (!Serial && millis() < 50000); //need this because it was waiting on serial
Why ?
Because of two things:
1
When powered by batteries, there's no led on. The Arduino doesn't show that it is working... That's a shame and something to be addressed later.
2
No temperature was reaching the other Arduino. What the hell was going on. Powering the Arduino by USB (first, using a powerbank), did light on a led, but still, no temperature on the other side.
Connecting the Arduino to the computer, did send temperature readings to the other side. But why ???
A closer look into the code and a Google search did produce some results. The thing is, the Arduino is waiting, forever (or 5s - but it didn't work, so I commented out the line) for a serial console... That only exists when connected to the computer.
After commenting all the lines referencing the Serial Console, it finally start sending temperature readings. Still, when powered by batteries, no LED is ON - so just remember that.
Here's the code for the receiving one.
#include <SPI.h> #include <LoRa.h> void setup() { Serial.begin(9600); while (!Serial); Serial.println("LoRa Receiver"); if (!LoRa.begin(866E6)) { Serial.println("Starting LoRa failed!"); while (1); } } void loop() { // try to parse packet float packetSize = LoRa.parsePacket(); if (packetSize) { // received a packet Serial.print("Received temperature '"); // read packet while (LoRa.available()) { Serial.print((char)LoRa.read()); } /* Serial.print("' with RSSI "); Serial.println(LoRa.packetRssi());*/ } }
and voilà
Here's both Arduinos connected to the computer, one sending the temperature and the other receiving it.
Here's the Arduino MKR1300 WAN on the remote place
And here's the result from the remote Arduino on the Arduino connected to the computer.
From here to sending to the Arduino IoT cloud is easy.
Next, let's experiment with all the other sensors and start putting all together .
Merry Christmas and Happy holidays.