NMEA statements appears infinitely in sim808 - arduino

when I upload the code on arduino mega with sim808 bk-808-v3.1 , I reach the following output on the serial monitor. A NMEA statements appears infinitely. what is the problem and how to solve it?
Note that i connect SMS antenna and GPS antenna with sim808
the code
#include <SoftwareSerial.h>
SoftwareSerial SIM808(10,11); //(RX-Pin,TX-Pin)
void setup() {
Serial.begin(9600);
SIM808.begin(9600);
}
void loop() {
if (SIM808.available())
Serial.write(SIM808.read());
if (Serial.available())
SIM808.write(Serial.read());
}

I actually don't know about SIM808. But the GPS module seems to properly outputing NMEA packets every seconds by reading the GPGGA packet.
If the problem is that messages are printed out too slowly, try using Serial.readStringUntil('\n') and Serial.print functions instead of Serial.read() and Serial.write() functions.
#include <SoftwareSerial.h>
SoftwareSerial SIM808(10,11); //(RX-Pin,TX-Pin)
void setup() {
Serial.begin(9600);
SIM808.begin(9600);
}
void loop() {
if (SIM808.available())
Serial.print(SIM808.readStringUntil('\n'));
if (Serial.available())
SIM808.print(Serial.readStringUntil('\n'));
}

Related

Sending data from Arduino UNO to NodeMCU over UART and processing received data on NodeMCU

I'm trying to send data from Arduino UNO to NodeMCU via UART.
What I want to do is that when Arduino UNO sends "on" String to the NodeMCU, NodeMCU lights up its builtin LED, when "off" - it turns off.
I send data from Arduino UNO via standard Serial.println (). On the NodeMCU I use the SoftwareSerial library. I assigned rx and tx to pins D7 and D8 accordingly. Serial ports on Arduino(standard) and NodeMCU(SoftwareSerial) are set at 9600 baud rate.
Standard Serial port (USB) of NodeMCU is set to 115200.
I send the string that I receive from the Arduino to the standard serial port of the node (connected to usb)
The question is:
On the standard port of NodeMCU, which I view through the Arduino IDE, messages coming from the arduino are displayed, and displayed correctly (those that were sent), but the NodeMCU does not want to accept them in conditional statements and light up my LED. Why?
At the same time, when I remap the virtual UART to its original pins (connected to USB, GPIO3 and GPIO1, and send the same messages via usb through the COM port view in the Arduino IDE, the LED turns on and off as I programmed it.
Do you have any ideas why this is happening?
By the way, I do not lower voltage coming from Arduino RX and TX pins from 5V to 3.3V, but since messages are recived coorectly, I don't think that this is causing a problem.
Here's my code:
Arduino:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("on");
delay(1000);
Serial.println("off");
delay(1000);
}
NodeMCU:
#include <SoftwareSerial.h>
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
Serial.println(str);
if(str == "on"){
digitalWrite(D4, HIGH);
}
if(str=="off"){
digitalWrite(D4, LOW);
}
}
Screenshot of COM4:
Screenshot of COM4:
UPD: I tried using sending 1 or 0 as int value via Serial.write() and s.read() and it works, maybe the prolem is in String type somehow
You Use İt Maybe Work
#include <SoftwareSerial.h>
String text = "";
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
text = str
Serial.println(text);
if(text == "on"){
digitalWrite(D4, HIGH);
}
if(text =="off"){
digitalWrite(D4, LOW);
}
}

serial communication between Arduino and Nodemcu

