Go Down

Topic: code compiles and uploads with no errors, nothing appears in serial monitor (Read 183 times) previous topic - next topic

Avram_Alter

I really appreciate all the help this community has given me so far. With that said, here is my current problem. 
I have an RFID reader hooked up to serial port (USB), and serial port 1. Using SerialPassthrough, I am attempting to send all the incoming data from the 2 RFID readers through the serial(USB). I then want the incoming data to be labelled with reader it came from. I concatenated a title to each array to allow me to do that. Once I did that, everything stopped working. No error codes, no flashing lights, nothing. Here is my code:

 

[/color]
Code: [Select]
int RFIDResetPin = 13;
////////////////////////////////////////////////////////////////////
//this uses the serial passthrough method, that sends data read by the serial1, 2 and 3 ports, sends them throught a TTL to the Serial0 port to be read by the computer
// read more about this method at [url=http://www.arduino.cc/en/Tutorial/SerialPassthrough][color=#1155cc]www.arduino.cc/en/Tutorial/SerialPassthrough[/color][/url]
//////////////////////////////////////////////////////////////////


void setup()

{
Serial.begin(9600);
Serial1.begin(9600);
pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);
}


void loop()
{
char tagString0[13];
int index = 0;
boolean reading = false;



if(Serial.available())
{

int readByte0 = Serial.read(); //read next available byte
if(readByte0 == 2) reading = true; //beginning of tag
if(readByte0 == 3) reading = false; //end of tag
if(reading && readByte0 != 2 && readByte0 != 10 && readByte0 != 13){
//store the tag



tagString0[index] = readByte0;
Serial.println(String("reader1: ") + tagString0); //read out any unknown tag
index ++;
}
}
clearTag(tagString0); //Clear the char of all value
resetReader(); //reset the RFID reader
char tagString1[13];


if(Serial1.available()){


int readByte1 = Serial1.read(); //read next available byte
if(readByte1 == 2) reading = true; //begining of tag
if(readByte1 == 3) reading = false; //end of tag
if(reading && readByte1 != 2 && readByte1 != 10 && readByte1 != 13){
//store the tag
tagString1[index] = readByte1;


Serial.write("Reader2: "  + Serial1.read());
index ++;
}
}
clearTag(tagString1); //Clear the char of all value
resetReader(); //eset the RFID reader
}
void resetReader(){


///////////////////////////////////
//Reset the RFID reader to read again.
///////////////////////////////////
digitalWrite(RFIDResetPin, LOW);
digitalWrite(RFIDResetPin, HIGH);
}
void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
for(int i = 0; i < strlen(one); i++){ one[i] = 0; } } boolean compareTag(char one[], char two[]){
  ///////////////////////////////////
  //compare two value to see if same,
  //strcmp not working 100% so we do this
  ///////////////////////////////////
  if(strlen(one) == 0) return false;
  //empty for(int i = 0; i < 12; i++){ if(one[i] != two[i]) return false; } return true;
  //no mismatches
}



thanks again everyone.


"Throw your soldiers into positions whence there is no escape, and they will prefer death to flight. If they will face death, there is nothing they may not achieve."
-Sun Tzu

Paul_KD7HB

Which Arduino board you are using is kind of important to know if you expect help.

Paul

blh64

You have several problems with your code.  The first is that you do not check how many chars you have read before you stuff them into your input buffer.  If you read more than 13 (the buffer size) you will over write memory and cause problems.

Second, you don't really have 'strings' in your input buffer unless *YOU* supply the trailing nul ('\0').  Your ClearTag() function uses strlen() which looks for that nul char...

GoForSmoke

reply seems locked up, I've lost 2 attempts so first this:

There is only one index for two RFID messages that may arrive concurrent?

There is no RFID library that I saw or defining or creating RFID objects.
There are a few other variables that you missed duplicating, the code is unfinished.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

GoForSmoke

When you make 2 RFIDs with 2 Serials, etc, you don't want

RFID0

RFID1

you want

RFID[ 2 ];  // so you can address which one with an index using code that can run either one the same.

Not so well known is that Serial, Serial1, Serial2, and Serial3 are all instances of the HardwareSerial class.
The upshot is that a pointer to HardwareSerial can be set to any of those that used to print that one.

Here's syntax for Serial, the others are the same, gotta have a Mega2560 to do all 4.
Code: [Select]

HardwareSerial *ser;  // ser is a pointer to a HardwareSerial object

void setup()
{
  Serial.begin( 115200 );

  ser = &Serial;  // pointer becomes address-of Serial

  if ( ser ) ser->println( "got it!" );  // with pointers use -> instead of . 
}          //  ser-> substitutes for Serial.   that's pointer-arrow for object-period

void loop()
{
}
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Robin2

Code: [Select]
@Avram It is a good general practice to print some message from setup() so you can see that the program has started properly. For example

Code: [Select]
Serial.println("Program started");

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Avram_Alter

I am using the mega2560. I'm new to all this, all help is much appreciated
"Throw your soldiers into positions whence there is no escape, and they will prefer death to flight. If they will face death, there is nothing they may not achieve."
-Sun Tzu

Go Up