Çözüldü2.19K görüntülenmeLoraarduino mega arduino-nano lorae32 softwareserial
0

Merhabalar,

Elimde 2 Nano + LoRa (3in1PCB) set var, bunlar kendi arasında haberleşiyor. Ayrıca bir Mega var. Mega’dan Nano’ya veri göndermek istiyorum. Mega Serial1’den veriyi gönderiyorum LoRa bağlı Nano’ya. Eğer Nano’da SoftwareSerial portunu listen yaparsam veriyi alabiliyorum ancak LoRa haberleşmesi kesiliyor. Listen yapmayıncada Mega’dan gönderdiğim mesajı okuyamıyorum. Yardımcı olabilir misiniz? Ayrıca kodları da soruya ekliyorum. 

Teşekkürler, iyi çalışmalar

//LoRa SENDER<br />#include "LoRa_E32.h"<br />#include <SoftwareSerial.h><br /> #if defined (__AVR_ATmega328P__)<br />char BOARD[]      = {"NANO"};<br />#elif defined (__AVR_ATmega2560__)<br />char BOARD[]      = {"Mega"};<br />#elif defined (__AVR_ATmega168__)<br />char BOARD[]      = {"Mini 168"};<br />#else<br />#warning "device type not defined"<br />#endif<br /> #define M0 7<br />#define M1 6<br />/*<br />   Pinler     Arduino Nano    Lora E32 433T20d<br />                  11                3<br />                  10                4<br />*/<br />#define loraRX 10<br />#define loraTX 11<br />#define megaRX 8<br />#define megaTX 9<br /> int cmp = -1;<br />const uint32_t baudRate = 9600;<br />char mystr[15] = "SELAM";<br /> SoftwareSerial loraSender(loraRX, loraTX); // Arduino RX <-- e32 TX, Arduino TX --> e32 RX<br />SoftwareSerial megaReceiver(megaRX, megaTX); // Arduino RX <-- mega TX, Arduino TX --> mega RX<br />LoRa_E32 e32ttl(&loraSender);<br /> struct Signal {<br />  char type[15];<br />  byte temp[4];<br />} data;<br /> void setup() {<br />  pinMode(M0, OUTPUT);<br />  pinMode(M1, OUTPUT);<br />     digitalWrite(M0, LOW);<br />  digitalWrite(M1, LOW);<br />   pinMode(megaRX, INPUT);<br />  pinMode(megaTX, OUTPUT);<br />     Serial.begin(baudRate);<br />  Serial.println(BOARD);<br />   megaReceiver.begin(baudRate);<br />     e32ttl.begin();<br />  delay(500);<br />}<br /> void loop() {<br />  mega();<br />  lora();<br />}<br /> void mega() {<br />  megaReceiver.listen();<br />  Serial.println(megaReceiver.available());<br />  if (megaReceiver.available()) {<br />    byte buf = megaReceiver.read();<br />    Serial.println("MEGA......");<br />    Serial.println(buf);<br />  }<br />  delay(1000);<br />}<br /> void lora() {<br />  Serial.println(e32ttl.available());<br />  while (e32ttl.available()  > 1) {<br />    //Gelen mesaj okunuyor<br />    ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Signal));<br />    struct Signal data = *(Signal*) rsc.data;<br />    Serial.print("Gelen Messaj: ");<br />    Serial.println(data.type);<br />    rsc.close();<br />    //Serial.println(mystr);<br />     //Gönderilecek paket veri hazırlanıyor<br />    struct Signal  {<br />      char type[15] = "Teknofest Lab.";<br />      byte temp[4];<br />    } data2;<br />     //strcpy(mystr, "TEST");<br />    //mega();<br />     *(float*)(data2.temp) = 31;<br />    //Serial.println(cmp);<br />    if (cmp == 1) {<br />      strcpy(data2.type, mystr);<br />    }<br />     ResponseStatus rs = e32ttl.sendFixedMessage(0, 63, 23, &data2, sizeof(Signal));<br />    Serial.println(rs.getResponseDescription());<br />  }<br />}<br /> //LoRa RECEIVER<br />#include "LoRa_E32.h"<br />#include <SoftwareSerial.h><br /> #if defined (__AVR_ATmega328P__)<br />char BOARD[]      = {"NANO"};<br />#elif defined (__AVR_ATmega2560__)<br />char BOARD[]      = {"Mega"};<br />#elif defined (__AVR_ATmega168__)<br />char BOARD[]      = {"Mini 168"};<br />#else<br />#warning "device type not defined"<br />#endif<br /> #define M0 7<br />#define M1 6<br />/*<br />   Pinler     Arduino Nano    Lora E32 433T20d<br />                  11                3<br />                  10                4<br />*/<br />#define loraRX 10<br />#define loraTX 11<br /> SoftwareSerial loraReceiver(loraRX, loraTX);<br />LoRa_E32 e32ttl(&loraReceiver);<br /> struct Signal {<br />  char type[15] = "MERHABA";<br />  byte temp[4];<br />} data;<br /> void setup() {<br />  pinMode(M0, OUTPUT);<br />  pinMode(M1, OUTPUT);<br />     digitalWrite(M0, LOW);<br />  digitalWrite(M1, LOW);<br />   Serial.begin(9600);<br />  Serial.println(BOARD);<br />   e32ttl.begin();<br />  delay(500);<br />}<br /> void loop() {<br />   ResponseStatus rs = e32ttl.sendFixedMessage(0, 44, 23, &data, sizeof(Signal));<br />  Serial.println(rs.getResponseDescription());<br />   delay(2000);<br />   while (e32ttl.available()  > 1) {<br />    ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Signal));<br />    struct Signal data = *(Signal*) rsc.data;<br />    Serial.print("Yer: ");<br />    Serial.println(data.type);<br />    Serial.print("Onay: ");<br />    Serial.println(*(float*)(data.temp));<br />    rsc.close();<br />  }<br />}<br /> //MEGA<br />#include <SoftwareSerial.h><br /> #if defined (__AVR_ATmega328P__)<br />char BOARD[]      = {"UNO", "NANO"};<br />#elif defined (__AVR_ATmega2560__)<br />char BOARD[]      = {"Mega"};<br />#elif defined (__AVR_ATmega168__)<br />char BOARD[]      = {"Mini 168"};<br />#else<br />#warning "device type not defined"<br />#endif<br /> //#define nanoRX 9<br />//#define nanoTX 8<br /> const uint32_t baudRate = 9600;<br /> //SoftwareSerial nanoLoRa(nanoRX, nanoTX);<br /> void setup() {<br />  //pinMode(nanoRX, INPUT);<br />  //pinMode(nanoTX, OUTPUT);<br />   Serial.begin(baudRate);<br />  Serial.println(BOARD);<br />   Serial1.begin(baudRate);<br />   //nanoLoRa.begin(baudRate);<br />}<br /> void loop() {<br />   //Serial.println(nanoLoRa.available());<br />  /*<br />  if (nanoLoRa.available()) {<br />    Serial.println("FROM-MEGA-TO-NANO");<br />    nanoLoRa.println("FROM-MEGA-TO-NANO");<br />  }<br />  */<br />  Serial.println(Serial1.available());<br />  if (Serial1.available()) {<br />    Serial.println("FROM-MEGA-TO-NANO");<br />    Serial1.println("FROM-MEGA-TO-NANO");<br />  }<br />  delay(1000);<br />}

Soru yeni cevaplara kapalıdır.
Mehmet En iyi cevap olarak seçildi Ağustos 1, 2022