Skip to content

ESP32 reset to zero GPIO pins in void loop #131

Closed
@XauTrop

Description

@XauTrop

Sorry if this issue is not appropiate here and point me to discuss or whaterver other forum you think is the appropiate.

I'm using a ESP32 testing an tmp36. Without connecting to the wifi the reading of the TMP63 is ok.
When I connect to the wifi the GPIO readings go to 0 permanently. I do a GPIO scan in the void setup and I got values, but doing the scan indise the void loop the values are always 0. A normal script passing just a temperature value to the gateway is working, so seems no problem loading the libraries (Webthings 0.12.0, arduinojson: 6.17.2, WiFi: 1.2.7). Here is the serial output:

11:24:38.815 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
11:24:38.861 -> configsip: 0, SPIWP:0xee
11:24:38.861 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
11:24:38.861 -> mode:DIO, clock div:1
11:24:38.861 -> load:0x3fff0018,len:4
11:24:38.861 -> load:0x3fff001c,len:1216
11:24:38.861 -> ho 0 tail 12 room 4
11:24:38.861 -> load:0x40078000,len:10944
11:24:38.861 -> load:0x40080400,len:6388
11:24:38.861 -> entry 0x400806b4
11:24:39.138 -> *** Initiallizing ... ***
11:24:39.138 -> GPIO: 25 - reading: 621
11:24:39.138 -> GPIO: 2 - reading: 48
11:24:39.138 -> GPIO: 3 - reading: 0
11:24:39.138 -> GPIO: 4 - reading: 0
11:24:39.138 -> GPIO: 5 - reading: 0
11:24:39.138 -> GPIO: 6 - reading: 0
11:24:39.138 -> GPIO: 7 - reading: 0
11:24:39.138 -> GPIO: 8 - reading: 0
11:24:39.138 -> GPIO: 9 - reading: 0
11:24:39.138 -> GPIO: 10 - reading: 0
11:24:39.138 -> GPIO: 11 - reading: 0
11:24:39.138 -> GPIO: 12 - reading: 0
11:24:39.138 -> GPIO: 13 - reading: 0
11:24:39.138 -> GPIO: 14 - reading: 2918
11:24:39.138 -> GPIO: 15 - reading: 3743
11:24:39.183 -> GPIO: 16 - reading: 0
11:24:39.183 -> GPIO: 17 - reading: 0
11:24:39.183 -> GPIO: 18 - reading: 0
11:24:39.183 -> GPIO: 19 - reading: 0
11:24:39.183 -> GPIO: 20 - reading: 0
11:24:39.183 -> GPIO: 21 - reading: 0
11:24:39.183 -> GPIO: 22 - reading: 0
11:24:39.183 -> GPIO: 23 - reading: 0
11:24:39.183 -> GPIO: 24 - reading: 0
11:24:39.183 -> GPIO: 25 - reading: 768
11:24:39.183 -> GPIO: 26 - reading: 686
11:24:39.183 -> GPIO: 27 - reading: 832
11:24:39.183 -> GPIO: 28 - reading: 0
11:24:39.183 -> GPIO: 29 - reading: 0
11:24:39.183 -> GPIO: 30 - reading: 0
11:24:39.183 -> GPIO: 31 - reading: 0
11:24:39.183 ->
11:24:39.183 -> Connecting to "My Network"
11:24:39.277 ->
11:24:39.790 -> .
11:24:39.790 -> Connected to My Network
11:24:39.790 -> IP address: 192.168.1.45
11:24:39.790 -> MDNS responder started
11:24:39.790 -> HTTP server started
11:24:39.790 -> http://192.168.1.45/things/Tmp36
11:24:41.283 -> - reading: 0
11:24:41.283 -> GPIO: 2 - reading: 0
11:24:41.283 -> GPIO: 3 - reading: 0
11:24:41.331 -> GPIO: 4 - reading: 0
11:24:41.331 -> GPIO: 5 - reading: 0
11:24:41.331 -> GPIO: 6 - reading: 0
11:24:41.331 -> GPIO: 7 - reading: 0
11:24:41.331 -> GPIO: 8 - reading: 0
11:24:41.331 -> GPIO: 9 - reading: 0
11:24:41.331 -> GPIO: 10 - reading: 0
11:24:41.331 -> GPIO: 11 - reading: 0
11:24:41.331 -> GPIO: 12 - reading: 0
11:24:41.331 -> GPIO: 13 - reading: 0
11:24:41.331 -> GPIO: 14 - reading: 0
11:24:41.331 -> GPIO: 15 - reading: 0
11:24:41.331 -> GPIO: 16 - reading: 0
11:24:41.331 -> GPIO: 17 - reading: 0
11:24:41.331 -> GPIO: 18 - reading: 0
11:24:41.331 -> GPIO: 19 - reading: 0
11:24:41.331 -> GPIO: 20 - reading: 0
11:24:41.331 -> GPIO: 21 - reading: 0
11:24:41.331 -> GPIO: 22 - reading: 0
11:24:41.331 -> GPIO: 23 - reading: 0
11:24:41.331 -> GPIO: 24 - reading: 0
11:24:41.331 -> GPIO: 25 - reading: 0
11:24:41.331 -> GPIO: 26 - reading: 0
11:24:41.331 -> GPIO: 27 - reading: 0
11:24:41.377 -> GPIO: 28 - reading: 0
11:24:41.377 -> GPIO: 29 - reading: 0
11:24:41.377 -> GPIO: 30 - reading: 0
11:24:41.377 -> GPIO: 31 - reading: 0
11:24:41.377 -> GPIO: 25 - reading: 0

