Issues using board to board serial

Hi,

I am using the tx and rx pins on my arduino boards to exchange data.

board A is connected to switches, when a switch is pressed it will send its corresponding number to board B, board B will then receive the signal and activate a digital output. The code works fine for sending the “1” and the “0” but any other numbers fail. What could be the cause? I was thinking along the lines of how it sends the data (HEX, DEC, OCT etc). Any help would be appreciated. :slight_smile:

The code for the boards are attached
(note please ignore the pwm sections these are working fine)

board_B.ino (1.13 KB)

board_A.ino (2.08 KB)

What is '49' (with single quotes) supposed to mean in board_B.ino?

whoops, that was when I tried the ASCII character maps, this did not work.. Its meant to be what is commented out next to it.

use string and char

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup() {

 Serial.begin(9600);
 
 inputString.reserve(200);
}



void loop() {

 if (stringComplete) {
   Serial.println(inputString); 


  
   inputString = "";
   stringComplete = false;
 }
 
 if(inputString="a"){ //// change 1-a 2-b 3-b 1/2/3/4/5/...

///// making your code 
}
 
 
}



void serialEvent() {
while (Serial.available()) {
   
   char inChar = (char)Serial.read(); 
 
   inputString += inChar;
  
   if (inChar == '\n') {
     stringComplete = true;
   } 
 }
 
 }

Please post your code here rather than attaching it.

What is '49' (with single quotes) supposed to mean in board_B.ino?

Somewhere between 49 and '1' at a guess.

if(inputString="a")Oh dear. Unless, of course, you really do want to set inputString to "a"

Arlove: use string and char

sp. "String"

I suggest you use one of the examples in serial input basics for receiving data. They are simple and reliable.

Then make your sending program match the requirements of the receiving program.

...R

AWOL: sp. "String"

Why? We try to discourage wasting resources on the String class.

PaulS: Why? We try to discourage wasting resources on the String class.

Because DOOM Arlove used a String in the sketch and I wanted to highlight the difference, not because I want to encourage their use, oh dear me, no.

AWOL:
Because DOOM Arlove used a String in the sketch and I wanted to highlight the difference, not because I want to encourage their use, oh dear me, no.

Oops. Missed that.

Thanks guys have managed to get everything working :)