Hello guys I have my ESP8266 connected to my Arduino. Then I typed in AT in the serial monitor. It confirmed this command with OK. After that I typed in AT+UART=9600, 8, 1, 0, 0 which gave me the response ERROR. Then I googled what I could do, which told me that I should try change the baud rate permanently with the command AT+IPR=9600. I did this but I got no response. After that I wondered if everything was ok so I typed in AT. No response. Now I'm a little bit sad because everything started to be great but I don't know how I can fix the whole problem. I also tried to upgrade its firmware with XTCOM Utility but it says it can't connect.
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup() {
Serial.begin(115200); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(115200);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}
void loop() {
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
This is my code. I tried it with both 9600 and 115200 but if I use 115200 the serial monitor just shows some garbage signs. It's kind of frustrating because I can't even interact with the serial monitor as my typed commands don't show up anymore. Do you have any idea how I could fix this problem?
EDIT:
I read that the command AT+IPR=9600 breaks the module and it can just be fixed by reflashing it. Sadly this doesn't work because it somehow can`t connect.
Related
Issue
-When using the ESP8266 wired up in this way it will randomly disconnect the USB interface when it powers the relay. It may then re-connect but is sporadic.
-The code can be viewed below, but essentially the relay is powered for 300ms then waits 10 seconds to loop.
Wiring Diagram https://i.stack.imgur.com/4mycx.png
Tests:
I have swapped out the relay, pump, ESP8266, aswell as re-wiring the circuit multiple times to check for a short. I also have a integer incrementing every loop cycle, when the ESP8266 is able to re-connect it will print this variable, which shows the board is not crashing:
Serial output
https://i.stack.imgur.com/ziM8g.png
I then modified the diagram so the 5v power was not in parallel, but where two different power sources, one for the ESP8266 and one for the pump circuit, however the same issue was observed:
Test Wiring Diagram https://i.stack.imgur.com/7S0aP.png
Question:
Why does the USB disconnect when sending the control signal to the relay?
Is there a way to mitigate this?
Code:
int relayInput = 5; // the input to the relay pin
int debug_test = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(relayInput, OUTPUT); // initialize pin as OUTPUT
}
void loop() {
// put your main code here, to run repeatedly:
debug_test ++ ;
Serial.println(debug_test);
digitalWrite(relayInput, HIGH); // turn relay on
Serial.println("Water on!");
delay(300);
digitalWrite(relayInput, LOW); // turn relay off
Serial.println("Water off!");
Serial.println("Waiting 10 seconds");
delay(10000);
}
Parts:
Pump - https://www.ebay.co.uk/itm/Mini-Water-Pump-DC-3V-4-5V-Fish-Tank-Fountain-Aquarium-Submersible-White-Parts/174211676084?hash=item288fd337b4:g:128AAOSwfQteYWF3
ESP8255 - https://www.amazon.co.uk/gp/product/B07F5FJSYZ/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
Relay - https://www.amazon.co.uk/gp/product/B07BVXT1ZK/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
Ok, so researching in to this, it seems when the pump is on it pulls more current (amps) than the PC can provide.
This will be used connected to a external power source which should supply enough current to it, however I also wanted the flexibility to connect it to a PC with a serial connection to troubleshoot.
So in the end something like this:
https://i.stack.imgur.com/MKD1h.png
You are driving a 5v relay module with 3.3v output, which works perfectly for some people but it depends on the relay module and the board, this might be the problem. or the relay draws more than 12mA which is the maximum current can the ESP8266's GPIO deliver.
so I suggest you use an external power source for the relay and control it through the pin (D1 in your case).
Or just use a generic 5v relay with an external 5v power source and control it using a transistor, here is a circuit.
Additional information: https://electronics.stackexchange.com/questions/213051/how-do-i-use-a-5v-relay-with-a-3-3v-arduino-pro-mini?
I am unable to read the serial pins in the NodeMCU Lua environment. I have only been able to read the USB serial port.
I have connected a serial adapter to the rx, tx, and g pins.
I have tried this code:
uart.on("data","\n",function(data) print("receive from uart:", data) end, 0)
I enter text in the ESplorer console and it does read that. It doesn't read anything I send over a serial adapter plugged into the rx/tx/g pins.
uart.write(0, "hello")
I disconnected the USB cable and powered it with the serial adapter. Nothing was sent using this code. I tried uart.write(0, and uart.write(1,.
How do I read the pin serial ports instead of the usb serial port?
I needed to unplug the USB cable. The device gets confused if the USB cable is plugged in and you're trying to use the pin serial port.
See my question on the esp forums:
https://www.esp8266.com/viewtopic.php?f=22&t=19768
You have to use different pins then the RX and TX as they are the same as the USB port you are connecting your NodeMCU with to your PC
You can use any other 2 free gpio pins as a serial port with the help of https://github.com/scottwday/EspSoftSerial library. This library is specificly for ESP8266 on which your NodeMCU is based.
This way you have 2 serial ports, one through the usb and another one to connect to other devices.
Some simpel code to implement the Software serial below.
#include <SoftwareSerial.h>
#define BAUD_RATE 9600
SoftwareSerial Serial2(D8, D7, false, 8); //Here you choose the pins you connect the RX TX device to
//The first pin you choose is RX the second TX
// in my example these are the D8 and D7 pins on the nodeMCU
// D8=RX .... D7=TX
void setup() {
Serial.begin(BAUD_RATE);
Serial2.begin(BAUD_RATE);
Serial.println(" ### Hello ###");
Serial2.println(" ### Hello ###");
}
void loop() {
}
}
I had this working fine a few months ago but can't seem figure out what's changed. I have several ESP-01 and I can upload using Arduino IDE with Generic 8266 board profile but I can't get anything to run. Nothing shows on the Serial Monitor. I've tried simple code like:
void setup() {
// put your setup code here, to run once:
delay(1000);
Serial.begin(115200);
delay(1000);
Serial.println("Hello, you've entered setup()...");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Good day, you're in loop()...");
delay(2000);
}
I've tried using a jumper to 3.3v on the ENable pin and a 10k resister. I've removed the GPIO0 after programming. Nothing seems to work. I have 4 chips so I know I'm not doing something.
I have 3.3v on VCC (measured), nothing on RST, EN to VCC (tried 10k to VCC), TX - RX, RX - TX, 0 - Gnd for programming, nothing on 2, Gnd - Gnd
I found the answer for this problem. It seems that the ESP-01 chip must have 10k resisters on GPIO 0, GPIO 2, and reset to VCC in order function properly. Although the chip seemed to accept the flash, the floating pins were causing problems. Once I added the pullup resisters, it was like magic, everything started working.
Just switch to boards version 2.4. It will work then
I've used the RedPark seriable cable with iOS before however, I've only been using it to receive data from an Arduino. My ambition is to be able to transmit information from the iPhone to the Arduino also.
At the moment it's set up to receive
Arduino RX -> Redpark TX
Arduino TX -> Redpark RX
Arduino 5V -> Redpark 5V
Arduino GND -> Redpark GND
The example I used was to toggle the LED on an Arduino board...
void setup() {
Serial.begin(9600); // Start the serial port
pinMode(13, OUTPUT); // Set the built-in LED to output mode
}
void loop() {
if (Serial.available()) { // If there's anything on the serial port,
byte cmd = Serial.read(); // read a single byte from it.
if (cmd == '1') { // If the command is the character '1',
digitalWrite(13, HIGH); // set the LED on
}
if (cmd == '0') { // If the command is the character '0',
digitalWrite(13, LOW); // set the LED off
Serial.print(cmd, BYTE);
}
}
}
I also used the accompanying iPhone app with the Redpark serial cable. I have confirmed I am able tor receive text (using the default app that comes with the RedPark serial cable. So I know that when the iPhone is connected to the Arduino, I am able to receive transmitted data from the Arduino. I can't however transmit any data (the default app allows you to transmit data + the app confirms that the iPhone has sent data. However I am unable to fall into this method on the Arduino, when sending from the iPhone.
if(Serial.available())
{
...
}
For reference, the iPhone I'm using is the iPhone5 with the 30 pin to lightning adapter.
I'm using the WiFly shield with Arduino, and everything works fine: I upload my skecth to Arduino via USB, I connect a 9V battery, I disconnect the USB, and the wifi module transmits everything fine (it transmits data to my web server).
When the battery runs out I replace with another battery, but then the wifi/arduino no longer communicates with my server..
I'm a newbie on Arduino and I don't understand whether if every time the power is off Arduino loses the program, or simply that the wifi is not able to auto-connect...
Is this a software problem or hardware?
And if software what am I doing wrong?
This is my sketch example - I'm just sending a string to my server:
#include "WiFly.h"
#include "Credentials.h" // includes ny user:pass wifi network
Client client("[***myserverip***]", 80);
void setup() {
Serial.begin(9600);
WiFly.begin();
if (!WiFly.join(ssid, passphrase)) {
Serial.println("Association failed.");
while (1) {
// Hang on failure.
}
}
connectServer();
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(60000); // check every minute
connectServer();
}
}
void connectServer() {
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
String query = "GET /arduino/test?q=testString HTTP/1.0";
client.println(query);
client.println();
} else {
Serial.println("connection failed");
}
}
So everything works fine but when I unplug the power and plug it back the arduino doesnt restart the process.
I found the solution myself - the problem was with the hardware.
The problem was in my Arduino UNO R2, there is a known bug.
I bought a UNO R3 and I don't have this problem anymore.
Its because Arduino board doesn't have on board power on reset when using external power supply so you will always need to reset it just after supplying power. You can put a capacitor at reset pin to eliminate this issue. But if you are using USB as a power source then USB controller will reset the Arduino so in that case you will never have this problem.