Problem connecting BMP280 to ESP8266 NodeMCU - check wiring - arduino

I am connecting a GY BMP280 to an ESP8266 NodeMCU:
with the wiring:
VCC = 3.3V
GND = GND
SCL = D1 (GPIO5)
SDA = D2 (GPIO4)
I use the Adafruit BMP280 Library by Adafruit version 2.6.6 And my program is as follows:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // create a BMP280 instance
#define SEALEVELPRESSURE_HPA 1013.25
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial console to open
}
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
}
void loop() {
float temperature = bmp.readTemperature();
float pressure = bmp.readPressure() / 100.0F;
float altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(pressure);
Serial.println(" hPa");
Serial.print("Altitude = ");
Serial.print(altitude);
Serial.println(" meters");
Serial.println();
delay(2000);
}
I have tried different ports and different code setups, this is in my opinion the most correct for what i need, but i keep getting the same output on my serial monitor:
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90: 3fffdad0 00000000 3ffee6fc 4020105c
3fffffa0: feefeffe feefeffe 3ffee750 40203268
3fffffb0: feefeffe feefeffe 3ffe85e0 40100ef5
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
�{���4��Could not find a valid BMP280 sensor, check wiring!
I really cant figure out the problem, does anyone here have an idea of what could cause the trouble?

The message
Soft WDT reset
means you're triggering the watchdog timer. The watchdog timer is part of the system which halts it with an error in case part of it runs for too long without allowing other parts to run.
In this case it's this code that triggers it:
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
Code on an ESP8266 (or ESP32) should not run loops like that indefinitely without ever calling yield() or delay() to allow other things to run. That's what triggers the watchdog.
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1)
yield();
}
As for why your code can't detect the sensor, have you used an I2C scanner to confirm that the device is even wired correctly?
If it is, the sensor has two possible I2C addresses, 0x76 and 0x77. The Adafruit library defaults to 0x77. Try 0x76.
if (!bmp.begin(0x76)) {
If that doesn't work then you have a hardware problem, which is off-topic here as Stack Overflow is for software. So if that doesn't work please post about it in the Arduino Stack Exchange.

Related

How does my ESP8266/NodeMCU communicate with my GSM Module SIM800L?

so I want to connect my SIM800L GSM Module to my NodeMCU. I bought a LM2596 DC-DC voltage regulator to convert the output voltage to ~4V for the SIM800L. Input voltage for the regulator is 9V/1A.
Everything is connected: RX from GSM to D5 (GPIO14), TX to D6 (GPIO12) and RST to D7 (GPIO13). The GPIOs are deliberately chosen, since I've read online, that the RX/TX Pins on the NodeMCU are used internally. I tried matching RX/TX pins before, but it's the same result (that's why I am certain, it has to be my code that is defect). A SIM card is also inserted in the GSM Module (with PIN).
I'm coding on the Arduino IDE and I'm using the GSMSim and SoftwareSerial libraries for connecting to the GSM Module. I've tried the example sketches from the GSMSim to communicate to the GSM Module, but I'm not getting any answer on my serial monitor.
I also tried manually sending commands to the GSM Module.
#include <GSMSim.h>
#include <SoftwareSerial.h>
// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples, i used HardwareSerial. You can change it anymore.
#define RX 14
#define TX 12
#define RESET 13
SoftwareSerial serial(RX, TX);
GSMSim gsmModule(serial, RESET);
void setup() {
serial.begin(115200); // If you dont change module baudrate, it comes with auto baudrate.
while(!serial) ;
Serial.begin(115200); // Serial for debug...
while(!Serial) ;
Serial.println("");
Serial.println("serial begin");
// Init module...
gsmModule.init(); // use for reseting module. Use it if you dont have any valid reason.
delay(100);
gsmModule.sendATCommand("AT+GMR");
if(serial.available()) Serial.println(serial.readString());
Serial.println("Sent AT");
}
OUTPUT:
serial.begin
Sent AT
Another example with the modified GSMSim_HTTP sketch:
#include <GSMSim.h>
#include <SoftwareSerial.h>
// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples, i used HardwareSerial. You can change it anymore.
#define RX 14
#define TX 12
#define RESET 13
SoftwareSerial serial(RX, TX);
GSMSim http(serial, RESET);
static volatile int num = 0;
void setup() {
serial.begin(115200); // If you dont change module baudrate, it comes with auto baudrate.
while(!serial) {
; // wait for module for connect.
}
Serial.begin(115200); // Serial for debug...
// Init module...
http.init(); // use for init module. Use it if you dont have any valid reason.
Serial.print("Set Phone Function... ");
Serial.println(http.setPhoneFunc(1));
//delay(1000);
Serial.print("is Module Registered to Network?... ");
Serial.println(http.isRegistered());
//delay(1000);
Serial.print("Signal Quality... ");
Serial.println(http.signalQuality());
//delay(1000);
Serial.print("Operator Name... ");
Serial.println(http.operatorNameFromSim());
//delay(1000);
//Serial.print("GPRS Init... ");
//Serial.println(http.gprsInit("internet")); // Its optional. You can set apn, user and password with this method. Default APN: "internet" Default USER: "" Default PWD: ""
//delay(1000);
Serial.print("Connect GPRS... ");
Serial.println(http.connect());
//delay(1000);
Serial.print("Get IP Address... ");
Serial.println(http.getIP());
delay(1000);
Serial.print("Get... ");
Serial.println(http.get("sera.erdemarslan.com/test.php"));
delay(1000);
Serial.print("Get with SSL and read returned data... ");
Serial.println(http.getWithSSL("erdemarslan.com/test.php", true));
delay(1000);
Serial.print("Post... ");
Serial.println(http.post("sera.erdemarslan.com/test.php", "name=Erdem&surname=Arslan", "application/x-www-form-urlencoded"));
delay(1000);
Serial.print("Post with SSL and read returned data... ");
Serial.println(http.post("erdemarslan.com/test.php", "name=Erdem&surname=Arslan", "application/x-www-form-urlencoded", true));
delay(1000);
Serial.print("Close GPRS... ");
Serial.println(http.closeConn());
//delay(1000);
// For other methods please look at readme.txt file.
}
void loop() {
// Use your Serial interface...
if(serial.available()) {
String buffer = "";
buffer = Serial1.readString();
num = num + 1;
Serial.print(num);
Serial.print(". ");
Serial.println(buffer);
}
// put your main code here, to run repeatedly:
}
OUTPUT:
serial.begin
Set Phone Function... 0
is Module Registered to Network?... 0
Signal Quality... 99
Operator Name... NOT CONNECTED
Connect GPRS... 0
Get IP Address...
Get module date time... ERROR:NOT_GET_DATETIME
Set timezone and time server... 0
Sync date time from server... AT_COMMAND_ERROR
Get module date time after sycn... ERROR:NOT_GET_DATETIME
Close GPRS... 0
I hope it's something obvious, since I am not familiar with AT commands at all.
Thanks!

How can I connect an ESP32 to an A6 GSM module?

I'm really in need of help with this problem and as most commonly advised, I have researched and researched and researched for days and I can't figure out what's wrong...
With that being said, I'm working on a project that uses an ESP-32S (pinout) and an A6 GSM module. (pinout) I'm attempting to get them connected to have the A6 send data to ThingSpeak... My problem is that I can't get it to work... I have the exact same configuration between the two using an ESP8266 and it connects and works but with the ESP32S it just doesn't seem to work...
Below is the code I have used to connect the 32 to the A6 and everything says success and pass but it won't change any ThingSpeak values using any methods...
#define TINY_GSM_MODEM_A6
#include "TinyGsmClient.h"
#include "ThingSpeak.h"
#define SerialMon Serial
HardwareSerial SerialAT(1);
bool modemConeted;
// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[] = "wireless.twilio.com";
const char user[] = "";
const char pass[] = "";
bool dataSent = false;
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
void setup(){
SerialMon.begin(9600);
delay(1000);
gsmModSetup();
}
void gsmModSetup() {
// Set GSM module baud rate
SerialAT.begin(9600, SERIAL_8N1, 27, 26, false); //27 and 26 are the pins on the ESP32S connected to the U_Rxd/U_Txd pins of A6
delay(3000);
SerialMon.println("Initializing modem...");
modem.init();
delay(3000);
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork()) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
SerialMon.print("Connecting to ");
SerialMon.print(apn);
if (!modem.gprsConnect(apn, user, pass)) {
SerialMon.println(" fail");
delay(5000);
return;
}
SerialMon.println(" OK");
}
void loop(){
}
I'm using a Twilo Sim card that's loaded with data (as said above it works with esp8266 so not the SIM and not the board) The only part of this code that doesn't pass is the part that says GPRS connect. it never says pass or fail. It just sits for like five minutes then continues.
After this, I try and post to ThingSpeak and it gives ThingSpeak ERROR-307 which means failed to connect to ThingSpeak...
I have tried 2 different ways
The what I find the easy and normal way
ThingSpeak.setField(1, temp);
ThingSpeak.setField(2, h);
ThingSpeak.setField(3, p);
ThingSpeak.setField(4, pt);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
and the more complicated way of connecting to the server then sends a GET command with all the values put together with strings.
if (client.connect(thingSpeakAddress, 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + WriteAPIKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(thingSpeakData.length());
client.print("\n\n");
client.print(thingSpeakData);
}
client.stop();
Yet neither work and I don't know what to do... My A6 is connected to the 32 using GPIO26 & 27 they're connected to the A6 U_Rxd/U_Txd pins. All boards share common ground as they should.
Any more guides to read or code to change or libraries to try would be extremely helpful as my days of digging has yielded nothing but frustration as one attempt after another fails. the readers of this really are my last hope in solving this problem that's hindering my farther progression.
(Any questions about anything on my end, please ask. -Thank you)
The enclose documentation shows ESP32S pins for HW Serial 0 RX/TX on pin GIPO01/GIPO03, HW Serial 1 RX/TX on pin GIPO09/GIPO10 Given you have attached no oter HW at the moment, why not try with the basic config with serial1Read about this: https://github.com/G6EJD/ESP32-Using-Hardware-Serial-Ports and use the latest core ESP32 package (as of today 23.3.2020 is 1.04, previous releases had issues with serial. Do notforget to setup the serial a given in the article its different to esp8266 (!) so much about code compability. If you use the code on both platforms, you have to work with
#ifdef ESP32
//configure serial for esp32
#elif ESP8266
//configure serial for esp8266
#else
#error "Hardware not supported"
#endif
Here a small test routine for just the serial communication. If you type something in the input line of serial monitor it should be mirrored in the output window
#include <HardwareSerial.h>
void setup() {
Serial.begin(9600);
// set the data rate for the HardwareSerial port
Serial2.begin(9600);
}
void loop() {
if (Serial2.available()) {
Serial.write(Serial2.read());
}
if (Serial.available()) {
Serial2.write(Serial.read());
}
}
You can then expand the serial2 to your settings. If it fails it may be dueto: U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though - so try Serial3.

ESP8266 to ESP8266 i2C Communication

I am trying to get my ESP8266's connect and send messages over an i2c bus. I am using a NodeMcu Development Board. Pins D1,D2 and GND are connected to each other.
The code on my master is :
#include <Wire.h>
void setup() {
Wire.begin(D1,D2); // join i2c bus (address optional for master)
Serial.begin(115200);
}
byte x = 0;
void loop() {
Wire.beginTransmission(8);
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
Serial.println("Transmitted");
x++;
delay(500);
}
And the code on my slave ESP is:
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(115200); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
Serial.println("Received..");
/*
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
*/
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
Running this gives no output on the receiver chip.
As mentioned in the comments it doesn't look like I2C is supported, but you could use PJON
You just need to connect a single wire to enable communication between the two devices
I'm not sure but I would expect the Wire library from Arduino to use the hardware I2C controller for ATMega. The I2C driver in the firmware from Espressif seems to be doing I2C over GPIO, that would hint there is no hw controller on ESP (what are the odds they would be the same anyway). So you need to use something else than Wire.h, thus I would suggest - try downloading something that fakes I2C over GPIO for your Arduino IDE. Like this .. maybe, I haven't tried that out. I know not a complete solution, but maybe at least this helps.. good luck!
ESP8266(I2C Master) to ESP8266(I2C Slave) works from version 2.5.0. Check out my comments on the ESP8266 GitHub

Cannot switch on Sigfox UART on Arduino shield

I am trying to get an Arduino Uno to send data via Sigfox. Using a Libelium Xbee Shield and Sigfox Module for Arduino (Cooking Hacks).
I tried to send a string using the example found in the Arduino library. The Arduino sketch is simple:
#include <Wire.h>
// Cooking API libraries
#include <arduinoClasses.h>
#include <arduinoUART.h>
#include <arduinoUtils.h>
#include <arduinoSigfox.h>
// Pin definition for Sigfox module error LED:
const int error_led = 13;
//////////////////////////////////////////////
uint8_t socket = SOCKET0; //Asign to UART0
//////////////////////////////////////////////
uint8_t error;
void setup()
{
Serial.begin(9600);
pinMode(error_led, OUTPUT);
//////////////////////////////////////////////
// 1. switch on
//////////////////////////////////////////////
error = Sigfox.ON(socket);
// Check status
if( error == 0 )
{
//"Switch ON OK"
digitalWrite(error_led, LOW);
Serial.println("Sigfox Switch ON -> SUCCES");
}
else
{
//"Switch ON ERROR"
digitalWrite(error_led, HIGH);
Serial.println("Switch Switch ON -> FAILED");
}
//////////////////////////////////////////////
// 2. send data
//////////////////////////////////////////////
// Send 12 bytes at most
error = Sigfox.send("000102030405060708090A0B");
// Check sending status
if( error == 0 )
{
//"Sigfox sending -> SUCCES"
digitalWrite(error_led, LOW);
Serial.println("Sigfox sending -> FAILED");
}
else
{
//"Sigfox packet sent ERROR"
digitalWrite(error_led, LOW);
Serial.println("Sigfox packet sent ERROR");
}
}
void loop()
{
//////////////////////////////////////////////
// 3. sleep
//////////////////////////////////////////////
}
The output on Serial port is the following:
AT
Sigfox Switch ON -> FAILED
AT$SF=000102030405060708090A0B
Sigfox sending -> FAILED
Connection between the Sigfox module and the board seems to be OK, because Sigfox.getID() is working, and the correct ID is retrieved. Also subscription of the device on the Sigfox platform seems to be OK.
How can I debug this? I have no idea how to start a diagnosis: something in the libraries? something in the sending? something in the hardware?. All help on this is appreciated.
Please double check Arduino TX is connected to Sigfox RX, and Arduino RX is connected to Sigfox TX
Check also, that the module has VCC on pin 1, and GND on pin 9.
If it still don't work, it's probably because there is something else connected to RX and TX lines. Remove it.
Personnaly, I put a logic analyser on these lines to check the dialog.
for the "ON": AT\r\n is sent, and "OK\r\n" is answered.
Hope this helps
The problem was relatively simple to solve. It turns out that it is not possible to run the combination Arduino/Xbee/Sigfox with the serial cable connected (I used it for power, and for sending debugging info to my computer).
All I had to do was:
put switch to USB
upload new code via serial cable
unplug the serial cable
put switch to Xbee
power the arduino via the 12V jacket (or other power input)
Then it works.

Weird behavior when using NodeMCU V3 with RF522

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!

Resources