Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E220_400MM22S Sending Lat and Long #172

Open
AdamHawkTrack opened this issue Apr 20, 2024 · 0 comments
Open

E220_400MM22S Sending Lat and Long #172

AdamHawkTrack opened this issue Apr 20, 2024 · 0 comments

Comments

@AdamHawkTrack
Copy link

Hi @SlashDevin ,

I really hope you can help. I've successfully used neogps for sending latitude and longitude via lora with Sandeep's Lora.h code on a SX1278 lora modules and worked perfectly. I'm trying to do the same with the ebyte e220-400mm22s module but Lora.h doesn't support the SX126x / LLCC68 chips so I'm trying to replicate with the lora.rf library. I can send the test "HeLoRa World!" without any issues, and I can add neogps and read GPS data at the same time, but I cannot successfully send the lat long. When using the lora.h previously it was as simple as adding lora.print(fix.latitude, 6); I'm just a beginner in electronics and coding so learning as I go, but not sure how I can get this to send the coordinates. When I try to send the GPS data over the receiver just get garbled message and multiple???? Do I need to convert the lat long to a char or something? Seems strange the example code works flawlessly.

Any help or advice would be really appreciated. I've added the example code below for your info.

Many thanks, Adam

Example Transmitter.......

#include <SX126x.h>

SX126x LoRa;

// Message to transmit
char message[] = "HeLoRa World!";
uint8_t nBytes = sizeof(message);
uint8_t counter = 0;

void setup() {

// Begin serial communication
Serial.begin(38400);

// Uncomment below to use non default SPI port
//SPIClass SPI_2(PB15, PB14, PB13);
//LoRa.setSPI(SPI_2, 16000000);

// Begin LoRa radio and set NSS, reset, busy, IRQ, txen, and rxen pin with connected arduino pins
// IRQ pin not used in this example (set to -1). Set txen and rxen pin to -1 if RF module doesn't have one
Serial.println("Begin LoRa radio");
int8_t nssPin = 10, resetPin = 9, busyPin = 4, irqPin = -1, txenPin = 8, rxenPin = 7;
if (!LoRa.begin(nssPin, resetPin, busyPin, irqPin, txenPin, rxenPin)){
Serial.println("Something wrong, can't begin LoRa radio");
while(1);
}

// Optionally configure TCXO or XTAL used in RF module
// Different RF module can have different clock, so make sure clock source is configured correctly
// uncomment code below to use TCXO
Serial.println("Set RF module to use TCXO as clock reference");
uint8_t dio3Voltage = SX126X_DIO3_OUTPUT_1_8;
uint32_t tcxoDelay = SX126X_TCXO_DELAY_10;
LoRa.setDio3TcxoCtrl(dio3Voltage, tcxoDelay);
// uncomment code below to use XTAL
//uint8_t xtalA = 0x12;
//uint8_t xtalB = 0x12;
//Serial.println("Set RF module to use XTAL as clock reference");
//LoRa.setXtalCap(xtalA, xtalB);

// Optionally configure DIO2 as RF switch control
// This is usually used for a LoRa module without TXEN and RXEN pins
//LoRa.setDio2RfSwitch(true);

// Set frequency to 915 Mhz
Serial.println("Set frequency to 915 Mhz");
LoRa.setFrequency(915000000);

// Set TX power, default power for SX1262 and SX1268 are +22 dBm and for SX1261 is +14 dBm
// This function will set PA config with optimal setting for requested TX power
Serial.println("Set TX power to +17 dBm");
LoRa.setTxPower(17, SX126X_TX_POWER_SX1262); // TX power +17 dBm for SX1262

// Configure modulation parameter including spreading factor (SF), bandwidth (BW), and coding rate (CR)
// Receiver must have same SF and BW setting with transmitter to be able to receive LoRa packet
Serial.println("Set modulation parameters:\n\tSpreading factor = 7\n\tBandwidth = 125 kHz\n\tCoding rate = 4/5");
uint8_t sf = 7; // LoRa spreading factor: 7
uint32_t bw = 125000; // Bandwidth: 125 kHz
uint8_t cr = 5; // Coding rate: 4/5
LoRa.setLoRaModulation(sf, bw, cr);

// Configure packet parameter including header type, preamble length, payload length, and CRC type
// The explicit packet includes header contain CR, number of byte, and CRC type
// Receiver can receive packet with different CR and packet parameters in explicit header mode
Serial.println("Set packet parameters:\n\tExplicit header type\n\tPreamble length = 12\n\tPayload Length = 15\n\tCRC on");
uint8_t headerType = SX126X_HEADER_EXPLICIT; // Explicit header mode
uint16_t preambleLength = 12; // Set preamble length to 12
uint8_t payloadLength = 15; // Initialize payloadLength to 15
bool crcType = true; // Set CRC enable
LoRa.setLoRaPacket(headerType, preambleLength, payloadLength, crcType);

// Set syncronize word for public network (0x3444)
Serial.println("Set syncronize word to 0x3444");
LoRa.setSyncWord(0x3444);

Serial.println("\n-- LORA TRANSMITTER --\n");

}

