ESP32 I2C mapping

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 I2C mapping

Postby WiFive » Sun Dec 31, 2017 9:08 am

Yes the hw support for 2 i2c can work with the right software tweaks which is what I said before

"only one is configured by default" means DIY

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 I2C mapping

Postby Duhjoker » Sun Dec 31, 2017 9:46 am

where should these tweaks take place? In the arduino/esp libraries? Or in the joy example? Will the defines I made in pins Arduino work?
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 I2C mapping

Postby Duhjoker » Sun Dec 31, 2017 11:43 pm

Could I please get some help on changing the pin assignments? ive googled "esp32 change pin out", "esp32 change pin assignment and every other way I could think of but I cant find any information on how to do so. What all do I need to do to add a second set of i2c ports?
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 I2C mapping

Postby WiFive » Mon Jan 01, 2018 2:33 am

You have to create a new twowire device for the second one

https://github.com/espressif/arduino-es ... e.cpp#L221

Then you have to make your libraries talk to the correct instance

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 I2C mapping

Postby Duhjoker » Mon Jan 01, 2018 7:43 am

I need to make a new two wire with the sda and scl pointing at the second set of pinouts I defined in pins_arduino?

I tried adding this to the wire.cpp but it just caused redefinition errors...

TwoWire Wire = TwoWire(1);

or should it be

TwoWire2 = TwoWire(1);
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 I2C mapping

Postby WiFive » Mon Jan 01, 2018 8:15 am

Code: Select all

TwoWire Wire2 = TwoWire(1);

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 I2C mapping

Postby Duhjoker » Mon Jan 01, 2018 9:36 am

Awesome thank you. Ok now how do I get that instance to point to the right pins? Or what is my next step?
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 I2C mapping

Postby WiFive » Mon Jan 01, 2018 11:06 am

Wire2.begin(SDA2, SCL2, freq)

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 I2C mapping

Postby Duhjoker » Tue Jan 02, 2018 1:22 am

Awesome!!! You rock!!! Thank you!!! Ok this seems pretty simple so far. So now it point to the pins that I changed in pins_arduino? Now about those pins.... What basic functions must the pins have to use them as my secondary I2C? I would like to have one set on one side of the huzzah and the secondary set on the other side. This will make it easier to shorten the lines due to placement of the huzzah on the back of the screen.

the pins are described here..

Code: Select all

Bottom row:
A0 - this is an analog input A0 and also an analog output DAC2. It can also be used as a GPIO #26
A1 - this is an analog input A1 and also an analog output DAC1. It can also be used as a GPIO #25
A2 - this is an analog input A2 and also GPI #34. Note it is not an output-capable pin!
A3 - this is an analog input A3 and also GPI #39. Note it is not an output-capable pin!
A4 - this is an analog input A4 and also GPI #36. Note it is not an output-capable pin!
A5 - this is an analog input A5 and also GPIO #4
21 - General purpose IO pin #21
Top row:
13 - This is GPIO #13 and also an analog input A12. It's also connected to the red LED next to the USB port
12 - This is GPIO #12 and also an analog input A11. This pin has a pull-down resistor built into it, we recommend using it as an output only, or making sure that the pull-down is not affected during boot.
27 - This is GPIO #27 and also an analog input A10
33 - This is GPIO #33 and also an analog input A9. It can also be used to connect a 32 KHz crystal.
15 - This is GPIO #15 and also an analog input A8
32 - This is GPIO #32 and also an analog input A7. It can also be used to connect a 32 KHz crystal.
14 - This is GPIO #14 and also an analog input A6
can analog pins be used? I need to be able to use the bottom row pins.

Do I need to add the SDA2 and SCL2 to the begin and protected in wire .h?

Code: Select all

TwoWire::TwoWire(uint8_t bus_num)
    :num(bus_num & 1)
    ,sda(-1)
    ,scl(-1)
    ,i2c(NULL)
    ,rxIndex(0)
    ,rxLength(0)
    ,txIndex(0)
    ,txLength(0)
    ,txAddress(0)
    ,transmitting(0)
{}

void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
{
    if(sdaPin < 0) {
        if(num == 0) {
            sdaPin = SDA;
        } else {
            return;
        }
    }

    if(sclPin < 0) {
        if(num == 0) {
            sclPin = SCL;
        } else {
            return;
        }
    }

    if(i2c == NULL) {
        i2c = i2cInit(num, 0, false);
        if(i2c == NULL) {
            return;
        }
    }

    i2cSetFrequency(i2c, frequency);

    if(sda >= 0 && sda != sdaPin) {
        i2cDetachSDA(i2c, sda);
    }

    if(scl >= 0 && scl != sclPin) {
        i2cDetachSCL(i2c, scl);
    }

    sda = sdaPin;
    scl = sclPin;

    i2cAttachSDA(i2c, sda);
    i2cAttachSCL(i2c, scl);

    flush();

    i2cInitFix(i2c);
}
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 I2C mapping

Postby Duhjoker » Wed Jan 03, 2018 3:43 am

Ok guys I'm almost there..... Whats the next step? any of the above?
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Who is online

Users browsing this forum: No registered users and 55 guests