1

I want to make my Arduino Uno and Genuino Zero communicate using UART. My Genuino Zero is the transmitter and the receiver is the Arduino Uno.

For the Arduino Uno, I am using the SoftSerial library. I have uploaded the transmitter and receiver codes.

My connection is as below:

Genuino Zero (RX) pin 0 ---------------- Arduino Uno pin 11

Genuino Zero (TX) pin1 ---------------- Arduino Uno pin 10

Ground ---------------------------------- Ground

The Arduino Uno's pin 10 is Rx and pin 11 is Tx, using SoftSerial.

The transmitter transmits 'a'. The receiver receives 'a' and turns a LED on. My problem is that on the receiver, I am not getting anything.

My code is here:

https://www.dropbox.com/s/4w8o2h2k4zs0it5/transmitter.txt?dl=0 https://www.dropbox.com/s/d50uizoz3iove9w/receiver.txt?dl=0

-------------------receiver---------------------

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

/* Simple Serial ECHO script : Written by ScottC 03/07/2012 */

/* Use a variable called byteRead to temporarily store the data coming from the computer */ byte byteRead;

void setup() {
// Turn the Serial Protocol ON Serial.begin(9600); mySerial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); }

void loop() { char a[8]; /* check if data has been sent from the computer: / if (Serial.available()) { / read the most recent byte / byteRead = Serial.read(); Serial.print("rushin\r\n"); /ECHO the value that was read, back to the serial port. / if(byteRead == 0x61) { digitalWrite(LED_BUILTIN, HIGH); Serial.write(byteRead); } } if (mySerial.available()) { / read the most recent byte / byteRead = mySerial.read(); mySerial.print("rushin\r\n"); /ECHO the value that was read, back to the serial port. */ if(byteRead == 0x61) { digitalWrite(LED_BUILTIN, HIGH); mySerial.write(byteRead); } } }

-------------------transmitter----------------------------------

/* DigitalReadSerial Reads a digital input on pin 2, prints the result to the serial monitor This example code is in the public domain. */

// digital pin 2 has a pushbutton attached to it. Give it a name: int pushButton = 7; // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // make the pushbutton's pin an input: pinMode(pushButton, INPUT); }

// the loop routine runs over and over again forever: void loop() { // read the input pin: int buttonState = digitalRead(pushButton); // print out the state of the button: Serial.println("a"); delay(1000); // delay in between reads for stability }

Beginner
  • 43
  • 2
  • 9
  • Post the code here. Links tend to disappear. – gre_gor Apr 03 '17 at 12:50
  • sorry. can't upload text file here. and link is ok – Beginner Apr 03 '17 at 12:58
  • Just copy paste the code here and format it into code block. – gre_gor Apr 03 '17 at 13:02
  • What does the product information say? "Unlike most Arduino & Genuino boards, the Zero runs at 3.3V. The maximum voltage that the I/O pins can tolerate is 3.3V. Applying voltages higher than 3.3V to any I/O pin could damage the board." – Mikael Patel Apr 03 '17 at 13:07
  • yes i know that. and i am working with 3.3 v – Beginner Apr 03 '17 at 13:16
  • And the Uno? How did you connect that? At least pin 11/TX would be 5V if you have not used any signal conversion. – Mikael Patel Apr 03 '17 at 14:35
  • Your receiver code won't say anything to the PC in response to data over the software serial - you only send the indication back on that. Likely you want to send some indication to the PC instead or as well. Also be wary of triggering messages that are longer than the ones sent, as they will take more time to transmit and could lead to missing new incoming data. – Chris Stratton Jun 10 '18 at 04:05

1 Answers1

1

Your Arduino Zero transmitter code transmits to the USB Serial ('Serial') only. If you want it to transmit to the serial comm on pin 0 and pin 1, you must have it write to Serial1. (Check variants.cpp file ) you will see that Serial1 is uses SERCOM0 which is on pin 0 and 1.

So, Your code should look like this (noitce "Serial" is replaced with "Serial1"):

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial1.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial1.println("a");
  delay(1000);
  // delay in between reads for stability
}
Jay
  • 3
  • 1