help with serail output arduino--arduino

Hello ,
I want ot make 2 Arduino “talk” with serial connection
the first one “Server” -

#include <SoftwareSerail.h>

SoftwareSerial Device(3,4);

void setup()
{

Device.begin(4800);
Serial.begin(4800);
}

void loop()
{

for (int i=0;i<254;i++)
{

Serial.print(cahr(i));
Device.print(char(i));
Device.print(char(i));
delay (150);
}

delay (2000);
}

when I look at the monitor I can see all the chars begin print.

now the server is connected via rs232-ttl to another Ardiono(client) to Pins 3,4
which have this code :

#include <SoftwareSerail.h>

SoftwareSerial Device(3,4);

void setup()
{

Device.begin(4800);
Serial.begin(4800);
}

void loop()
{

Device.listen();
while (Device.available() > 0 )
{

char InByte = Device.read();
if (InByte == 10 )
{
Serail.println("");

}
else
{
Serial.print(InByte);
}

}



}

I can see the data , but it’s in gibrish

   ּ4«ז³f,cֶf0±ֶYֻ.cײe0ƒ¦3ֳ$ƒhA‹ֶֻ,cֶֻ,cֶ²ׁvš׃,ƒ³f.›&™–,cֶּ0ֻ2kµµµµ²mµµµ’µ0†ֻ,c3–,c–Mc3˜*#˜dPM
               Yֻ,cֶe,±ֶֻ,‹V˜ֹG“mּ1›fœ,cֻ,‹f3˜6c¦³ֳµ[mmµµµ[mmµµMֶּ*£ײ0¨M
                                                              Yֻ,cֶ–,cֶe,ֵV˜ֹP›f1ֵֶ3–0FjCƒ3››™–,cֶּׁf•2kר[mmµµµµ,ֶeESלj¦CYֽ8ƒ63«,cֶ–1ƒF3–,“vבµµµµ;µֻ,cֶe,±ֶֻ,c¦³ֳ$ƒ­h0ֵF³ֻ0»ֶ5ֻ,cֶYֽ0ƒf•2kר«µ[mmµµµmµµµ«mµµµµ–Mƒז3׃,e4Sל4S±Yֻ,cֶe,±ֶֺES4©Mcfּ4sf–Vֶֻ,³3›,S&³…[mmµµµ«mµµµµµµG;#v5jCƒ3š1ƒ6f«,ֶֻ1ƒF3–,“–˜µµµ«µ,ֶֻ,cֶ²ׁv´«,ֶּ,ƒֶ3–0ƒֶf,ֱֶ3ּ,«ֶf–0ƒֶf,ƒֶ3ּ,»–˜’G;ֽf2‹&™™,ƒֶ3˜,ƒvf,ֱּ,ƒֶc[mmµµµµ«µµµmµµµµ5Mֻ,ƒ3•5kŒ²¨Gmf1¡&œ,cֶe,‹f3ּ6c¦³fmµµµµµµµ5,±ֶ0ֶ™f
                            Yeּ±ֶֻ,cֶe*k¨Rfּׁז³f,±ֶֻ,‹f3ּ6c¦³ֳµµµ[µ,ּ,k
                                                            0³—ֶֽ5–,cֶY›0ƒfe25µ[mm5µ[mm

waht could be the problem ?
do I need to overcome the rs232-ttl device ? and send the data directly?

Thanks ,

david1234:
waht could be the problem ?
do I need to overcome the rs232-ttl device ? and send the data directly?

There is no need of TTL-RS232 conversion between the two Arduinos. You can connect them directly using the Software UART Ports. The connection should be:

SRX (3) <--------------- STX (4) //SRX for RX-pin of Software UART Port
STx (4) ---------------- SRX (3)
GND <--------------> GND

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R

I have also try to connect then directlly
PIN3--->PIN4
PIN4--->PIN3
GND--->GND

which is strange

still getiing gibrish

about the code of reading - I'm not there yet
I just want to see I'm reading the data correct
after it I will edit to EOL,SOL....

Thanks ,

david1234:
about the code of reading - I’m not there yet

Unless your code is working how can you know that you are receiving gibberish?

Post the latest version of your two programs and make sure silly spelling mistakes (like the following) have been corrected

#include <SoftwareSerail.h>

…R

thi is the sender code

#include <SoftwareSerial.h>
#include <Wire.h>


SoftwareSerial Device1(10, 11);

char inByte;


void setup()
{

  Serial.begin(4800);
Device1(4800);

Serial.println ("*****Starting******");
delay (100);
for (int i=0;i<5;i++)
{
Serial.println ("Please wait.");
delay (500);
  
}

}


void loop()
{  
 for (int i=0;i<254;i++)
 {
  Serial.print(i);
  Device1l.write(i);
 
  delay (100);
 }
Serial.println("Done");
delay (1500);

 
}

And this is the RX code

#include <SoftwareSerial.h>
#include <Wire.h>



SoftwareSerial Device1(5, 6);


char inByte;


void setup()
{

  Device1.begin(4800);
  Serial.begin(4800);


Serial.println ("*****Starting******");
delay (100);
for (int i=0;i<5;i++)
{
Serial.println ("Please wait.");
delay (500);
  
}

}

void loop()
{  

  while (Device1.available() > 0)
  {
       
  inByte = Device1.read();
  if (inByte==10)
  {
    Serial.println("");
  }
  else
  {
  Serial.print(inByte);
  
  
  }
  }



 
}
  • The sender is Pro-mini
  • the Rx is Arduino ethernet
    if its metter somehow…

david1234:
I have also try to connect then directlly
PIN3--->PIN4
PIN4--->PIN3
GND--->GND

which is strange

still getiing gibrish

If this is how you have them connected, it is no wonder you are getting gibberish !!!

.

the connection is OK:
PIN5 → PIN11
PIN6 → PIN10
GND–>GND

but I think my problem was in the Arduino Ethernet…
I took Pro-Mini , (with the same wiring\ code) and now it’s working .

So now I have 2 Pro-mini working

Now I’m trying to read data from 2 serial devices -
this is the serve sdie?(the one thatwill get the 2 serail data)
but when I use this code

#include <SoftwareSerial.h>
#include <Wire.h>


SoftwareSerial Device1(5, 6);
SoftwareSerial Device2(3, 4);

//int OldValue = '0';
//int NewValue = '0';
char inByte;


void setup()
{
  // initialize serial communication at 9600 bits per second:
  Serial.begin(4800);

  Device1.begin(4800);
  Device2.begin(4800);



  Serial.println ("*****Starting******");
  delay (100);
  for (int i = 0; i <5; i++)
  {
    Serial.println ("Please wait.");
    delay (500);

  }
Device1.listen();
Device2.listen();
}


void loop()
{

  Check1();
  delay (1000);
  Serial.print("going to 2nd device");

  Check2();
  delay (1000);



}

void Check1 ()
{

  while (Device1.available() > 0)
  {

    inByte = Device1.read();
    if (inByte == 10)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte);
  

    }
  }

}

void Check2 ()
{
 // 
  while (Device2.available() > 0)
  {

    inByte = Device2.read();
    if (inByte == 10)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte);
  
    }
  }



}

I took 2 pro mini that both of them have this code for sending data

#include <SoftwareSerial.h>
#include <Wire.h>


SoftwareSerial Device1(10, 11);

char inByte;


void setup()
{

  Serial.begin(4800);
Device1(4800);

Serial.println ("*****Starting******");
delay (100);
for (int i=0;i<5;i++)
{
Serial.println ("Please wait.");
delay (500);
  
}

}


void loop()
{  
 for (int i=0;i<254;i++)
 {
  Serial.print(i);
  Device1l.write(i);
 
  delay (100);
 }
Serial.println("Done");
delay (1500);

 
}

but I only get
"going to 2nd device"

the connection is the same
pin11(Device1)-pin5(Device0)
pin11(Device2)-pin3 (Device0)
Gnd–GND–GND

when I disable Device2.listen - it read data from Device1
?

can it be that arduino pro mini can’t open\listen from 2 serail ports?
should I start a new post? or continue here?

You'd need the receiver Arduino connected to another PC.

Were you expecting the Serial Monitor to display both the receiver and transmitter's data?

I will expalin the setup:

I have 3 Arduino mini
Device0 - is Rx only (need to get data from 2 serail devices , using ping 5 and 3 ).
Device1 - is Tx only (using pin 11 to send data).
Device2 - is Tx only (using pin 11 to send data).
every Arduino mini is connected to a computer

the sending is OK - I have chack it before in the first code - so no problem there.

this is my Rx code(from Device0):

#include <SoftwareSerial.h>
#include <Wire.h>


SoftwareSerial Device1(5, 6);
SoftwareSerial Device2(3, 4);


char inByte;


void setup()
{
  Serial.begin(4800);
  Device1.begin(4800);
  Device2.begin(4800);



  Serial.println ("*****Starting******");
  delay (100);
  for (int i = 0; i < 5; i++)
  {
    Serial.println ("Please wait.");
    delay (500);

  }


}


void loop()
{
  Check1();

  delay (1000);

   Check2();

 delay (1000);



}

void Check1 ()
{
 
  while (Device1.available() > 0)
  {

    inByte = Device1.read();
    if (inByte == 119)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte);
    

    }
  }

}

void Check2 ()
{
  
  while (Device2.available() > 0)
  {

    inByte = Device2.read();
    if (inByte == 10)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte);
     

    }
  }



}

