Softwareserial.read() returning -1

Good afternoon,

Apologies if it's been addressed before, I've tried to locate a thread which might help me resolve my issue without success...

I've tried implementing the RFID sketch from here: RFIDAccessControlSingle/RFIDAccessControlSingle.pde at master · practicalarduino/RFIDAccessControlSingle · GitHub, and have found that it did not work with the setup I've made by following the supplied instructions.

The circuit is very simple and has been confirmed to work with the exception of the RFID component, however, confirmed correct according to the schematic located here: http://www.practicalarduino.com/schematics/rfid-access-control-main-schematic-v1.1.pdf.

After this, I've tried going much simpler, disconnecting everything from the Arduino and using a combination of the first code block found here: http://www.circuitstoday.com/interfacing-rfid-with-arduino — and adding a Serial.println statement inside the loop to see what is being written, while shorting the Tx and Rx pins so that it writes and listens to itself.

Doing all this has (at best) returned a -1, indicating that it had not received anything on the Rx pin.

Assuming the schematic is correct, is there anything else that could be done to see how this can be fixed? I've tried changing pin numbers too, but am completely lost now.

I'd really appreciate any help with this.

Sincere thanks

Assuming the schematic is correct

does not lead to assuming that you followed it correctly.

is there anything else that could be done to see how this can be fixed?

You could:

Post your code
Post a picture of how things are actually connected

Hi PaulS,

Thanks for getting back to me...

Apologies, I should have written "Assuming the schematic was followed correctly" - my mistake...

The code I've used is as follows:

Set 1:

/* #include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of Software Serial Library
Serial.begin(9600); //Setting the baud rate of Serial Monitor
Serial.println("starting up...");
//mySerial.write("SD0");
}

void loop()
{

mySerial.write(1236);
if(mySerial.available()>0)
{
Serial.println(mySerial.read());

delay(100);
}
}*/

Set 2

/*#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of Software Serial Library
Serial.begin(9600); //Setting the baud rate of Serial Monitor
}void loop()
{
//mySerial.write("Hello");
//if(mySerial.available()>0)
mySerial.print("hello");
{
Serial.println(mySerial.read());
delay(150);
}
}*/

And Set 3:

#include <SoftwareSerial.h>
SoftwareSerial serial(9,10);
int analogValue;

void setup()
{
serial.begin(9600);
}

void loop()
{
// read the analog input on pin 0:
analogValue = analogRead(A0);

// print it out in many formats:
serial.print(analogValue); // print as an ASCII-encoded decimal
serial.print("\t"); // print a tab character
serial.print(analogValue, DEC); // print as an ASCII-encoded decimal
serial.print("\t"); // print a tab character
serial.print(analogValue, HEX); // print as an ASCII-encoded hexadecimal
serial.print("\t"); // print a tab character
serial.print(analogValue, OCT); // print as an ASCII-encoded octal
serial.print("\t"); // print a tab character
serial.print(analogValue, BIN); // print as an ASCII-encoded binary
serial.print("\t"); // print a tab character
// serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
// value by 4 because analogRead() returns numbers
// from 0 to 1023, but a byte can only hold values
// up to 255)
serial.print("\t"); // print a tab character
serial.println(); // print a linefeed character

// delay 10 milliseconds before the next reading:
delay(10);
}

These are the most recent sets of code I've used in attempting to get the Arduino to communicate to itself (after realising that it was failing to communicate with the RFID reader).

Apologies, when trying to upload the photos, it fails with an error message "Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator." - It's just 2 jpegs which meet the size requirements - happy to PM them if required.

Thanks again

mySerial.write(1236);

Hmmm. What is the input argument type for the write() method?

Not that it really matters as all of the "code" in "Set 1" (whatever that means) is a comment...

None of the code reads from an RFID device, that I can see.

It makes little sense to keep the hardware serial pins free for debugging when you don't actually use them for debugging.

PaulS,

I may have missed anything constructive here from all the attitude — correct, all the code up until the third set of test code has been commented out so that it doesn't interfere with the code execution.

Correct again in seeing that there is nothing set to read in from an RFID device - that code was mentioned in the url in my original message.

The hardware pins were kept free for the purpose of self-interrogation — also mentioned in my original message — this is to see if the Arduino is even sending and receiving the messages.

Cheers

The hardware pins were kept free for the purpose of self-interrogation -- also mentioned in my original message -- this is to see if the Arduino is even sending and receiving the messages.

The point is that if you are not using the hardware serial pins to read from an external device, and you shouldn't if you don't have to, then you should use them for debugging.

What is ACTUALLY connected to the software serial pins?

Ah ok, I think I get what you mean... I guess, seeing so many examples using the software serial pins, I assumed that it should work the same.

The initial sketch I've used, which attempts to communicate with the RFID reader (which I understand to be a published and working sketch) uses pins 4 and 5 for Rx and Tx, so I've copied that and connected them to the RFID reader opposing (Rx to Tx and Tx to Rx) pins on the reader.

The issue arose because the transponder tags I'm using is not a default one set in the reader (although are compatible), so I've had to send a command to the reader to tell it to accept the tag in accordance with the RFID datasheet and as instructed by the manufacturer.

Doing this didn't seem to make the reader accept the tags, to which the RFID reader OEM recommended I self-interrogate the Arduino to ensure that it is in fact receiving/sending the command, which led me here.

Doing something like shorting the Tx and Rx pins on the Arduino, we were hoping to confirm that it is receiving the messages it's sending by printing them on the console via the hardware serial COM port and confirming whether the reader itself was faulty or not, but this was without success.

So, what WAS connected to the software serial pins was the respective Tx and Rx pins of the reader.

Hope that makes sense?

Thanks again