Arduino as I2C slave talk to RPiPython i2c write_bus_data usageAardvark I2C VB programming issue… API is ambiguous with regard to WRITE functionArduino as slave with multiple i2c addressesI2C between RPI and Arduino using ProcessingRaspberry Pi as Slave in I2C and arduino as masterSending a JSON String via I2C between Arduino and RPi IOT C#How to read pot connected to arduino from Rpi using python and i2cI2C: Raspberry Pi (Master) read Arduino (Slave)RPi/Arduino I2C - Losing connection after some time (C++)Use Arduino Mega as I2C Slave with RPi3

Spicing up a moment of peace

How to save money by shopping at a variety of grocery stores?

Is this homebrew "Faerie Fire Grenade" unbalanced?

How to handle inventory and story of a player leaving

Can a network vulnerability be exploited locally?

Don't look at what I did there

Pen test results for web application include a file from a forbidden directory that is not even used or referenced

How can I improve my formal definitions

How to differentiate between two people with the same name in a story?

Could a complex system of reaction wheels be used to propel a spacecraft?

How do I portray irrational anger in first person?

I feel cheated by my new employer, does this sound right?

Are spot colors limited and why CMYK mix is not treated same as spot color mix?

How to understand payment due date for credit card?

Do manacles provide any sort of in-game mechanical effect or condition?

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

What checks exist against overuse of presidential pardons in the USA?

Journal published a paper, ignoring my objections as a referee

Inspiration for failed idea?

Normalized Malbolge to Malbolge translator

What are ways to record who took the pictures if a camera is used by multiple people

Should I use the words "pyromancy" and "necromancy" even if they don't mean what people think they do?

Can this planet in a binary star system exist?

Where should I draw the line on follow up questions from previous employer



Arduino as I2C slave talk to RPi


Python i2c write_bus_data usageAardvark I2C VB programming issue… API is ambiguous with regard to WRITE functionArduino as slave with multiple i2c addressesI2C between RPI and Arduino using ProcessingRaspberry Pi as Slave in I2C and arduino as masterSending a JSON String via I2C between Arduino and RPi IOT C#How to read pot connected to arduino from Rpi using python and i2cI2C: Raspberry Pi (Master) read Arduino (Slave)RPi/Arduino I2C - Losing connection after some time (C++)Use Arduino Mega as I2C Slave with RPi3






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I use an Arduino as I2C slave to treat some Ultrasonic sensors and send revelant data to a Raspberry. The code running on Arduino :



void setup() 
// initialize i2c as slave
Serial.begin(9600);
Wire.begin(SLAVE_ADDRESS);
// define callbacks for i2c communication
Wire.onReceive(receiveData);
Wire.onRequest(sendData);

// useless


void loop()
// useless


// callback for received data
void receiveData(int byteCount)
int i = 0;
while (Wire.available())
number[i] = (char) Wire.read();
i++;

number[i] = '';
Serial.println(atoi(number));
if(atoi(number) != 0) caseN = atoi(number);


int SonarSensor(int trigPin,int echoPin)

// uselesss


// callback for sending data
void sendData()
if(caseN == 1) Wire.write(distance1);
else if(caseN == 2) Wire.write(distance2);
else if(caseN == 3) Wire.write(distance3);
else if(caseN == 4) Wire.write(distance4);
else if(caseN == 5)

if(state == 0)

state = 1;
digitalWrite(ledPin, HIGH);

else

state = 0;
digitalWrite(ledPin, LOW);


else Wire.write(0);



I do a first version of the bus "chat" with Python and it works very well :



import smbus
import time

bus = smbus.SMBus(1)


address = 0x04

def writeNumber(value):
bus.write_byte(address, value)
return -1

def readNumber():
number = bus.read_byte_data(address, 1)
return number

while True:
data = raw_input("Enter the data to be sent : ")
data_list = list(data)
for i in data_list:
writeNumber(int(ord(i)))
time.sleep(.1)

writeNumber(int(0x0A))


I am trying to do the same in C but it looks a little bit more difficult :



#include "i2c-dev.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <string.h>

int main()
const int adapter_nr = 1;
char filename[20];
snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
const int file = open(filename, O_RDWR);
if (file < 0)
printf("Unable to connect to Atmega, I2C plugged ? DC ok ?");
exit(EXIT_FAILURE);


// Atmega address
const int addr = 0x04;

