We are trying to communicate between 2 Arduino's (1 Nano and 1 Mega) and a Raspberry Pi. This communication works till we add an SPI Connection to our RFID Scanner (RC522). We ran into the problem that the I2C stops working properly.

Not the same problem as the other question this problem involves SPI and the other not. The other problem has been solved.

Schematic: Schematic

Problem: I2C bus fills up after some time and when checked by Raspberry Pi all I2C communication stops. We think this happens because of the combination of SPI and I2C. But the problem only occurs when the RPI checks the I2C but with the ic2detect -y 1 command


Code Nano:

(We send RFID data to Mega)

#include <Wire.h>
#include "SPI.h"
#include "MFRC522.h"

#define SS_PIN 10
#define RST_PIN 9
#define SP_PIN 8

MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;

void setup() {


void loop() {


void requestEvent() {
 if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())

  // Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  // Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
      piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
      piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));

  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
      String(rfid.uid.uidByte[i], HEX) +
      (i != 3 ? ":" : "");
  Serial.print("Send to Mega: ");




Code Mega:

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
  Wire.requestFrom(0x10, 11);

  String uid = "";

  while (Wire.available()) {
    char c = "";
    c = Wire.read();
    uid += c;
  if (uid.indexOf(':') != 2) {


We would like to communicate between the Arduino's when the Raspberry Pi is master.

  • In this problem we have SPI and the other not. The other post has been solved. – Michielvk Nov 22 '17 at 14:45
  • The other says "the problem that the i2c communication failed between the Nano and Mega". This says " We ran into the problem that the I2C stops working properly." To me it looks like the same question. – user31481 Nov 22 '17 at 14:55
  • No, i2c works. Until we try to addd a spi communication. – Michielvk Nov 22 '17 at 15:04
  • @LookAlterno - I believe this is a totally different problem, the next step on, because now "they" have added pull up resistors. – Code Gorilla Nov 23 '17 at 13:50
  • 1
    @frarugi87 Your way of programming it is a lot better than our idea. And we will try to use the Pi as master and try to do what you suggested. Thanks in advance. – Michielvk Nov 29 '17 at 15:35