1

I am trying to accomplish 1-wire communication between 2 Arduinos and so I wanted to start off by having 1 Arduino toggle a digital output pin and have the other read the state of that pin. To accomplish this, I have 2 computers with Arduino IDE installed and each one is connected to one Arduino Uno. Both Arduino Uno's are connected with a single male-male jumper cable on Pin 13 of the header. I am watching the state of the pin by looking at the prints in the Serial Console on both computers.

Here is a diagram of my setup:

Computer1 ---> Arduino1[Sender] --------> Arduino2[Receiver] -----> Computer2

The problem I have is that I am seeing when I first start both Arduinos - the sender is definitely toggling the output pin high->low->high forever - but the receiver Arduino only shows its input pin as toggling for a few seconds and then it gets stuck high. Sometime later, it may go low for 1 iteration, but then sticks at high again. What is going on? I would expect to see the sender and receiver show high->low->high forever. The code seems simple but I must be doing something wrong - thanks for your help.

Sender Code:

int led = 13; // Comm Pin

// Setup pins
void setup() {

  // put your setup code here, to run once:
  Serial.begin(9600);

  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);

}

void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("high");
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("low");
  delay(1000);               // wait for a second
}

Receiver Code:

int led = 13; // Comm Pin

// Setup pins
void setup() {

  // put your setup code here, to run once:
  Serial.begin(9600);

  // Pin is an input - normal state high
  pinMode(led, INPUT);

}
void loop() {

  // Put your main code here, to run repeatedly:
  Serial.println(digitalRead(led));
  delay(1000);

}
2
  • 4
    Do both Arduino share common GND? If not, your circuit just cannot work the way you want.
    – jfpoilpret
    Jun 12, 2015 at 4:28
  • 1
    You should try to reduce the refresh time period on the receiver to 100ms and check if this still happens.
    – jfpoilpret
    Jun 12, 2015 at 4:30

1 Answer 1

-1

You should add a random delay in setup of receiver and reduce the sampling time of the receiver to 200ms.

That said, digital communication is an INSANELY EXTREMELY complex process, especially on the physical layer. This is not the correct way for two arduinos to digitally communicate.

Unless you are a teacher and are trying to demonstrate why this would fail, (not criticising), you mustn't use it.

You should use the Arduino wire library to establish communication instead. You can send whole integers, and it's totally reliable (it uses hash checks, guaranteeing correct communication even at 1152000 baud). As a comparison, you're at 1 baud.

You can get a tutorial here: http://www.instructables.com/id/I2C-between-Arduinos/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.