Whre is Software Serial for UNO tocommunication with other UNO RX TX D0 D1

Hello,

Where is this library to download ?

it's to incorpore fonctions in my soft sensor to transmit in first time into second UNO card,
e. g. to see on the second UNO the outputs of LEDs

D2 and D3 are outputs for led1 and led 2 on first UNO
D4 and D5 will be outputs or two leds on second UNO

transmit by table ASCII with TX RX on first UNO in D0 D1

And, have you realised that or similary ?

Thank you

John

john35S:
Where is this library to download ?

The SoftwareSerial library for the Uno comes pre-installed with the Arduino IDE, so you don't need to download it.

john35S:
transmit by table ASCII with TX RX on first UNO in D0 D1

Pins 0 and 1 on the Uno are the hardware serial port Serial. Those pins are used for communication with your computer, such as printing to Serial Monitor and uploading sketches. You may find that you're unable to upload sketches to the Uno when you have something connected to pins 0 and 1. So I recommend that you not use those pins. You can use any pins on the Uno for SoftwareSerial. If you are going to use pins 0 and 1, then it is silly to use the SoftwareSerial library, since these pins have hardware serial capability, which is greatly superior to software serial.

1. This is the type of connection being described in Post#1 of @pert between your two UNOs using Software Serial Ports.
uno1uno2.png
Figure-1:

2. This is the sketch that controls LED1, LED2 and LED3, LED4.
(1) You enter HL from the InputBox of Serial Monitor (Fig-2) and click on the Send Button (choose Line ending tab at No line ending option); as a result, LED1-LED2 of UNO1 will be ON-OFF; LED2-LED3 of UNO2 will also be ON-OFF.

(2) You enter HH from the InputBox of Serial Monitor (Fig-2) and click on the Send Button (choose Line ending tab at Newline option); as a result, LED1-LED2 of UNO1 will be ON-ON; LED2-LED3 of UNO2 will also be ON-ON.
SerialMonitor.png
Figure-2:

Sketch of UNO-1:
Your sketch may be something like this (untested):

#include<SoftwareSerial.h> //SoftwareSerial.h file was included in my PC when I installed IDE
SoftwareSerial SUART(4, 5);   //SRX = 4, STX = 5
char x, y;

void setup()
{
    Serial.begin(9600);
    SUART.begin(9600);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
}

void loop()
{
    byte n = Serial.available();  //checking if there is any data in Serial FIFO Buffer
    if(n == 2)   //there are 2 data bytes in Buffer
    {
        x = Serial.read();    //bring out the first data byte from FIFO Buffer
        if(x == 'H')              //checking if it is character H that has come from InputBox of Serial Monitor
        {
            digitalWrite(2, HIGH);
        }
        else                         //the first data byte that has come from the InputBox of Serial Monitor is L
        {
            digitalWrite(2, LOW);
        }
        
        y = Serial.read();     //bring out the 2nd data byte from FIFO Buffer
        if(y == 'H')
        {
            digitalWrite(3, HIGH);
        }
        else
        {
            digitalWrite(3, LOW);
        }
        SUART.write(x);     //send first data byte to UNO-2 over Software Serial Port named SUART
        SUART.write(y);     //send 2nd data byte to UNO-2
    }
}

Sketch of UNO-2:
Follow Sketch-1 and try to write few lines and then we will complete.

SerialMonitor.png

uno1uno2.png

For Arduino to Arduino serial communication its easiest to use a reliable and proven serial transfer library.

The linked library will automatically packetize your data, transmit it, and parse it on the other Arduino for reliable transfer. The library can transfer individual bytes, ints, floats, arrays, and even whole classes! It's also downloadable through the Arduino IDE's Libraries Manager (search "SerialTransfer").

Example Code:
TX Arduino:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  myTransfer.txBuff[0] = 'h';
  myTransfer.txBuff[1] = 'i';
  myTransfer.txBuff[2] = '\n';
  
  myTransfer.sendData(3);
  delay(100);
}

RX Arduino:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  if(myTransfer.available())
  {
    Serial.println("New Data");
    for(byte i = 0; i < myTransfer.bytesRead; i++)
      Serial.write(myTransfer.rxBuff[i]);
    Serial.println();
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");
    Serial.println(myTransfer.status);
  }
}

Also, for a really simple overview of serial communication concepts, take a look at this tutorial.

The OP is using UNO which has no Serial1 Port. Can SerialTransfer.h Library be used to create software serial port? Any example will be appreciated.

Hello,

Thanks for the posts,

