Basically I got an Arduino Uno with a DF Robot Gravity Alcohol Sensor and the ESP01 that I use to send my data to the Matlab service ThingSpeak.
However after running the code it says WIFI CONNECTION FAILED.
HOWEVER since its a 2.4GHz hotspot from my phone, I see that the ESP has indeed successfully connected to the Wifi but the serial monitor says otherwise.
Also I found out that whenever I use the 0 and 1 ports on the UNO for the ESP only to test out AT commands on an empty sketch, it fully responds fine with OK's on all of them and successfuly connects to a network, disconnects, resets, ect.
But with my code and on pins 6,7 or 10,11 nothing appears to work.
It worked before however it sent my HTTP requests but sometimes just stopped working out of nowhere.
Any ideas?
So you have permanently changed the ESP-01 baud-rate to 9600 ?
You should most definitely use a voltage divider on the ESP-01 rx to reduce the UNO's 5v logic level to a safe 3.3v.
(i use UNO tx -> 1K -> Esp rx -> 1K -> 1K -> GND) The ESP-01 will break at some point otherwise (if it hasn't already)
Keep in mind that when you just use the UNO as a USB to TTL converter (as you do) you connect UNO Tx to ESP Tx and UNO Rx to ESP Rx. When you connect to the UNO on swSerial, you need to cross the Rx & Tx lines.
UNO Tx -> (voltage divider) -> ESP Rx
UNO Rx <- ESP Tx
Also here you need to use a voltage divider (though there is a 10K pullup on RST)
The esp8266 is a 3.3v device and do not let anybody convince you that it is 5v tolerant. It just isn't.
Putting 5v on the RST in particular is risky since this may potentially increase the voltage on Vcc.
There is no real need to reset manually anyway, just connect RST to 3.3v or even leave it free-floating.
If you do want to manually reset, the best approach would be to switch the pin to INPUT.
digitalWrite(HARDWARE_RESET, LOW);
pinMode(HARDWARE_RESET, OUTPUT); // disables the esp
pinMode(HARDWARE_RESET, INPUT); // enables the esp the 10K pullup will pull it high
There is something to be said for that, but given that only 1 I2C sensor is used, just the ESP-01 should suffice and ditching the UNO (or just keeping it as an uploader) will also work.
You can use the same connections to upload your own firmware, just connect GPIO 0 to GND and power-cycle the ESP-01 and upload code using the esp8266 core. This will overwrite the ESP-01 AT-commands firmware
Regardless, stop connecting the ESP to 5v before it breaks if it hasn't already (partly)
IF your I2C thingy is OK for 3.3v, a more sensible approach might be to keep the ESP-01 you already have, as I understand it can be configured to run the I2C bus, and you can ditch the Uno. If it's not good for 3.3v, I guess an ESP32 is inappropriate anyway
That is using swI2C. The ESP8266 unlike the ESP32 does not have a mutex that allows free assignment of the GPIO pins to peripherals. (just a few options for UART0)
Don't know if the CH_PD pin has a pullup on that breakout board, but otherwise it should be connected to Vcc
using a ESP-01 connected to a BMP280 using I2C pins GPIO0 (SDA) and GPIO2 (SCL)
// BMP280 test for ESP-01 - I2C use pins GPIO0 (SDA) and GPIO2 (SCL)
/***************************************************************************
This is a library for the BMP280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BMEP280 Breakout
----> http://www.adafruit.com/products/2651
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
//#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println(F("BMP280 test"));
Wire.begin(0, 2); // for ESP-01 I2C use pins GPIO0 (SDA) and GPIO2 (SCL)
if (!bme.begin(0x76)) { // <<<< CHANGED from 0x77
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
Serial.println("BMP280 sensor found!");
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
Serial.println(" Pa");
Serial.print("Approx altitude = ");
Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
Serial.println(" m");
Serial.println();
delay(2000);
}
serial monitor output
BMP280 test
BMP280 sensor found!
Temperature = 23.54 *C
Pressure = 99530.03 Pa
Approx altitude = 150.53 m
Temperature = 24.21 *C
Pressure = 99947.56 Pa
Approx altitude = 115.32 m
Temperature = 24.72 *C
Pressure = 100028.59 Pa
Approx altitude = 108.50 m
Temperature = 24.99 *C
Pressure = 100027.59 Pa
Approx altitude = 108.58 m
Temperature = 25.07 *C
Pressure = 99521.88 Pa
Approx altitude = 151.22 m
Temperature = 25.92 *C
Pressure = 99728.09 Pa
Approx altitude = 133.81 m
Temperature = 26.36 *C
Pressure = 99741.06 Pa
Approx altitude = 132.72 m
Temperature = 26.63 *C
Pressure = 99698.52 Pa
Approx altitude = 136.30 m
photo ESP-01 plugged into a ESP-01 Helper V3 connected to a BMP280