SoftSerial Not Working ESP8266 - arduino

I am trying to communicate with my ESP8266 module through Arduino Mega with the ESP's Rx pin connected to Mega's Pin 7 the ESP's Tx pin connected to Mega's Pin 6. I tried to run the following test code:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(6, 7);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Started");
// set the data rate for the SoftwareSerial port
esp8266.begin(9600);
esp8266.write("AT\r\n");
}
void loop() {
if (esp8266.available()) {
Serial.write(esp8266.read());
}
if (Serial.available()) {
esp8266.write(Serial.read());
}
}
I get no response from the ESP8266 module. I then tried to use the Mega's dedicated Tx and Rx pins (1 and 0 respectively). I can send commands using the serial monitor and it replies. First I sent AT+CIOBAUD=9600 under a 115200 baud to change the baud rate of my ESP module to 9600. Then under 9600 baud I sent AT+UART_DEF=9600,8,1,0,0. It replied OK for both as expected. I tried again to run this program but I'm still getting no response from the ESP 8266 module. I also tried simply switching the Rx and Tx pins just to be safe. Still doesn't work. Any ideas on what I might be doing incorrectly?

As you've mentioned in comments, SoftwareSerial esp(6,7) works on UNO but not on Mega. That should be hint big enough to google the Arduino SoftwareSerial reference page, particularly the Limitation section.
In short, unlike UNO the Mega doesn't have Pin Change Interrupt capability on all pins. So you can't have Rx pin on pin 6.

Related

HC-05 Module AT command mode won't respond

I've been trying to connect two HC-05 bluetooth modules together as master and slave devices. I know that to do this i need to establish one as a slave device and one as a master using the AT command mode. I am using an arduino nano with each of the modules and the circuit i have used is shown:
Vcc -----> 5V
GND ----> GND
Rx ------> Rx
Tx ------> Tx
I followed various online tutorials and have used this code:
include SoftwareSerial.h
SoftwareSerial BTSerial(0, 1); // RX | TX
void setup()
{
Serial.begin(9600);
BTSerial.begin(9600); // HC-05 default speed in AT command more
Serial.println("Enter AT commands:");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()){
Serial.write(BTSerial.read());
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available()){
BTSerial.write(Serial.read());
}
}
Using the button on the module or by setting the EN pin high, i am able to put the module into AT mode as displayed by the LED blinking every 2 seconds. However, i receive no response after sending commands to the module using the serial monitor when i should receive a confirmation of my command.
Any ideas where i'm going wrong?
Here's the solution that eventually worked for me: I used this circuit with a voltage divider:
Vcc -----> 5V
GND ----> GND
D2 ------> Tx
D3 ------> Rx
I ended up having to buy an Uno for this to work, I'm assuming then that my Nano's were faulty in some way. I then used the following code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
void setup()
{
Serial.begin(9600);
BTSerial.begin(38400); // HC-05 default speed in AT command more
Serial.println("Enter AT commands:");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()){
Serial.write(BTSerial.read());
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available()){
BTSerial.write(Serial.read());
}
}
This allowed me to enter the AT mode and also receive responses.
One of the issues was that I was using the Tx and Rx pins which are also used to communicate with the computer so cannot be used with the HC-05 at the same time.
Another issue was the baudrate: I alternated between 9600 and 38400 for each communication until I found a combination that worked, and adjusted the speed in the Serial monitor so that it made sense.
Then I was able to use the command mode normally.

Arduino Nano no serial communication SIM800C

I am trying to get my SIM800C to talk with my Arduino. There is no communication happening, though.
#include <SoftwareSerial.h>
SoftwareSerial at(2, 3);
void setup() {
Serial.begin(9600);
at.begin(9600);
}
void loop() {
// try every 2 seconds
delay(2000);
Serial.println("sending AT ... ");
at.println("AT");
while (at.available() > 0) {
Serial.write(at.read());
}
}
I am not able to get an OK back. SIM800C is supposed to detect the baud rate by itself.
I am sure there has to be a simple stupid mistake. I just don't know what to do at this point. I obviously already checked for cable break. Out of desperation I already tried to switch RX and TX. I also tried different baud rates (whatever is within the usual limitations of SoftwareSerial) but it should automatically detect it once a couple of AT commands got in anyway.
Weird enough, the pin PWX on the SIM800C needs to be hooked up to a GND to work. It started blinking every second now and is responding to AT commands.
Also it turned out that this specific module does not ship with autobauding enabled, as stated by the SIM800C documentation. The correct baud rate is 115200.
There are some problems you need to consider:
Use below sample code which transfers data between PC and SIM. Sometimes SIM module would go into power down state and won't respond on any AT command but would print some results in the serial monitor.
As already mentioned in comments it seems that your wiring is wrong and as you declared Software Serial as SoftwareSerial at(2, 3); which means pin 2 is Rx on Arduino and should connect to Tx pin of SIM and pin 3 is Tx on Arduino and should connect to Rx pin of SIM. Please don't mess with the pins and connect the pins like below correctly.
Arduino SIM
Rx 2 ----> Tx
Tx 3 ----> Rx
I'm not sure if you can power on SIM800 with a 500mA USB connector, make sure that use an external 1/2 A power supply for VCC of SIM module.
Look at the blink speed of SIM module if it connected and powered on it would blinky with 3 seconds delay and if it blinks fast, it means that it is being restarted. Also if SIM powered on correctly it would print some info like SIM READY, CALL READY, etc.
Try other baud rates like 115200 and see if you get anything on power on.
I put some macro definition to make pin mappings more clear.
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D2
#define SIM800_TX_PIN 2
//SIM800 RX is connected to Arduino D3
#define SIM800_RX_PIN 3
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
Yes this module will not work in this configuration. There is a pin of V_TTL With 5V pin.. This pin enables the TTL logic converter of your GSM.. You have to connect this pin to 5V in case of arduino and to 3V in case of ESP8266.See the pin configuration here

