Lora E45-TTL-100 Basic Arduino setup - arduino

I used this code to send data from the Arduino board to LoRa E45-TTL. The board seems to transmit data, but the receiving node doesn't seem to receive data. I am a real beginner to LoRa technology and any help is highly appreciated. The sending and receiving node codes I used are below:
Sender Node
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("000106,supun");
delay(2000);
}
Receiver Node
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available()) {
char x=Serial.read();
Serial.println(x);
delay(200);
}
}

This post mentions a similar problem, with a hackish solution to close Serial and re-open it.
void loop() {
Serial.print("Test");
Serial.end();
delay(30);
Serial.begin(9600);
delay(70); //The rest of requested delay. So 100 - 30 = 70
}

Related

SIM7600CE - How to know when SIM card is registered into network by software

I am trying to set up the SIM7600CE to have it connect to the internet whenever I turn it on with Arduino Mega. I know how to turn it on with software by set the pin D12 to HIGH but I don't know how to read the signal of the NETLIGHT pin to get to know when the NETLIGHT starts to blink, which means the SIM card is registered into network successfully. Is there any way I can read that signal? Or is there any other way I can acknowledge when SIM card is registered into network successfully by software?
edit: I am trying to get the information that my SIM7600 is connected by using AT command. Even though I can send the AT command, I cannot parse the response. The result of the code below turns out that the Serial keeps printing the string "at+csq" constantly. Can anybody help?
#define mySerial Serial1
#define PWRKEY 12
void setup()
{
digitalWrite(PWRKEY, HIGH); //Press the boot button
Serial.begin(115200);
delay(500);
mySerial.begin(115200);
delay(5000);
while (1)
{
Serial.println("AT+CSQ"); //AT command for Signal quality test
updateSerial();
delay(1500);
}
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());
}
while (mySerial.available())
{
Serial.write(mySerial.read());
if (Serial.find("+CSQ: ")) //Find the AT+CSQ response
{
char c = mySerial.read();
if (c != '9') //check the first digit after "+CSQ: ", +CSQ: 99,99 means not detectable,
{
Serial.println("connected");
break;
}
}
}
Checkout the AT manual for the MODEM. Enable all URCs related to network registration, once registered on the network - you will receive a URC that will have information if your SIM was able to register on the network or not.
I have solved the problem with the same logic. However, I tried to just write and read in the SIM7600 serial, with some printing on the monitor to guide/debug. Plus, I used a connection flag as a condition to break the while loop when the MODEM is connected.
#define mySerial Serial1
#define PWRKEY 12
bool connectionFlag = 0; //will be set when connected
void setup()
{
digitalWrite(PWRKEY, HIGH); //Press the boot button
Serial.begin(115200);
delay(500);
mySerial.begin(115200);
delay(5000); //Give it a little time to initialize
while (1)
{
mySerial.println("AT+CSQ"); //AT command for Signal quality test
connectionCheck();
if (connectionFlag ==1) break;
delay(1500);
}
Serial.println("done");
mySerial.println("AT+CSQ"); //Get the CSQ response to confirm.
updateSerial();
}
void loop()
{
updateSerial();
}
void connectionCheck()
{
delay(500);
while (mySerial.available())
{
// Serial.write(mySerial.read());
if (mySerial.find("+CSQ: ")) //Find the AT+CSQ response
{
Serial.print("initializing\t");
char c = mySerial.read();
if (c != '9') //check the first digit after "+CSQ: ", +CSQ: 99,99 means not detectable,
{
Serial.println("connected");
connectionFlag = 1;
break;
}
}
}
}
void updateSerial()
{
delay(500);
if (mySerial.available())
{
Serial.write(mySerial.read());
}
if (Serial.available())
{
mySerial.write(Serial.read());
}
}

Use Serial in Arduino as variable

I would like to choose which Serial should be used on my Mega (e.g. Serial for development & testing, and then Serial3 for communication with another board). I came with this code:
HardwareSerial HWSerial = Serial; //or Serial1, Serial2, Serial3
void setup() {
HWSerial.begin(115200);
}
void loop() {
HWSerial.println("Hello world!");
delay(1000);
}
However, this produces only first two bytes and a NUL ("He␀").
What am I doing wrong?
Note: I know I could use
HardwareSerial* HWSerial = &Serial; //or Serial1, Serial2, Serial3
void setup() {
HWSerial->begin(115200);
}
void loop() {
HWSerial->println("Hello world!");
delay(1000);
}
which works. I was, however, in fact planning to use ArduinoJSON and the serializeJson(JSONObj, serial) function which won't accept a pointer, so I'm stuck there - and my approach compiles, but again, produces only first two bytes...

