Support for SPI connected SX1278
This commit is contained in:
3
.vscode/arduino.json
vendored
3
.vscode/arduino.json
vendored
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"board": "arduino:avr:pro",
|
"board": "bsfrance:avr:lora32u4",
|
||||||
"configuration": "cpu=16MHzatmega328",
|
|
||||||
"sketch": "crossbow.ino",
|
"sketch": "crossbow.ino",
|
||||||
"port": "COM23",
|
"port": "COM23",
|
||||||
"output": "./build"
|
"output": "./build"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# QuadMeUp Crossbow
|
# QuadMeUp Crossbow
|
||||||
|
|
||||||
_QuadMeUp Crossbow_ is a DIY project that gives 5km (at least) of RC link for UAV (airplanes and drones) for a price below $40. I uses SX1276 (LoRa 868MHz/915MHz) compatible (like HopeRF RFM95W) radio modules connected to Arduino compatible boards. It can be regular Arduino connected via SPI to SX1276 or dedicated board like _Adafruit Feather 32u4 RFM LoRa_ or _LoRa32u4 II_
|
_QuadMeUp Crossbow_ is a DIY project that gives 5km (at least) of RC link for UAV (airplanes and drones) for a price below $40. I uses SX1278 (LoRa 868MHz/915MHz) compatible (like HopeRF RFM95W) radio modules connected to Arduino compatible boards. It can be regular Arduino connected via SPI to SX1278 or dedicated board like _Adafruit Feather 32u4 RFM LoRa_ or _LoRa32u4 II_
|
||||||
|
|
||||||
# Current state
|
# Current state
|
||||||
|
|
||||||
|
|||||||
80
crossbow.ino
80
crossbow.ino
@@ -1,7 +1,11 @@
|
|||||||
|
#include <LoRa.h>
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
|
||||||
// #define DEVICE_MODE_TX
|
// #define LORA_HARDWARE_SERIAL
|
||||||
#define DEVICE_MODE_RX
|
#define LORA_HARDWARE_SPI
|
||||||
|
|
||||||
|
#define DEVICE_MODE_TX
|
||||||
|
// #define DEVICE_MODE_RX
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main defines for device working in TX mode
|
* Main defines for device working in TX mode
|
||||||
@@ -199,14 +203,55 @@ uint8_t get10bitLowShift(uint8_t channel) {
|
|||||||
return 8 - get10bitHighShift(channel);
|
return 8 - get10bitHighShift(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void computeCrc(uint8_t dataByte) {
|
||||||
|
qspCrc ^= dataByte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Serial port used to send data
|
||||||
|
*/
|
||||||
|
#ifdef LORA_HARDWARE_SERIAL
|
||||||
|
|
||||||
|
void radioPacketStart(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void radioPacketEnd(void) {
|
||||||
|
Serial.end();
|
||||||
|
delay(E45_TTL_100_UART_DOWNTIME);
|
||||||
|
Serial.begin(UART_SPEED);
|
||||||
|
}
|
||||||
|
|
||||||
void writeToRadio(uint8_t dataByte) {
|
void writeToRadio(uint8_t dataByte) {
|
||||||
//Compute CRC
|
//Compute CRC
|
||||||
qspCrc ^= dataByte;
|
computeCrc(dataByte);
|
||||||
|
|
||||||
//Write to radio
|
//Write to radio
|
||||||
Serial.write(dataByte);
|
Serial.write(dataByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LORA_HARDWARE_SPI
|
||||||
|
|
||||||
|
void radioPacketStart(void) {
|
||||||
|
LoRa.beginPacket();
|
||||||
|
}
|
||||||
|
|
||||||
|
void radioPacketEnd(void) {
|
||||||
|
LoRa.endPacket();
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeToRadio(uint8_t dataByte) {
|
||||||
|
//Compute CRC
|
||||||
|
computeCrc(dataByte);
|
||||||
|
|
||||||
|
//Write to radio
|
||||||
|
LoRa.write(dataByte);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0,0);
|
display.setCursor(0,0);
|
||||||
@@ -216,7 +261,19 @@ display.display();
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void setup(void) {
|
void setup(void) {
|
||||||
|
|
||||||
|
#ifdef LORA_HARDWARE_SERIAL
|
||||||
Serial.begin(UART_SPEED);
|
Serial.begin(UART_SPEED);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LORA_HARDWARE_SPI
|
||||||
|
if (!LoRa.begin(868E6)) {
|
||||||
|
Serial.println("LoRa init failed. Check your connections.");
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
LoRa.onReceive(onReceive);
|
||||||
|
LoRa.receive();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_RX
|
#ifdef DEVICE_MODE_RX
|
||||||
pinMode(PIN_LED, OUTPUT);
|
pinMode(PIN_LED, OUTPUT);
|
||||||
@@ -299,17 +356,28 @@ void loop(void) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LORA_HARDWARE_SERIAL
|
||||||
if (Serial.available()) {
|
if (Serial.available()) {
|
||||||
qspDecodeIncomingFrame(Serial.read());
|
qspDecodeIncomingFrame(Serial.read());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (transmitPayload) {
|
if (transmitPayload) {
|
||||||
transmitPayload = false;
|
transmitPayload = false;
|
||||||
|
|
||||||
|
radioPacketStart();
|
||||||
qspEncodeFrame(qspFrameToSend, qspPayloadLength, qspPayload);
|
qspEncodeFrame(qspFrameToSend, qspPayloadLength, qspPayload);
|
||||||
Serial.end();
|
radioPacketEnd();
|
||||||
delay(E45_TTL_100_UART_DOWNTIME);
|
|
||||||
Serial.begin(UART_SPEED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LORA_HARDWARE_SPI
|
||||||
|
void onReceive(int packetSize) {
|
||||||
|
if (packetSize == 0) return;
|
||||||
|
|
||||||
|
while (LoRa.available()) {
|
||||||
|
qspDecodeIncomingFrame(LoRa.read());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user