Go Down

Topic: QSerialPort opens Arduino but is not writting in. (Read 486 times) previous topic - next topic

CharlieHdz

Hi, I have a program where I send commands from Qt to Arduino Uno Serial.

I had tested several functions with the Serial Monitor in IDE, and it worked.

The problem is the write from Qt application. The sequence is to set up the Serial device, then open it and lastly write a command to the Arduino.

When I open the Arduino from Qt, the L led blink a few times, then it turns off itself, and later it's on stately.

What does that mean? -Is it identifying or receiving information?

This info will be very useful to understand where is the error, but I bet that is in the writing. There is no code errors or Serial error, it just doesn't write... Even when I create a program that turns on LEDs whatever command is set in the Serial... It still not responding.


void getSimpleSerial(){
  if(Serial.available()){
    turnOn();
  }
}



void loop() {
  getSimpleSerial();
}

Kind Regards

ieee488

Whenever any program connects to the USB, the Arduino will first check to see whether a sketch is being uploaded. If there isn't then it resumes to ordinary serial port.
http://forum.arduino.cc/index.php?topic=25175.0

CharlieHdz

I'm aware about this startup time, even in thet serial monitor, you need to wait. Even though, The Arduino had started a long time before writing from Qt.

Do you know what the "L" led described above means?

I'm pretty sure that is connected but the Application is not able to write somehow.

CrossRoads

L flashing means that D13, the SCK pin, is being toggled. Usually by the board being reset a few times and trying to kick off the bootloader, which is not seeing download activity and finally starting your sketch.

Where is you setup() to call out Serial.begin(with a speed here)?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CharlieHdz

L flashing means that D13, the SCK pin, is being toggled. Usually by the board being reset a few times and trying to kick off the bootloader, which is not seeing download activity and finally starting your sketch.

Where is you setup() to call out Serial.begin(with a speed here)?
L flashing means that D13, the SCK pin, is being toggled. Usually by the board being reset a few times and trying to kick off the bootloader, which is not seeing download activity and finally starting your sketch.

Where is you setup() to call out Serial.begin(with a speed here)?
Interesting, because I'm not downloading anything, I'm just open it and sending a character...That is confusing for me.

void setup() {
  pinMode(RED_PIN,OUTPUT);
  pinMode(GREEN_PIN,OUTPUT);
  pinMode(BLUE_PIN,OUTPUT);

  Serial.begin(9600);
}

In the C++ program I did pretty much the same...

    microPort->setBaudRate(QSerialPort::Baud9600);
    microPort->setDataBits(QSerialPort::Data8);
    microPort->setParity(QSerialPort::NoParity);
    microPort->setStopBits(QSerialPort::OneStop);
    microPort->setFlowControl(QSerialPort::NoFlowControl);

AFAIK, I don't need to configure anything else to make it worked.

PaulS

Quote
Interesting, because I'm not downloading anything, I'm just open it and sending a character...That is confusing for me.
Post your Qt code. If you have a function like:

Code: [Select]
void needToSendSerialData(uint8_t someDataToSend)
{
   microPort->open();
   microPort->write(someDataToSend);
   microPort->close();
}

you will be causing the Arduino to reset every time you want to send it data.
The art of getting good answers lies in asking good questions.

ieee488

#6
Jan 10, 2018, 03:23 pm Last Edit: Jan 10, 2018, 03:24 pm by ieee488
.


PaulS

The art of getting good answers lies in asking good questions.

ieee488

I wish I'd said that.
There is no way to delete a post on this forum.
I had too many tabs open.

PaulS

There is no way to delete a post on this forum.
I had too many tabs open.
There is the "Report to moderator" link in every post. The way to delete a post is to ask a moderator to do it. But, not after being called out on it.
The art of getting good answers lies in asking good questions.

CharlieHdz

Actually, I solved it so far.

The solution was to wait a few ms to the startup and send commands finish.

    QCoreApplication a(argc, argv);

    LedStripsSender s;
    QTest::qWait(500);

    for(char c;cin>>c;){
        if(c == 'i' || c=='o'){
            s.send(c);
            QTest::qWait(500);
        }
        if(c=='q')
            break;
        else
            qDebug()<<"Main():: command not supported";
    }
    return 0;

Now, I'm interested in know how much it las Arduino to startup (surely depends of the Arduino program).

The qWait after sending message is to ensure that the command was sent. This is because the application gives back the Serial Port resources.

I'm going to make it as solved, thanks.

PaulS

Quote
Now, I'm interested in know how much it las Arduino to startup (surely depends of the Arduino program).
No, it is not dependent on the program. On startup, the bootloader starts, looking for a new sketch to be loaded. After a measurable time, the bootloader will concede that that is not going to happen. So, the currently loaded sketch starts running. init() is called, which does exactly the same amount of work for a blink sketch, an empty sketch, or a sketch that nearly fills the flash memory. Then, setup gets called, and the Arduino is up and running.

Now, the sketch can do all kinds of things before Serial.begin() is called, and your app can send the Arduino data. But, you shouldn't plan on doing that. Get Serial up and going first.
The art of getting good answers lies in asking good questions.

Go Up