Is it possible to connect an external I2C device?


If I look at the STM32 specs it seems that I2C1 is availble on pins PB5, PB6 and PB7 and they are connected to the SparkCore D2, D1 and D0. Therefor I assume that those pins can be used as an I2C interface to an external I2C device. Is this assumption correct?


That’s correct, Henk!

Thanks Zach. I need some more I/O, now I can plan to use an I2C I/O expander.

@zach would these pins (D1, D0) be used through an implementation of the Arduino Wire library? Is this currently available in the code?

1 Like

I’m curious about this as well. I would like to port some code from an Arduino to the SparkCore, which is currently using this library (from dsscircuits)

We are in the process of making most of the native Arduino libraries available on the Spark Core, which also includes Arduino Wire!


Currently I have an arduino uno connected to other arduinos via i2c. I would like to substitute the uno master with the spark core.
Since all the slaves are working using 5V, and the spark core uses a 3.3V what should I do in order to safely make an i2c communication between the spark and arduinos?
Thank you

dk, I think Zach said on another thread that the digital pins on the spark core are all 5V tolerant, so it should be ok to connect your i2c pullup resistors to 5V.

The other option is to connect the pullup resistors to 3.3V. This would probably also be ok, since most 5V devices will read 3.3V as a high signal level. However, if you attached a large number of i2c devices to the bus, or used long lines, this might become marginal.

@d82k The I/O lines used for I2C communication on the Core aren’t 5V tolerant. You would need to use a logic level convertor in-between. One solution is to use the Spark Shield-Shield which has an on-board logic level convertor (TXB0108).

The hardware files for this Shield are available on GitHub here.


I double checked with the datasheet and it turns out that the SCL and SDA lines are indeed 5V tolerant but the optional SMBA pin isn’t. So one could indeed get away without using a level convertor. (unconfirmed)

Thank you @PaulRB and @mohit for your replies, so this looks like I can freely connect the spark core (as master) to the other two homemade arduinos running 5V via I2C…
Regarding the pull up resistors, should I use them or are not necessary? between SCL and SDA pins of the spark core and 3.3V or the 5V?
thank you again,

You have to use pull-up resistors (unless one of the devices on the bus already has them fitted, but they usually don’t). I2c bus devices use open-collector outputs. They can only pull down, so you need those resistors to pull up. The internal pull-up resistors on the atmega chips are not really strong enough.

Not that anyone is asking here, but missing documentation made this a frustrating journey for me: If anyone is using an Arduino Due, the SDA and SCL data lines have internal 1k pull-up resistors on them, so you don’t need to worry about it, and that board - like the Spark Core - uses 3.3V, making it a natural fit for pairing with the Spark, and it’s about four times faster than an uno.

Beware, though, if you have more than 3 or 4 Dues on the bus, the 1k’s are all basically in parallel, and you’ll approach the current limits of the pins, possibly to the demise of hundreds of dollars worth of electronics! The solution to this that I’ve found is to use the SDA1 and SCL1 pins packaged on the Due for boards subsequent to the first, as they do NOT have pull-up resistors. That data is accessed using the Wire1 instance of TwoWire rather than Wire.

1 Like

Are you sure? I read that because of a high pull up need (to detect for the bidirectionnal) that it does not support i2c.