# New and need help with my code

**URL:** <https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814>\
**Category:** Programming\
**Created:** [November 22, 2021, 4:18pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814 "2021-11-22T16:18:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jegs67](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jegs67](https://forum.arduino.cc/u/jegs67)\
**Post date:** [November 22, 2021, 4:18pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/1 "2021-11-22T16:18:46Z")

</div>

#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

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [November 22, 2021, 4:20pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/2 "2021-11-22T16:20:31Z")

</div>

> [@jegs67](#):
>
> The # represents the value form incomingByte

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

Please remember to use code tags when posting code

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [November 22, 2021, 4:25pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/3 "2021-11-22T16:25:14Z")

</div>

[Read the forum guidelines](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966) 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](https://forum.arduino.cc/t/serial-input-basics-updated/382007) may be of interest.

---

<div class="post-metadata">

**Author:** ![330R](https://avatars.discourse-cdn.com/v4/letter/3/d78d45/32.png) [@330R](https://forum.arduino.cc/u/330R)\
**Post date:** [November 22, 2021, 4:26pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/4 "2021-11-22T16:26:07Z")

</div>

> [@jegs67](#):
>
> Ex: [TR#######]

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

---

<div class="post-metadata">

**Author:** ![jegs67](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jegs67](https://forum.arduino.cc/u/jegs67)\
**Post date:** [November 22, 2021, 4:28pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/5 "2021-11-22T16:28:18Z")

</div>

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.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/8/b/9/8b9f6978ee07580bb7db0c59b73bf4f17788e76f.png)

---

<div class="post-metadata">

**Author:** ![jegs67](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jegs67](https://forum.arduino.cc/u/jegs67)\
**Post date:** [November 22, 2021, 4:32pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/6 "2021-11-22T16:32:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [November 22, 2021, 4:34pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/7 "2021-11-22T16:34:33Z")

</div>

> [@jegs67](#):
>
> `myserial.print(command_scantag);`

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:

```arduino
  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("]");
  }

```

---

<div class="post-metadata">

**Author:** ![330R](https://avatars.discourse-cdn.com/v4/letter/3/d78d45/32.png) [@330R](https://forum.arduino.cc/u/330R)\
**Post date:** [November 22, 2021, 4:34pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/8 "2021-11-22T16:34:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jegs67](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jegs67](https://forum.arduino.cc/u/jegs67)\
**Post date:** [November 22, 2021, 4:37pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/9 "2021-11-22T16:37:13Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![jegs67](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jegs67](https://forum.arduino.cc/u/jegs67)\
**Post date:** [November 22, 2021, 4:38pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/10 "2021-11-22T16:38:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![330R](https://avatars.discourse-cdn.com/v4/letter/3/d78d45/32.png) [@330R](https://forum.arduino.cc/u/330R)\
**Post date:** [November 22, 2021, 4:41pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/11 "2021-11-22T16:41:14Z")

</div>

> [@jegs67](#):
>
> Is there a way to display just the 11th string of numbers?

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

---

<div class="post-metadata">

**Author:** ![jegs67](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jegs67](https://forum.arduino.cc/u/jegs67)\
**Post date:** [November 22, 2021, 4:45pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/12 "2021-11-22T16:45:08Z")

</div>

Thank You, let me try it out.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 21, 2022, 4:45pm UTC](https://forum.arduino.cc/t/new-and-need-help-with-my-code/927814/13 "2022-05-21T16:45:47Z")

</div>

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