[SX127x] Fixed typos in examples
This commit is contained in:
parent
0bafe185a9
commit
1bc2633048
7 changed files with 71 additions and 67 deletions
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
RadioLib SX127x Channel Activity Detection Example
|
||||
|
||||
This example scans the current LoRa channel and detects
|
||||
valid LoRa preambles. Preamble is the first part of
|
||||
LoRa transmission, so this can be used to check
|
||||
if the LoRa channel is free, or if you should start
|
||||
This example scans the current LoRa channel and detects
|
||||
valid LoRa preambles. Preamble is the first part of
|
||||
LoRa transmission, so this can be used to check
|
||||
if the LoRa channel is free, or if you should start
|
||||
receiving a message.
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
@ -48,11 +48,11 @@ void loop() {
|
|||
|
||||
if (state == PREAMBLE_DETECTED) {
|
||||
// LoRa preamble was detected
|
||||
Serial.println(" detected preamble!");
|
||||
Serial.println(F(" detected preamble!"));
|
||||
|
||||
} else if (state == CHANNEL_FREE) {
|
||||
// no preamble was detected, channel is free
|
||||
Serial.println(" channel is free!");
|
||||
Serial.println(F(" channel is free!"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
RadioLib SX127x FSK Modem Example
|
||||
|
||||
This example shows how to use FSK modem in SX127x chips.
|
||||
|
||||
|
||||
NOTE: The sketch below is just a guide on how to use
|
||||
FSK modem, so this code should not be run directly!
|
||||
Instead, modify the other examples to use FSK
|
||||
|
@ -29,7 +29,7 @@ void setup() {
|
|||
// current limit: 100 mA
|
||||
// data shaping: Gaussian, BT = 0.3
|
||||
// sync word: 0x2D 0x01
|
||||
// OOK modulation: false
|
||||
// OOK modulation: disabled
|
||||
int state = fsk.beginFSK();
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
|
@ -44,7 +44,7 @@ void setup() {
|
|||
// lora.begin() start LoRa mode (and disable FSK)
|
||||
// lora.beginFSK() start FSK mode (and disable LoRa)
|
||||
|
||||
// the following settings can also
|
||||
// the following settings can also
|
||||
// be modified at run-time
|
||||
state = fsk.setFrequency(433.5);
|
||||
state = fsk.setBitRate(100.0);
|
||||
|
@ -53,7 +53,7 @@ void setup() {
|
|||
state = fsk.setOutputPower(10.0);
|
||||
state = fsk.setCurrentLimit(100);
|
||||
state = fsk.setDataShaping(0.5);
|
||||
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
|
||||
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
state = fsk.setSyncWord(syncWord, 8);
|
||||
if (state != ERR_NONE) {
|
||||
|
@ -82,7 +82,7 @@ void loop() {
|
|||
// FSK modem can use the same transmit/receive methods
|
||||
// as the LoRa modem, even their interrupt-driven versions
|
||||
// NOTE: FSK modem maximum packet length is 63 bytes!
|
||||
|
||||
|
||||
// transmit FSK packet
|
||||
int state = fsk.transmit("Hello World!");
|
||||
/*
|
||||
|
@ -123,7 +123,7 @@ void loop() {
|
|||
// it can be enabled by setting node address, broadcast
|
||||
// address, or both
|
||||
//
|
||||
// to transmit packet to a particular address,
|
||||
// to transmit packet to a particular address,
|
||||
// use the following methods:
|
||||
//
|
||||
// fsk.transmit("Hello World!", address);
|
||||
|
@ -161,7 +161,7 @@ void loop() {
|
|||
|
||||
// using the direct mode, it is possible to transmit
|
||||
// FM notes with Arduino tone() function
|
||||
|
||||
|
||||
// it is recommended to set data shaping to 0
|
||||
// (no shaping) when transmitting audio
|
||||
state = fsk.setDataShaping(0.0);
|
||||
|
@ -193,7 +193,7 @@ void loop() {
|
|||
Serial.println(F("[SX1278] Unable to start direct reception mode, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
|
||||
// NOTE: you will not be able to send or receive packets
|
||||
// while direct mode is active! to deactivate it, call method
|
||||
// fsk.packetMode()
|
||||
|
|
|
@ -65,26 +65,26 @@ void loop() {
|
|||
Serial.println(F("success!"));
|
||||
|
||||
// print the data of the packet
|
||||
Serial.print("[SX1278] Data:\t\t");
|
||||
Serial.print(F("[SX1278] Data:\t\t"));
|
||||
Serial.println(str);
|
||||
|
||||
// print the RSSI (Received Signal Strength Indicator)
|
||||
// of the last received packet
|
||||
Serial.print("[SX1278] RSSI:\t\t");
|
||||
Serial.print(F("[SX1278] RSSI:\t\t"));
|
||||
Serial.print(lora.getRSSI());
|
||||
Serial.println(" dBm");
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print the SNR (Signal-to-Noise Ratio)
|
||||
// of the last received packet
|
||||
Serial.print("[SX1278] SNR:\t\t");
|
||||
Serial.print(F("[SX1278] SNR:\t\t"));
|
||||
Serial.print(lora.getSNR());
|
||||
Serial.println(" dBm");
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print frequency error
|
||||
// of the last received packet
|
||||
Serial.print("Frequency error:\t");
|
||||
Serial.print(F("Frequency error:\t"));
|
||||
Serial.print(lora.getFrequencyError());
|
||||
Serial.println(" Hz");
|
||||
Serial.println(F(" Hz"));
|
||||
|
||||
} else if (state == ERR_RX_TIMEOUT) {
|
||||
// timeout occurred while waiting for a packet
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
RadioLib SX127x Receive with Inerrupts Example
|
||||
RadioLib SX127x Receive with Interrupts Example
|
||||
|
||||
This example listens for LoRa transmissions and tries to
|
||||
receive them. Once a packet is received, an interrupt is
|
||||
triggered. To successfully receive data, the following
|
||||
settings have to be the same on both transmitter
|
||||
settings have to be the same on both transmitter
|
||||
and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
|
@ -44,10 +44,10 @@ void setup() {
|
|||
while (true);
|
||||
}
|
||||
|
||||
// set the function that will be called
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
lora.setDio0Action(setFlag);
|
||||
|
||||
|
||||
// start listening for LoRa packets
|
||||
Serial.print(F("[SX1278] Starting to listen ... "));
|
||||
state = lora.startReceive();
|
||||
|
@ -98,44 +98,44 @@ void loop() {
|
|||
|
||||
// reset flag
|
||||
receivedFlag = false;
|
||||
|
||||
|
||||
// you can read received data as an Arduino String
|
||||
String str;
|
||||
int state = lora.readData(str);
|
||||
|
||||
|
||||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = lora.receive(byteArr, 8);
|
||||
*/
|
||||
|
||||
|
||||
if (state == ERR_NONE) {
|
||||
// packet was successfully received
|
||||
Serial.println("[SX1278] Received packet!");
|
||||
|
||||
Serial.println(F("[SX1278] Received packet!"));
|
||||
|
||||
// print data of the packet
|
||||
Serial.print("[SX1278] Data:\t\t");
|
||||
Serial.print(F("[SX1278] Data:\t\t"));
|
||||
Serial.println(str);
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print("[SX1278] RSSI:\t\t");
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print(F("[SX1278] RSSI:\t\t"));
|
||||
Serial.print(lora.getRSSI());
|
||||
Serial.println(" dBm");
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print("[SX1278] SNR:\t\t");
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print(F("[SX1278] SNR:\t\t"));
|
||||
Serial.print(lora.getSNR());
|
||||
Serial.println(" dBm");
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print frequency error
|
||||
Serial.print("[SX1278] Frequency error:\t");
|
||||
Serial.print(F("[SX1278] Frequency error:\t"));
|
||||
Serial.print(lora.getFrequencyError());
|
||||
Serial.println(" Hz");
|
||||
|
||||
Serial.println(F(" Hz"));
|
||||
|
||||
} else if (state == ERR_CRC_MISMATCH) {
|
||||
// packet was received, but is malformed
|
||||
Serial.println("CRC error!");
|
||||
|
||||
Serial.println(F("CRC error!"));
|
||||
|
||||
}
|
||||
|
||||
// we're ready to receive more packets,
|
||||
|
|
|
@ -20,8 +20,12 @@
|
|||
// SX1278 module is in slot A on the shield
|
||||
SX1278 loraSX1278 = RadioShield.ModuleA;
|
||||
|
||||
// SX1272 module is in slot B on the shield
|
||||
SX1272 loraSX1272 = RadioShield.ModuleB;
|
||||
// if you're not using RadioShield, you can specify
|
||||
// the connection yourself
|
||||
// NSS pin: 6
|
||||
// DIO1 pin: 4
|
||||
// DIO2 pin: 5
|
||||
SX1272 loraSX1272 = new Module(6, 4, 5);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
@ -48,7 +52,7 @@ void setup() {
|
|||
|
||||
// initialize the second LoRa instance with
|
||||
// non-default settings
|
||||
// this LoRa link will have high data rate,
|
||||
// this LoRa link will have high data rate,
|
||||
// but lower range
|
||||
// NOTE: when using spreading factor 6, the total packet
|
||||
// length has to be known in advance!
|
||||
|
@ -81,32 +85,32 @@ void setup() {
|
|||
|
||||
// set carrier frequency to 433.5 MHz
|
||||
if (loraSX1278.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
|
||||
Serial.println("Selected frequency is invalid for this module!");
|
||||
Serial.println(F("Selected frequency is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set bandwidth to 250 kHz
|
||||
if (loraSX1278.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) {
|
||||
Serial.println("Selected bandwidth is invalid for this module!");
|
||||
Serial.println(F("Selected bandwidth is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set spreading factor to 10
|
||||
if (loraSX1278.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) {
|
||||
Serial.println("Selected spreading factor is invalid for this module!");
|
||||
Serial.println(F("Selected spreading factor is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set coding rate to 6
|
||||
if (loraSX1278.setCodingRate(6) == ERR_INVALID_CODING_RATE) {
|
||||
Serial.println("Selected coding rate is invalid for this module!");
|
||||
Serial.println(F("Selected coding rate is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set LoRa sync word to 0x14
|
||||
// NOTE: value 0x34 is reserved for LoRaWAN networks and should not be used
|
||||
if (loraSX1278.setSyncWord(0x14) != ERR_NONE) {
|
||||
Serial.println("Unable to set sync word!");
|
||||
Serial.println(F("Unable to set sync word!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
@ -114,20 +118,20 @@ void setup() {
|
|||
// NOTE: 20 dBm value allows high power operation, but transmission
|
||||
// duty cycle MUST NOT exceed 1%
|
||||
if (loraSX1278.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) {
|
||||
Serial.println("Selected output power is invalid for this module!");
|
||||
Serial.println(F("Selected output power is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set over current protection limit to 80 mA (accepted range is 45 - 240 mA)
|
||||
// NOTE: set value to 0 to disable overcurrent protection
|
||||
if (loraSX1278.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) {
|
||||
Serial.println("Selected current limit is invalid for this module!");
|
||||
Serial.println(F("Selected current limit is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set LoRa preamble length to 15 symbols (accepted range is 6 - 65535)
|
||||
if (loraSX1278.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) {
|
||||
Serial.println("Selected preamble length is invalid for this module!");
|
||||
Serial.println(F("Selected preamble length is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
@ -135,11 +139,11 @@ void setup() {
|
|||
// NOTE: set value to 0 to enable autmatic gain control
|
||||
// leave at 0 unless you know what you're doing
|
||||
if (loraSX1278.setGain(1) == ERR_INVALID_GAIN) {
|
||||
Serial.println("Selected gain is invalid for this module!");
|
||||
Serial.println(F("Selected gain is invalid for this module!"));
|
||||
while (true);
|
||||
}
|
||||
|
||||
Serial.println("All settings succesfully changed!");
|
||||
Serial.println(F("All settings succesfully changed!"));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
|
@ -58,20 +58,20 @@ void loop() {
|
|||
|
||||
if (state == ERR_NONE) {
|
||||
// the packet was successfully transmitted
|
||||
Serial.println(" success!");
|
||||
Serial.println(F(" success!"));
|
||||
|
||||
// print measured data rate
|
||||
Serial.print("[SX1278] Datarate:\t");
|
||||
Serial.print(F("[SX1278] Datarate:\t"));
|
||||
Serial.print(lora.getDataRate());
|
||||
Serial.println(" bps");
|
||||
Serial.println(F(" bps"));
|
||||
|
||||
} else if (state == ERR_PACKET_TOO_LONG) {
|
||||
// the supplied packet was longer than 256 bytes
|
||||
Serial.println(" too long!");
|
||||
Serial.println(F(" too long!"));
|
||||
|
||||
} else if (state == ERR_TX_TIMEOUT) {
|
||||
// timeout occured while transmitting packet
|
||||
Serial.println(" timeout!");
|
||||
Serial.println(F(" timeout!"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
RadioLib SX127x Transmit with Inerrupts Example
|
||||
RadioLib SX127x Transmit with Interrupts Example
|
||||
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
|
@ -40,7 +40,7 @@ void setup() {
|
|||
while (true);
|
||||
}
|
||||
|
||||
// set the function that will be called
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
lora.setDio0Action(setFlag);
|
||||
|
||||
|
@ -57,7 +57,7 @@ void setup() {
|
|||
0x78, 0xAB, 0xCD, 0xEF};
|
||||
state = lora.transmit(byteArr, 8);
|
||||
*/
|
||||
|
||||
|
||||
if (state != ERR_NONE) {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
|
@ -86,7 +86,7 @@ void loop() {
|
|||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
int state = lora.startTransmit("Hello World!");
|
||||
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x56,
|
||||
|
@ -97,7 +97,7 @@ void loop() {
|
|||
// NOTE: when using interrupt-driven transmit method,
|
||||
// it is not possible to automatically measure
|
||||
// transmission data rate using getDataRate()
|
||||
|
||||
|
||||
if (state != ERR_NONE) {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
|
|
Loading…
Add table
Reference in a new issue