I2C between arduinos

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/

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:

#include <Wire.h>

1 Like

See the IDE example projects for the Wire library.

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

Thank you, I will do that.

This library ? 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.

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.

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).

1 Like

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:

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

// 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);
}

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

1 Like

Fair enough

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:

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

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

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?

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