Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Esp32 and BMX160, change I2c Pins

    The_new_doctor
    New Poster

    Esp32 and BMX160, change I2c Pins

    Hi everyone, 
    it's my first time with an Arduino-like device and I'm currently trying to connect an Imu BMX160 to the board in two different by from the default one, but i'm having a problem: I know that the Esp32 is able to use almost any pin for I2C as they show in this site in which they use an Adafruit sensor https://www.electrorules.com/esp32-i2c-communication-set-pinsmultiple-bus-interfaces-and-peripherals...

     But I don't know why it doesnt work with the one that I have. The code that I am using is the example, so I've tried to modify that like this

     

     

     */
    #include <DFRobot_BMX160.h>
    #include <Wire.h>
    
    #define I2C_SDA 25
    #define I2C_SCL 26
    
    TwoWire I2C = TwoWire(0);
    
    
    DFRobot_BMX160 bmx160;
    void setup(){
      I2C.begin(I2C_SDA, I2C_SCL);
      bmx160.begin(&TwoWire);
      Serial.begin(115200);
      delay(100);
      
      
      //init the hardware bmx160  
      if (bmx160.begin(&TwoWire) != true){
        Serial.println("not found");
        while(1);
      }

     

     

    But obviously it doesn't work because the function .begin in the library doesn't ask for a variable  that define the position and instead it's in the constructor 

    class DFRobot_BMX160{
      public:
        DFRobot_BMX160(TwoWire *pWire=&Wire);
        
        /**
         * @fn begin
         * @brief set the i2c addr and init the i2c.
         * @return returns the initialization status
         * @retval true Initialization succeeded
         * @retval false Initialization  failed
         */
        bool begin();
    
    ...


    So my question is, how can I manage to change that?

     

    Thanks in advance

    1 REPLY 1
    BSTRobin
    Community Moderator

    Re: Esp32 and BMX160, change I2c Pins

    Hi The_new_doctor,

    We know little about Arduino code on ESP32. Suggest you refer more information on Arduino forum how to use I2C on ESP32.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist