Hey I am having a lot of problems with programming my Adafruit RFM 9x LoRa device. I am tryin to get sensor data sent over the connection of my LoRa:s but have not had any success doing that.
The problem is that i don´t quite understand the code behind the send function and am not able to put the codes together from the LoRa and my sensors. My one sensor i am trying to get working is an Adafruit 3115A2. The sensor is connected to the Arduino threw I2C pins and the LoRa is connected with the recommended wiring.
I get them talking to each other until adding the code for the sensor. Any help is highly appreciated!
Here is the code for the LoRa i´ve tried:
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
#define RF95_FREQ 433.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(9600);
delay(100);
Serial.println("Arduino LoRa TX Test!");
// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
while (1);
}
Serial.println("LoRa radio init OK!");
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
rf95.setTxPower(23, false);
}
int16_t packetnum = 0;
void loop()
{
Serial.println("send #");
// Send a message to rf95_server
char radiopacket[20] = "Hello World # ";
itoa(packetnum++, radiopacket+13, 10);
radiopacket[19] = 0;
rf95.send((uint8_t *)radiopacket, 20);
rf95.waitPacketSent();
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
delay (1000);
}
And here is the code for MPL3115A2 sensor:
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>
// Power by connecting Vin to 3-5V, GND to GND
// Uses I2C - connect SCL to the SCL pin, SDA to SDA pin
// See the Wire tutorial for pinouts for each Arduino
// http://arduino.cc/en/reference/wire
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
void setup() {
Serial.begin(9600);
Serial.println("Adafruit_MPL3115A2 test!");
}
void loop() {
if (! baro.begin()) {
Serial.println("Couldnt find sensor");
return;
}
float pascals = baro.getPressure();
Serial.print(pascals/3377); Serial.println(" Inches (Hg)");
float altm = baro.getAltitude();
Serial.print(altm); Serial.println(" meters");
float tempC = baro.getTemperature();
Serial.print(tempC); Serial.println("*C");
delay(250);
}