How do I fix HM-10 BLE module from returning odd characters?

I am trying to send data to an Arduino via a HM-10 module(BLE) from a MacOS device and am following this guide. For my wiring, I have done the following: I have the RX pin on the HM-10 hooked to the TX on the Arduino; the TX pin on the HM-10 to the RX on the Arduino; the VCC on the HM-10 to the 3.3V on the Arduino; the GND on the HM-10 to the GND on the Arduino.
I am using the following code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(0, 1); //RX|TX
void setup(){
Serial.begin(9600);
BTSerial.begin(9600); // default baud rate
Serial.println("AT commands: ");
}
void loop(){
//Read from the HM-10 and print in Serial Moniter
if(BTSerial.available()) {
Serial.write(BTSerial.read());
}
//Read from the Serial Moniter and print to the HM-10
if(Serial.available()) {
BTSerial.write(Serial.read());
}
}
When I send AT+NAME?, I should be receiving OK+NAME:HMSoft, but I keep on getting a string of odd characters: AV⸮5⸮. In addition, none of the commands seem to have any effect.
What am I doing wrong that I am unable to interact with the HM-10 from my computer?
SoftwareSerial BTSerial(0, 1); //RX|TX
You are using hardware serial pins for software serial. And you are then using both, which corrupts the data.
Move the software serial pins to different ones, like 2 and 3.
After changing the pins to 2 and 3, choose Both NL&CR option to send commands to Arduino through the IDE. Otherwise it's not going to work.

ESP8266 serial returning 'garbage' to Arduino

I bought ESP8266 module and I connected to Arduino UNO board through SoftwareSerial (PIN 10 - RX, PIN 11 - TX),
I have also expternal power suply for ESP8266 5V (450mA) it reduced to 3.3V by step-down converter.
Connections:
ESP 8266
Vcc - 3.3V from external powers suply
CH_PD - 3.3V from external powers suply
GND - GND from external
RESET - not connected
GPIO - not connected
GPI2 - not connected
RX <- 5V from Arduino reduced to 3.3V by 3x10K ohm resistors
TX -> 3.3 to arduino
Electrical connections
and I upload to Arduino sample program to test esp8266 communication.
Arduino program:
#include <SoftwareSerial.h>
const byte rxPin = 10; // Wire this to Tx Pin of ESP8266
const byte txPin = 11; // Wire this to Rx Pin of ESP8266
// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);
void setup() {
Serial.begin(9600);
ESP8266.begin(9600); // Change this to the baudrate used by ESP8266
delay(1000); // Let the module self-initialize
}
void loop() {
delay(100);
Serial.println("Sending an AT command...");
ESP8266.println("AT\r\n");
delay(30);
while (ESP8266.available()){
String inData = ESP8266.readStringUntil('\n');
Serial.println("Got reponse from ESP8266: " + inData);
}
}
but i not working corectly... When Arduino send message to ESP. ESP returns only rubish.. withot "Ready" and don't get firmware information. I tested all speed baud it look's the same...
Serial monitor - printscreen
When I manually send "AT" command from serial monitor EPS don't response anything!
Connection is perfect. By default, the baud rate of esp8266 is 115200. So for the first time keep the baud rate 115200 both for esp8266 and serial monitor.
Serial.begin(115200)
ESP8266.begin(115200)
Now it is needed to change the baud rate of esp8266. Commands can be sent through serial communication.Use this command.
AT+CIOBAUD=9600
After this the above code should work as expected.
Change the 10K resistor.Don't use it.When you use High value resistor it suppress the current hence you will not read any signals from that side.
Try using Low value resistor and in 9600 baud rate
If you want to program esp module with arduino uno you need to bypass the arduino and write the code
Steps:
pins
arduino tx-->rx (esp)
arduino rx-->tx(esp)
3.3v supply -->vcc,ch_pd (esp)
GND -->GND, Gpi0(esp)
Baudrate works for me is 9600,57600
Do not use SoftwareSerial for Speeds above 19200 Baud.
Per default the ESP8266 talks at 115000 Baud. Connect it directly to the computer with USB/ Serial, use putty at 115000 Baud to talk to the ESP. Change the baud rate of the ESP to 19200 (AT+CIOBAUD=19200 for early FW version, AT+UARTsomething for newer).
SoftwareSerial should work than, but I don't use it any more - all kinds of problems; HardwareSerial is so much better. Just switch the Arduino RX/TX pins between computer and ESP; no monitor output then though; use the LED to give you clues.
Use a logic level converter for the esp8266 Rx pin. Arduino logic is 5.0 v, and esp8266 is 3.3v logic.
Make the ground of ext power supply and arduino common.

Xbee explorer in pc communication with Xbee in arduino

I have a Xbee explorer on the pc, and one arduino with the arduino wireless shield with another Xbee there. Using XCTU I can receive data from the arduino to the PC but not the other way around, sending using XCTU to the arduino.
If I send from the XCTU only the led RSSI from the arduino wireless shield is on but it should be the RX led.
This is the tutorial I'm using Link
Here's the code I'm using on the arduino, booth antennas are S1 Xbee antennas and the antennas are all default values restore
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
SoftwareSerial XBee(10,11); // RX, TX
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
Serial.println("first if");
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.println("second if");
Serial.write(XBee.read());
}
}
Please precise the operating mode on your two xbee modules thier model( it can be hard to communicate when using XBEE3), and their DL, DH

Resources