title: Connect Arduino with Qt
body: <p>I'm sending "R" char from Qt to Arduino<br>
  and waiting on that R, to make the LED blink on Arduino. But it doesn't work...  </p>
  
  <p>I think it might be a problem with waitFotBytesWritten or ASCI...<br>
    N.B: Any signal is good; don't need to be a char.   </p>
  
  <p>My Qt code:</p>
  
  <pre><code>QSerialPort serial;
          serial.setPortName("PORT_NAME");
          serial.open(QIODevice::ReadWrite);
          serial.setBaudRate(QSerialPort::Baud9600);
          serial.setDataBits(QSerialPort::Data8);
          serial.setParity(QSerialPort::NoParity);
          serial.setStopBits(QSerialPort::OneStop);
          serial.setFlowControl(QSerialPort::NoFlowControl);
  
          if (serial.isOpen() &amp;&amp; serial.isWritable())
          {
              qDebug() &lt;&lt; "Ready..." &lt;&lt; endl;
              serial.write("R");
  
              if(serial.flush())
                  {
                      qDebug() &lt;&lt; "ok" &lt;&lt; endl;
                  }
                  qDebug() &lt;&lt;"value sent!!! "&lt;&lt; endl;
                  serial.close();
          }
  </code></pre>
  
  <p>My Arduino code</p>
  
  <pre><code>int led = 13; 
  
  void setup()   
  {   
  pinMode(led, OUTPUT);    
  }
  
  void loop() 
  {
  
  if (Serial.read() == 'R') //blink on 5sec  
  {  
    digitalWrite(led, HIGH);   
    delay(5000);              
    digitalWrite(led, LOW);    
  } 
  
  else //Blink on and off 1 sec,1sec  
  {  
     digitalWrite(led, HIGH);   
    delay(1000);              
    digitalWrite(led, LOW);   
    delay(1000);  
  }
  
  }
  </code></pre>
  
  <p>Qt output says: </p>
  
  <pre><code> Manufacturer:  "Arduino (www.arduino.cc)"  
  Busy:  false   
  Ready...   
  ok   
  value sent!!!   
  </code></pre>
  
  <p>Any help would be appreciate</p>
  
  <hr>
  
  <p>Here is complete code:</p>
  
  <p>Qt:</p>
  
  <pre><code>#include &lt;QtCore/QCoreApplication&gt;
  #include &lt;QtCore/QDebug&gt;
  
  #include &lt;QtSerialPort/QSerialPort&gt;
  #include &lt;QtSerialPort/QSerialPortInfo&gt;
  #include &lt;QString&gt;
  
  QT_USE_NAMESPACE
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      QSerialPortInfo info("usbmodem621");
      // Check info of the port
              qDebug() &lt;&lt; "Name        : " &lt;&lt; info.portName();
              qDebug() &lt;&lt; "Manufacturer: " &lt;&lt; info.manufacturer(); //if showing manufacturer, means Qstring &amp;name is good
              qDebug() &lt;&lt; "Busy: " &lt;&lt; info.isBusy() &lt;&lt; endl;
  
              // Initialize Serial
              QSerialPort serial;
              serial.setPortName("usbmodem621");
              serial.open(QIODevice::ReadWrite);
              serial.setBaudRate(QSerialPort::Baud9600);
              serial.setDataBits(QSerialPort::Data8);
              serial.setParity(QSerialPort::NoParity);
              serial.setStopBits(QSerialPort::OneStop);
              serial.setFlowControl(QSerialPort::NoFlowControl);
  
              if (serial.isOpen() &amp;&amp; serial.isWritable())
              {
                  qDebug() &lt;&lt; "Is open : " &lt;&lt; serial.isOpen() &lt;&lt; endl;
                  qDebug() &lt;&lt; "Is writable : " &lt;&lt; serial.isWritable() &lt;&lt; endl;
  
                  QString string("R\n");
                  QByteArray ba("R\n");
                  serial.write(ba);
                  if (serial.bytesToWrite() &gt; 0)
                  {
                      serial.flush();
                      if(serial.waitForBytesWritten(1000))
                      {
                          qDebug() &lt;&lt; "data has been send" &lt;&lt; endl;
                      }
  
                  }
                  if(serial.flush())
                      {
                          qDebug() &lt;&lt; "ok" &lt;&lt; endl;
                      }
                      qDebug() &lt;&lt;"value sent!!! "&lt;&lt; endl;
                      serial.close();
              }
  
              else
              {
                  qDebug() &lt;&lt; "An error occured" &lt;&lt; endl;
              }
              return 0;
  }
  </code></pre>
  
  <p>Arduino:</p>
  
  <pre><code>int led = 13; 
  
  void setup() 
  { 
  Serial.begin(9600);
  pinMode(led, OUTPUT); 
  }
  
  void loop() 
  { 
  
    if (Serial.available() &gt; 0)
    {
    digitalWrite(led, HIGH);  
    delay(5000);             
  
    if(Serial.read() == 'R')
    {
    digitalWrite(led, LOW);   
    delay(1000);  
    }  
    }
  
  else
  {
     digitalWrite(led, HIGH);  
    delay(1000);             
    digitalWrite(led, LOW);  
    delay(1000);  
  }
  
  }
  </code></pre>