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
}