Hello,
I am having a heck of a time sending and receiving (decoding correctly) .
I am sending payload defined as byte where as the <> as chars. the payload corresponds to button presses. I see the TX working correctly in serial monitor and mapped out case statements in the RX section based on the numbers I see in serial monitor.
When I connect the two MCU's together. TX to RX pin, I am not seeing any expected response in hardware (turning on/off LEDS). If I connect the RX section to serial monitor I can send < 10 > for example and triggers my hardware output. Currently I have LEDS on a port and I can trigger them with serial monitor.
I have a feeling I am not "talking" the same serial language across TX and RX, but both work independently with serial monitor. I know this has got to be a simple thing I am missing.
TX section:
void transmitIr() {
Serial.print('<'); // transmit start character
Serial.print(loadTX_Decode); // transmit button press status
Serial.print('>'); // transmit end of transmission character
}
The RX section:
void RecvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
// ---------------------------------------------------------------------------------------------------
// DecodeIR converts the serial data from 2 byte characters, to 1 byte integer. Then hands it down to
// the switch case to update the status of the MotorDutyRight, MotorDutyLeft, MotorSelectRight and
// MotorSelectLeft.
// ---------------------------------------------------------------------------------------------------
void DecodeIR() {
if (newData == true) {
ReceivedIR = 0;
ReceivedIR = atoi(receivedChars); // covert text string to integer
switch (ReceivedIR) {
case 10: // Forward
MotorDutyRight = 255; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 255;
MotorSelectRight = HIGH; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = HIGH;
break;
case 20: // Reverse
MotorDutyRight = 255; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 255;
MotorSelectRight = LOW; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = LOW;
break;
case 30: // Right
MotorDutyRight = 100; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 255;
MotorSelectRight = LOW; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = HIGH;
break;
case 40: // Left
MotorDutyRight = 255; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 100;
MotorSelectRight = HIGH; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = LOW;
break;
case 50: // Foward + Right
MotorDutyRight = 100; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 255;
MotorSelectRight = HIGH; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = HIGH;
break;
case 60: // Forward + Left
MotorDutyRight = 255; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 100;
MotorSelectRight = HIGH; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = HIGH;
break;
case 70: // Reverse + Right
MotorDutyRight = 100; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 255;
MotorSelectRight = LOW; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = LOW;
break;
case 80: // Reverse + Left
MotorDutyRight = 255; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 100;
MotorSelectRight = LOW; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = LOW;
break;
case 90: // Turbo
MotorDutyRight = 255; // Duty cycle to motor 0 = FULL OFF, 255 = FULL ON
MotorDutyLeft = 255;
MotorSelectRight = HIGH; // HIGH = motor bridge forward, LOW = reverse
MotorSelectLeft = HIGH;
break;
default: // Stop movement
MotorDutyRight = 0;
MotorDutyLeft = 0;
break;
}
newData = false;
}
}