The RPi and arduino are connected by I2C and the arduino sends coordinates to the RPi through the wire library. However, the RPi only receives and prints out 0 when it should print out the coordinate.

Here is the arduino code:

int pushButton = 2;
#include <Wire.h>

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  // print out the state of the button:


         // delay in between reads for stability

Here is the RPi code:

enter image description here


I2C is a bus, i.e. there can be many devices on the bus.

As it is a bus there is a need to prevent devices interfering with each others communications.

To that end the bus is designed to have one master and one or more slaves.

The master initiates all communication. It chooses the slave to communicate with as part of the I2C transaction.

The Raspberry Pi (with the standard Linux driver) only operates as a master.

In your example the Pi must request the data (as it does) but the Arduino must be a slave and must only place data on the bus during the requested transaction.

You will have to rewrite your Arduino code to act as a slave. Don't ask me how as I haven't used I2C on an Arduino.

| improve this answer | |

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.