Now I only get data from Device2 (PIN 3 ) ,if I connect the Tx from Device1 to Pin3 - I get data from device1
so the cables are OK , and both senders are OK
but I can’t get the data from both devices.
why?

#include <SoftwareSerial.h>


SoftwareSerial Device1(5, 6);
SoftwareSerial Device2(3, 4);


char inByte1;
char inByte2;


void setup()
{
  Serial.begin(4800);
  Device1.begin(4800);
  Device2.begin(4800);



  Serial.println ("*****Starting******");
  delay (100);
  for (int i = 0; i < 5; i++)
  {
    Serial.println ("Please wait.");
    delay (500);

  }


}


void loop()
{

  if (Device1.available())
  {

    inByte1 = Device1.read();
    if (inByte1 == 119)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte1);
    

    }
  }


  if (Device2.available())
  {

    inByte2 = Device2.read();
    if (inByte2 == 10)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte2);
     

    }
  }



}

is in it the same?

#include <SoftwareSerial.h>
#include <Wire.h>


SoftwareSerial Device1(5, 6);
SoftwareSerial Device2(3,4);

char inByte;
char inByte2;


void setup()
{
  Serial.begin(4800);
  
  Device1.begin(4800);
  Device2.begin(4800);



  Serial.println ("*****Starting******");
  delay (100);
  for (int i = 0; i < 5; i++)
  {
    Serial.println ("Please wait.");
    delay (500);

  }


}


