It's my first time trying out the esp8266 on the arduino uno, using the ITEADLIB_Arduino_WeeESP8266 library. However I am not able to get anything done, not even wifi.getversion().
Here's the Serial Monitor output
setup begin
FW Version:
to station err
Join AP failure
setup end
(forever loop)
And here's the code
#include "ESP8266.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
ESP8266 wifi(mySerial);
#define SSID "AndroidAP"
#define PASSWORD "12345678"
void setup(void)
{
}
void loop(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version: ");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStation()) {
Serial.print("to station ok\r\n");
} else {
Serial.print("to station err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
Serial.print("setup end\r\n");
Serial.println("");
delay(10000);
}
I followed the instruction on the github readme, and the led on the esp8266 is on the whole time, so I guess it is not a wiring issue. Is it possible that the 8266 is dead?
You may try this Serial.begin(115200);
Related
I am using the below code with arduino-uno, but often getting "Could not find a valid MPU6050 sensor
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Serial.begin(115200);
Serial.println("Initialize MPU6050");
while (!mpu.begin()) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
}
void loop() {
}
My Arduino is working fine,
So, I checked MPU6050 using below code,
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
Got Output as expected
Scanning...
I2C device found at address 0x68 !
done
From the above output I hope GPU6050 is working
How can I get values from GPU6050?
Your code is working as expected, it tells you in setup() when it can't connect to the device, until it can.
So when it stops printing the message, it is connected.
Now in loop() you should write your code to negotiate with the device.
Here's an excellent place to start with.
I'm doing a project where I have to connect to a WiFi network. So, I've used this code for ESP32 to connect to a WiFi network -
#include <Arduino.h>
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.begin("XYZXYZ", "asdfghjkl");
// Wait for WiFi to be connected
uint32_t notConnectedCounter = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.println("Wifi connecting...");
notConnectedCounter++;
if(notConnectedCounter > 50) { // Reset board if not connected after 5s
Serial.println("Resetting due to Wifi not connecting...");
ESP.restart();
}
}
Serial.print("Wifi connected, IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
}
The code I mentioned above worked well but for some reason, it is not working now. Now when I power the ESP32, it gives out something like (or similar to) this-
}⸮~⸮}⸮n~⸮~ֶ⸮}⸮⸮⸮n⸮~n⸮⸮]⸮⸮⸮⸮⸮⸮D⸮b⸮⸮z⸮}⸮⸮⸮1]⸮⸮}⸮⸮~⸮⸮|⸮⸮~}⸮]⸮}⸮=~]⸮⸮]⸮⸮]⸮]⸮⸮n⸮⸮ ֎UvHX⸮.,⸮⸮a⸮⸮⸮]⸮⸮>]⸮>⸮]⸮]⸮n>⸮⸮⸮>>⸮]⸮⸮>]⸮]⸮⸮6⸮
What can I do to solve this?
Make sure your Serial.begin(11520) speed parameter is the same as Serial Monitor speed parameter value.
I have transferred the values from Arduino mega to nodeMCU through serial communication. But I'm not able to transfer the values to firebase. An error is occuring -
Error compiling for board NodeMCU 1.0 (ESP-12E Module)
This is the code :
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set these to run example.
#define FIREBASE_HOST "https://agro-775df.firebaseio.com/"
#define FIREBASE_AUTH "YRyEHN5YcQ4DSdviYX5ciiqWQBwQmhAIneFlcXbK"
#define WIFI_SSID "vintage"
#define WIFI_PASSWORD "barapi"
String str;
char bu[10];
int one,two,three;
int temp,humi;
void setup()
{
Serial.begin(115200);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
while(!Serial)uj{
}
}
int n = 0;
void loop() {
if (Serial.available())
{
str=Serial.readString();
}
// set string value
Firebase.setString("message",str);
// handle error
if (Firebase.failed())
{
Serial.print("setting /message failed:");
`` Serial.println(Firebase.error());
return;
}
delay(1000);
}
Go to tools->Board and then check weather your board model is selected correctly or not.
Go to tools->serial port and check weather the COM port is selected correctly or not.
Change Esp8266 board driver's version for example 2.6.3 install...Sometimes try 2-3 times
I'm attempting to use the RF522 with my NodeMCU v3 using the SPI interface. I was able to hook the RF522 to my Pi Zero and get it to scan both the chip that came with it as well as the NFC of my phone so I'm fairly confident the hardware is good.
Here's what I've found so far (connections are documented in code below):
If I hook everything up, I cannot upload my Arduino sketch
(espcomm_upload_mem failed) and I cannot run a script that is on the
NodeMCU.
If I disconnect the 3v power to the RF522, I can upload the script and run it.
If I leave the 3v power disconnect, the program fails the self test: mfrc522.PCD_PerformSelfTest()
If I plug the 3v power line in after the NodeMCU boots but before the self test, it passes the self test and runs!
I never find a card (repeats "No new card..." forever). Tried existing chip and phone but nothing was found.
I'm not sure why having the power installed keeps everything else from starting and I have no idea why I can't read a card when the self-test passes! Does anyone else have experience getting the RF522 and NodeMCU to work together?
Code:
#include <ESP8266WiFi.h> //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <PubSubClient.h>
#include <SPI.h>
#include <MFRC522.h>
/*
*RST GPIO15 -- D8
*SDA(SS) GPIO2 -- D4
*MOSI GPIO13 -- D7
*MISO GPIO12 -- D6
*SCK GPIO14 -- D5
*GND GND
*3,3V 3,3V
*/
#define SS_PIN 2 // D4 -- SDA-PIN for RC522
#define RST_PIN 15 // D8 -- RST-PIN for RC522
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
WiFiClient espClient;
PubSubClient mqtt(espClient);
const char* MQTT_user = "rfid.local";
const char* MQTT_server = "mqtt.local";
const char* topic_base = "home/rfid/";
void setup() {
Serial.begin(115200);
Serial.println("Lets get started!!");
WiFiManager wifiManager;
wifiManager.setTimeout(180);
if(!wifiManager.autoConnect("RFID", "RFID")) {
Serial.println("Failed to connect and hit timeout");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println("Connected...yippie!");
mqtt.setServer(MQTT_server, 1883);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
if (mfrc522.PCD_PerformSelfTest())
Serial.println("RF522 Passed self test!");
else {
Serial.println("RF522 Failed self test!");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println("Waiting for someone to scan...");
}
void reconnectMQTT() {
// Loop until we're reconnected
while (!mqtt.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (mqtt.connect(MQTT_user, MQTT_user, MQTT_user)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(mqtt.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
// Make sure we are still connected!
if (!mqtt.connected()) {
reconnectMQTT();
}
mqtt.loop();
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
Serial.println("No new card...");
delay(1000);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Can't read card...");
delay(1000);
return;
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
//mqtt.publish(topic_base...);
}
The problem was that I needed to call mfrc522.PCD_Init(); again after performing the self test and version dump. Once I did this, everything worked as expected!
I am having Issue while connecting ESP8266 with Arduino Mega. It always says "Module have no response."
Please check and correct me if I am wrong anywhere.
I am using below code and and wiring diagram is
My Code:
//#include <SoftwareSerial.h>
//use mega Serial 2 for serial monitor; Serial 1 on pins 19 (RX) and 18 (TX);// Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX).
#define SSID "SopraSteria"
#define PASS "1234567890"
#define DST_IP "220.181.111.85" //baidu.com
//SoftwareSerial dbgSerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
//serial 2 is to esp8266
Serial2.begin(9600);//9600 (mine), 57600, 115200
Serial2.setTimeout(2000);
//serial 0 is to usb
Serial.begin(115200);
while(!Serial);
while(!Serial2);
//dbgSerial.begin(9600); //can't be faster than 19200 for softserial
//dbgSerial.println("ESP8266 Demo");
Serial.println("ESP8266 Demo on Mega2560");
while(Serial2.available()>0)
Serial2.read();
delay(1000);
//test if the module is ready
Serial2.println("AT+RST");
//delay(1000);
//delay(1000);
Serial.println("Resetting module");
Serial2.flush();
//if(Serial2.find("ready"))
if(Serial2.find("Ready")||Serial2.find("ready"))
{
//dbgSerial.println("Module is ready");
Serial.println("Module is ready");
}
else
{
//dbgSerial.println("Module have no response.");
Serial.println("Module have no response.");
//while(1);
}
delay(1000);
//connect to the wifi
boolean connected=false;
for(int i=0;i<5;i++)
{
if(connectWiFi())
{
connected = true;
break;
}
}
if (!connected){
//while(1);
Serial.println("Not Connected.");
}
delay(1000);
//print the ip addr
Serial2.println("AT+CIFSR");
Serial.println("ip address:");
while (Serial2.available())
Serial.write(Serial2.read());
//set the single connection mode
Serial2.println("AT+CIPMUX=0");
}
void loop()
{
//connectWiFi();
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
Serial2.println(cmd);
Serial.println(cmd);
Serial.println(cmd);
if(Serial2.find("Error")) return;
cmd = "GET / HTTP/1.0\r\n\r\n";
Serial2.print("AT+CIPSEND=");
Serial2.println(cmd.length());
if(Serial2.find(">"))
{
//dbgSerial.print(">");
Serial.print(">");
}else
{
Serial2.println("AT+CIPCLOSE");
//dbgSerial.println("connect timeout");
Serial.println("connect timeout");
delay(1000);
return;
}
Serial2.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial2.available())
{
char c = Serial2.read();
//dbgSerial.write(c);
Serial.write(c);
//if(c=='\r') dbgSerial.print('\n');
if(c=='\r') Serial.print('\n');
}
//dbgSerial.println("====");
Serial.println("====");
delay(1000);
}
boolean connectWiFi()
{
Serial2.println("AT+CWMODE=1");
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
//dbgSerial.println(cmd);
Serial2.println(cmd);
Serial.println(cmd);
delay(2000);
if(Serial2.find("OK"))
{
//dbgSerial.println("OK, Connected to WiFi.");
Serial.println("OK, Connected to WiFi.");
return true;
}else
{
//dbgSerial.println("Can not connect to the WiFi.");
Serial.println("Can not connect to the WiFi.");
return false;
}
}
From the schema I can see, that device uses 3V logic (I guess it from tension divider)? In that case if you communicate with 5V logic, then you should use 5v/3v buffers on Tx and Rx. This is my guess and my advice:
Always debug communication problems with oscilloscope.
Without this you simply cannot know what is happening.
Also make some other debugging. You assume, that device responds with ready or Ready, but try to print this out, what it actually really gave on output. Otherwise it's impossible for us to debug your piece of hardware without your hardware in the hands.
Also please make a note, that this is not appropriate forum for this kind of questions as there is https://arduino.stackexchange.com/.
Sorry #DawidPi thats not completly correct.
Yes it´s right thats not opimal to do it with a voltage divider. But this is not the problem. To solve the problem with the 3.3 TX will work (surely at 9600 baud --> I did it already like this)
Your problem is the power of your Arduino board. The ESP needs much current. Your board will not support this high current. You have to supply your ESP wih an external supply. I can recommend a fix voltage regulator like the LF33CV. Youse it with two condensators and it will work :-)
Wiring like here: .
If you use a LF33CV your UE should be between 4.3 and 40V. For testing I used the 5V of my USB-port. That will also work.
Try starting your ESP like this:
#define pin_reset 2 //Connect to RST pin of ESP8266
bool start()
{
pinMode(PinReset, OUTPUT);
delay(1);
pinMode(PinReset, INPUT);
delay(1000);
if (Serial.find("Ready"))
{
delay(1000);
return true;
}
else
{
return false;
}
}