Go Down

Topic: Basic software serial doesn't work (Read 154 times) previous topic - next topic

Biasedturkey

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;
  }
 
 

 
}


srnet

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."
Co-Designer of the worlds smallest (known) operational satellite, $50SAT.
http://www.50dollarsat.info/
http://www.loratracker.uk/

groundFungus

#2
Jun 25, 2019, 06:42 pm Last Edit: Jun 25, 2019, 06:44 pm by groundFungus
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.

Deva_Rishi

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.
To 'Correct' you have to be Correct. (and not be condescending..)

Biasedturkey

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 .


srnet

srnet: my project doesn't requires simultaneous data flow.
Your 'project' might not but the code you posted does.
Co-Designer of the worlds smallest (known) operational satellite, $50SAT.
http://www.50dollarsat.info/
http://www.loratracker.uk/

Go Up