This code sends allows me to send AT commands through the serial monitor to a wifi board and recieve an output. The code which uses Serial1 works, but I can't get it to work using software serial. The baud rate is correct.
Hardware Serial code:
void setup() {
// Initialize the Serial communication
Serial.begin(600);
// Initialize the Serial1 communication
Serial1.begin(600);
// Wait for the sensor to reboot
delay(1000);
}
void loop() {
if (Serial.available()) { // If anything comes in from the computer
Serial1.write(Serial.read()); // send it to the sensor
}
if (Serial1.available()) { // If anything comes in from the sensor
Serial.write(Serial1.read()); // send it to the computer
}
}
software serial code:
#include <SoftwareSerial.h>
// Create a software serial object with pin 6 as RX and pin 7 as TX
SoftwareSerial sensorSerial(6, 7);
void setup() {
// Initialize the Serial communication with the computer
Serial.begin(600);
// Initialize the software serial communication with the sensor
sensorSerial.begin(600);
// Wait for the sensor to reboot
delay(1000);
}
void loop() {
if (Serial.available()) { // If anything comes in from the computer
sensorSerial.write(Serial.read()); // send it to the sensor
}
if (sensorSerial.available()) { // If anything comes in from the sensor
Serial.write(sensorSerial.read()); // send it to the computer
}
}
Any help would be much appreciated