New and need help with my code

#include <SoftwareSerial.h>

#define RXPIN 2
#define TXPIN 3
#define sketch // UHF_RFID_Reader
#define program // PC Lap Counter
#define TR // Transponder system
char command_scantag[]={0x18,0x03,0xFF};//const
char buffer [10];
int incomingByte;

SoftwareSerial myserial(RXPIN,TXPIN);

void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");
myserial.begin(9600);
Serial.println("[RFtagid] Ready");

}
void loop()
{
// turn on antenna
while(Serial.available())
{
incomingByte = Serial.read();
//if(incomingByte='r')
{
myserial.print(command_scantag);
}

}
delay(1000);
while (myserial.available())
{
incomingByte = myserial.read();

char buffer[10];
sprintf(buffer,"[TR%i]",incomingByte);
Serial.print(buffer);

                              // Serial.print("[TR");               // Original formual
                             //Serial.print(incomingByte,HEX);    
                            //Serial.print("]");

}
}

I am trying to get the code to readout like this. Ex: [TR#######]
The # represents the value form incomingByte.

Thank You

That looks like what it is doing
What is the problem?

Please remember to use code tags when posting code

Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Robin2's serial input basics tutorial may be of interest.

In decimal, a byte will take at most 3 digits. Do the 7 '#' actually mean something? Do you want some padding?

The program is functioning correctly, but the new value appears as the following below.
I am trying to get one whole value as shown [TR19115022214] instead of every three numbers.

Thank You

Serial Ready
[RFtagid] Ready
[TR191] [TR150] [TR22] [TR214].... etc.

Yes, the number represent a tag ID.
Is there a way to choose a line of numbers to display instead?

That only works for null-terminated character strings. Since your array doesn't include a terminator, you have to specify the number of bytes to send:
myserial.print(command_scantag, 3);

Did you want more than one byte per output message? That would be more like:

  if (myserial.available())
  {
    Serial.print("[TR");
    while (mySerial.available())
    {
      incomingByte = myserial.read();
      if (incomingByte < 0x10)
        Serial.print('0'); // Leading 0
      Serial.print(incomingByte, HEX);
    }
    Serial.println("]");
  }

How does the output algorithm find out when you are done sending data? It is just spitting out each byte as it receives it.

P.S. It is more usual to output this kind of info as a chain of 2-digit hexadecimal value. Why do you want decimal? How will you tell apart 191-150-22 and, say, 19-11-50-22 ? If you go for BF9616, no doubt is possible: 2 chars, one byte, always.

Each passive tag I use the value changes on the 11th string of numbers. Is there a way to display just the 11th string of numbers? Ex [TR86]
[TR191][TR150][TR22][TR214][TR182][TR150][TR246][TR182][TR54][TR214][TR86][TR235][TR249][TR0]

Yes sir, that is correct I need more than one byte.

It is not a string: your code makes it into one. Save the values in an array and display the value at index 10.

Thank You, let me try it out.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.