@ Pert, Ok for D0 and D1. deconnected to load the sketch.

I going to use for UNO 1 the Output D2 and D3 wires to UNO 2

and on UNO 2 input same wires in D3 and D2

I do not use 2 portables PC, the UNO 2 will be on battery 9 volts. One PC only.

@ GolamMostafa, I see yours shematics it's very well ,it's good for me.

I do not use 2 portables PC, the UNO 2 will be on battery 9 volts. One PC only,

wires output on D2 and D3 on the first UNO, to second UNO input D3 D2

it's possible no use the wires STX SRX in this solution ???

in your soft, what is HH and HL ???
where is L ??? that no undestand.

thanks you
Regards

John

john35S:
in your soft, what is HH and HL ???
where is L ??? that no undestand.

HH for HIGH and HIGH; that means you are sending HIGH commands to ignite LED1 and LED2.
HL for HIGH and LOW; that means you are sending HIGH commands to ignite LED1 and LOW command to turn-off LED2.
and son on....

There are only four combinations:
HH
HL
LH
LL

The ASCII codes of characters H and L can be found in the following Table.

The ASCII code of H is : 0x48 = 72 decimal
The ASCII code of L is: 0x4C = 76 decimal

Hello GolamMostafa,

Thanks for the Post,

I see the code for H and L colon 4 row 8 = 48 for H and for L colon 4 row C = 4C

e.g. for W colon 5 row 7 = 57 Right ???

now, what is that 0x ??? in 0x48

The second question in my post number #5 For the Wires in D2 in D3 on the two UNO cards and one Portable PC only, no using STX and SRX pins ??? Please give me your solution.

Regards
John

1. One PC and two UNO based UART connection is this:
uno1uno2x.png
Figure-1:

(1) Make the following connections:
Connect DPin-5 (STX = TX-pin of Software UART Port) of UNO-1 with DPin-2 (Digital Pin 2) of UNO-2.
Connect DPin-4 (SRX = RX-pin of Software UART Port) of UNO-1 with DPin-3 (Digital Pin 3) of UNO-2.
Connect GND pin of UNO1 with GND pin of UNO-2.
Connect LED1 + R1 circuit with DPin-2 of UNO-1.
Connect LED2 + R2 circuit with DPin-3 of UNO-1.

2. Note:
48 is decimal forty eight = 4x10 + 8x1
0x48 (zero axe four eight) is 48 in hexadecimal base = 4x16 + 8x1 = 72 in decimal.

uno1uno2x.png

Tks GolamMostafa,

You can see my shematic in download jpg


(moderator-added img tags)

GolamMostafa:
The OP is using UNO which has no Serial1 Port. Can SerialTransfer.h Library be used to create software serial port? Any example will be appreciated.

Yes, the library works with all serial stream objects (hardware, usb, and all types of softwareserial). All you have to do to make it work is pass the softwareserial class as argument to the begin() member function instead of Serial1.

Power_Broker:
Yes, the library works with all serial stream objects (hardware, usb, and all types of softwareserial). All you have to do to make it work is pass the softwareserial class as argument to the begin() member function instead of Serial1.

Example sketches between two UNOs, please.

john355,

On the Uno with the switches, send "1H" when switch1 is on. Send "1L" when switch1 is off. Send "2H" when switch2 is on and "2L" when switch 2 is off.

On the Uno with the LEDs, you need to continuously read on the 2nd serial port.
Read 2 characters and process the information.

GolamMostafa:
Example sketches between two UNOs, please.

It's a really straightforward fix, but if you insist...

This is a full duplex version (same exact code can be run on both Unos):

#include "SerialTransfer.h"
#include <SoftwareSerial.h>

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

void setup()
{
  Serial.begin(115200);
  mySerial.begin(9600);
  myTransfer.begin(mySerial);
}

void loop()
{
  myTransfer.txBuff[0] = 'h';
  myTransfer.txBuff[1] = 'i';
  myTransfer.txBuff[2] = '\n';
  
  myTransfer.sendData(3);
  delay(100);

  if(myTransfer.available())
  {
    Serial.println("New Data");
    for(byte i = 0; i < myTransfer.bytesRead; i++)
      Serial.write(myTransfer.rxBuff[i]);
    Serial.println();
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");
    Serial.println(myTransfer.status);
  }
}

Also, I updated the library examples to include ones depicting compatibility with the SoftwareSerial.h library.

Hello everybody,

Thanks you for yours posts,

You can see my shematic now with UNO1 and UNO2. (in Post number 9).

