Hello,
I am working on a project with ESP32 azure iot kit and i want to read its sensors. I am coding in arduino IDE. I am trying to scan the I2C bus for the devices and then proceed, using the WIRE library, although i am not able to detect any device.Can anyone advice me on this?In addition,is there a way to use he "esp-iot-solution" library of ESP-IDF in arduino IDE? That would solve many issues.
Thank you!
I2C bus usage through arduino IDE
-
- Posts: 20
- Joined: Fri Jul 26, 2019 5:50 pm
Re: I2C bus usage through arduino IDE
First off, try the standard i2c scanner:
https://playground.arduino.cc/Main/I2cScanner/
That should find any devices attached to the unit, and get you started. Some thoughts from there.
If the scanner does NOT work:
* Make sure you have the SCL and SDA pins connected up correctly to the board, and there are pull-up resistors (either on the board you are attaching, or you wire some up yourself - see the i2c wikipedia article).
* Make sure your code is using the right SCL and SDA pins internally. I believe you can Serial.print(SDA) to see what pin is used.
* Play with the Wire.begin statement. It can take up to 3 arguments: the first two are the SCL and SDA pins, but I forget the order, and then the speed, which should be either (100*1000) or (400*1000) for 100KHz or 400 KHz respectively.
* Beware of other Wire.begin statements in your libraries - you might do a good Wire.begin, then the library does another that overwrites what you did.
* Check you libraries for explicit calls to specific CPUs in the definition, since it might not be ESP32-aware. For example, the Adafruit PN532 library has this line:
#if defined(__AVR__) || defined(__i386__) || defined(ARDUINO_ARCH_SAMD) || defined(ESP8266) || defined(ARDUINO_ARCH_STM32)
I needed to change it to this line, adding in ESP32 at the end:
#if defined(__AVR__) || defined(__i386__) || defined(ARDUINO_ARCH_SAMD) || defined(ESP8266) || defined(ARDUINO_ARCH_STM32) || defined(ESP32)
'luck.
https://playground.arduino.cc/Main/I2cScanner/
That should find any devices attached to the unit, and get you started. Some thoughts from there.
If the scanner does NOT work:
* Make sure you have the SCL and SDA pins connected up correctly to the board, and there are pull-up resistors (either on the board you are attaching, or you wire some up yourself - see the i2c wikipedia article).
* Make sure your code is using the right SCL and SDA pins internally. I believe you can Serial.print(SDA) to see what pin is used.
* Play with the Wire.begin statement. It can take up to 3 arguments: the first two are the SCL and SDA pins, but I forget the order, and then the speed, which should be either (100*1000) or (400*1000) for 100KHz or 400 KHz respectively.
* Beware of other Wire.begin statements in your libraries - you might do a good Wire.begin, then the library does another that overwrites what you did.
* Check you libraries for explicit calls to specific CPUs in the definition, since it might not be ESP32-aware. For example, the Adafruit PN532 library has this line:
#if defined(__AVR__) || defined(__i386__) || defined(ARDUINO_ARCH_SAMD) || defined(ESP8266) || defined(ARDUINO_ARCH_STM32)
I needed to change it to this line, adding in ESP32 at the end:
#if defined(__AVR__) || defined(__i386__) || defined(ARDUINO_ARCH_SAMD) || defined(ESP8266) || defined(ARDUINO_ARCH_STM32) || defined(ESP32)
'luck.
Re: I2C bus usage through arduino IDE
Thank you for your reply scotthauck!
I figured it out and it was the pin declaration .I used to Serial.println(SDA), but the printed pins were finally not the correct pins that should have been used.
A little bit more carefull with the datasheets and the problem solved.
I figured it out and it was the pin declaration .I used to Serial.println(SDA), but the printed pins were finally not the correct pins that should have been used.
A little bit more carefull with the datasheets and the problem solved.
Who is online
Users browsing this forum: No registered users and 87 guests