• Hacking ESP32 - multiplexing I2C

    10/12/2023 at 21:47 5 comments

    • Multiple devices with the same I2C address? 
    • Don't like bit-banging? 
    • No money for extra I2C multiplexer? 
    • Spare IO ports ? 

    ==> Continue reading !

    This was a short proof of concept to use the IO_MUX capability of the ESP32 to change online the PINs used for the I2C communication. Basically, the I2C  hardware module can be connected to nearly every pin ofd the ESP32 and this switch can be done on the fly. I was not sure how good this work but a fast breadboard build and software sketch showed that it works like charme! See the picture and the code snippet below. Combining this with this nice hack to use only one SCL or SDA  for multiple devices (link), this could be even more advantagous in several cases and save costs/space for an I2C multiplexer!

    Picture of the breadboard setup:


    The code snippet running on the ESP32:
    // ESP32 S3 Dataseeht (as example) https://www.elecrow.com/download/product/DLC35010R/esp32-s3_datasheet_en.pdf
    // Example i2c driver: https://github.com/espressif/esp-idf/blob/master/components/driver/i2c/i2c.c
    
    #include <Wire.h>
    #include "C:\Users\pagantroll\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.12\tools\sdk\esp32c3\include\driver\include\driver\i2c.h"
    #include "C:\Users\pagantroll\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.12\tools\sdk\esp32\include\esp_rom\include\esp_rom_gpio.h"
    
    #include <DFRobot_QMC5883.h>
    DFRobot_QMC5883 compass(&Wire, QMC5883_ADDRESS );
    
    #define I2C_SDA1 3 
    #define I2C_SCL1 4
    #define I2C_SDA2 1 
    #define I2C_SCL2 2
    
    void activate_I2C_GPIO_a() {
      i2c_set_pin(0, I2C_SDA1,I2C_SCL1, GPIO_PULLUP_ENABLE,GPIO_PULLUP_ENABLE,I2C_MODE_MASTER);
      esp_rom_gpio_connect_out_signal(I2C_SCL2, SIG_GPIO_OUT_IDX, false, false);
      esp_rom_gpio_connect_out_signal(I2C_SDA2, SIG_GPIO_OUT_IDX, false, false);
    }
    
    void activate_I2C_GPIO_b() {
      i2c_set_pin(0, I2C_SDA2,I2C_SCL2, GPIO_PULLUP_ENABLE,GPIO_PULLUP_ENABLE,I2C_MODE_MASTER);
      esp_rom_gpio_connect_out_signal(I2C_SCL1, SIG_GPIO_OUT_IDX, false, false);
      esp_rom_gpio_connect_out_signal(I2C_SDA1, SIG_GPIO_OUT_IDX, false, false);
    }
    
    void readMagSensor() {
      sVector_t mag = compass.readRaw();
      Serial.print(mag.XAxis);Serial.print(",");
      Serial.print(mag.YAxis);Serial.print(",");
      Serial.print(mag.ZAxis);Serial.print(",");
    }
    
    
    void setup() {
    
      Serial.begin(115200);  
      Serial.println("Tesing I2C Multiplexing");
      
      Wire.begin(I2C_SDA1, I2C_SCL1);
    
      activate_I2C_GPIO_a();
      while (!compass.begin()) {
        Serial.println("Could not find a valid 5883 sensor on first port, check wiring!");
        delay(500);
      } Serial.println("First sensor initialized");
    
      activate_I2C_GPIO_b();
      while (!compass.begin()) {
        Serial.println("Could not find a valid 5883 sensor on second port, check wiring!");
        delay(500);
      } Serial.println("Second sensor initialized");
    
    }
    
    
    void loop() {
      delay(20);
    
      activate_I2C_GPIO_a();
      readMagSensor();    
    
      activate_I2C_GPIO_b();
      readMagSensor();    
    
      Serial.println("");
    }
    

    P.S.: Also thanks to the ESP forum (link) who gave me very fast advice!

    P.S.: Here the results with a common SCL line and only two seperate SDA lines. Works comparable nice :-)

  • 6D Mouse DIY Link List

    09/15/2023 at 21:01 0 comments

    See the officale page I am maintening right now: link


    The professional product tear down: link or link or link 

    And here are all know DIY projects (only full 6D in this list)

    Project NameAuthorlinkPictureDetection / Electronics
    Mechanics
    OS3M Mousecolton.baldridgelink
    inductance to digital sensors for distance to w/ metal object as Stewart platform
    3D print (included printed spring mechanism)
    Shamrock SixnavBrian Lu
    (GreenCap)
    link

    IR LED + Phototransistor
    3D print with variable thickness (damping of IR light by displacement)
    3x X/Y detectionin 120° setting
    3D
    Printing + Springs
    Space Mushroomshiuralink1

    link_video
    Stewart platform made from potentiometers (3x 2D analog joysticks)3D printed
    spacefoxPepijn de Voslink1
    link_video
    Stewart platform made from potentiometers.3D prints & cuts from triplex
    6D (axsotic)valentin heunlink

    Simple  6D Space Mouse
    Bastel Baus
    link
    linear hall sensors
    3D printed with metal spring