title: Array Data Reading Failed
body: <p>I am reading the data from a &quot;Torque Wrench&quot; using &quot;USB Host Shield2.0&quot; and Arduino UNO. I am receiving correct data from my &quot;Torque Wrench&quot; Data is receiving in a array.
  But when I started reading data after &quot;for&quot; loop inside <code>Void loop()</code>  I am receiving incorrect data. I attached Both output pictures correct and incorrect data.</p>
  <p>Basically I am read data from Torque Wrench and send to receiver using Nrf24l01. I am receiving incorrect data.</p>
  <p>My question is :- Why I am reading Incorrect data outside &quot;for&quot; loop.</p>
  <ol>
  <li>Correct Data inside &quot;for&quot; loop :- <a href="https://i.stack.imgur.com/YB8Ov.png" rel="nofollow noreferrer">enter image description here</a></li>
  <li>Incorrect Data outside &quot;for&quot; loop :- <a href="https://i.stack.imgur.com/lbmit.png" rel="nofollow noreferrer">enter image description here</a></li>
  </ol>
  <pre><code>#include &lt;SPI.h&gt; // for SPI communication
  #include &lt;nRF24L01.h&gt;
  #include &lt;RF24.h&gt;
  
  #include &lt;cdcacm.h&gt;
  #include &lt;usbhub.h&gt;
  
  //#include &quot;pgmstrings.h&quot;
  
  // Satisfy the IDE, which needs to see the include statment in the ino too.
  #ifdef dobogusinclude
  #include &lt;spi4teensy3.h&gt;
  #endif
  #include &lt;SPI.h&gt;
  
  
  
  RF24 radio(7, 8); // CE, CSN
  const byte address[6] = {'R','x','A','A','A','B'}; // the address the the module
  
  class ACMAsyncOper : public CDCAsyncOper
  {
  public:
      uint8_t OnInit(ACM *pacm);
  };
  
  uint8_t ACMAsyncOper::OnInit(ACM *pacm)
  {
      uint8_t rcode;
      // Set DTR = 1 RTS=1
      rcode = pacm-&gt;SetControlLineState(3);
  
      if (rcode)
      {
          ErrorMessage&lt;uint8_t&gt;(PSTR(&quot;SetControlLineState&quot;), rcode);
          return rcode;
      }
  
      LINE_CODING  lc;
      lc.dwDTERate  = 9600;
      lc.bCharFormat  = 0;
      lc.bParityType  = 0;
      lc.bDataBits  = 8;
  
      rcode = pacm-&gt;SetLineCoding(&amp;lc);
  
      if (rcode)
          ErrorMessage&lt;uint8_t&gt;(PSTR(&quot;SetLineCoding&quot;), rcode);
  
      return rcode;
  }
  
  USB     Usb;
  //USBHub     Hub(&amp;Usb);
  ACMAsyncOper  AsyncOper;
  ACM           Acm(&amp;Usb, &amp;AsyncOper);
  
  
  
  
  void setup() {
  
    Serial.begin(9600);
    radio.begin();
    radio.openWritingPipe(address);
    radio.setPALevel(RF24_PA_MAX);
    radio.stopListening(); 
  
    #if !defined(__MIPSEL__)
    while (!Serial); 
  #endif
    Serial.println(&quot;Start&quot;);
  
    if (Usb.Init() == -1)
        Serial.println(&quot;USB Not Connected&quot;);
  
    delay( 200 ); 
   
  
  }
  
  void loop() {
    
    
  
     Usb.Task();
   
      if( Acm.isReady()) {
         uint8_t rcode;
  
         /* reading the keyboard */
         if(Serial.available()) {
           uint8_t data= Serial.read();
           /* sending to the phone */
           rcode = Acm.SndData(1, &amp;data);
           if (rcode)
              ErrorMessage&lt;uint8_t&gt;(PSTR(&quot;SndData&quot;), rcode);
         }
  
         delay(10);
  
          uint8_t  buf[64];
          uint16_t rcvd = 64;
          char text[64];
          
          rcode = Acm.RcvData(&amp;rcvd, buf);
           if (rcode &amp;&amp; rcode != hrNAK)
              ErrorMessage&lt;uint8_t&gt;(PSTR(&quot;Ret&quot;), rcode);
  
              if ( rcvd ) { 
             
               for(uint16_t i=0; i &lt; rcvd; i++ ) 
                { 
                 // Serial.print((char)buf[i]);  // correct Data read from torque wrench
                  text[i] = (char)buf[i];
                }
  
                
                Serial.println(text);  // reading wrong data here
                
                //radio.write(&amp;text, sizeof(text));   
                //Serial.println(text);               
              }
          delay(10);
      }
    
  }
  </code></pre>