Arduino mega SIM800l special characters - arduino

I have a problem with the Arduino mega board and the SIM800L module I connect to the RX and TX pins of the module and when I enter the serial monitor it returns these characters, what could it be?
void setup() {
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
Serial1.begin(9600);
}
void loop() {
delay(500);
while (Serial.available()) {
Serial1.write(Serial.read()); //Forward what Serial received to Software Serial Port
}
while(Serial1.available()) {
Serial.write(Serial1.read()); //Forward what Software Serial received to Serial Port
}
}

After so much searching and looking on the oscilloscope I have found the solution, In case you are using a LM2596 buck converter to power up the module, remember to common all the ground of the circuit.

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

How do I repeatedly send an AT command to a Bluetooth module arduino

I've been working on a project and want an Arduino uno with an HM-19 Bluetooth module to repeatedly send an AT command to the module then print the modules result in the serial monitor. I'm having trouble and it is only returning the number 53 and not the response 'OK'. Thanks for any insight you're able to give.
//import Software Serial to communicate over comms port
#include <SoftwareSerial.h>
// 0 and 1 are the tx and rx pins ans should be where the hm-19 is
// may be 0,1 instead
SoftwareSerial HM19(1,0);
void setup() {
// begin serial monitor and wait for something(?, found online)
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
//tell user it's started
Serial.println("Started");
//I believe this begins the monitor for the HM-19
HM19.begin(9600);
delay(1000);
}
void loop() {
// give user status report
delay(1000);
Serial.println("Sending an AT command...");
// need to find if this is how you send an AT command (currenty send 'AT' as a test)
HM19.write("AT\r");
delay(30);
//wait for the HM19 to respond then print it out
int HMresponse = 0;
if (HM19.available()){}
HMresponse = HM19.read();
Serial.println(HMresponse);
}

GSM not responsing?

using gsm 6A module with arduino mega
gsm utx to 3 arduin
gsm rtx to 2 arduino
gsm gnd to gnd arduin
I am not getting any response from gsm and further AT and other command are not displaying.
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
good day sir. the rx and tx of gsm module should also be connected to rx and tx ports of arduino mega.

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

Communicating serially through arduino xbeeshield

I have a ladyada xbee adapter on the computer side and an arduino xbeeshield which I am trying to communicate with over wireless. Both xbees are configured correctly in that I can receive data from the xbeeshield to the computer. However it doesn't work the other way i.e. xbeeshield does not echo a byte sent from the computer serially. Any idea what I might be doing wrong? (Note: When I connect the arduino board to the computer using USB cable, the echo program works just fine. It seems to be a problem in wireless mode only)
processing code
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
Serial.print((char) Serial.read());
delay(10);
}
}
I am just sending keystrokes from computer and waiting for a reply. I am not getting any.
I use the code I answered to the following question in regards to sending serial bytes from PC to Xbee/Arduino. It's been working fine for months. Ensure you've configured both your Xbee modules on the PC and Arduino side. Ensure your PAN ID's are the same as well.
Arduino making decision according to a packet received from serial port
What version of the Xbee modules are you using? My code works with Series 1 but should work with newer versions as well.
Try using softwareSerial library and connecting Tx and Rx to pin 4 and 2. Run the following sketch and tell me what happens. Change the Baudrate value to match your own
#include <SoftwareSerial.h>
uint8_t pinRx = 2 , pinTx = 4; // the pin on Arduino
long BaudRate = 57600; // Please set your Baudrate. It should match the one in XC-TU
char GotChar, getData;
// Xbee SoftwareSerial initialization
SoftwareSerial xbee(pinRx, pinTx); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println( "Welcome to the XBee Communication Test" );
Serial.print("BaudRate:");
Serial.println(BaudRate);
Serial.print(" Rx Pin#");
Serial.println(pinRx,DEC);
Serial.print(" Tx Pin#");
Serial.println(pinTx,DEC);
// set the data rate for the SoftwareSerial port
xbee.begin( BaudRate );
xbee.println("Setup Completed!");
}
void loop()
{
if (Serial.available())
{
GotChar = Serial.read();
xbee.print(GotChar);
Serial.print(GotChar);
}
while (xbee.available()>0)
{
Serial.println("Ohohoh");
getData = xbee.read();
Serial.print(" Received: );
Serial.print(getData);
Serial.println();
if(getData == 'a')
{
Serial.println(" sbam");
}
else if(getData == 'b')
{
Serial.println(" sbo");
}
}
}
Upload the program and open the serial monitor. Do you get the 'Setup completed' message on the computer? What happens if you send 'a' or 'b' from the Pc to the Arduino?

Resources