void loop()
{

  Check1();

  Check2();
 



}

void Check1 ()
{
  if (Device1.available())
  {

    inByte = Device1.read();
    if (inByte == 119)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte);
     
    }
  }

}

void Check2 ()
{
 
  if (Device2.available())
  {

    inByte2 = Device2.read();
    if (inByte2 == 10)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte2);
      
    }
  }



}

only show me data from Device2

My sketch is for the receiver Arduino.

To verify your transmitter code, have Arduino #1 count from 0 to 255 and have Arduino #2 count down from 255 to 0.

Your transmitters should be sending bytes and nothing else.

david1234:
I will expalin the setup:

I have 3 Arduino mini
Device0 - is Rx only (need to get data from 2 serail devices , using ping 5 and 3 ).
Device1 - is Tx only (using pin 11 to send data).
Device2 - is Tx only (using pin 11 to send data).
every Arduino mini is connected to a computer

What are the Pin 11s from Device1 and Device2 connected to?

You cannot simply connect two Tx pins to one Rx pin. To do that you need some external components (diodes and a resistor).

Also it is not practical to use two instances of SoftwareSerial. Only one of them can be listening at any one time.

The proper way to receive from a number of Arduinos is to use a Mega which has 3 spare HardwareSerial ports.

...R

Robin2:
What are the Pin 11s from Device1 and Device2 connected to?

You cannot simply connect two Tx pins to one Rx pin. To do that you need some external components (diodes and a resistor).

Also it is not practical to use two instances of SoftwareSerial. Only one of them can be listening at any one time.

The proper way to receive from a number of Arduinos is to use a Mega which has 3 spare HardwareSerial ports.

...R

It looks like he is connecting the pin 11s to pin 5 and pin 3.

.

I don't think you understand the setting:

1st Tx arduino is sendin 0-255 using PIN11 (SoftwareSerial Device1(10, 11);
2nd Tx arduino is sending 255-0 using PIN11 (SoftwareSerial Device1(10, 11);

Rx Arduno is using 2 serial ports
SoftwareSerial Device1(5, 6);
SoftwareSerial Device2(3,4);
so I don't think I have any electric problem....

but with the code above I only get the 2nd Arduino - I get 255-0 values only...

what else can I check \ do \ test to see why it is ?

Thanks ,

You don't seem to be using the listen() function to select which of your SoftwareSerial instances is listening.

...R

where to put it?

I have try to use it like this :

void Check1 ()
{
 Device1.listen();
  if (Device1.available())
  {

    inByte = Device1.read();
    if (inByte == 35)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte);
      
    }
  }



}


void Check2 ()
{
 Device2.listen();
  if (Device2.available())
  {

    inByte2 = Device2.read();
    if (inByte2 == 35)
    {
      Serial.println("");
    }
    else
    {
      Serial.print(inByte2);
      
    }
  }



}

I get gibrish

�‎‎‎��t‎ץ‎1mם�dn��וקףץ‎����W�וumף�3�r-jakו‎ץ‎�קצ�‏פ��ז�‎5ףa6ף�=$+�מ�\hע�‏

and what I need to get is :

this data from device1:

$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvw

this data from device 2 :

wvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$

Thanks ,

david1234:
where to put it?
I have try to use it like this :

To my mind you are trying to use SoftwareSerial inappropriately. For what you are trying you would need some means to tell Device1 that it has permission to send and then you would listen for its data until the complete message is received. At that stage you would tell Device2 that it has permission to send and listen for its message.

If you can't control the sending in that way then you need to use a Mega that has 3 spare HardwareSerial ports that operate independently of each other.

In any case the way your program is written you have no way to know, on the Serial Monitor, which byte came from which device.

...R

No - I can't control the data been send to me .
but lets say I know what shpuld be the data from Device1&2 , and I know it is 400ms long (justfor example)
can't I tell the Arduino that he will listen to each port for 1 second?
so I will see:
Device1 data for 1 seconds
delay of 500ms
Device2 data for 1 seconds
delay 500ms
.........
.........
.........
.........
and so on?

Thanks ,

*** also , how can this be ?