# I2C between arduinos

**URL:** <https://forum.arduino.cc/t/i2c-between-arduinos/1141373>\
**Category:** General Guidance\
**Created:** [June 25, 2023, 1:38am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373 "2023-06-25T01:38:01Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 1:38am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/1 "2023-06-25T01:38:01Z")

</div>

I am trying to create a master and slave connection between two arduino and in the tutorial that I am using it states that I have include the \<Wire.h\> library but when I type it into the search bar in the IDE there is no result. My question is: is there another library that does the same thing or a way to get the library from a different source? Furthermore, will AS3935MI library work? The description states:  
Supports I2C and SPI via the Wire and SPI libraries, respectively  
Supports I2C and SPI interfaces via other libraries (e.g. Software I2C) by inheritance  
Automatic antenna tuning

Tutorial:[https://www.instructables.com/I2C-between-Arduinos/](https://www.instructables.com/I2C-between-Arduinos/)

---

<div class="post-metadata">

**Author:** ![gm310509](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gm310509/32/618767_2.png) [@gm310509](https://forum.arduino.cc/u/gm310509)\
**Post date:** [June 25, 2023, 1:42am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/2 "2023-06-25T01:42:34Z")

</div>

I am not sure which "search bar" you are referring to, but I believe the wire library comes with the Arduino IDE.

Thus all you need to do is enter this near the top of your program and before you attempt to use any of the "Wire" resources:

```arduino
#include <Wire.h>

```

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [June 25, 2023, 1:46am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/3 "2023-06-25T01:46:10Z")

</div>

> [@kf1989](#):
>
> when I type it into the search bar in the IDE there is no result.

See the IDE example projects for the Wire library.

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 1:46am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/4 "2023-06-25T01:46:30Z")

</div>

Oh okay, I have had to go into the library manager and install libraries before so I assumed it was the same with Wire.h

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 1:46am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/5 "2023-06-25T01:46:56Z")

</div>

Thank you, I will do that.

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [June 25, 2023, 1:54am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/6 "2023-06-25T01:54:26Z")

</div>

This library ? [https://bitbucket.org/christandlg/as3935mi/src/master/](https://bitbucket.org/christandlg/as3935mi/src/master/)  
I see no reason why it should not work.

Be careful when using the I2C bus to communicate between two Arduino boards. You can do that for testing and to learn from. For a real project, you better avoid it, especially when there are motors in the project. The I2C bus is a weak bus, because the high level is created with pullup resistors.

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 2:02am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/7 "2023-06-25T02:02:53Z")

</div>

So the reason that I am asking is because I am trying to make the RFID lock and include the screen without using a breadboard, I really just need more slots so that I can wire up the LCD to the system. I dont want to use a breadboard because I wont be able to mount it in the box. My idea was to add the master code in with the RFID code then the slave code to a different arduino so that I can use those connections.

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [June 25, 2023, 2:08am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/8 "2023-06-25T02:08:11Z")

</div>

> [@Koepel](#):
>
> Be careful when using the I2C bus to communicate between two Arduino boards

I have 2 years running 8 Nano, 1 master with 7 slaves, almost 3 feet between the master and the furthest slave, without problems (of course there are no motors in the project).

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 2:11am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/9 "2023-06-25T02:11:27Z")

</div>

So if I just add a file through the sketch tab and take out the void setup and void loop do you think it will work? How do you make the code work with 2 different sketches on one arduino?

Well, when I tried it I got some error codes:

```arduino
C:\Users\Anon\OneDrive\Desktop\Arduino Sketches\rfid-2source\FIQF6CLIBL621XX.ino:11:3: error: 'Wire' does not name a type
   Wire.begin();
   ^~~~
C:\Users\Anon\OneDrive\Desktop\Arduino Sketches\rfid-2source\FIQF6CLIBL621XX.ino:12:1: error: expected declaration before '}' token
 }
 ^

exit status 1

Compilation error: 'Wire' does not name a type

```

Master Code

```arduino
// Chapter 7 - Communications
// I2C Master
// By Cornel Amariei for Packt Publishing

// Include the required Wire library for I2C
#include <Wire.h>

int x = 0;

  // Start the I2C Bus as Master
  Wire.begin(); 
}

  Wire.beginTransmission(9); // transmit to device #9
  Wire.write(x); // sends x 
  Wire.endTransmission(); // stop transmitting
 
  x++; // Increment x
  if (x > 5) x = 0; // `reset x once it gets 6
  
  delay(500);
}

```

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [June 25, 2023, 2:37am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/10 "2023-06-25T02:37:41Z")

</div>

> [@kf1989](#):
>
> I got some error codes:

Learn a bit more about C/C++ before starting your own experiments.

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 2:40am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/11 "2023-06-25T02:40:14Z")

</div>

Fair enough

---

<div class="post-metadata">

**Author:** ![gm310509](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gm310509/32/618767_2.png) [@gm310509](https://forum.arduino.cc/u/gm310509)\
**Post date:** [June 25, 2023, 3:18am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/12 "2023-06-25T03:18:22Z")

</div>

Yeah there are a few that are included in the IDE.

There is probably a list online, but I've never seen one. Instead I use the github repository as a guide for which ones are included:

> **[ArduinoCore-avr/libraries at master · arduino/ArduinoCore-avr](https://github.com/arduino/ArduinoCore-avr/tree/master/libraries)**
>
> master/libraries

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 11:11am UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/13 "2023-06-25T11:11:35Z")

</div>

I did figure it out though haha got to love this forum.

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [June 25, 2023, 2:43pm UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/14 "2023-06-25T14:43:49Z")

</div>

The compiler says that the problem is in the file "FIQF6CLIBL621XX.ino".  
Can you show that file ?

---

<div class="post-metadata">

**Author:** ![kf1989](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kf1989](https://forum.arduino.cc/u/kf1989)\
**Post date:** [June 25, 2023, 2:54pm UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/15 "2023-06-25T14:54:51Z")

</div>

I was actually able to figure it out after I read a demo on how to run multiple .ino in the same sketch. I have gone a different direction sense then though as even with the master and slave done I didnt really see what i could use it for. I am really new to this and didnt seem like it was useful. What would you use it for?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 22, 2023, 2:54pm UTC](https://forum.arduino.cc/t/i2c-between-arduinos/1141373/16 "2023-12-22T14:54:59Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
