Weather sensing in Smokeshire
Adafruit Feather 32u4 RFM95 LoRa Radio - 868 or 915 MHz
Adafruit Feather 32u4 RFM95 LoRa Radio - 868 or 915 MHz
NO MCU
Sparkfun ESP8266 thing
WON'T WORK WITH ADAFRUIT FTDI PROGRAMMER
NOT REALLY ENOUGH FREE PINS ANYWAY
Adafruit Feather 32u4 Basic Proto
The 32u4 doesn't have a lot of IRQs
The 32u4 doesn't have a lot of IRQs and the only ones available are on pins 0, 1, 2, 3 which are also the Serial RX/TX and I2C pins. So it's not great because you have to give up one of those pins.
The 32u4 doesn't have a lot of IRQs and the only ones available are on pins 0, 1, 2, 3
The 32u4 doesn't have a lot of IRQs and the only ones available are on pins 0, 1, 2, 3 which are also the Serial RX/TX and I2C pins.
Nice bit of performance, low power, Feather form factor
Feathers have built-in LiPO charging hardware (nice).
Wish I'd bought ones with more capacity.
Less complicated than working with the blasted FeatherWings
The MCP9808 is a favorite of mine because low-power (super low-power) and accurate.
The BMEs add pressure and humidity but are far less efficient (at least WRT the Arduino libraries I have for them).
Everything onto headers...
Low-level driver that supports the Semtech LoRa chip I'm using...
// LoRa 9x_TX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (transmitter)
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example LoRa9x_RX
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
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!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
int16_t packetnum = 0; // packet counter, we increment per xmission
void loop()
{
Serial.println("Sending to rf95_server");
// Send a message to rf95_server
char radiopacket[20] = "Hello World # ";
itoa(packetnum++, radiopacket+13, 10);
Serial.print("Sending "); Serial.println(radiopacket);
radiopacket[19] = 0;
Serial.println("Sending..."); delay(10);
rf95.send((uint8_t *)radiopacket, 20);
Serial.println("Waiting for packet to complete..."); delay(10);
rf95.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
Serial.println("Waiting for reply..."); delay(10);
if (rf95.waitAvailableTimeout(1000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))
{
Serial.print("Got reply: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("Receive failed");
}
}
else
{
Serial.println("No reply, is there a listener around?");
}
delay(1000);
}
// Arduino9x_RX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (receiver)
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example Arduino9x_TX
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
// Blinky on receipt
#define LED 13
void setup()
{
pinMode(LED, OUTPUT);
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(9600);
delay(100);
Serial.println("Arduino LoRa RX 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!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(LED, HIGH);
RH_RF95::printBuffer("Received: ", buf, len);
Serial.print("Got: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
// Send a reply
uint8_t data[] = "And hello back to you";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(LED, LOW);
}
else
{
Serial.println("Receive failed");
}
}
}
Tx (Transmit)
Rx (Receive)
Helpfully gives me
/**
* Return most significant 8 bits of the first 32 bits of
* this MCU's device ID for use as a device address.
* This is for SAMD MCUs only
*/
uint8_t getID() {
volatile uint32_t val1;
volatile uint32_t *ptr1 = (volatile uint32_t *)0x0080A00C;
val1 = *ptr1;
return val1 >> 24;
}
typedef struct {
uint32_t offset;
float mcp_temperature;
float mpl_pressure;
float mpl_temperature;
uint8_t deviceID;
uint8_t capabilities;
} ClientPacket;
ClientPacket packet;
/**
* Put things in the packet struct...
**/
/**
* Create a uint8_t array of the same memory
* size as packet
*/
uint8_t data[sizeof(packet)];
// memcpy all the things (and subsequently transmit)
memcpy(data, &packet, sizeof(packet));
/**
* Init struct...
**/
ClientPacket lastPacket;
/**
* Copy received byte buffer into it
**/
memcpy(&lastPacket, buf, sizeof(lastPacket));
I can put it in a tree!
I can make it talk to me!
ENRAGING FAIL
const parsedChunk = {
date : chunk.readDoubleLE(0),
offset : chunk.readUInt32LE(8),
mcp_temperature: chunk.readFloatLE(12),
mpl_pressure : chunk.readFloatLE(16),
mpl_temperature: chunk.readFloatLE(20),
deviceID : chunk.readUInt8(24),
capabilities : chunk.readUInt8(25)
};