Go Down

Topic: Problem: I2C Configuration Between Two Arduinos (Read 982 times) previous topic - next topic

012anonymousxyz

Hello and thank you all! Here are my codes:
Arduino Master:
Code: [Select]

#include <Wire.h>

int counter = 0;

void setup() {
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(1);
  Wire.write(counter);
  Wire.endTransmission();
  counter++;
  delay(1000);
}

Arduino Slave:
Code: [Select]

#include <Wire.h>

int val = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin(1);
}

void loop() {
  val = Wire.read();
  Serial.println(val);
  delay(1000);
}


My problem is that the serial monitor only prints -1 repeatedly, indicating that I'm not receiving any data (I had a while loop waiting for serial data (Wire.available()==0) but got rid of it because there was no printing going on period.
I think it might be a physical configuration thing:
I have both the A5 pins connected to a rail on my breadboard, which is connected to high via a 10k ohm resistor.
I have both the A4 pins connected to a rail on my breadboard, which is connected to high via a 10k ohm resistor.
I have the ground pins on my two Arduinos connected to each other.
I have a ground pin from my slave Arduino connected to my breadboard.
I have one 5V output pin from my slave Arduino connected to my breadboard

PaulS

#1
Feb 12, 2013, 06:27 pm Last Edit: Feb 12, 2013, 06:29 pm by PaulS Reason: 1
On the slave, you should have an onRequest event handler registered. That gets called when the master wants to talk to the slave.

Quote
I had a while loop waiting for serial data (Wire.available()==0) but got rid of it because there was no printing going on period.

I2C is not serial. That Wire.available() never reported a value greater than 0 should be a clue that the devices are not talking.

Show a picture or schematic of your setup.

Quote
I have both the A5 pins connected to a rail on my breadboard, which is connected to high via a 10k ohm resistor.
I have both the A4 pins connected to a rail on my breadboard, which is connected to high via a 10k ohm resistor.

This does not sound right. The I2C pins should not be connected the +V rail.
The art of getting good answers lies in asking good questions.

MaLi

Google Nick Gammon. He wrote a nice master/slave routine for sending data between two arduinos.

hope it helps,
MaLi

Go Up