Failed to connect ESP8266: Invalid head to Packet (0xf0) D: - arduino

I am working with an arduino, rather learning to use it, I bought the esp8266 module to transmit data over wifi, but every time I upload a script it throws me the following error:
Failed to connect ESP8266: Invalid head to Packet (0xf0)
The selected port does not exist or the board is not connected
I already installed the drivers and libraries, select the COM4 port and checked in the device manager that it is correct.
As I was asked, here is the code I am trying to use.
#include <SoftwareSerial.h>
void setup()
{ Serial.begin(115200);
BT1.begin(115200);
}
void loop()
{ String B= "." ;
if (BT1.available())
{ char c = BT1.read() ;
Serial.print(c);
}
if (Serial.available())
{ char c = Serial.read();
BT1.print(c);
}
}
I connected the arduino via usb, the esp8266 using the breadboard, it is an ESP8266 ESP-01.
I hope you can help me.
(It's my first time on this site, sorry for the lack of info the first time)

Related

AT works at half for HC05

I am currently trying to send my sensor data from my Arduino to an android app made on android studio using an HC05 module for Arduino.
I tried to configure the HC05 as every tutorial on the internet says, but i meet some problems.
I am using the arduino code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int PotPin = A7;
int Vdata = 15;
void setup() {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println("Enter AT commands:");
mySerial.begin(38400);
}
void loop()
{
Vdata = analogRead(PotPin);
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
When I type "AT" in the Serial monitor, it returns me "OK" (that is normal).
But when I try to see the name/the address/the password of the module, it returns me "Error:(0)". The strangest thing is that the command " AT+NAME="NameWanted" " or even " "AT+PWD="4321" " works since it correctly changes the name of the module.
I looked on the internet but I didn't see someone with the same problem as mine, I hope someone will lead me to the solution!
Thanks
I found out what's the problem. My mcu's bauderate was bigger (115200), then my hc05's bauderate (38400). With this bauderate, my MCU sent the messages faster, then hc05 could read it. So, I decreased the bauderate of my MCU and now it's working

Data are not sent between Arduino uno and NodeMcu esp8266 at all time

I am sending data from Arduino UNO R3 to nodeMcu esp8266. In that case sometime data are send properly but at sometime data are are not send by arduino or not get by nodemcu esp8266.Also tx light not blinks after i upload the code to the Arduiono.
enter code here
Code Uploaded to Arduino:
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(10,11);
SoftwareSerial h(10,11);
int i=0;
void setup() {
// put your setup code here, to run once:
s.begin(9600);
Serial.begin(9600);
}
int f1=0;
int f2=0;
String st="sy";
void loop() {
f1=f1+1;
f2=f2+2;
// put your main code here, to run repeatedly:
StaticJsonBuffer <1000> bf;
StaticJsonBuffer <1000> rec;
JsonObject& root=bf.createObject();
JsonObject& receives=rec.parseObject(h);
if (receives==JsonObject::invalid())
{
Serial.println("no data from nodemcu");
root["data3"]="no data from nide";
}
else
{
root["data3"] = receives["data3"];
//st = (const char*)receive["data3"];
}
root["data1"]=f1;
root["data2"]=f2;
//root["data3"]=st;
if(s.available()>0)
{
root.printTo(s);
Serial.println("send");
}
else
{
Serial.println("NOt Available");}
//i=i+1;
//s.write(i);
delay(1000);
}
In your code thera are two reasons I can spot on the first look:
1 Never use delay in server client applications. Delay stops proccessing and inhibts communication. For more details how to avoid look at the blinkwithoutdelay built in Example in the Arduino IDE.
2. You use ArduinoJSON: This lib is absolute overkill for 99% of the applications it is used for. Don't get me wrong - the lib offers fantastic features, but if not needed this can be regarded as bloat-ware.
I wrote my own simple JSON coding/decoding (~250 lines of code) for a performant application using an Arduino as "Signal generator" and the ESP8266/ESP32 as a webserver. Communication between Arduino and ESPis time critical and so far it works over a year without problems,

How to use SoftwareSerial with ESP8266

I'm trying to get an ESP8266 to work with Arduino by using PlatformIO. But, I get errors when importing SoftwareSerial.h
Tried: Arduino IDE, PlatformIO, Change baudrate, change port
How can I get SoftwareSerial to work with the ESP8266?
#include <SoftwareSerial.h>
SoftwareSerial BTserial(3, 1); // RX | TX
char Bluetooth_Name = ' ';
void setup()
{
// Arduino IDE serial monitor
Serial.begin(9600);
// HC-05 default serial speed for AT mode is 38400
BTserial.begin(38400);
// Wait for hardware to initialize
delay(1000);
// Print debug string
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
reading = BTserial.read();
Serial.println(reading);
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
reading = Serial.read();
BTserial.write(reading);
}
}
I want to use the SoftwareSerial without errors.
Error code:
Compiling .pio\build\huzzah\lib0be\EspSoftwareSerial_ID168\SoftwareSerial.cpp.o
In file included from C:\Users\Bart\.platformio\lib\EspSoftwareSerial_ID168\src/SoftwareSerial.h:27:0,
from C:\Users\Bart\.platformio\lib\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:23:
C:\Users\Bart\.platformio\lib\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:144:10: error: expected ';' at end of member declaration
bool IRAM_ATTR push(T&& val);
^
Actually the standard software serial library didn't work for me with my NodeMCU v1.0... And in the rare cases when it worked, it was very limited. Maybe check out this library:
ESP 8266/32 Software Serial Library
in platformio.ini you can add the following line to choose a specific version which compiles with the latest released 8266 platform
lib_deps_external =
plerup/espsoftwareserial#5.0.3 ; this version compiles with a standard 8266 platform
Using this way the code is directly fetched from github.

XBee S2C and XBee S1 Pro communication

I have an XBee S1 Pro, which is configured as a coordinator. and an XBee S2C, which is configured as an end-node. Both are loaded with the 802.15.4 firmware. By using XCTU, I sent and received the data in Transparent mode.
I have now configured the end-node to API-1 mode and connected it to an Arduino Nano. I want to read the payload. Here is my Arduino code:
void setup() {
Serial.begin(9600);
Serial.println("Setup done...");
while (!Serial) {;}
}
void loop() {
if (Serial.available()) {
for (int i = 0; i < 8;i++) {
byte discard = Serial.read();
}
Serial.write(Serial.read());
Serial.print(",");
}
When I send 'hello' from the coordinator I get:
Setup done...
FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,
Is there an easier way to do this like using the Arduino XBee library?
Could someone kindly help me?
Have you confirmed that the two XBee modules are joined to the same network? My understanding was that S1 was just 802.15.4, and S2 was ZigBee. You should probably start your project with identical networking hardware to eliminate that as a source of problems.
I'd recommend following a tutorial and using that code to establish a working starting point for any code you want to write.
Edit: adding some code
First off, you need to have two serial ports. One for your console where you can see the output of Serial.print() and the other for communicating with the XBee module.
Second, start with this loop:
void loop() {
// echo bytes received on XBee module to serial console
if (XBee.available()) {
Serial.write(XBee.read());
Serial.print(",");
}
// echo bytes received on serial console to XBee module
if (Serial.available()) {
XBee.write(Serial.read());
}
}
This way you're dumping every byte you receive, and only calling XBee.read() when there's data available to read.
You might want to keep your XBee module at 9600 baud, but increase your stdio interface (Serial) to 115200 since you're printing more than one character per byte received from the XBee module.

Sending AT commands to a GSM/GPRS and displaying the reply on a Serial Monitor

I am quite rusty when it comes to Serial ports. I want to send an AT command to a GSM/ GPRS shield connected to my Arduino UNO. The AT command I want to pass in particular is the command to get a networks signal strength.
I am using the SIM900 and SoftwareSerial library to send the command as the GSM library does not compile correctly for me. Meaning I have to use the SoftwareSerial library.
I have this example code from the SIM900 library working that relies on reading inputs from the serial monitor to carry out commands but I need it to be automated and the command to be passed in hardcoded. In this example code, the place of interest is the simplehwread() method.
#include "SIM900.h"
#include <SoftwareSerial.h>
int numdata;
char inSerial[40];
int i=0;
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
//Read for new byte on serial hardware,
//and write them on NewSoftSerial.
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread()
{
i=0;
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")) {
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")) {
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
} else {
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread()
{
gsm.SimpleRead();
}
No matter how I modify this code, the command does not get passed in and response displayed while the method here does it but not the way I want it to be done. i.e Direct input. Could anyone assist here?
i have dealt with exactly this scenario at a company with a cellular radio on board. there are many status signals that come over and if not dealt with appropriately these status flags from the cell modem will be lost
you need to look at the data sheets associated with your cell modem and its protocol so you know what flags to watch for at the various steps taken along the way from configuration, to eventual connection to cellular service.
multi-threaded coding techniques must be followed as well.
keep in mind that the comm channel is not ideal and there WILL be failures. provided your coding techniques are sound and you follow protocol requirements, then it should work.
Ron
Boise, ID

Resources