Home:ALL Converter>Arduino Master - Slave setup

Arduino Master - Slave setup

Ask Time:2015-07-19T05:34:10         Author:Ste Prescott

Json Formatter

The master board is a Arduino Uno and the slave is a Arduino Yun. I have them both wired up using A4 & A5 of one board to attach to the A4 & A5 pin on the other. They are both powered separately but share the same ground like the diagram below.

Board setup

The code for both master and slave are below. If the slave board is not powered the master knows it can not talk to the slave and won't print out Loop until the slave is powered. This suggests that the master knows of the slave.

However the slave never receives this signal from the master. receiveEvent is never called.

I am doing this as I have ran out of pins on the master and want the slave to control a LCD display that takes up several pins as I'm sure you all know.

Any help would be great, thanks.

Master

#include <Wire.h>

#define SLAVE_ADDRESS 0x9

void setup() {
  Serial.begin(9600); 

  Wire.begin();

  delay(1000);
}

void loop() {
    Wire.beginTransmission(SLAVE_ADDRESS);
    Wire.write('T');
    Wire.endTransmission();
    Serial.println("Loop");
    delay(1000);
}

Slave

#include <Wire.h>

#define SLAVE_ADDRESS 0x9

void setup() {
  Serial.begin(9600); 

  delay(1000);

  Wire.begin(SLAVE_ADDRESS);
  Wire.onReceive(receiveEvent);

  Serial.println("Setup");
}

void loop() {
//  Serial.println("Loop");
}

void receiveEvent(int howMany){
  Serial.println("Receive event");

  while (Wire.available() > 0)
  {
    char c = Wire.read();
    Serial.println(c);
  }
}

Author:Ste Prescott,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31495802/arduino-master-slave-setup
yy