ESP8285 i2c Pins

I would crash too, seeing that meathook grasping at me :stuck_out_tongue_winking_eye:

That print statement comes before the Blynk.begin() command to connect to the server… so it actually connects just fine and crashes later in the code…

Adding in #define BLYNK_PRINT Serial at the beginning of your sketch will give a bit more info in the serial monitor.

I loaded your sketch and tested, and it is crashing when it actually tries to read the sensor… I suspect it is either not seeing the sensor (as in my case) or that there is a problem with the pin choices for that board (both kinda related actually).

Commenting out these lines allow the sketch to run. You can try commenting out only one at a time to see if it makes any difference on your side.

  //pressure = bme.readPressure();
  //temperature = bme.readTemperature();
  //humidity = bme.readHumidity ();
1 Like

So the original NodeMCU code works on the ESP8285 but you get no readings (because you don’t know where to connect your sensor).

If you add this line:

then re-run the code (without any sensor connected) then it crashes - is that correct?

It looks like you’re in the UK (BT Hub in your Wi-Fi credentials) in which case it’s gone 2am. Maybe time to sleep on it and have a fresh look at it tomorrow?

Pete.

1 Like

:joy::sweat_smile::rofl:

I’ll try commenting out those lines and see what happens.

Yes

Yes.

I’m not at work until Monday, site is flooded, bad weather and a burst water main. So i’ll be up late to night and sleep in tomorrow ready for a late night down the pub with a few of the lads. Plus I find it hard to stop messing with these things, my brain wont turn off.

The NodeMCU sketch works fine except no sensor data.

Change pins…

@Gunner I don’t see how those pin numbers and GPIO’s relate to one another. Do the pin numbers start at Ground because I’m presuming its pin 1? 9 pin each side, 18 in total. So pin 9 would be EN and pin14 would be GPIO12 ?

The pin number is probably what you use in the sketch and the IO, or GPx, is what you use on the board.

EDIT - updated my image with fancy handwriting :stuck_out_tongue_winking_eye:

1 Like

DOH! Of course …

But if I use the Wire.begin(9, 14) it crashes?

Is there another way to force it to use the pins I want?

Should be Wire.begin(14, 9);

With board GP14 going to the sensors SCL pin and the boards GP2 going to the sensors SDA pin

Note that the sketchs use of the #14 does NOT relate to the boards #14

1 Like

@Gunner Tried it 3 times now, crashes everytime, over and over. Is the Wire.begin(14, 9); the only option?

Adafruit BME280 test:
[23563] Connecting to BTHub6-P38S
[26064] Connected to WiFi
[26064] IP: 192.168.1.76
[26064] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on ESP8266

[26137] Connecting to blynk-cloud.com:8442
[26259] Ready (ping: 30ms).

Exception (28):
epc1=0x40205024 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont 
sp: 3fff0750 end: 3fff09d0 offset: 01a0

>>>stack>>>
3fff08f0:  3fffdab0 00000000 3fffd9d0 3ffef99c  
3fff0900:  00000000 00000000 00000001 3ffef9b0  
3fff0910:  00000000 3ffef344 3ffef588 4020510c  
3fff0920:  63383561 00000061 3ffef588 402051ac  
3fff0930:  00006ea6 3ffef99c 402060fc 3ffef9b0  
3fff0940:  3fffdad0 3ffef99c 00000000 402017fb  
3fff0950:  000003ff 3ffef5f0 3ffef5cc 40203980  
3fff0960:  00000000 3ffef5f0 3ffef5cc 3ffef99c  
3fff0970:  00000000 3ffef344 3ffef588 40203719  
3fff0980:  00000000 3ffef8dc 3ffef994 3ffef99c  
3fff0990:  00000000 3ffef344 3ffef344 40203b6c  
3fff09a0:  3fffdad0 00000000 3ffef994 402038e5  
3fff09b0:  3fffdad0 00000000 3ffef994 40206148  
3fff09c0:  feefeffe feefeffe 3ffef9b0 40100710  
<<<stack<<<
H!⸮⸮H⸮⸮⸮

Here’s the code, just in case.

    #define BLYNK_PRINT Serial
    #include <Blynk.h>
    #include <ESP8266WiFi.h>
    #include <Wire.h>
    #include <BlynkSimpleEsp8266.h>
    #include <Adafruit_Sensor.h>
    #include <Adafruit_BME280.h>
    #define SEALEVELPRESSURE_HPA (1013.25)
    //Setup connection of the sensor
    Adafruit_BME280 bme; // I2C

    char auth[] = "3efa4091d9xxxxx3fe454a58ca";
    char ssid[] = "xxxxx";
    char pass[] = "xxxxx";
    
    BlynkTimer timer;

    float pressure;     //To store the barometric pressure (Pa)
    float temperature;  //To store the temperature (°C)
    int humidity;      //To store the humidity (%) (you can also use it as a float variable)

    void setup() {
      //Wire.begin(int sda, int scl)
      Wire.begin(14, 9);    //Begin the sensor
      Serial.begin(9600); //Begin serial communication at 9600bps
      Serial.println("Adafruit BME280 test:");
      Blynk.begin(auth, ssid, pass);
      timer.setInterval(2000L, ReadSensors);   // read sensor every 2s 
      
    }

    void ReadSensors(){
      //Read values from the sensor:
      pressure = bme.readPressure();
      temperature = bme.readTemperature();
      humidity = bme.readHumidity ();

      Blynk.virtualWrite(V1, pressure/100);     // write pressure to V1 value display widget
      Blynk.virtualWrite(V2, temperature);  // write temperature to V2 value display widget
      Blynk.virtualWrite(V3, humidity);    // write altimeter to V3 value display widget
      
      //Print values to serial monitor:
      Serial.print(F("Pressure: "));
      Serial.print(pressure);
      Serial.print(" Mb");
      Serial.print("\t");
      Serial.print(("Temp: "));
      Serial.print(temperature);
      Serial.print(" °C");
      Serial.print("\t");
      Serial.print("Humidity: ");
      Serial.print(humidity); // this should be adjusted to your local forcase
      Serial.println(" %");    
      //delay(2000); //Update every 2 sec  
    }

    void loop() {
      Blynk.run();
      timer.run();
    }

Comment out each of these and try, then uncomment one at a time for all three, trying each time… probably will crash on any, but… testing :slight_smile:

1 Like

@Gunner
Crashed with only Temperature.
Crashed with only Pressure.
Crashed with only Humidity.

But didn’t crash with non of them.

Now I know this probably means something to you, but I haven’t a clue. So what did we just find out?

OK, clearly something wrong with the library, settings or sensor… but since it worked with the ESP8266, I would think the sensor is fine.

How is the I2C address for that sensor even determined? I don’t really see anything in the code.

In the NodeMCU sketch I added 0x76 to “bme.begin(0x76);” but thats now gone, replaced with “Wire.begin(14, 9);”.

0x76 is the sensors address - it has only two, 0x77 is the other one.

1 Like

It seems there is enough difference with the ESP8285 and that example sketch… I tried some googling for others, and while I found some they seemed much more complex and utilising other sensors as well.

Basically this is more a sensor 101 issue, rather than Blynk and I have ran out of ideas without having the same sensor and board to test on.

why did you remove bme.begin?

I’m unable to establish which are the i2c pins so used “Wire.begin(14, 9);” instead of “bme.begin();” in the hope it would solve that issue. However, I think replacing the “bme.begin();” is the way forward as it runs perfectly, just need to solve the i2c pin problem.

i would still think you need to ‘begin’ the sensor?

the sensor is ID’d at:

Adafruit_BME280 bme; // I2C

then referenced in the routine as “bme”:

  pressure = bme.readPressure();
  temperature = bme.readTemperature();
  humidity = bme.readHumidity ();

how is it going to work if you don’t tell it to begin?

1 Like

um, so it runs perfectly?

Well, it runs without crashing. :wink: