Closed JayZeeM closed 6 months ago
I recommend changing message to a char of fixed length. I'm not sure you can use strings in a struct as the length is unknown.
Do you have an example code for a char with fixed length?
Not tested but it at least compiles
// create struct for sender and receiver struct Transceiver { char name[10]; } ;
// populate data on sender side Transceiver Data; strcpy(Data.name, "kris"); // keep length under 10
// on receiver after you got data Serial.println(Data.name);
PS... chars are very different and to be honest can be pain full... Pointers, strcat, strcpy and other non-intuitive functions to perform very basic string operations. But... chars are native to C and Strings are not. In my early day of the Arduino world 've spent many months chasing random crashes and memory issues created from string fragmentation.
`/*
This example shows how to connect to an EBYTE transceiver using an ESP32
/*
This example shows how to connect to an EBYTE transceiver using an ESP32
This code for for the sender
ESP32 won't allow SoftwareSerial (at least I can't get that lib to work so you will just hardwire your EBYTE directly to the Serial2 port
*/
/ WARNING: IF USING AN ESP32 DO NOT USE THE PIN NUMBERS PRINTED ON THE BOARD YOU MUST USE THE ACTUAL GPIO NUMBER /
// i recommend putting this code in a .h file and including it // from both the receiver and sender modules struct DATA { char message[10];
};
// these are just dummy variables, replace with your own int Chan; DATA MyData; unsigned long Last;
// create the transceiver object, passing in the serial and pins EBYTE Transceiver(&Serial2, PIN_M0, PIN_M1, PIN_AX);
void setup() {
Serial.begin(9600);
Serial2.begin(9600); Serial.println("Starting Reader");
// this init will set the pinModes for you Transceiver.init();
// all these calls are optional but shown to give examples of what you can do
// Serial.println(Transceiver.GetAirDataRate()); // Serial.println(Transceiver.GetChannel()); Transceiver.SetAddressH(1); Transceiver.SetAddressL(1); Chan = 18 ; Transceiver.SetChannel(Chan); // save the parameters to the unit, // Transceiver.SetPullupMode(1); // Transceiver.SaveParameters(PERMANENT);
// you can print all parameters and is good for debugging // if your units will not communicate, print the parameters // for both sender and receiver and make sure air rates, channel // and address is the same Transceiver.PrintParameters();
}
void loop() {
// if the transceiver serial is available, proces incoming data // you can also use Transceiver.available()
if (Serial2.available()) {
// i highly suggest you send data using structures and not
// a parsed data--i've always had a hard time getting reliable data using
// a parsing method
Transceiver.GetStruct(&MyData, sizeof(MyData));
// note, you only really need this library to program these EBYTE units
// you can call readBytes directly on the EBYTE Serial object
// Serial2.readBytes((uint8_t*)& MyData, (uint8_t) sizeof(MyData));
// dump out what was just received
Serial.print("message"); Serial.println(MyData.message);
// if you got data, update the checker
delay(2000);
} else { // if the time checker is over some prescribed amount // let the user know there is no incoming data if ((millis() - Last) > 1000) { Serial.println("Searching: "); Last = millis(); }
} } `
this is my receiver code and my Serial monitor is only printing this Model no.: 0 Version : 0 Features : 0
Mode (HEX/DEC/BIN): 0/0/0 AddH (HEX/DEC/BIN): 1/1/1 AddL (HEX/DEC/BIN): 1/1/1 Sped (HEX/DEC/BIN): 0/0/0 Chan (HEX/DEC/BIN): 12/18/10010 Optn (HEX/DEC/BIN): 0/0/0 Addr (HEX/DEC/BIN): 101/257/100000001
message message message message message message message
I am using the same channel and address for both LoRa
I use this lib and ESP's all the time and have been successful. all zeros generally indicates wiring where the serial lines are not corrected. Try increasing the pin recovery
in the .h change the 50 to say 100
just for fun call these lines after Transceiver.init()
delay(1000); Transceiver.PrintParameters();
If you are using the above code, settings are never getting saved (temporarily or permanently).
// Transceiver.SaveParameters(PERMANENT);
Is there any soc med that I can talk with you privately sir?
I just tried the example code on and ESP32 (dev kit) and with 3 different EBYTE modules. All fired right up and output the model and correct parameters.
E22-900t22d I powered it only through my laptop and connected the pins to their respective pins. Like AUX M0 M1 to their pins in esp32 and im using TX0 and RX0 because my ESP32 doesn't have TX2 and RX2. Do I have to connect 3.3V on the RX and TX of E22?
I also use E32 433T20D i have 1 set of each EByte module so 2 pcs of E32 433T20D and 2 pcs of E22 900T22D
The code above is used for the E22
that would be the problem can't use serial 0 (or 1) as they are tied to hardware internally. ESP32 has serial2 available on the hardware pins I call out. If you can;t use those pins, you will have to use softwareserial.h and chose different ones
I have 3 UARTs in one project and I had to use sofwareserial.h
like this....
SoftwareSerial Serial_A(33, 32); // ESP RX, TX SoftwareSerial Serial_B(21, 22);// ESP RX, TX
EBYTE Transceiver(&Serial_A, PIN_M0, PIN_M1, PIN_AX);
But I cant use SoftwareSerial.h with ESP32 do you have any sample code?
Sure, here u go.
/ WARNING: IF USING AN ESP32 DO NOT USE THE PIN NUMBERS PRINTED ON THE BOARD YOU MUST USE THE ACTUAL GPIO NUMBER /
// note my experience with ESP's is you cannot pick any pin some will not support serial // these work for me, 21 22 also work
// i recommend putting this code in a .h file and including it // from both the receiver and sender modules struct DATA { unsigned long Count; int Bits; float Volts; float Amps;
};
// these are just dummy variables, replace with your own int Chan; DATA MyData; unsigned long Last;
SoftwareSerial Serial_1(PIN_RX , PIN_TX ); // MCU Rx Tx connect to EBYTE Tx Rx
// create the transceiver object, passing in the serial and pins EBYTE Transceiver(&Serial_1, PIN_M0, PIN_M1, PIN_AX);
void setup() {
Serial.begin(9600);
Serial_1.begin(9600);
Serial.println("Starting Reader");
// this init will set the pinModes for you Serial.println(Transceiver.init());
// all these calls are optional but shown to give examples of what you can do
// Serial.println(Transceiver.GetAirDataRate()); // Serial.println(Transceiver.GetChannel()); // Transceiver.SetAddressH(0); // Transceiver.SetAddressL(0); // Chan = 16; // Transceiver.SetChannel(Chan); // save the parameters to the unit, // Transceiver.SaveParameters(PERMANENT);
// you can print all parameters and is good for debugging // if your units will not communicate, print the parameters // for both sender and receiver and make sure air rates, channel // and address is the same Transceiver.PrintParameters();
}
void loop() {
// measure some data and save to the structure MyData.Count++; MyData.Bits = analogRead(A0); MyData.Volts = MyData.Bits * ( 5.0 / 1024.0 );
// i highly suggest you send data using structures and not // a parsed data--i've always had a hard time getting reliable data using // a parsing method Transceiver.SendStruct(&MyData, sizeof(MyData));
// note, you only really need this library to program these EBYTE units
// you can call write directly on the EBYTE Serial object
// Serial2.write((uint8_t*) &Data, PacketSize );
// let the use know something was sent Serial.print("Sending: "); Serial.println(MyData.Count); delay(1000);
}
Model no.: 53 Version : 48 Features : 14
Mode (HEX/DEC/BIN): C0/192/11000000 AddH (HEX/DEC/BIN): 0/0/0 AddL (HEX/DEC/BIN): 0/0/0 Sped (HEX/DEC/BIN): 19/25/11001 Chan (HEX/DEC/BIN): 10/16/10000 Optn (HEX/DEC/BIN): 44/68/1000100 Addr (HEX/DEC/BIN): 0/0/0
Hello I tried using the send and receive examples of ESP32 and changing the structure message with
String message;
and edited the other parts as well but on the receiver side it is not showing the message I inputed which is "Hello"