Go Down

Topic: Read serial from serialsoftware (Read 268 times) previous topic - next topic

smallpoul

Hi,
    here my problem, I got a little home automation box that send data trough serial. I want to read these data to eventually use it with the arduino, for now, all i want is to read these output, since i only got a uno and nano, both only have one serial rx/tx. So i use one to plug in the box and the other on my laptop to read the data with the software serial library. the only data that it show on the screen when i press a button on my box is some garbage like some yyyyyy. here's my code:

Code: [Select]
/*
  Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 2 (connect to TX of other device)
* TX is digital pin 3 (connect to RX of other device)

created back in the mists of time
modified 9 Apr 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

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

 
  Serial.println("Start reading");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
}

And the other


And the other

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 4); // RX, TX

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

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
}

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


tx to rx
rx to tx
gnd to gnd
vin to vin

Thanks in advance

jack wp

Good luck, Jack

PaulS

Quote
tx to rx
rx to tx

A picture that shows the actual connection would convey far more information. To me, this statement looks like you connected pins 0 and 1 on each board to the opposite pins on the other board. But, those are NOT the pins you are reading from/writing to, in the SoftwareSerial instances.

If you meant that you connected the pins that the software serial instances use to each other, you should have used actual pin numbers.

Go Up