I want to send data from my ESP8266 device to an Arduino Uno board via UART.
The ESP8266 has been flashed with NodeMCU firmware (the build has the following timestamp: nodemcu-master-8-modules-2017-05-30-19-21-49-integer). The firmware has been built using only the following modules: file, gpio, net, node, tmr, uart, websocket, wifi. The ESP8266 board itself is an Adafruit Huzzah board.
The ESP board is powered via a Serial Cable from my laptop USB. The cable I am using is this one, which provides me 5V for powering my board and I know the USB on my Mac can supply the 500mA needed.
The Arduino is also powered via the other USB port on my computer.
The ESP board and the Arduino are connected as follows:
ESP8266
TX RX GND
| | |
| | |
10 11 |
RX TX GND
Arduino
The Adafruit Huzzah board claims that:
The TX pin is the output from the module and is 3.3V logic. The RX pin
is the input into the module and is 5V compliant (there is a level
shifter on this pin)
So there shouldn't be a need for a level converted between these two.
The code I am running on the ESP8266 board, as init.lua is:
uart.setup(0,115200,8,0,1)
tmr.alarm(0, 5000, 0, function()
uart.write(0, "A", 19)
end)
The code I am running on the Arduino is:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
MeetAndroid meetAndroid;
SoftwareSerial sSerial(rxPin, txPin);
uint8_t lastByte;
uint8_t serialBuffer[64];
int count = 0;
int onboardLed = 13;
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
sSerial.begin(115200);
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
}
void loop() {
while (sSerial.available() > 0) {
serialBuffer[count] = sSerial.read();
count++;
}
for (int i = 0; i < count; i++) {
Serial.println(serialBuffer[i]);
}
}
What I see on the Serial Monitor in Arduino once I reset my ESP board is garbage:
⸮⸮⸮⸮⸮⸮Z,⸮}⸮߿⸮ߏ⸮\⸮⸮LYLYLYLYL⸮L⸮L⸮L⸮L⸮L (((((⸮$⸮$⸮$⸮$⸮$⸮$⸮4⸮0⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮# ((((⸮$:⸮&i(⸮⸮
After a short delay it starts printing out line upon line of garbage after this initial line. It's clear to me that, somewhere, there is a mismatch.
I've looked for previous questions on this matter, but the only one I could find that was the closest to my use stated simply that one ought to read the docs, which was not very helpful.
Does anyone know what is amiss here?
You have to set a proper baud-rate. You can set the baud-rate on the bottom right corner of the serial monitor.
I prefer to use the standard debug baud rate of 9600.
I believe those are two different problems.
The first line of garbage after booting up actually belongs to esp8266's firmware, it's default baud rate is 74880 and if you open a serial monitor on that baud rate, you can see something like this:
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
The second problem is with the softwareSerial library.
Based on this (and my own experience), maximum reliable baud rate seems to be around 28800 and you've set it up to high.
I recommend decreasing the baud rate or switching to other libraries such as AltSoftSerial.
Related
I want to send a simple AT-Command like: AT\r\n from the ESP32 to the Fanstel BC805M (nRF52805M) breakout board. My goal is to get an answer.
Problem: The Esp32 does not get an answer from the BC805M.
Setup
Hardware
The ESP32 is connected by usb cable to my Mac.
The ESP32 connects to the BC805M by five cables -> 3V3->VDD, GND->GND, Rx->Tx, Tx->Rx, GPIO32(high)->GPIO04(P004). Rx and Tx from ESP32 are Serial2 (not the Serial0 of the programmer). The P004 pin from BC805M is set to high to enable "command-mode".
Software
The BC805M came already preloaded with The AT commands code.
The ESP32 is flashed by a simple Serial2 write/read arduino code:
#include <HardwareSerial.h>
#define RXD2 16
#define TXD2 17
#define CMD_MODE 32
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
pinMode(CMD_MODE, OUTPUT);
digitalWrite(CMD_MODE, HIGH);
delay(1000);
Serial.println("start");
}
void loop() {
Serial2.write("AT\r\n");
delay(500);
if(Serial2.available()){
Serial.write(Serial2.read());
}
}
On Monitor, I received nothing: Terminal Output
What I tested
I connected the two ESP32 Rx and Tx Serial2 Pins with each other and the monitor prints AT AT AT ... (so this works)
I connected the ESP32 with the BC805M not by crossing Tx and Rx but like: Rx->Rx, Tx->Tx; I received the message
BlueNor 200622 started
on my monitor. This means I read the values of the Rx pin of the BC805M and wrote them to my monitor. Shouldn't this message be sent on on the Tx pin of the BC805M?
I connected to the BC805M per Android App, which connects to it via Bluetooth Low Energy. I sent commands from the app to the BC805M. But I got no response. I could read the commands I sent on the Rx Pin of the BC805M.
I connected solely the BC805M per usb to my mac and ran Arduino-IDE's monitor, the monitor prints absolutely nothing and writing AT-Commands also results into nothing.
The Fanstel support just wrote me that the BC805M Evaluation Board is NOT preloaded with the AT-Command firmware.
Only the BC805M module has it preloaded.
That explains why the AT-Commands did not work.
I have started learning about arduino and just bought a bluetooth module, HC-05. From where i bought, it says it has range of approx.10 meters. I made hc-05 connection with arduino in below described ways
I am using it as a slave with default configurations, 9600 baud rate and HC-05 name with pin 1234
GND of HC05 -> GND of `arduino`
VCC of HC05 -> 5V of `arduino`
TX of HC05 -> RX of `arduino`
RX of HC05 -> TX of `arduino` via voltage divider network 2k---|---1k
Below is my arduino code
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
int pin = 13;
char c = ' ';
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
pinMode(pin,OUTPUT);
// HC-05 default serial speed for communication mode is 9600
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
if (BTserial.available()>0){
c = BTserial.read();
Serial.println(c);
switch (c){
case '1' :
digitalWrite(pin,HIGH);
break;
case '2' :
digitalWrite(pin,LOW);
break;
default: break;
}
}
}
Following things happening to me:
When I power the module I am able to discover it with my phone but only when I hold my phone very near to the module. If I move away from the HC05 module, for example 3-4 feet, I am not able to discover it.
2.After connecting with it (while holding phone near to the module), I am able to send data to it but again, if I move away , only a few steps, I am unable to send data and I disconnect from it automatically. Also if I change direction of the antenna even then no communication happens.
My purpose is to control my home's lights and TV with the help of this module and Relays. But HC05 is useless so far. I was hoping that I would code it and wire it and hang it on a wall and interact it with and andoird app.
Is it suppose to happen like this? or there's something wrong with my module's antenna
thank you.
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
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.
I bought a new ESP8266 WIFI module (8pins) and flashed firmware (from https://raw.githubusercontent.com/nodemcu/nodemcu-flasher/master/Win32/Release/ESP8266Flasher.exe) it using arduino Duemilanove correctly.
I have gone through many troubleshooting steps, but on reset module does give some gibberish response, but no Ready/OK response from "AT" command.
Red LED
of module is always on but Blue light is off.
Steps taken :-
To supply enough current i used Beaglebone 3V3 supply as module Vcc.
But i'm not able to receive any response from AT commands.
Arduino Tx (5V) has brought down to 3v3 using voltage divider and
connected to Rx
In Flash settings ensured baud rate was 115200 and all settings correct
Module is working fine presumably as tried with 2 more modules same thing
Here's my connections:
//////////////////////////////////////////////////////////////////////////////
/////// CONNECTIONS ////////
/////////////////////////////////////////////////////////////////////////////
/*
ESP8266 VCC -> BeagleBone 3.3
ESP8266 GND -> Common GND (Arduino & BeagleBone)
ESP8266 CH_PD -> 3K resistor -> VCC
ESP8266 RST -> VCC or pin 13(arduino)
GPIO CAB BE LEFT OPEN OR TIED HIGH
ESP8266 Tx -> pin2 (Arduino software serial Rx)
ESP8266 Rx <- Voltage Divider <- pin3 (Arduino software serial Tx)
*/
Here's my code
#define esp8266 Serial2
#define CH_PD Vcc // but needs a narrow low pulse
#define speed8266 9600 // This is the speed that worked with my ESP8266
void setup()
{
esp8266.begin (speed8266);
Serial.begin(9600);
reset8266(); // Pin CH_PD need a reset before start communication
}
void loop()
{
while(esp8266.available())
{ Serial.write(esp8266.read()); }
while(Serial.available())
{ esp8266.write(Serial.read()); }
}
/*************************************************/
// Reset funtion to accept communication
void reset8266 ()
{
pinMode(CH_PD, OUTPUT);
digitalWrite(CH_PD, LOW);
delay(300);
digitalWrite(CH_PD, HIGH);
}
Here's the output on Serial Monitor
Arduino Serial Monitor Output
Kindly help me what am i doing wrong ?
I don't want to use another FTDI chip while arduino already have it.
At the moment I can only give you a part answer (seems I can't comment yet :) ).
The gibberish is normal when starting/resetting the ESP, it's just the boot code which outputs a boot message at 74880 baud (Which is basically the default baud rate 115200, but because the ESP starts at a lower cpu frequency, the baud rate is also lower, boot frequency is 26 mhz, normal frequency is 40 mhz, 26/40 * 115200 = 74880. If you can set your serial client to 74880 baud you should see the message, but it's an odd baudrate, so it might be hard or impossible to set.
So gibberish on reset is good! It means the ESP is working and happy, the problem is with your software (as you determined yourself too).
I assume your code is on the Arduino side?
The big question is what is flashed on the ESP, and what it's expected bahaviour is. From your question I'm not 100% sure what you did flash on it..
I think you might've flashed nodemcu on it though, which would not respond to AT commands, try to flash the 'original' AT rom from Espressif Systems on it?