Home › Forum › Le librerie ospitate nel sito › EBYTE E32 dispositivi LoRa UART sx1278/sx1276. › Ebyte LORA E32 comunicazione tra Arduino ed esp32 › Rispondi a: Ebyte LORA E32 comunicazione tra Arduino ed esp32
16 Luglio 2020 alle 21:53
#5316
Ciao Massimiliano,
qui lo sketch per il sender Arduino
#include "Arduino.h"
//#define E32_TTL_1W
//#define FREQUENCY_915
#include "LoRa_e32.h"
#define RX 4
#define TX 5
#define M0 7
#define M1 6
//HardwareSerial lora(2);
//LoRa_E32 e32ttl1w(&lora,RX,TX, UART_BPS_RATE_9600,SERIAL_8N1);
//LoRa_E32 e32ttl1w(RX, TX, 3); //, 3, 7, 6);
LoRa_E32 e32ttl1w(4, 5, 3, 7, 6);
// Variables globales
unsigned long interval = 15000; // interval between sends
unsigned long lastSendTime = 0; // last send time
byte msgCount = 0; // count of outgoing messages
long randNumber;
void setup() {
//Inicio comunicacion serie con monitor
Serial.begin(9600);
delay(500);
Serial.println();
e32ttl1w.begin();
//Configuro el nodo LoRa
nodeConfig();
}
void loop() {
// Wait a few seconds between measurements.
if (millis() - lastSendTime > interval) {
// print a random number from 10 to 19
randNumber = random(10, 20);
String trama = String(randNumber);
ResponseStatus rs = e32ttl1w.sendFixedMessage(0, 3, 0x10,trama);
Serial.println("Sending " + trama);
Serial.println(rs.getResponseDescription());
lastSendTime = millis(); // timestamp the message
msgCount++;
}
delay(100);
}
void nodeConfig(){
ResponseStructContainer c;
c = e32ttl1w.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDH = 0x0;
configuration.ADDL = 0x1;
configuration.CHAN = 0x10;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.fec = FEC_1_ON;
configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
configuration.OPTION.transmissionPower = POWER_20;
configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;
//printParameters(configuration);
// Set configuration changed and set to not hold the configuration
ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
Serial.print("Config: ");
Serial.println(rs.getResponseDescription());
}
And here the esp32 receiver
#include "Arduino.h"
//#define E32_TTL_1W
//#define FREQUENCY_915
#include "LoRa_E32.h"
// Not needed Serial2 have already this pins
//#define RX 16
//#define TX 17
#define AUX 18
#define M0 21
#define M1 19
//HardwareSerial serial1(2);
//LoRa_E32 e32ttl1w(&serial1,RX,TX, 18, UART_BPS_RATE_9600,SERIAL_8N1);
LoRa_E32 e32ttl1w(&Serial2, AUX, M0, M1);
void setup() {
// pinMode(M0, OUTPUT);
// pinMode(M1, OUTPUT);
//Inicio comunicacion serie con monitor
Serial.begin(9600);
delay(500);
// Establezco M0 y M1 en alto para configurar LoRa
// digitalWrite(M0, HIGH);
// digitalWrite(M1, HIGH);
// Startup all pins and UART
e32ttl1w.begin();
//Configuro el nodo LoRa
nodeConfig();
// Establezco M0 y M1 en bajo para trabajar con LoRa
// digitalWrite(M0, LOW);
// digitalWrite(M1, LOW);
}
void loop() {
if (e32ttl1w.available() > 0) {
Serial.println("----------");
ResponseContainer rc = e32ttl1w.receiveMessage();
Serial.println(rc.data);
// Is something goes wrong print error
if (rc.status.code != 1) {
rc.status.getResponseDescription();
} else {
// Print the data received
Serial.println(rc.data);
}
}
delay(500);
}
void nodeConfig(){
ResponseStructContainer c;
c = e32ttl1w.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDH = 0x0;
configuration.ADDL = 0x3;
configuration.CHAN = 0x10;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.fec = FEC_1_ON;
configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
configuration.OPTION.transmissionPower = POWER_20;
configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;
//printParameters(configuration);
// Set configuration changed and set to not hold the configuration
ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
Serial.print("Config: ");
Serial.println(rs.getResponseDescription());
}
Per lo shema di connessione di arduino fai riferimento all’articolo dello shield
Credo che sia tutto ok ma magari dammi un feedback.
Ciao Renzo