I'm trying to read voltage value using Analog pin A0 in arduino uno and transmit the read voltage to Nodemcu but not getting same voltage at NodeMcu as on Arduino side for Ex. for 5 volt at Arduino i get only 4 volt at Nodemcu.
i have made the delay of both the sketches equal even tried without any delay
also tried connecting the ground pin of both device
ARDUINO CODE
#include <SoftwareSerial.h>
SoftwareSerial s(5,6);
void setup() {
s.begin(9600);
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int ADCdata = analogRead(A0);
float voltage = (ADCdata * 0.0048828125);
Serial.println(ADCdata);
Serial.println(voltage);
if(s.available()>0)
{
s.write(voltage);
}
delay(1000);
}
NODEMCU CODE
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5);
void setup() {
s.begin(9600);
Serial.begin(9600);
}
void loop() {
s.write("s");
if (s.available()>0)
{
data=s.read();
Serial.println(data);
}
delay(1000);
}
I would send the float data as a string:
s.println(value)
This will append a newline to mark the end of the string.
On the receiving side, read the line and convert to float.
float value = s.parseFloat();

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);
}
}

ESP8266 connected to my Arduino Uno

I have the ESP8266 connected to my Arduino Uno. With a blank sketch I can use Serial Monitor to connect it to my wifi network using these commands
AT+IPR=9600
AT+CWMODE=1
AT+CWJAP="SSID_HERE",""
It get's an ip and everything. But now I want my sketch to just do this using this code
#include <SoftwareSerial.h>
#define SSID "SSID_HERE"
void setup(){
Serial.begin(9600);
Serial.setTimeout(5000);
delay(1000);
}
boolean connectWiFi()
{
// connect
Serial.println("AT+CWMODE=1");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"");
delay(2000);
if(Serial.find("OK"))
{
Serial.println("AT+CIFSR");
Serial.flush();
delay(1000);
return true;
}
else
{
// Can not connect to the WiFi.
return false;
}
}
But it doesn't work.. The Serial.println shows up in the Serial Monitor, but the ESP8266 doesn't seem to respond. What am I missing?
AT -commands ends with carriage return, so you need to add '\r' to every command you print.
In your code lines looks like:
Serial.println("AT+CWMODE=1\r");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"\r");
Serial.println("AT+CIFSR\r");
Reference: https://en.wikibooks.org/wiki/Serial_Programming/Modems_and_AT_Commands/Special_Commands_and_Character_Sequences
The problem here is that you are trying to use pins 0 & 1 for the serial comms, well its part of the problem.. Because the arduino uses serial as well, it for me is only really good to use pins 0 & 1 for serial when i've grounded the reset pin on the arduino. This turns the arduino into a dummy device.
You can use something like software serial and two different pins instead, this way you will not interfere with the hardware serial of the arduino.
Also just to note, the below example will barely work.. For some it will for others it wont.. The problem here is that software serial does not really work / run at 115200..
You can change baud rate via AT+UART_DEF=19200,8,1,0,0 which will also disable flow control, then use software serial with a different speed mySerial.begin(19200)
Using Serial.println("TEXT") will send the line returns for you, so no need to add them unless you use Serial.print("TEXT\r\n")
DO NOT USE: AT+IPR= as this will brick it and require a reflash
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
pinMode(11, INPUT);
pinMode(10, OUTPUT);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("ARDUINO: Starting");
mySerial.begin(115200);
Serial.println("ARDUINO: Sending AT Command");
mySerial.println("AT");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Arduino + GPRS m95 not responding

Im trying to communicate with a Quectel M95 GSM module but im just receiving squares as a response. The module is supposed to auto baud but it seems that it is not working.
The code that im using i took it from David Barnes question:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
SoftwareSerial mySerial(rxPin,txPin); // RX, TX
void setup(){
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
Serial.println("Arduino serial initialized!");
delay(10);
mySerial.begin(9600);
Serial.println("Software serial initialized!");
delay(10);
}
void loop(){
issueCommand("AT");
readSerial();
delay(3*1000);
while(true){
readSerial();
}
}
void issueCommand(char* msg){
mySerial.println(msg);
Serial.print(msg);
delay(10);
}
void readSerial(){
while (mySerial.available()){
Serial.write(mySerial.read());
delay(10);
}
}
Im getting the following as an answer from the GSM:
What can it be? I have tried everything :/ Even if i try it using Windows Hyperterminal i dont recieve anything.
Thanks a lot.
Can you please try the same code by switching RX and TX values. I tried your sample and it worked successfully. Maybe you connected RX TX pins wrong.

Resources