I have tested my BMP280 on an Arduino Uno and it can be found but when I connect it as below, the code gets stuck in the BMP280 test loop. Not sure what I might be missing.
/* HTTPS on ESP8266 with follow redirects, chunked encoding support
Version 3.0
Author: Sujay Phadke
Github: @electronicsguy
Copyright (C) 2018 Sujay Phadke <electronicsguy123@gmail.com>
All rights reserved.
Example Arduino program
*/
#include <ESP8266WiFi.h>
#include "HTTPSRedirect.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
// Fill ssid and password with your network credentials
const char* ssid = "SSID";
const char* password = "Pwd@";
float temperature;
float humidity;
float pressure;
#define ALTITUDE 19.812 // Altitude in Hamilton, NZ
#define SLEEP_LENGTH 60*15
Adafruit_BME280 bme; // I2C
const char* host = "script.google.com";
// Replace with your own script id to make server side changes
const char *GScriptId = "GScriptId";
const int httpsPort = 443;
// Write to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?";
HTTPSRedirect* client = nullptr;
void setup() {
Serial.begin(115200);
Serial.flush();
//BME280 Test
Serial.println(F("BME280 test connection"));
bool status = bme.begin(0x76);
if (!status) {
while (1);
}
Serial.println("Success!");
Serial.println("");
Serial.print("Connecting to wifi: ");
Serial.println(ssid);
// flush() is needed to print the above (connecting...) message reliably,
// in case the wireless connection doesn't go through
Serial.flush();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Use HTTPSRedirect class to create a new TLS connection
client = new HTTPSRedirect(httpsPort);
client->setInsecure();
client->setPrintResponseBody(true);
client->setContentTypeHeader("application/json");
Serial.print("Connecting to ");
Serial.println(host);
// Try to connect for a maximum of 5 times
bool flag = false;
for (int i = 0; i < 5; i++) {
int retval = client->connect(host, httpsPort);
if (retval == 1) {
flag = true;
break;
}
else
Serial.println("Connection failed. Retrying...");
}
if (!flag) {
Serial.print("Could not connect to server: ");
Serial.println(host);
Serial.println("Exiting...");
return;
}
temperature = bme.readTemperature();
Serial.print("Temperature: "); Serial.println(temperature);
humidity = bme.readHumidity();
Serial.print("Humidity: "); Serial.println(humidity);
pressure = bme.readPressure(); // pressure in Pa
pressure = bme.seaLevelForAltitude(ALTITUDE, pressure);
pressure = pressure / 100.0F; // pressure in hPa
Serial.print("Pressure: "); Serial.println(pressure);
// Send memory data to Google Sheets
String urlFinal = url + "Temperature=" + temperature + "&Humidity=" + humidity + "&Pressure=" + pressure;
Serial.print("urlFinal "); Serial.println(urlFinal);
client->GET(urlFinal, host, false);
// delete HTTPSRedirect object
delete client;
client = nullptr;
delay(3000);
ESP.deepSleep(SLEEP_LENGTH * 1000000,WAKE_RF_DEFAULT); // // deepSleep time is defined in microseconds. Multiply seconds by 1e6
delay(100);
}
void loop() {
}```
Hi Gilshultz, thanks for that that. Just need to confirm; pull-up means put the resistor from the pin to the 5V line? Do I do one for both the SCL and SDA pins?
The initialisation of the bme-object is done without any parameters. This means the library is expecting that the I2C-device is connected to that IO-pins that are dedicated to act as the I2C-interface.
On ESP8266-nodeMCU-bboards this is GPIO4 and GPIO5 which aren't available on a ESP-01
So in the codeline that creates the BME-object you have to specify which IO-pins shall act as the I2C-bus
Here I found an article about a guy that makes use of all four IO-pins of the ESP-01. tricky but programming needs to disconnect from your sensors everytime.
If you can afford to buy a ESP8266 nodeMCU-board I would do that.
If I understand the above referenced "Instructable" correctly, all I should need to do is to change the first part of setup() to
void setup() {
Serial.begin(115200);
Serial.flush();
Wire.pins(0, 2);
Wire.begin(0, 2);
//BME280 Test
Serial.println(F("BME280 test connection"));
bool status = bme.begin(); //The I2C address of the sensor I use is 0x76
if (!status) {
while (1);
}
i.e. add the Wire commands and remove 0x76 from the bme.begin
As I am only using the BME280, I only need the two pins.
But this does not seem to work either. Maybe it's because I am tired; will look again tomorrow.
If you can afford to spend $10 you could buy such a logic analyser
it looks like this
if you do a search on your own you will find them in different online-shops for $10
These logic analysers are able to record digital signals at high-speed with the software PulseView. PulseView can decode I2C, Serial, Onwire CAN-Bus etc.
So you can take a close look if the I2C-bus is working as expected.
I have used the ESP-01 successfully in the past without shorting the RST pin across 3.3V. As per my schematic I have only needed to bridge CH_PD and VCC.
Old ESP01 need shorting the RST pin across 3.3V, new ones not.
Old one should be blue, new ones shold be much darker near black.
I forgot this and wandered for an hour why it didn't start. Anyway use serial out, in my setup TX is still free for debug.