void loop() {

// Transmit message and counter
// write() method must be placed between beginPacket() and endPacket()
LoRa.beginPacket();
LoRa.write(message, nBytes);
LoRa.write(counter);
LoRa.endPacket();

// Print message and counter in serial
Serial.print(message);
Serial.print(" ");
Serial.println(counter++);

// Wait until modulation process for transmitting packet finish
LoRa.wait();

// Print transmit time
Serial.print("Transmit time: ");
Serial.print(LoRa.transmitTime());
Serial.println(" ms");
Serial.println();

// Don't load RF module with continous transmit
delay(5000);

}

Example Receiver.......

#include <SX126x.h>

SX126x LoRa;

void setup() {

// Begin serial communication
Serial.begin(38400);

// Uncomment below to use non default SPI port
//SPIClass SPI_2(PB15, PB14, PB13);
//LoRa.setSPI(SPI_2, 16000000);

// Begin LoRa radio and set NSS, reset, busy, txen, and rxen pin with connected arduino pins
// IRQ pin not used in this example (set to -1). Set txen and rxen pin to -1 if RF module doesn't have one
Serial.println("Begin LoRa radio");
int8_t nssPin = 10, resetPin = 9, busyPin = 4, irqPin = -1, txenPin = 8, rxenPin = 7;
if (!LoRa.begin(nssPin, resetPin, busyPin, irqPin, txenPin, rxenPin)){
Serial.println("Something wrong, can't begin LoRa radio");
while(1);
}

// Optionally configure TCXO or XTAL used in RF module
// Different RF module can have different clock, so make sure clock source is configured correctly
// uncomment code below to use TCXO
Serial.println("Set RF module to use TCXO as clock reference");
uint8_t dio3Voltage = SX126X_DIO3_OUTPUT_1_8;
uint32_t tcxoDelay = SX126X_TCXO_DELAY_10;
LoRa.setDio3TcxoCtrl(dio3Voltage, tcxoDelay);
// uncomment code below to use XTAL
//uint8_t xtalA = 0x12;
//uint8_t xtalB = 0x12;
//Serial.println("Set RF module to use XTAL as clock reference");
//LoRa.setXtalCap(xtalA, xtalB);

// Optionally configure DIO2 as RF switch control
// This is usually used for a LoRa module without TXEN and RXEN pins
//LoRa.setDio2RfSwitch(true);

// Set frequency to 915 Mhz
Serial.println("Set frequency to 915 Mhz");
LoRa.setFrequency(915000000);

// Set RX gain. RX gain option are power saving gain or boosted gain
Serial.println("Set RX gain to power saving gain");
LoRa.setRxGain(SX126X_RX_GAIN_POWER_SAVING); // Power saving gain

// Configure modulation parameter including spreading factor (SF), bandwidth (BW), and coding rate (CR)
// Transmitter must have same SF and BW setting so receiver can receive LoRa packet
Serial.println("Set modulation parameters:\n\tSpreading factor = 7\n\tBandwidth = 125 kHz\n\tCoding rate = 4/5");
uint8_t sf = 7; // LoRa spreading factor: 7
uint32_t bw = 125000; // Bandwidth: 125 kHz
uint8_t cr = 5; // Coding rate: 4/5
LoRa.setLoRaModulation(sf, bw, cr);

// Configure packet parameter including header type, preamble length, payload length, and CRC type
// The explicit packet includes header contain CR, number of byte, and CRC type
// Packet with explicit header can't be received by receiver with implicit header mode
Serial.println("Set packet parameters:\n\tExplicit header type\n\tPreamble length = 12\n\tPayload Length = 15\n\tCRC on");
uint8_t headerType = SX126X_HEADER_EXPLICIT; // Explicit header mode
uint16_t preambleLength = 12; // Set preamble length to 12
uint8_t payloadLength = 15; // Initialize payloadLength to 15
bool crcType = true; // Set CRC enable
LoRa.setLoRaPacket(headerType, preambleLength, payloadLength, crcType);

// Set syncronize word for public network (0x3444)
Serial.println("Set syncronize word to 0x3444");
LoRa.setSyncWord(0x3444);

Serial.println("\n-- LORA RECEIVER --\n");

}

void loop() {

// Request for receiving new LoRa packet
LoRa.request();
// Wait for incoming LoRa packet
LoRa.wait();

// Put received packet to message and counter variable
// read() and available() method must be called after request() or listen() method
const uint8_t msgLen = LoRa.available() - 1;
char message[msgLen];
uint8_t counter;
// available() method return remaining received payload length and will decrement each read() or get() method called
uint8_t i=0;
while (LoRa.available() > 1){
message[i++] = LoRa.read();
}
counter = LoRa.read();

// Print received message and counter in serial
Serial.print(message);
Serial.print(" ");
Serial.println(counter);

// Print packet/signal status including package RSSI and SNR
Serial.print("Packet status: RSSI = ");
Serial.print(LoRa.packetRssi());
Serial.print(" dBm | SNR = ");
Serial.print(LoRa.snr());
Serial.println(" dB");

// Show received status in case CRC or header error occur
uint8_t status = LoRa.status();
if (status == SX126X_STATUS_CRC_ERR) Serial.println("CRC error");
else if (status == SX126X_STATUS_HEADER_ERR) Serial.println("Packet header error");
Serial.println();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant