Hello Rui and Sara,
My LoRa-sender, originally built up from your course, I want to extend with a BME280 sensor. Because I added already an RTC (DS3231) that is using I2C also, I have to find a solution.
I was lucky to find your blog
https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
Implementing this is only giving bad results. Using same default pins for all I2C devices is giving crashes.
So I tried different strategies from your blog:
and this one:
but with bad results. I tried the sketches as given at those links.
I tried now with just two devices BME280 and tested this on TTGO ESP32 LoRa and on DOIT ESP32.
Nothing works.
The second BME280 is never found. I used pins 33 (SDA) and 32 (SCL)>
I was wondering if you tried yourself these implementations and sketches and if so, what could be reason for my troubles.
Here https://github.com/espressif/arduino-esp32/issues/977 I found in post of Kutscher07 some info (in comments at top of sketch) as that some resistors should be used. For me not straight clear why?
I tried this sketch too (ignoring the resistors notes), but same problems with second BME280.
So what I have to do to add a BME280 to my LoRa-sender with RTC?
Regards,
Jop
Hi Jop.
All sketches that we post in our blog were tested. We don’t publish code that was not tested by us. So, we know that was working at the time we wrote the post.
Can you connect your BME280 sensor to the ESP32 default I2C pins and run an I2C scanner sketch? Run this for both of your sensors:
https://raw.githubusercontent.com/RuiSantosdotme/Random-Nerd-Tutorials/master/Projects/LCD_I2C/I2C_Scanner.ino
What do you get? Then try to run it using the pins you’ll connect to your LoRa board. Do you get the same result?
What is the BME280 sensor that you’re using? Does it have 4 pins or 6 pins? Recently, one of our readers reported problems with the BME280 with 6 pins. He said that the sensor only worked after connecting the SDO pin to GND.
What LoRa board are you using and which pins are you connecting the BME280 to? Also, the other peripherals are connected to which pins?
I’m currently building a project with the TTGO LoRa32 board with a BME280 connected and everything works fine. However, it took me a bit of time to choose the right pins. Not all pins worked well when trying to connect the BME280 sensor.
When using I2C communication the data lines should be pulled up by resistors. However, because the BME280 sensor comes in a breakout board, it already includes the resistors on its circuitry. So, no need to worry about this.
Finally, do you get any errors when trying to implement our sketches? What errors exactly?
Regards,
Sara
Hi Sara,
Before I answer all your questions, you wrote:
I’m currently building a project with the TTGO LoRa32 board with a BME280 connected and everything works fine. However, it took me a bit of time to choose the right pins. Not all pins worked well when trying to connect the BME280 sensor.
Can you tell me what pins you’ve found working? I work also with this TTGO LoRa32 (V1)
Thnx, for your reply,
Jop
btw, I2C address scanner sketch I used, but is finding only one BME. An adapted version, see link in my 1st blog, and addessing second TwoWire(1) is also only finding the first BME280, connected to the default i2c-pins
further: I’ve available both types BME280 (4 and 6 pins), but I used for my test two 4-pin BME280
Hi Jop.
I’m using this board: https://makeradvisor.com/esp32-sx1276-lora-ssd1306-oled/
I connected the BME280 to the board like this:
These pins were not being used neither by the LoRa transceiver chip or by the OLED.
And I created another I2C bus to communicate with the BME280 on my code because I dind’t want to use the same used by the OLED display.
So, I defined the BME280 as follows (before the setup())
//BME280 definition #define SDA 21 #define SCL 13 TwoWire I2Cone = TwoWire(1); Adafruit_BME280 bme;
Then, in the setup() initialized the BME280 as follows:
I2Cone.begin(SDA, SCL, 100000); bool status1 = bme.begin(0x76, &I2Cone); if (!status1) { Serial.println("Could not find a valid BME280_1 sensor, check wiring!"); while (1); }
Then, in the loop(), I used the readTemperature() and readHumidity() functions.
I hope this helps.
Regards,
Sara
Hello Sara,
Thnx for your lightning fast response. And it helped, but a bit in a different way.
I see you combined pin 21 (SDA, default for I2C) with 13 for SCL.
But my problem is connecting 2 I2C-devices and for that I just experimented with 2 x bme80-sensors.
In my real project I have to combine one bme280 with 2 other I2C-devices (one is RTC DS3231)
Your combining default pin with just another pin brought me to trying for the other bme280 this combination: pin 20 (SCL, 1st default for I2C) with GPIO12. Did NOT work, so tried GPIO14. This worked! But as you see in the pin lay-out for this TTGO LoRA, pin 14 is ‘forbidden’ (LoRa-RST).
So I tried GPIO25, works also. So both bme280’s are found and working.
Also GPIO17 combined with 20 works.
BUT… it seems for me logical to keep pin 21 and pin 22 together again for controlling one BME280, as these are the default I2C-pins. And your pin 13 (SCL) I could combine with consecutively pin 14, pin 25 and pin 17 (as SDA). These combinations work all ok for controlling the second bme280. But it is all according ‘trial and error’.
The idea that most pins on a EPS32 are multipurpose isn’t quite true, as 33 (SDA) and 32 (SCL) did not work for me. There my ‘desperate’ search for help started.
After all I tried and I decided to use GPIO4 for SDA and GPIO15 for SCL as these are also marked as I2C SDA and SCL, but for the internal TTGO OLED.
For 3 reasons:
- in my Solar driven LoRa-sender the pins 13, 14, 25 and 17 are already used for other purposes (14 LoRa-RST)
- the OLED on this board doesn’t work at all (from the beginning) and for a sender I don’t need a display
- also these pins seems to be meant for I2C, so why not use them as meant
As for the ESP32 TTGO, I have same version as you showed in your post. This is version V1. I mailed Rui short ago that Andreas Spiess was not very positive about this V1; I thought because of the frequency spectrum.
Did not yet tried my board for real long range transceiving. That will come.
With wat board setting you compile your sketches for this TTGO? I use ‘Heltec WiFi LoRa 32’. Is there also a SDK for this TTGO? I miss info in your tutorial about this TTGO LoRa.
Thnx Sara and regards,
Jop
Hi Jop.
I used those pins because they were not being used by any other peripheral in my board.
You can use the BME280 in the same pins as other I2C devices as long as they have different I2C addresses.
We don’t have any tutorial with the Heltec Wifi LoRa32.
We have the TTGO LoRa32 OLED board, and in the Arduino IDE, I selectthe TTGO LoRa-32c OLED V1 in the Arduino IDE.
We’ve tested the communication range yesterday, and the maximum we got was 180 meters in open field with the TTGO LoRa32 OLED board.
Regards,
Sara