Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Send low to all the 60 gpio pins on arduino when a button is pressed
Forum Updated to NodeBB v4.3 + New Features

Send low to all the 60 gpio pins on arduino when a button is pressed

Scheduled Pinned Locked Moved Solved Mobile and Embedded
11 Posts 3 Posters 2.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    Maybe its too much for the board in one go ?

    1 Reply Last reply
    1
    • J Offline
      J Offline
      jkprog
      wrote on last edited by
      #3

      Can you suggest me a solution or an alternate way to do it? Because I need to have a button to turn on and off all the gpio pins of the arduino.

      mrjjM 1 Reply Last reply
      1
      • J jkprog

        Can you suggest me a solution or an alternate way to do it? Because I need to have a button to turn on and off all the gpio pins of the arduino.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #4

        @jkprog
        You could try with a QTimer and only turn 1 off pr timer tick
        so there will be a small delay between each command.

        Like

        class MainWindow : public QMainWindow {
          Q_OBJECT
         public:
          explicit MainWindow(QWidget* parent = 0);
          ~MainWindow();
          QTimer* timer; // <<<<<<<<<< the timer
          int ID = 2; // <<<<<<<<<< pin id 
         public slots:
          void MyTimerSlots(); // <<<<<< for timer to call
         private slots:
          void on_pushButton_clicked();
         private:
          Ui::MainWindow* ui;
        };
        
        and in .cpp
        
        MainWindow::MainWindow(QWidget* parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow) {
          ui->setupUi(this);
        
          ID = 2; // member
          timer = new QTimer(this);
          connect(timer, SIGNAL(timeout()), this, SLOT(MyTimerSlots()) );
        
        }
        
        void MainWindow::MyTimerSlots() {
          QString OUT = QString  ("<on, %1, 1>").arg(ID++); // create the string
          qDebug() << OUT; // for testing
          //serial.write(OUT); // activate this again.
          if (ID > 32)  { timer->stop(); } // make sure it stops
        }
        
        void MainWindow::on_pushButton_clicked() {
          timer->start(500); // 500 ms. try less later
        }
        

        and you get pr 500 ms

        "<on, 2, 1>"
        "<on, 3, 1>"
        "<on, 4, 1>"
        "<on, 5, 1>"
        "<on, 6, 1>"
        "<on, 7, 1>"
        "<on, 8, 1>"
        "<on, 9, 1>"
        "<on, 10, 1>"
        "<on, 11, 1>"
        "<on, 12, 1>"
        "<on, 13, 1>"
        "<on, 14, 1>"
        "<on, 15, 1>"
        ...

        So the exciting part if this works or its something else.

        the test project.
        https://www.dropbox.com/s/8j6lwdnrcahqd7i/serialtimer.zip?dl=0

        1 Reply Last reply
        2
        • J Offline
          J Offline
          jkprog
          wrote on last edited by
          #5

          Running this program gives the following error:

          error: no matching function for call to 'QSerialPort::write(QString&)'
          serial.write(OUT);
          ^

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Note
            Write wants char * or Qbytearray

            you can do
            serial.write(OUT.toStdString().c_str()); // ugly ;)

            1 Reply Last reply
            1
            • J Offline
              J Offline
              jkprog
              wrote on last edited by
              #7

              The only change i made to the program was : serial.write(OUT.toStdString().c_str(),OUT.size() );
              And its working.. :-)
              Thank you :-)

              mrjjM 1 Reply Last reply
              2
              • J jkprog

                The only change i made to the program was : serial.write(OUT.toStdString().c_str(),OUT.size() );
                And its working.. :-)
                Thank you :-)

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @jkprog
                Super, so i guess the board needed a moment to process the input in between.
                We are using 500 ms. You might be able to lower that to 100-200 for a faster on/off.

                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  Hi,

                  OUT.toLatin1() will be way cleaner.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  mrjjM J 2 Replies Last reply
                  3
                  • SGaistS SGaist

                    Hi,

                    OUT.toLatin1() will be way cleaner.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #10

                    @SGaist

                    Thanks , i can never remember the name
                    as i want to to be called toByteArray ;)
                    Much cleaner than std::string + c_str()

                    1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Hi,

                      OUT.toLatin1() will be way cleaner.

                      J Offline
                      J Offline
                      jkprog
                      wrote on last edited by
                      #11

                      @SGaist thank you :)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved