Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Arduino pro mini i2c slave

Tue Jul 26, 2016 2:21 pm

i'm starting to play with a arduino pro mini (clone from china) i bought some time ago.
Since it has digital pins, pwm control. analogue in and so on, i thought i would have found tons of sketches to turn this into a "sensor" for raspberry on i2c (something like a mcp23017 + a 8 ways adc and so on)
But my googling miserably failed so i'm wondering if i lost something (About feasibility of this task)
something like that a sketch managing i2c slave and all of this would never fit in arduino's memory.
On the other hand, this could be a stupid idea for a reason i'm missing :)


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

Re: Arduino pro mini i2c slave

Tue Jul 26, 2016 2:50 pm

Of course you can make the Atmel devices i2c slaves; whether there is a library to do this, I do not know-- nor do I care.

I am interested in making the arduino (or pyboard) into an i2S, SPI, or i2c 'slave'. Its very feasible , and will take far less memory than you suspect.

You will need to setup the registers, and you'll need to setup the protocol; which of course means that you will need to read-up on the i2c protocol and try to understand how to get your device to (not only communicate with your protocol) communicate on the i2c bus 'just lilke' any other i2c slave device on the bus !

i2c is tricky; at the low level where understanding occurs; don't get frustrated, dive in and learn. Its absolutely feasible.


Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Arduino pro mini i2c slave

Tue Jul 26, 2016 2:55 pm

it's much easier than that..
this seems to contain every info to create a "working" i2c slave, i'm surprised i could not find an available "pre made" sketch to make a sensor out of an arduino.. that's all :)

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

Re: Arduino pro mini i2c slave

Tue Jul 26, 2016 2:58 pm

There should be an example sketch to handle I2C.

Here's one which I have used on a TI Launchpad using Energia (a sort of clone of the Arduino IDE targeted at TI chips).

Code: Select all

// Wire Slave Receiver
// by Nicholas Zambetti <>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.

#include <Wire.h>

void setup()
  Wire.begin(41);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);           // start serial for output

void loop()

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
  while(1 < Wire.available()) // loop through all but the last
    char c =; // receive byte as a character
    Serial.print(c);         // print the character
  int x =;    // receive byte as an integer
  Serial.println(x);         // print the integer

void requestEvent()
  Wire.write("hello "); // respond with message of 6 bytes
                       // as expected by master

User avatar
Posts: 125
Joined: Mon Oct 29, 2012 2:56 pm
Contact: Website

Re: Arduino pro mini i2c slave

Wed Jul 27, 2016 6:53 am

Here is some good code for both Pi and Arduino, short and easy.

Beaware that there is a well known i2c bug on the Raspberry Pi to do with clock stretching. ... -217047171 ... c-bug.html

If you are planning on doing many reads a second, you will get random errors. Slowing down the i2c bus can help mitigate this.
Mark -- -- Creator of;
+ BerryIMU
+ Berry GPS-IMU
+ PiScreen - A 3.5" TFT for the Rasspberry Pi

Return to “Interfacing (DSI, CSI, I2C, etc.)”