Forsco
Posts: 1
Joined: Sun Apr 26, 2015 4:00 pm

is it possible to turn gpio pins in to i2c pins???

Mon Apr 27, 2015 7:05 pm

I was wondering if it is possible to assigin gpio pin to be i2c pins so that I can have multipul i2c pins? this is since one i2c pin will only allow me to control four “8x8 adafruit led backpacks” at once where as I am trying to control 9 at once so I need the additional i2c pins to do this. so the question I am asking is if it is possible to assign gpios to be i2c pins and if so how to do so. however if this is not possible a recommendation as to alternative solution would also be greatly appreciated.

User avatar
joan
Posts: 13930
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 27, 2015 7:50 pm

Recent Pi's have two I2C buses (gpios 0/1 and 2/3). However use of bus 0 (gpios 0/1) is discouraged.

You could bit bang I2C on other gpios.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 27, 2015 8:03 pm

joan wrote:You could bit bang I2C on other gpios.
'bit bang' is a pejorative term meaning that you actually provide the clock and data signals yourself within your own code and with your own timings; this is usually discouraged because the timings are not as precise (at the high level) as they might otherwise be at a lower level within the i2c library code.

The answer to your question is 'yes,' you may assign any of the 'general purpose' input output pins for the job of i2c sda and scl; this is what Joan means by 'bit banging'.

I will further add that the i2c protocol is fiendish. It is one of the most convoluted difficult to understand and contrary protocols in the industry... with a good library support i2c is usable once you get the hang of it, but its finicky and its prone to be grumpy. You've been warned.
marcus
:ugeek:

User avatar
DougieLawson
Posts: 35163
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 27, 2015 8:14 pm

There's already a second set of i2c_vc pins (/dev/i2c-0), but BEWARE they don't have the resistors to be OK with a 5V0 I2C device.

physical pin #27 is SDA0, physical pin #28 is SCL0, they're intended to be used by the EEPROM on an official HAT board.
http://pi.gadgetoid.com/pinout/i2c
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 27, 2015 8:21 pm

DougieLawson wrote: physical pin #27 is SDA0, physical pin #28 is SCL0, they're intended to be used by the EEPROM on an official HAT board.
http://pi.gadgetoid.com/pinout/i2c
Dougie just reminded me, the most important reason why you don't want to do this yourself... it is possible, if you are not *very* careful, to over-write an eeprom on a HAT board and destroy it! So, you not only have the opportunity to have the wrong voltage level on an IO pin (possibly destroying one of your IO blocks, if not the entire PI) but also have your HAT board never work again.

:)
... are we having fun yet?
marcus
:ugeek:

User avatar
mikronauts
Posts: 2702
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 27, 2015 9:21 pm

bit banging even 100khz I2C will use up a significant fraction of a Raspberry Pi's CPU.

This is less of a concern on a Pi2 as it has four cores, but is definitely a waste.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi


User avatar
rpdom
Posts: 14167
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 15, 2019 1:13 pm

Was this really worth reviving a four-year-old dead topic for?
Signature is on holiday.

User avatar
procount
Posts: 1627
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 15, 2019 1:42 pm

Just in case this nekro sparks interest in anyone else, you can now get the kernel to bitbang i2c on any gpio using the i2c-gpio overlay.
Search /boot/overlays/README for i2c-gpio in Raspbian.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22245
Joined: Sat Jul 30, 2011 7:41 pm

Re: is it possible to turn gpio pins in to i2c pins???

Mon Apr 15, 2019 2:03 pm

It might be a necro, but its still valid AFAICT.

4 years? Pah, we had one the other day that was over 5 IIRC.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Return to “Advanced users”