The code (a bit dirty due to several tests):
#define ARDUINOJSON_USE_LONG_LONG 1

#include <Arduino.h>
#include <Thing.h>
#include <WebThingAdapter.h>
#include <WiFi.h>
int tempPin = 25; //analog input pin constant

int temprdVal; // temperature sensor raw readings

float volts; // variable for storing voltage

float temp; // actual temperature variable
char ssid[] = "";
char password[] = "
";
int status = WL_IDLE_STATUS;
//const String mDNSHostname = "Temp36sensor";
WebThingAdapter* adapter;
const char* sensorTypes[] = {"TemperatureSensor", nullptr};
ThingDevice sensor("Tmp36", "Temp36 Temperature Sensor", sensorTypes);
ThingProperty sensorTemp("temperature", "", NUMBER, "TemperatureProperty");
ThingProperty sensorHumd("humidity", "", NUMBER, nullptr);
ThingProperty sensorPres("pressure", "", NUMBER, nullptr);

void setup()
{
// initialize serial:

Serial.begin(115200);
Serial.println("*** Initiallizing ... ***");
read_gpio();
for (tempPin = 2; tempPin < 32; tempPin++) {
temprdVal = analogRead(tempPin);
Serial.print("GPIO: ");
Serial.print(tempPin);
Serial.print(" - reading: ");
Serial.println(temprdVal);

}

Serial.println("");
Serial.print("Connecting to "");
Serial.print(ssid);
Serial.println(""");
#if defined(ESP8266) || defined(ESP32)
WiFi.mode(WIFI_STA);
#endif
WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
bool blink = true;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");

Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
adapter = new WebThingAdapter("tempsensor", WiFi.localIP());
// Set units for properties
sensorTemp.unit = "celsius";

// Associate properties with device
sensor.addProperty(&sensorTemp);
// Associate device with connection
adapter->addDevice(&sensor);
// Start mDNS and HTTP server
adapter->begin();

Serial.println("HTTP server started");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.print("/things/");
Serial.println(sensor.id);
delay(1500);
}
Serial.print(" - reading: ");
Serial.println(temprdVal);
}

void loop()
{

//read the temp sensor and store it in tempVal
for (tempPin = 2; tempPin < 32; tempPin++) {
temprdVal = analogRead(tempPin);
Serial.print("GPIO: ");
Serial.print(tempPin);
Serial.print(" - reading: ");
Serial.println(temprdVal);

}
int tempPin = 25; //analog input pin constant
temprdVal = analogRead(tempPin);
Serial.print("GPIO: ");
Serial.print(tempPin);
Serial.print(" - reading: ");
Serial.println(temprdVal);
volts = temprdVal/1023.0; // normalize by the maximum temperature raw reading range

temp = (volts - 0.5) * 100 ; //calculate temperature celsius from voltage as per the equation found on the sensor spec sheet.

Serial.print(" Temperature is: "); // print out the following string to the serial monitor
Serial.print(temp); // in the same line print the temperature
Serial.println (" degrees C"); // still in the same line print degrees C, then go to next line.
ThingPropertyValue value;
value.number = temp;
sensorTemp.setValue(value);
adapter->update();
delay(10000); // wait for 1 second or 1000 milliseconds before taking the next reading.
}

Any advise?
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions