SoftwareSerial Issue

hi there
just playing with Software Serial and two Arduino, i’m trying to send a number of 45 every 1s to my other Arduino and then send it back up the Serial to the PC, but all i get is ( - ) any idea?

here is my code which sends the 45

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



void setup() {
   mySerial.begin(9600);
}


void loop() {
   mySerial.write(45); 
    delay(1000);
}

here is the code what sends it back to the PC

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


void setup()  
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Hello All");
  mySerial.begin(9600);
}

void loop() 
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

thanks Joe

45 is the Ascii code for -

So it is working perfectly.

Do your testing with a more obvious character such as 'A'

...R

o i see lol

can i altar it so what i put in is what i get out?

so i presume this is why i could not get this to work either?

mySerial.println(analogRead(sensePin));

once again how can i overcome this?

thanks Joe

Joes: can i altar it so what i put in is what i get out?

Please explain more clearly what you would like to happen.

...R

read an analog input then send it down the serial to the other Arduino

Hi, I assume by "it" you mean the value of the analog input, is that correct? Have a look at AnalogInOutSerial in the Example submenu of the Arduino IDE.

Joes:
read an analog input then send it down the serial to the other Arduino

Isn’t that what you have already achieved with the code in your original post ?

…R

got it sorted now :slight_smile: thanks for your help here is my code:

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



void setup() {
   mySerial.begin(9600);
}


void loop() {
    analogValue = analogRead(A0);

    mySerial.print(analogValue); 
   mySerial.print("\t"); 

    delay(1000);                
}

i do have one more question tho, this line what state where the TX and RX pins are ( SoftwareSerial mySerial(10, 11); ) is it possable to select just a TX as i only have one pin left in my project ?

Yes, I believe someone has recently created a version of SoftwareSerial to allow you to only specify one pin. You may need to search on GitHub.

If you only need to transmit, then set the receive to one of your input pins and then tell SoftwareSerial to stop listening for incoming data.