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. QT Quick Arduino Bluetooth Help
Forum Updated to NodeBB v4.3 + New Features

QT Quick Arduino Bluetooth Help

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 2 Posters 3.9k Views 1 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.
  • M Offline
    M Offline
    Msamples795
    wrote on last edited by
    #1

    hey guys i need alot of help i cant seem to wrap my brain around this i am very new to qt quick application but i got an interface design for my project but i am having trouble figuring out how to interface my program with bluetooth i am having trouble finding some simple examples of transmitting data from my qt quick application to my arduino.

    My project:
    I am building a automated mobile bar. i plan to send a string of data say for example the name of a drink from the QT Quick program over bluetooth to the arduino. the arduino will then take that string and run certain motors based on the input. i already have the arduino program running and controlling certain motors based on a string input through the serial monitor. and i already have the desired layout with my qt quick program. but i cant seem to figure out a way for my qt quick program to send a string based on a drink selected over bluetooth to my arduino.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Msamples795
      wrote on last edited by
      #2

      My Qt Code i havent altered anything but the main.qml file
      @import QtQuick 2.0
      import QtQuick 2.1
      import QtQuick.Controls 1.0
      import QtQuick.Layouts 1.0

      Rectangle {
      id: root
      width: 800
      height: 666
      color: "#2b3049"
      border.width: 9
      border.color: "#ffffff"
      opacity: 1

      Button {
          id: button1
          x: 421
          y: 589
          width: 356
          height: 27
          text: "Dispense"
      }
      
      Rectangle {
          id: rectangle1
          x: 20
          y: 19
          width: 383
          height: 597
          color: "#ffffff"
          border.width: 7
          border.color: "#000000"
          anchors.bottomMargin: 32
          anchors.bottom: parent.bottom
      
          TableView {
              id: drinkTable
              x: 7
              y: 6
              width: 368
              height: 583
              anchors.bottomMargin: 8
              anchors.leftMargin: 7
              anchors.topMargin: 6
              anchors.rightMargin: 8
              anchors.fill: rectangle1
              TableViewColumn{ role: "name" }
              model: drinkList
      
               }
      
          ListModel
          {
              id: drinkList
      
              ListElement{
                  name: "Long Island"
                  ingredients :"1/2 oz triple sec \n1/2 oz light rum \n1/2 oz gin \n1/2 oz vodka \n1/2 oz tequila \n1 oz sour mix \nCola "
                  picture: "http://0.tqn.com/d/cocktails/1/I/I/-/-/-/113253549628.jpg"
                  serial: "LONGIS"
              }
              ListElement{
                  name: "White Russian"
                  ingredients : "1 1/2 oz vodka \n3/4 oz Kahlua coffee liqueur \n3/4 oz cream"
                  picture: "http://0.tqn.com/d/cocktails/1/I/e/N/-/-/svedka-ice-kaffe.jpeg"
                  serial: "WHITERU"
              }
              ListElement{
                  name: "Taquila Sunrise"
                  ingredients : "4 oz orange juice \n2 oz tequila \n1/2 oz grenadine \nOrange slice for garnish \nMaraschino cherry for garnish"
                  picture: "http://0.tqn.com/d/cocktails/1/I/3/K/-/-/tequila-sunrise.jpg"
                  serial: "TEQUILASU"
              }
      
          }
      
      }
      
      Rectangle {
          id: rectangle2
          x: 421
          y: 19
          width: 356
          height: 547
          color: "#ffffff"
          border.width: 7
          border.color: "#000000"
          anchors.bottomMargin: 82
          anchors.bottom: parent.bottom
      
          ListView {
              x: 94
              y: 23
              width: 169
              height: 183
              anchors.leftMargin: 57
              anchors.topMargin: 7
              anchors.rightMargin: 57
              anchors.bottomMargin: 133
      
              Text { text: drinkList.get(drinkTable.currentRow).ingredients }
              }
      
              Image {
                  id: image1
                  x: 66
                  y: 249
                  width: 225
                  height: 249
                  fillMode: Image.PreserveAspectFit
                  source: drinkList.get(drinkTable.currentRow).picture
              }
      }
      
      StatusBar {
          id: status_bar1
          x: 0
          y: 645
          width: 286
          height: 21
      }
      

      }
      @

      i want to Take the serial part of the list element and transmit it to arduino

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Msamples795
        wrote on last edited by
        #3

        Here is my arduino code

        @#include <Arduino.h>

        //pin assignment
        //Enable Pins
        const int EnablePinMotor12 = 22; //enable pin l293d pin 1
        const int EnablePinMotor34 = 24; //enable pin l293d pin 9
        const int EnablePinMotor56 = 26; //enable pin l293d pin 1 chip 2

        //PWM Pins
        const int PWM1 = 2; //PWM Input motor 1 pin 2
        const int PWM2 = 3; //PWM Input motor 2 pin 7
        const int PWM3 = 4; //PWM Input motor 3 pin 10
        const int PWM4 = 5; //PWM Input motor 4 pin 15
        const int PWM5 = 6; //PWM Input motor 5 pin 2 chip 2
        const int PWM6 = 7; //PWM Input motor 6 pin 7 chip 2

        //Buttron pins
        const int button1Pin = 23; // the number of the pushbutton pin
        const int button2Pin = 25; // the number of the pushbutton pin
        const int button3Pin = 27; // the number of the pushbutton pin
        const int button4Pin = 29; // the number of the pushbutton pin
        const int button5Pin = 31; // the number of the pushbutton pin
        const int button6Pin = 33; // the number of the pushbutton pin

        // LED pins
        const int Ledpin1 = 13; //Led PIn

        //Status Variable
        int button1State = 0; // variable for reading the pushbutton status
        int button2State = 0; // variable for reading the pushbutton status
        int button3State = 0; // variable for reading the pushbutton status
        int button4State = 0; // variable for reading the pushbutton status
        int button5State = 0; // variable for reading the pushbutton status
        int button6State = 0; // variable for reading the pushbutton status

        // Ingredient Variables
        int ingredient1 = 0;
        int ingredient2 = 0;
        int ingredient3 = 0;
        int ingredient4 = 0;
        int ingredient5 = 0;
        int ingredient6 = 0;

        String inputString = ""; // a string to hold incoming data
        boolean stringComplete = false; // whether the string is complete
        String savedDrink = "";

        void error(uint8_t flag, uint8_t values){
        Serial.print("ERROR: ");
        Serial.print(flag);
        }
        void setup(){

        //Pin Mode assignment

        pinMode(button1Pin, INPUT);
        pinMode(button2Pin, INPUT);
        pinMode(button3Pin, INPUT);
        pinMode(button4Pin, INPUT);
        pinMode(button5Pin, INPUT);
        pinMode(button6Pin, INPUT);

        pinMode(EnablePinMotor12, OUTPUT);
        pinMode(EnablePinMotor34, OUTPUT);
        pinMode(EnablePinMotor56, OUTPUT);

        pinMode(PWM1, OUTPUT);
        pinMode(PWM2, OUTPUT);
        pinMode(PWM3, OUTPUT);
        pinMode(PWM4, OUTPUT);
        pinMode(PWM5, OUTPUT);
        pinMode(PWM6, OUTPUT);

        pinMode(Ledpin1, OUTPUT);

        delay(1000);

        Serial.begin(9600);
        Serial.println("DRINKING COMMENCE");
        inputString.reserve(200);
        savedDrink.reserve(200);
        }
        void serialEvent() {
        while (Serial.available()) {
        // get the new byte:
        char inChar = (char)Serial.read();
        // add it to the inputString:
        inputString += inChar;
        // if the incoming character is a newline, set a flag
        // so the main loop can do something about it:
        if (inChar == '\n') {
        stringComplete = true;
        }
        }
        }
        void buttonState(){

        button1State = digitalRead(button1Pin);
        button2State = digitalRead(button2Pin);
        button3State = digitalRead(button3Pin);
        button4State = digitalRead(button4Pin);
        button5State = digitalRead(button5Pin);
        button6State = digitalRead(button6Pin);
        

        }
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Msamples795
          wrote on last edited by
          #4

          @
          void motorControl(){

          if (inputString == "FLUSH\n"){

                    Serial.println ("STARTING FULL SYSTEM FLUSH");
          
                    Serial.println ("ENABLING MOTORS");
                    digitalWrite(EnablePinMotor12, HIGH);
                    digitalWrite(EnablePinMotor34, HIGH);
                    digitalWrite(EnablePinMotor56, HIGH);
          
                    Serial.println ("ACTIVATING");
                    analogWrite(PWM1, 175);
                    analogWrite(PWM2, 175);
                    analogWrite(PWM3, 175);
                    analogWrite(PWM4, 175);
                    analogWrite(PWM5, 175);
                    analogWrite(PWM6, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
          
                    Serial.println ("DEACTIVATING");
                    analogWrite(PWM1, 0);
                    analogWrite(PWM2, 0);
                    analogWrite(PWM3, 0);
                    analogWrite(PWM4, 0);
                    analogWrite(PWM5, 0);
                    analogWrite(PWM6, 0);
          
                    Serial.println ("DISABLING MOTORS");
                    digitalWrite(EnablePinMotor12, LOW);
                    digitalWrite(EnablePinMotor34, LOW);
                    digitalWrite(EnablePinMotor56, LOW);
          

          }
          if (inputString == "M1\n"){

                    Serial.println ("STARTING MOTOR 1");
          
                    Serial.println ("ENABLING MOTOR 1");
                    digitalWrite(EnablePinMotor12, HIGH);
          
                    Serial.println ("ACTIVATING MOTOR 1");
                    analogWrite(PWM1, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
                    Serial.println ("DEACTIVATING");
                    analogWrite(PWM1, 0);
          
                    Serial.println ("DISABLING MOTOR 1");
                    digitalWrite(EnablePinMotor12, LOW);
          

          }
          if (inputString == "M2\n"){

                    Serial.println ("STARTING MOTOR 2");
          
                    Serial.println ("ENABLING MOTOR 2");
                    digitalWrite(EnablePinMotor12, HIGH);
          
                    Serial.println ("ACTIVATING MOTOR 2");
                    analogWrite(PWM2, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
          
                    Serial.println ("DEACTIVATING");
                    analogWrite(PWM2, 0);
          
                    Serial.println ("DISABLING MOTOR 2");
                    digitalWrite(EnablePinMotor12, LOW);
          

          }
          if (inputString == "M3\n"){

                    Serial.println ("STARTING MOTOR 3");
          
                    Serial.println ("ENABLING MOTOR 3");
                    digitalWrite(EnablePinMotor34, HIGH);
          
                    Serial.println ("ACTIVATING MOTOR 3");
                    analogWrite(PWM3, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
          
                    Serial.println ("DEACTIVATING");
                    analogWrite(PWM3, 0);
          
                    Serial.println ("DISABLING MOTOR 3");
                    digitalWrite(EnablePinMotor34, LOW);
          

          }
          if (inputString == "M4\n"){

                    Serial.println ("STARTING MOTOR 4");
          
                    Serial.println ("ENABLING MOTOR 4");
                    digitalWrite(EnablePinMotor34, HIGH);
          
                    Serial.println ("ACTIVATING MOTOR 4");
                    analogWrite(PWM4, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
          
                    Serial.println ("DEACTIVATING");
                    analogWrite(PWM4, 0);
          
                    Serial.println ("DISABLING MOTOR 4");
                    digitalWrite(EnablePinMotor34, LOW);
          

          }
          if (inputString == "M5\n"){

                    Serial.println ("STARTING MOTOR 5");
          
                    Serial.println ("ENABLING MOTOR 5");
                    digitalWrite(EnablePinMotor56, HIGH);
          
                    Serial.println ("ACTIVATING MOTOR 5");
                    analogWrite(PWM5, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
          
                    Serial.println ("DEACTIVATING");
                    analogWrite(PWM5, 0);
          
                    Serial.println ("DISABLING MOTOR 5");
                    digitalWrite(EnablePinMotor56, LOW);
          

          }

          if (inputString == "M6\n"){

                    Serial.println ("STARTING MOTOR 6");
          
                    Serial.println ("ENABLING MOTOR 6");
                    digitalWrite(EnablePinMotor56, HIGH);
          
                    Serial.println ("ACTIVATING MOTOR 6");
                    analogWrite(PWM6, 175);
          
                    Serial.println ("DISPENSING");
                    delay(2000);
          
                    Serial.println ("DEACTIVATING");
          
                    analogWrite(PWM6, 0);
          
                    Serial.println ("DISABLING MOTOR 6");
                    digitalWrite(EnablePinMotor56, LOW);
          

          }

          }
          void loop(){
          buttonState();
          motorControl();

          /* if (button1State == HIGH) {
          digitalWrite(EnablePinMotor12, HIGH);
          Ledpin1 == HIGH;
          analogWrite(PWM1, 175);
          delay(2000);
          digitalWrite(EnablePinMotor12, LOW);
          Ledpin1 == LOW;
          }
          else {
          digitalWrite(EnablePinMotor12, LOW);
          }*/

          if (stringComplete) { // print the string when a newline arrives:
          Serial.println(inputString);
          savedDrink = inputString;
          // clear the string:
          inputString = "";
          stringComplete = false;
          }
          }
          @

          as you see in my code my if statement under my motorControl function will run certain motor based on a serial string input

          The idea seems basic to me just simply call the mac address of the bluetooth module transmit the string but i know the coding is more complicated then that

          can someone please help me Thank you

          PS. Moderators i posted this where is best see fit but i wasn't sure so if there is a better place for this to be post it would be much appreciated if this topic was pushed to the most helpful location Thank you

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Msamples795
            wrote on last edited by
            #5

            oh and i also want to have show in the status bar connected but i'm sure if i could figure out the basics of using bluetooth i hopefully might be able to figure out how to say if the device is connected

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kuzulis
              Qt Champions 2020
              wrote on last edited by
              #6

              In case use Bluetooth SPP, you can try the QtSerialPort module.

              In this case:

              1. You should make a Bluetooth SPP connection between PC and Arduino (pair).
              2. Use QSerialPortInfo to select desired serial device (will be the virtual serial port by Bluetooth connection on Windows or /dev/rfcommX on Linux).
              3. Use QSerialPort to read/write your control commands.

              PS: But the Qt Quick here no make sense.. Seems.. Because QtSerialPort can be use from the C++ code.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Msamples795
                wrote on last edited by
                #7

                do you think you can link me an example of that so i can see what your talking about i am new to qt programming and i dont know how to install a module add-on for windows and i cant seem to find out how

                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