1

Somehow during an experiment, I managed to wreck my i2c SDA and SCL pins on my raspberry pi (pins 3 & 5). I was considering converting two of my gpio pins into another i2c bus, but I thought it might simply be easier to somehow re-purpose my EEprom i2c pins (pins 27 & 28) to act in the same fashion as pins I blew, since they're already affiliated with i2c.

I know that generally you shouldn't mess with these pins since they're critical when it comes to communicating with HATs for the raspberry pi. However, in my specific case, I don't plan on having any HATs, just direct communication with one i2c device.

If it's really necessary, the device I'm trying to communicate with is the mcp23008 on the mcp23x08 eval-board.

I'd love to know if this approach is possible and if so, what is the best way to approach?

-Thanks

  • It's possible but it isn't recommended as GPIO0 & GPIO1 don't have the pullup resistors and they're reserved for use by an official HAT. – Dougie Apr 8 at 12:42
  • Even if I were to use GPIO0 & 1, I'm guessing the procedure would be similar to using any other GPIO? ie. utilizing overlays and editing /boot/config.txt? – Shaun the Sheep Apr 8 at 12:53
2

It is simpler just to use another pair of GPIO as a software I2C bus.

There is no real advantage in using GPIO 0/1.

Whatever you do you will need to ensure that the GPIO you use are conneted to pull-ups to 3V3. I suggest you use resistors in the range 2 to 4 k ohm for the pulls.

See /boot/overlays/README for details of creating a software I2C bus.

Name:   i2c-gpio
Info:   Adds support for software i2c controller on gpio pins
Load:   dtoverlay=i2c-gpio,<param>=<val>
Params: i2c_gpio_sda            GPIO used for I2C data (default "23")

        i2c_gpio_scl            GPIO used for I2C clock (default "24")

        i2c_gpio_delay_us       Clock delay in microseconds
                                (default "2" = ~100kHz)

        bus                     Set to a unique, non-zero value if wanting
                                multiple i2c-gpio busses. If set, will be used
                                as the preferred bus number (/dev/i2c-<n>). If
                                not set, the default value is 0, but the bus
                                number will be dynamically assigned - probably
                                3.

E.g. to add an I2C bus #3 using GPIO 17 for SDA and GPIO 27 for SCL add the following entry to /boot/config.txt

dtoverlay=i2c-gpio,i2c_gpio_sda=17,i2c_gpio_scl=27,bus=3

| improve this answer | |
  • Alright, thanks for the insight. – Shaun the Sheep Apr 8 at 12:07
  • I do have to ask though, what makes the EEPROM pins so different from pins 3 & 5 that would make using them as a regular i2c bus so inconvenient? Also, since the EEPROM are already i2c, doesn't that mean that they already have pull up resistors installed, meaning that I wouldn't need to add any external pull up resistors? – Shaun the Sheep Apr 8 at 16:53
  • Use them if you want. I don't know if doing so will screw up the system or not. You will soon find out. The I2C bus requires pull-ups. Breakout modules for I2C devices sometimes have pulls fitted. However they might be to 5V which would damage the Pi GPIO. – joan Apr 8 at 17:00
  • What kind of damage do you think it would cause? As in damage with interfacing with devices via i2c or damage to the pi itself and operation? – Shaun the Sheep Apr 8 at 17:05
  • Connect 5V to a Pi GPIO? Damage in the sense the GPIO would stop working followed by the Pi not working and needing to buy a new one. – joan Apr 8 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.