if(ioctl(file, I2C_SLAVE, addr) < 0)

printf("Fail to reach Atmega");
exit(EXIT_FAILURE);


const __u8 add = 5; // Ask to "distance 5"
i2c_smbus_write_byte_data(file, 0x04, add); // What is the adress ?


const __u8 reg = 0x0A;
const __s32 result = i2c_smbus_read_byte_data(file, reg);
if(result < 0)

printf("Fail to reach Atmega reg");
exit(EXIT_FAILURE);

else

printf("Distance %d cm n", result);


close(file);

return(EXIT_SUCCESS);



As I mentionned in the code, I don't know which register adress my Arduino slave has. I can see in the Arduino COM terminal a lot of 0 and only 0.



I hope you will understand my problem. Thanks.










share|improve this question






























    2















    I use an Arduino as I2C slave to treat some Ultrasonic sensors and send revelant data to a Raspberry. The code running on Arduino :



    void setup() 
    // initialize i2c as slave
    Serial.begin(9600);
    Wire.begin(SLAVE_ADDRESS);
    // define callbacks for i2c communication
    Wire.onReceive(receiveData);
    Wire.onRequest(sendData);

    // useless


    void loop()
    // useless


    // callback for received data
    void receiveData(int byteCount)
    int i = 0;
    while (Wire.available())
    number[i] = (char) Wire.read();
    i++;

    number[i] = '';
    Serial.println(atoi(number));
    if(atoi(number) != 0) caseN = atoi(number);


    int SonarSensor(int trigPin,int echoPin)

    // uselesss


    // callback for sending data
    void sendData()
    if(caseN == 1) Wire.write(distance1);
    else if(caseN == 2) Wire.write(distance2);
    else if(caseN == 3) Wire.write(distance3);
    else if(caseN == 4) Wire.write(distance4);
    else if(caseN == 5)

    if(state == 0)

    state = 1;
    digitalWrite(ledPin, HIGH);

    else

    state = 0;
    digitalWrite(ledPin, LOW);


    else Wire.write(0);



    I do a first version of the bus "chat" with Python and it works very well :



    import smbus
    import time

    bus = smbus.SMBus(1)


    address = 0x04

    def writeNumber(value):
    bus.write_byte(address, value)
    return -1

    def readNumber():
    number = bus.read_byte_data(address, 1)
    return number

    while True:
    data = raw_input("Enter the data to be sent : ")
    data_list = list(data)
    for i in data_list:
    writeNumber(int(ord(i)))
    time.sleep(.1)

    writeNumber(int(0x0A))


    I am trying to do the same in C but it looks a little bit more difficult :



    #include "i2c-dev.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <math.h>
    #include <string.h>

    int main()
    const int adapter_nr = 1;
    char filename[20];
    snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
    const int file = open(filename, O_RDWR);
    if (file < 0)
    printf("Unable to connect to Atmega, I2C plugged ? DC ok ?");
    exit(EXIT_FAILURE);


    // Atmega address
    const int addr = 0x04;

    if(ioctl(file, I2C_SLAVE, addr) < 0)

    printf("Fail to reach Atmega");
    exit(EXIT_FAILURE);


    const __u8 add = 5; // Ask to "distance 5"
    i2c_smbus_write_byte_data(file, 0x04, add); // What is the adress ?


    const __u8 reg = 0x0A;
    const __s32 result = i2c_smbus_read_byte_data(file, reg);
    if(result < 0)

    printf("Fail to reach Atmega reg");
    exit(EXIT_FAILURE);

    else

    printf("Distance %d cm n", result);


    close(file);

    return(EXIT_SUCCESS);



    As I mentionned in the code, I don't know which register adress my Arduino slave has. I can see in the Arduino COM terminal a lot of 0 and only 0.



    I hope you will understand my problem. Thanks.










    share|improve this question


























      2












      2








      2








      I use an Arduino as I2C slave to treat some Ultrasonic sensors and send revelant data to a Raspberry. The code running on Arduino :



      void setup() 
      // initialize i2c as slave
      Serial.begin(9600);
      Wire.begin(SLAVE_ADDRESS);
      // define callbacks for i2c communication
      Wire.onReceive(receiveData);
      Wire.onRequest(sendData);

      // useless


      void loop()
      // useless


      // callback for received data
      void receiveData(int byteCount)
      int i = 0;
      while (Wire.available())
      number[i] = (char) Wire.read();
      i++;

      number[i] = '';
      Serial.println(atoi(number));
      if(atoi(number) != 0) caseN = atoi(number);


      int SonarSensor(int trigPin,int echoPin)

      // uselesss


      // callback for sending data
      void sendData()
      if(caseN == 1) Wire.write(distance1);
      else if(caseN == 2) Wire.write(distance2);
      else if(caseN == 3) Wire.write(distance3);
      else if(caseN == 4) Wire.write(distance4);
      else if(caseN == 5)

      if(state == 0)

      state = 1;
      digitalWrite(ledPin, HIGH);

      else

      state = 0;
      digitalWrite(ledPin, LOW);


      else Wire.write(0);



      I do a first version of the bus "chat" with Python and it works very well :



      import smbus
      import time

      bus = smbus.SMBus(1)


      address = 0x04

      def writeNumber(value):
      bus.write_byte(address, value)
      return -1

      def readNumber():
      number = bus.read_byte_data(address, 1)
      return number

      while True:
      data = raw_input("Enter the data to be sent : ")
      data_list = list(data)
      for i in data_list:
      writeNumber(int(ord(i)))
      time.sleep(.1)

      writeNumber(int(0x0A))


      I am trying to do the same in C but it looks a little bit more difficult :



      #include "i2c-dev.h"
      #include <stdio.h>
      #include <stdlib.h>
      #include <fcntl.h>
      #include <errno.h>
      #include <math.h>
      #include <string.h>

      int main()
      const int adapter_nr = 1;
      char filename[20];
      snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
      const int file = open(filename, O_RDWR);
      if (file < 0)
      printf("Unable to connect to Atmega, I2C plugged ? DC ok ?");
      exit(EXIT_FAILURE);


      // Atmega address
      const int addr = 0x04;

      if(ioctl(file, I2C_SLAVE, addr) < 0)

      printf("Fail to reach Atmega");
      exit(EXIT_FAILURE);


      const __u8 add = 5; // Ask to "distance 5"
      i2c_smbus_write_byte_data(file, 0x04, add); // What is the adress ?


      const __u8 reg = 0x0A;
      const __s32 result = i2c_smbus_read_byte_data(file, reg);
      if(result < 0)

      printf("Fail to reach Atmega reg");
      exit(EXIT_FAILURE);

      else

      printf("Distance %d cm n", result);


      close(file);

      return(EXIT_SUCCESS);



      As I mentionned in the code, I don't know which register adress my Arduino slave has. I can see in the Arduino COM terminal a lot of 0 and only 0.



      I hope you will understand my problem. Thanks.










      share|improve this question














      I use an Arduino as I2C slave to treat some Ultrasonic sensors and send revelant data to a Raspberry. The code running on Arduino :



      void setup() 
      // initialize i2c as slave
      Serial.begin(9600);
      Wire.begin(SLAVE_ADDRESS);
      // define callbacks for i2c communication
      Wire.onReceive(receiveData);
      Wire.onRequest(sendData);

      // useless


      void loop()
      // useless


      // callback for received data
      void receiveData(int byteCount)
      int i = 0;
      while (Wire.available())
      number[i] = (char) Wire.read();
      i++;

      number[i] = '';
      Serial.println(atoi(number));
      if(atoi(number) != 0) caseN = atoi(number);


      int SonarSensor(int trigPin,int echoPin)

      // uselesss


      // callback for sending data
      void sendData()
      if(caseN == 1) Wire.write(distance1);
      else if(caseN == 2) Wire.write(distance2);
      else if(caseN == 3) Wire.write(distance3);
      else if(caseN == 4) Wire.write(distance4);
      else if(caseN == 5)

      if(state == 0)

      state = 1;
      digitalWrite(ledPin, HIGH);

      else

      state = 0;
      digitalWrite(ledPin, LOW);


      else Wire.write(0);



      I do a first version of the bus "chat" with Python and it works very well :



      import smbus
      import time

      bus = smbus.SMBus(1)


      address = 0x04

      def writeNumber(value):
      bus.write_byte(address, value)
      return -1

      def readNumber():
      number = bus.read_byte_data(address, 1)
      return number

      while True:
      data = raw_input("Enter the data to be sent : ")
      data_list = list(data)
      for i in data_list:
      writeNumber(int(ord(i)))
      time.sleep(.1)

      writeNumber(int(0x0A))


      I am trying to do the same in C but it looks a little bit more difficult :



      #include "i2c-dev.h"
      #include <stdio.h>
      #include <stdlib.h>
      #include <fcntl.h>
      #include <errno.h>
      #include <math.h>
      #include <string.h>

      int main()
      const int adapter_nr = 1;
      char filename[20];
      snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
      const int file = open(filename, O_RDWR);
      if (file < 0)
      printf("Unable to connect to Atmega, I2C plugged ? DC ok ?");
      exit(EXIT_FAILURE);


      // Atmega address
      const int addr = 0x04;

      if(ioctl(file, I2C_SLAVE, addr) < 0)

      printf("Fail to reach Atmega");
      exit(EXIT_FAILURE);


      const __u8 add = 5; // Ask to "distance 5"
      i2c_smbus_write_byte_data(file, 0x04, add); // What is the adress ?


      const __u8 reg = 0x0A;
      const __s32 result = i2c_smbus_read_byte_data(file, reg);
      if(result < 0)

      printf("Fail to reach Atmega reg");
      exit(EXIT_FAILURE);

      else

      printf("Distance %d cm n", result);


      close(file);

      return(EXIT_SUCCESS);



      As I mentionned in the code, I don't know which register adress my Arduino slave has. I can see in the Arduino COM terminal a lot of 0 and only 0.



      I hope you will understand my problem. Thanks.







      c arduino raspberry-pi i2c






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 22:11









      NicolasColsoulNicolasColsoul

      213 bronze badges




      213 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          0















          Why not define the slave address so you will know exactly what it is. Plus this will allow you to set different address if in the future you use more than 1 arduino.



          Run this line of code before Setup on the arduino. You can change the address to anything you want as long as it isn't used by another system on the I2C connection.



          #define SLAVE_ADDRESS 0x29 //slave address,any number from 0x01 to 0x7F


          Here is a Tutorial discussing using Arduino as a slave






          share|improve this answer

























          • Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

            – NicolasColsoul
            Mar 28 at 8:56












          • Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

            – Hojo.Timberwolf
            Mar 28 at 8:59











          • It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

            – NicolasColsoul
            Mar 28 at 9:59


















          0















          You need to know the correct I2C slave address that your Arduino is using.



          Luckily, Raspberry Pi has can detect any I2C device connected and show you their address using the following command:



          sudo i2cdetect -y 1


          or



          sudo i2cdetect -y 0


          Note: The first command works for all the latest Raspberry Pi3 and Pi2 (models A, B, B +) and Pi Zero. The second command is only if you are using older models.



          For more information you can have a look at here (Enable I2C) or here (Configuring I2C). Both are similar and you can just skip to the bottom where they explain how to use the above command.






          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387243%2farduino-as-i2c-slave-talk-to-rpi%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0















            Why not define the slave address so you will know exactly what it is. Plus this will allow you to set different address if in the future you use more than 1 arduino.



            Run this line of code before Setup on the arduino. You can change the address to anything you want as long as it isn't used by another system on the I2C connection.



            #define SLAVE_ADDRESS 0x29 //slave address,any number from 0x01 to 0x7F


            Here is a Tutorial discussing using Arduino as a slave






            share|improve this answer

























            • Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

              – NicolasColsoul
              Mar 28 at 8:56












            • Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

              – Hojo.Timberwolf
              Mar 28 at 8:59











            • It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

              – NicolasColsoul
              Mar 28 at 9:59















            0















            Why not define the slave address so you will know exactly what it is. Plus this will allow you to set different address if in the future you use more than 1 arduino.



            Run this line of code before Setup on the arduino. You can change the address to anything you want as long as it isn't used by another system on the I2C connection.



            #define SLAVE_ADDRESS 0x29 //slave address,any number from 0x01 to 0x7F


            Here is a Tutorial discussing using Arduino as a slave






            share|improve this answer

























            • Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

              – NicolasColsoul
              Mar 28 at 8:56












            • Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

              – Hojo.Timberwolf
              Mar 28 at 8:59











            • It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

              – NicolasColsoul
              Mar 28 at 9:59













            0














            0










            0









            Why not define the slave address so you will know exactly what it is. Plus this will allow you to set different address if in the future you use more than 1 arduino.



            Run this line of code before Setup on the arduino. You can change the address to anything you want as long as it isn't used by another system on the I2C connection.



            #define SLAVE_ADDRESS 0x29 //slave address,any number from 0x01 to 0x7F


            Here is a Tutorial discussing using Arduino as a slave






            share|improve this answer













            Why not define the slave address so you will know exactly what it is. Plus this will allow you to set different address if in the future you use more than 1 arduino.



            Run this line of code before Setup on the arduino. You can change the address to anything you want as long as it isn't used by another system on the I2C connection.



            #define SLAVE_ADDRESS 0x29 //slave address,any number from 0x01 to 0x7F


            Here is a Tutorial discussing using Arduino as a slave







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 8:40









            Hojo.TimberwolfHojo.Timberwolf

            5594 silver badges18 bronze badges




            5594 silver badges18 bronze badges















            • Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

              – NicolasColsoul
              Mar 28 at 8:56












            • Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

              – Hojo.Timberwolf
              Mar 28 at 8:59











            • It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

              – NicolasColsoul
              Mar 28 at 9:59

















            • Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

              – NicolasColsoul
              Mar 28 at 8:56












            • Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

              – Hojo.Timberwolf
              Mar 28 at 8:59











            • It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

              – NicolasColsoul
              Mar 28 at 9:59
















            Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

            – NicolasColsoul
            Mar 28 at 8:56






            Thanks for your answer but it is already done. See the line Wire.begin(SLAVE_ADDRESS);

            – NicolasColsoul
            Mar 28 at 8:56














            Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

            – Hojo.Timberwolf
            Mar 28 at 8:59





            Calling SLAVE_ADDRESS without defining though makes it the default. Your question was about what the slave address is correct? By defining it you will know exactly what the slave address is, or is that not the question?

            – Hojo.Timberwolf
            Mar 28 at 8:59













            It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

            – NicolasColsoul
            Mar 28 at 9:59





            It is defined, I remove useless lines to improve visibility. #define SLAVE_ADDRESS 0x04

            – NicolasColsoul
            Mar 28 at 9:59













            0















            You need to know the correct I2C slave address that your Arduino is using.



            Luckily, Raspberry Pi has can detect any I2C device connected and show you their address using the following command:



            sudo i2cdetect -y 1


            or



            sudo i2cdetect -y 0


            Note: The first command works for all the latest Raspberry Pi3 and Pi2 (models A, B, B +) and Pi Zero. The second command is only if you are using older models.



            For more information you can have a look at here (Enable I2C) or here (Configuring I2C). Both are similar and you can just skip to the bottom where they explain how to use the above command.






            share|improve this answer





























              0















              You need to know the correct I2C slave address that your Arduino is using.



              Luckily, Raspberry Pi has can detect any I2C device connected and show you their address using the following command:



              sudo i2cdetect -y 1


              or



              sudo i2cdetect -y 0


              Note: The first command works for all the latest Raspberry Pi3 and Pi2 (models A, B, B +) and Pi Zero. The second command is only if you are using older models.



              For more information you can have a look at here (Enable I2C) or here (Configuring I2C). Both are similar and you can just skip to the bottom where they explain how to use the above command.






              share|improve this answer



























                0














                0










                0









                You need to know the correct I2C slave address that your Arduino is using.



                Luckily, Raspberry Pi has can detect any I2C device connected and show you their address using the following command:



                sudo i2cdetect -y 1


                or



                sudo i2cdetect -y 0


                Note: The first command works for all the latest Raspberry Pi3 and Pi2 (models A, B, B +) and Pi Zero. The second command is only if you are using older models.



                For more information you can have a look at here (Enable I2C) or here (Configuring I2C). Both are similar and you can just skip to the bottom where they explain how to use the above command.






                share|improve this answer













                You need to know the correct I2C slave address that your Arduino is using.



                Luckily, Raspberry Pi has can detect any I2C device connected and show you their address using the following command:



                sudo i2cdetect -y 1


                or



                sudo i2cdetect -y 0


                Note: The first command works for all the latest Raspberry Pi3 and Pi2 (models A, B, B +) and Pi Zero. The second command is only if you are using older models.



                For more information you can have a look at here (Enable I2C) or here (Configuring I2C). Both are similar and you can just skip to the bottom where they explain how to use the above command.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 16 at 11:22









                I AI A

                11 bronze badge




                11 bronze badge






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387243%2farduino-as-i2c-slave-talk-to-rpi%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript