0

I am following this tutorial of a very basic serial communication between 2 arduino unos.

I have made the connections as given and connected the arduino unos to 2 separate laptops via USB.

Code1:

char mystr[3] = "Hello"; //String data

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
}

void loop() {
  Serial.write(mystr,5); //Write the serial data
  delay(1000);
}

Code 2:

char mystr[5]; //Initialized variable to store recieved data

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
}

void loop() {
  Serial.readBytes(mystr,5); //Read the serial data and store in var
  delay(1000);
}

Error on arduino following code 1:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 1602 bytes (4%) of program storage space. Maximum is 32256 bytes.
Global variables use 188 bytes (9%) of dynamic memory, leaving 1860 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Arduino running code 2 is stuck on the uploading and does not fininsh uploading.

The solutions on the internet only talk of the scenarios where the arduino is having trouble communication with the computer and so the solutions given are:

  1. check com port
  2. check that correct board is selected
  3. do not insert the arduinos in usb 3
  4. press reset button

None of these is my problem as I have checked them all. The arduinos themselves are working fine. I have a very strong feeling that there is a problem with the pins 0 and 1, i.e. with serial comm.

Please help.

  • 1
    When you program the Arduinos you need to unplug all cables from D0 and D1, otherwise the upload will fail. Have you anything connected to D0 or D1 while uploading? – Maximilian Gerhardt Mar 6 '18 at 18:29
  • 2
    While not a solution to the problem you posed, this line in Code 1: char mystr[3] = "Hello"; //String data is not good -- you can't allocate 3 bytes in an array and assign a string that requires 6 bytes of data (5 characters, plus null terminator.) – jose can u c Mar 6 '18 at 18:29
  • Also, the error text you list for Code 1 can't be right with that code, because it should give a compile error. Are you sure you have pasted the right responses? – jose can u c Mar 6 '18 at 18:32
  • @josecanuc yes pretty sure I have pasted the right errors.. and I changed [3] to [6] – Aki Mar 6 '18 at 18:37
  • 2
    one of the things that you have to learn in programming, is to identify a problem correctly. .... you are unable to upload a sketch to an arduino, yet your question title is Problem in serial communication between 2 arduinos ... that title is absolutely incorrect – jsotola Mar 6 '18 at 20:09
1

I am guessing you have connected 2 arduinos together using their hardware serial ports while uploading. This cause uploading to fail as those ports are getting two signals at the same time.

Break this connection before upload and then it should work. You can reconnect them after upload.

If you want to avoid this you can use different pins with software serials for communication.

Also consider using Serial.available() on the reading end to see if there is data to be read.

  • Normally "guessing" is discouraged, but as this absolutely horrible "tutorial" literally instructs the unsuspecting to make this problematic connection, you are probably right. Whoever wrote that terrible guide has done the world a disservice. – Chris Stratton Mar 10 '18 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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