@ The first UNO With UNO1 only, the two LEDs had connect in D11 and D12 with Resistors 220 Ohms.

When SW1 pressed, LED1 is HIGH
When SW2 pressed, LED2 is HIGT
When SW1 and SW2 no pressed , LED1 and LED2 are LOW
this sketch is made and it's ok

@ now, on this schematic, no LEDs on UNO1

@ I put a second UNO , UNO2

The LED1 and the LED2 are connected output D2 and D3 with the Resistors
The orders transmitted with wires D11 and D12 when SW1 or SW2 pressed.

When SW1 and SW2 no pressed , wires and pins on D11 and D12 are LOW;

@ Project

Transmission to HC05 modul arduino, this levels in TX on Bluetooth to Android signal
for tablet.

what job !

First : I must write and download a different sketch fot each UNO card, and witch incorporates the
sketck determining the buttons on A0.

TKS
john

complement,

I must write and download a different sketch for each UNO card, witch incorporates the sketch determining the buttons on A0.

buttons for UNO1 card
leds for UNO2 card

right ?

Thanks

Regards John

ieee488:
john355,

On the Uno with the switches, send "1H" when switch1 is on. Send "1L" when switch1 is off. Send "2H" when switch2 is on and "2L" when switch 2 is off.

On the Uno with the LEDs, you need to continuously read on the 2nd serial port.
Read 2 characters and process the information.

Hello ieee488

Thanks for this post,

Have you read my last Post 16 and the number 15

Regards
John

description
// for UNO 1  with 2 butons SW1 SW2 on analoginput A0; output D2 for SW1, D3 for SW2 
// for UNO 1  with 2 butons SW3 SW4 on A1 ;  output D4 for SW3, D5 for SW4
// for UNO 1  with 2 butons SW5 SW6 on A2 ;  output D6 for SW5, D7 for SW6 
// for UNO 1  with 2 butons SW7 SW8 on A3 ;  output D8 for SW7, D9 for SW8
// and for UNO 1  with 1 buton SW9    on A4
//       for UNO 1  with 1 buton SW10   on A5  
// ALL butons analoginput by Resistors PULLDOWN
// each pin D2 D3 D4 D5 D6 D7 D8 D9 with LED and resistor
// D10 and D11 are LED output to UNO2 with Serialcom declared mySerialspe 
// ...
// on UNO2 , LED1 High when SW9 High only and this level Tx to HC05 module 
// on UNO2 , LED2 High when SW10 High only and this level Tx to HC05 module
// ...

// to download in UNO 1
//...
#include<SoftwareSerial.h>
SoftwareSerial mySerialspe(10,11); //Serial com between Uno1 and Uo2 cards, pins 11 and 12 
SoftwareSerial bluetoothSerial(0,1); //Serial comm to module HC05, pins 1 and 2

  // UNO 1  First input A0 
int sensor1Pin=A0;
int sensor1Value=0;
float tension1;
int val1;
int LedPin3 = 3;
int LedPin4 = 4; // this Leds 3 or 4, selected output by tension level on A0 
  
   // second input A1
int sensor2Pin = A1;
int sensor2value = 0;
float tension2;
int val2;
int LedPin5 = 5;
int LedPin6 = 6; // this leds 5 or 6, selected output by tension level on A1

  // 3th input A2
int sensor3Pin = A2;
int sensor3value = 0;
float tension3;
int val3;
int LedPin7 = 7;
int LedPin8 = 8; // this leds 7 or 8, selected output by tension level on A2

  // 4th input A3
int sensor4Pin= A3;
int sensor4value = 0;
float tension4;
int val4;
int LedPin9 = 9;
int ledPin10 = 10; // this leds 9 or 10, selected output by tension level on A3 

void setup(){
// declare the outputs for two leds and the inputs for buttons-sensors
Serial.begin(9600);
pinMode(LedPin1,output);
pinMode(LedPin2, output);
pinMode(sensor1Pin, input);
}

void loop(){
// read the value from the sensor1
val1=analogRead(0);
tension1=(val1*4,9)/1000;
Serial.print("value read after converter= ");
Serial.print(val1);
Serial.println("Digital read= ");
Serial.print(tension1);
Serial.print ( Volts);
Serial.println();
delay(200); 
       

}

  
//   Is't  Correct this first half of sketch ?   ? 
// I suspect an error when I will WRITE this line: tension2=(val2*4,9)/1000;
// it's (2*4,9)/1000; or I must write "val" by other way ?
 
//  John

[/code]

IN last post number 18 the sketch half part.

right ?

John.