newsoftserial query

Hi,
ive been trying to get the newsoftserial library working but for some reason it doesnt seem to work for me . I have 2 arduino clones ( atmega8 based ) . They both have common ground and im using pins 7 and 8 as RX and TX for the newsoftserial library. so pin 7 of 1 arduino is connected to pin 8 of the other arduino AND pin 8 of 1 arduino is connected to pin 7 of the other arduino.

This is the code that i have on one arduino which basically transmits

#include <NewSoftSerial.h>

NewSoftSerial mySerial(7, 8);

void setup()  
{
 // Serial.begin(57600);
 // Serial.println("Goodnight moon!");

  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop()                     // run over and over again
{

  mySerial.println("inside loop");
  delay(1000);
}

This is the code on the other arduino which ideally receives the data transmitted from the other arduino and outputs it to the normal Serial port

#include <NewSoftSerial.h>

NewSoftSerial mySerial(7, 8);

void setup()  
{
Serial.begin(9600);
  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
 Serial.println("hi");
}

void loop()                     // run over and over again
{
if(mySerial.available())
{
 Serial.println(mySerial.read()); 
  Serial.println("received");
}
 
}

For some reason when i upload the respective codes to the respective arduinos and monitor the serial port at the receiver arduino. All i get is the serial output “hi” which is in the setup() function. i dont see any other data.Would really appreciate some help…Thanks…

Besides pins 7 and 8, what other pins are connected? Specifically, are the grounds connected?

@PaulS thanks for the reply. Yes the grounds have been connected to each other(common ground) . No other pins as such are connected as this is just a test that im running to see if newSerialSoft is working for me. I do have an LED at pin 13. The arduino which receives the content is connected to the PC via rx/tx ( RS232 ) . the arduino which transmits the text is not connected via any serial connection

You could have a timing problem.

Try to change the baudrate of the hardware serial of the second Arduino to something a bit faster than 9600 e.g. 115200.
Also the softserial can be much faster e.g. 38400.

void setup()  
{
Serial.begin(9600);  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  Serial.begin(115200);
  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
 Serial.println("hi");
}

void loop()                     // run over and over again
{
if(mySerial.available() > 0)    <<<<<<< EXPLICIT > 0
{
 Serial.println(mySerial.read()); 
  Serial.println("received");
}

@robtillaart thanks for your reply. I did what you said..changed hardware serial baud rate to 115200 and softserial baudrate to 38400 ( on both the arduinos). I also changed the baud rate to 115200 on the serial monitor of the arduino IDE.. but still no luck.. same issue..Does this have something to do with the atmega8?is newsoftwareserial not compatible with atmega8?

I have no atmega 8, so you need to dive in the code of the library, to check how it works for the atmega 8. Maybe add some small mods to see if initialization works correctly. NSS uses some tables for timing and you need to check if a table is available for atmega8

Rob

@robtillaart Thanks for the reply.. yea i will check out the library.Also the site only mentions about atmega 168 & 328 so i guess atmega8 isnt supported by default..

YOu can add a table for the ATmega8 yourself (based upon existing tables) and if it works post it here for confirmation.

Rob