Sending Float Data Type from Arduino to ESP32 (NodeMCU)

I am trying to have a NodeMCU(ESP32) receive a floating data type from an Arduino Uno but I do not have any idea how. Can someone please guide me through the process? For now, I have the basic serial communication code sending a single digit Int from the Arduino to the NodeMCU.
Sender (Arduino Uno):
int val = 1;
void setup()
{
Serial.begin(19200);
}
void loop()
{
Serial.write(val);
delay(3000);
}
Receiver (NodeMCU):
#include <HardwareSerial.h>
HardwareSerial receiver(2);
void setup()
{
receiver.begin(19200, SERIAL_8N1, 16, 17);
Serial.begin(9600);
}
void loop()
{
if(receiver.available() > 0)
{
int received = receiver.read();
Serial.println(received); //tried printing the result to the serial monitor
}
delay(3000);
}
Write/read in the form you use it, is for single bytes only. A float in Arduino consists of 4 bytes.
You can use write to send a series of bytes, and you have to read those bytes, arriving one after the other, depending on the serial speed. Synchronization/lost bytes might be a problem, here in this simple solution I assume the best.
Sender:
float val = 1.234;
void setup() {
Serial.begin(19200);
}
void loop() {
Serial.write((byte*)&val,4);
delay(3000);
}
Receiver:
#include <HardwareSerial.h>
HardwareSerial receiver(2);
void setup()
{
receiver.begin(19200, SERIAL_8N1, 16, 17);
Serial.begin(9600);
}
void loop()
{
if(receiver.available() > 0)
{
delay(5); // wait for all 4 bytes
byte buf[4];
byte* bp = buf;
while (receiver.available()) {
*bp = receiver.read();
if (bp - buf < 3) bp++;
}
float received = * (float*)buf;
Serial.println(received, 3); // printing the result to the serial monitor
}
delay(100); // not really required, should be smaller than sender cycle
}

Unable to do Arduino Mega to Arduino Mega serial communication

Based on the circuit below, I tried hooking up two Arduino Mega for serial communication.
The code for sender:
char mystr[3] = "Hello"; //String data
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
Serial.write(mystr, 5); //Write the serial data
delay(1000);
}
The code for receiver:
char mystr[5]; //Initialized variable to store received data
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
Serial.readBytes(mystr, 5); //Read the serial data and store in var
delay(1000);
}
There is no output in the Serial console of Arduino. Could someone please inform me of the possible cause and solution for the same. If I've missed out anything, over- or under-emphasized a specific point let me know in the comments.
If I understood this right you have one Arduino connected to your pc and to another Arduino?
The problem is that you need to specify which Serial port to use:
That is rather easy, just type Serial1 or Serial2 instead of just Serial. That allows you to open 2 Serial ports: One to your other Arduino and one to your Computer for Displaying the results !
LINK: https://www.arduino.cc/en/Tutorial/MultiSerialMega
You need to check available data from serial:
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
Serial.readBytes(mystr, 5);
Serial.print("I received: ");
Serial.println(mystr, DEC);
}
}

Conflict between Arduino delay function and SoftwareSerial

It seems that I have a conflict between SoftwareSerial and the delay function on my Arduino (GeekCreit bought on Banggood). I am trying to use SoftwareSerial to send AT commands to an ESP-01.
When I perform:
#include <SoftwareSerial.h>;
SoftwareSerial esp8266(8,9);
void setup() {
Serial.begin(9600);
while (!Serial) ;
esp8266.begin(9600);
esp8266.println("AT");
}
void loop() {
if(esp8266.available()) {
while(esp8266.available()) {
Serial.print(esp8266.read());
}
}
}
Everything works well, the AT command is sent and I receive the response from my ESP.
But when I add a delay before sending the AT command, nothing happens: no command sent, no answer from the ESP.
#include <SoftwareSerial.h>;
SoftwareSerial esp8266(8,9);
void setup() {
Serial.begin(9600);
while (!Serial) ;
esp8266.begin(9600);
delay(2000);
esp8266.println("AT");
}
void loop() {
if(esp8266.available()) {
while(esp8266.available()) {
Serial.print(esp8266.read());
}
}
}
Am I doing something wrong, has someone experienced the same problem?
I have tried to use AltSoftSerial instead but I have the same issue with it.

Resources