Arduino Forum

Using Arduino => Programming Questions => Topic started by: Biasedturkey on Jun 25, 2019, 06:06 pm

Title: Basic software serial doesn't work
Post by: Biasedturkey on Jun 25, 2019, 06:06 pm
Pin 6 ( software serial Tx pin )  is connected to  pin 5 ( softeware serial Rx )
Send character 'J' t to the software serial Tx  pin 6
Read that character on software serial  Rx pin 5
Print that character on the terminal.

Problem: nothing is printed on the terminal
It  looks like SoftSerial.available() is always false.


Code: [Select]

// SoftwareSerial1
// Receives 1 character from pin 6 (Tx ) on pin 5 ( Rx)
//Print it on the terminal

#include<SoftwareSerial.h>


char SoftReceive;
boolean newData = false;
SoftwareSerial SoftSerial( 5,6 );


void setup()
{
  Serial.begin( 9600 );
  SoftSerial.begin( 9600 );
   
}

void loop()
{
  SoftSerial.listen();
  SoftSerial.write('J');
  delay( 5000 );
 
  if( SoftSerial.available()  )
  {
     SoftReceive = SoftSerial.read();
     newData = true;
  }
  if( newData = true)
  {
   
    Serial.println(SoftReceive);
    newData = false;
  }
 
 

 
}

Title: Re: Basic software serial doesn't work
Post by: srnet on Jun 25, 2019, 06:37 pm
Lookup the Software Serial reference;

"If your project requires simultaneous data flows, see Paul Stoffregen's AltSoftSerial library. AltSoftSerial overcomes a number of other issues with the core SoftwareSerial, but has it's own limitations. Refer to the AltSoftSerial site for more information."
Title: Re: Basic software serial doesn't work
Post by: groundFungus on Jun 25, 2019, 06:42 pm
Code: [Select]
if ( newData = true)
Might want to have a look at the if statement reference (= assignment, == comparison).

If you turn on compiler warnings to "all" in preferences you would have seen a warning that hints at the problem.

But I don't think that software serial will work that way, anyhow.
Title: Re: Basic software serial doesn't work
Post by: Deva_Rishi on Jun 25, 2019, 06:45 pm
you can not write and read using swSerial at the same time. Tx disables interrupts and does not allow anything else to be done while transmitting. There is no hardware buffer at all. Transmission within the same board is not possible (also not with AltSoftSerial btw) Also there is really no point.
Title: Re: Basic software serial doesn't work
Post by: Biasedturkey on Jun 26, 2019, 06:48 pm
srnet: my project doesn't requires simultaneous data flow.
groundFungus: of course   if ( newData = true)   was a typo, and I changed the compiler warnings in the preferences.
Deva_Rishi: I built that simple circuit in order to learn about software serial and with your explanations I realize  that it can't work. I found a small tutorial about software serial that works: Transmit data from the Uno to a Nodemcu board .

Title: Re: Basic software serial doesn't work
Post by: srnet on Jun 26, 2019, 07:00 pm
srnet: my project doesn't requires simultaneous data flow.
Your 'project' might not but the code you posted does.