¡Hola!
Estoy probando el código que sale en los ejemplos que vienen con las librerías. Lo he probado tanto con arduino mega como con el uno. Ahí va el código que uso:
Para el que recibe:
Code:
#include <Wire.h>
// Cooking API libraries
#include <arduinoUtils.h>
// Include the SX1272 and SPI library:
#include "arduinoLoRa.h"
#include <SPI.h>
int e;
char my_packet[100];
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Print a start message
Serial.println(F("SX1272 module and Arduino: receive packets without ACK"));
// Power ON the module
e = sx1272.ON();
Serial.print(F("Setting power ON: state "));
Serial.println(e, DEC);
// Set transmission mode and print the result
e |= sx1272.setMode(4);
Serial.print(F("Setting Mode: state "));
Serial.println(e, DEC);
// Set header
e |= sx1272.setHeaderON();
Serial.print(F("Setting Header ON: state "));
Serial.println(e, DEC);
// Select frequency channel
e |= sx1272.setChannel(CH_10_868);
Serial.print(F("Setting Channel: state "));
Serial.println(e, DEC);
// Set CRC
e |= sx1272.setCRC_ON();
Serial.print(F("Setting CRC ON: state "));
Serial.println(e, DEC);
// Select output power (Max, High or Low)
e |= sx1272.setPower('H');
Serial.print(F("Setting Power: state "));
Serial.println(e, DEC);
// Set the node address and print the result
e |= sx1272.setNodeAddress(8);
Serial.print(F("Setting node address: state "));
Serial.println(e, DEC);
// Print a success message
if (e == 0)
Serial.println(F("SX1272 successfully configured"));
else
Serial.println(F("SX1272 initialization failed"));
}
void loop(void)
{
// Receive message
e = sx1272.receivePacketTimeout(10000);
if ( e == 0 )
{
Serial.print(F("Receive packet, state "));
Serial.println(e, DEC);
for (unsigned int i = 0; i < sx1272.packet_received.length; i++)
{
my_packet[i] = (char)sx1272.packet_received.data[i];
}
Serial.print(F("Message: "));
Serial.println(my_packet);
}
else {
Serial.print(F("Receive packet, state "));
Serial.println(e, DEC);
}
}
Para el que emite..
Code:
#include <Wire.h>
// Cooking API libraries
#include <arduinoUtils.h>
// Include the SX1272 and SPI library:
#include "arduinoLoRa.h"
#include <SPI.h>
int e;
char message1 [] = "Packet 1, wanting to see if received packet is the same as sent packet";
char message2 [] = "Packet 2, broadcast test";
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Print a start message
Serial.println(F("SX1272 module and Arduino: send packets without ACK"));
// Power ON the module
e = sx1272.ON();
Serial.print(F("Setting power ON: state "));
Serial.println(e, DEC);
// Set transmission mode and print the result
e |= sx1272.setMode(4);
Serial.print(F("Setting Mode: state "));
Serial.println(e, DEC);
// Set header
e |= sx1272.setHeaderON();
Serial.print(F("Setting Header ON: state "));
Serial.println(e, DEC);
// Select frequency channel
e |= sx1272.setChannel(CH_10_868);
Serial.print(F("Setting Channel: state "));
Serial.println(e, DEC);
// Set CRC
e |= sx1272.setCRC_ON();
Serial.print(F("Setting CRC ON: state "));
Serial.println(e, DEC);
// Select output power (Max, High or Low)
e |= sx1272.setPower('H');
Serial.print(F("Setting Power: state "));
Serial.println(e, DEC);
// Set the node address and print the result
e |= sx1272.setNodeAddress(3);
Serial.print(F("Setting node address: state "));
Serial.println(e, DEC);
// Print a success message
if (e == 0)
Serial.println(F("SX1272 successfully configured"));
else
Serial.println(F("SX1272 initialization failed"));
}
void loop(void)
{
// Send message1 and print the result
e = sx1272.sendPacketTimeout(8, message1);
Serial.print(F("Packet sent, state "));
Serial.println(e, DEC);
delay(4000);
// Send message2 broadcast and print the result
e = sx1272.sendPacketTimeout(0, message2);
Serial.print(F("Packet sent, state "));
Serial.println(e, DEC);
delay(4000);
}
He probado diferentes modos, direcciones y potencias... y con el Arduino Uno no llegan los mensajes.
La multiprotocol es la version 2.
Aqui la foto:
https://www.dropbox.com/s/30dfctt0mkbdo ... 3.jpg?dl=0Es la primera vez que pruebo estas antenas y la verdad no tengo muy claro como hacerlas funcionar.
Y ya que estoy aprovecho para preguntaros: ¿Solo funcionan con emisor o receptor o pueden hacer las dos cosas a la vez? Comunicacion Duplex de esa que creo que le llaman..
Un saludo y muchas gracias por vuestro tiempo