Çözüldü2.22K 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
0

sonuç noldu konuyu kapatıyorum.

Mehmet En iyi cevap olarak seçildi Ağustos 1, 2022
0

kodu okumak baya zor oldu ama 2. listeni ben göremedim. listen komutunu kullanım örneği olarak şuraya bakabilirsin.

https://codebender.cc/example/SoftwareSerial/TwoPortReceive#TwoPortReceive.ino

mega içinde mi software serial kullanıyorsun anlamadım MEGA da 4 tane hardware serial var zaten serial2 falan kullansan daha iyidir.

Mehmet Cevaplanan soru Haziran 25, 2022
0

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

Software Developer Cevaplanan soru Haziran 24, 2022
0

kodu göremiyorum tekrar düzgün görünecek şekilde atar mısın. çözüm

iki tane listen yapmak

I2C ile arduinoları haberleştirmek (https://www.instructables.com/I2C-between-Arduinos/#:~:text=Step%201%3A%20How%20to%20Connect,Connect%20it%20with%20a%20jumper.)

son olarak arduinoları hardware serial ile haberlşetirmek

Mehmet Cevaplanan soru Haziran 24, 2022