Arduino communication to processing via bluetooth

edited April 2017 in Arduino

I would like to send a variable in bluetooth from arduino to processing .. For now I can send it and display it but the worry is that it is in an Array list and I would like it to be a Variable int to be able to modify a slider. An idea ?

Answers

  • I would like to send a variable in bluetooth from arduino to processing .. For now I can send it and display it but the worry is that it is in an Array list and I would like it to be a Variable int to be able to modify a slider.

    Too many ideas in a single paragraph. What have you accomplished so far? You say you can send data... are you doing it via serial? Related to the array part, don't worry about it yet. The first part is to get the B2 part going. For that, you can explore previous posts:https://forum.processing.org/two/search?Search=bluetooth

    Kf

  • For the moment I send the value of a potentiometer by seeing bluetooth with an HC-05, I manage to display it without worries, the only worries is that characters in table and I would like to convert them to variable int or Float

  • You are displaying the values of your arduino in Processing via B2? Perfect. For the second part, could you provide a sample code of your approach? I might be able to help.

    Kf

  • edited April 2017

    `` //importation des différentes librairies import ketai.net.nfc.record.*; import ketai.camera.*; import ketai.net.*; import ketai.ui.*; import ketai.cv.facedetector.*; import ketai.sensors.*; import ketai.net.nfc.*; import ketai.data.*; import ketai.net.bluetooth.*;

    import controlP5.*;
    
    import android.content.Intent;
    import android.os.Bundle;
    import ketai.net.bluetooth.*;
    import ketai.ui.*;
    import ketai.net.*;
    
    PFont fontMy;
    boolean bReleased = true; //Pas de changement d'état de la réponse si le doigt reste //appuyé sur l'écran.
    KetaiBluetooth bt;
    boolean isConfiguring = true;
    String info = "";
    KetaiList klist;
    ArrayList devicesDiscovered = new ArrayList();
    
    ControlP5 cp5;
    
    int c1,c2;
    
    float n,n1;
    
    PFont p = createFont("Arial",40);
    
    int sliderValue = 100;
    
    Textarea myTextarea;
    
    int c = 0;
    
    int value_vit = 1;
    
    int value_inc = 180;
    
    Println console;
    
    void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     bt = new KetaiBluetooth(this);
    }
    
    void onActivityResult(int requestCode, int resultCode, Intent data) {
     bt.onActivityResult(requestCode, resultCode, data);
    }
    
    
    
    
    
    
    
    void setup () {
    size (displayWidth, displayHeight); // taille de la fenètre en pleine écran
    orientation(LANDSCAPE);   // fixe l'orientation en paysage
    background(255); // mets le fond en blanc
    
     cp5 = new ControlP5(this);
    
     // create a new button with name 'buttonA'
      cp5.addButton("Gauche")
         .setValue(0)
         .setPosition(width/15,height/1.45)
         .setSize(width/11,height/7)
         .setColorBackground(color(0,5,112))
         .setFont(createFont("arial",width/60))
         ;
      cp5.addButton("Droite")
         .setValue(0)
         .setPosition(width/5,height/1.45)
         .setSize(width/11,height/7)
         .setColorBackground(color(0,5,112))
         .setFont(createFont("arial",width/60))
         ;  
    
      cp5.addButton("Arret")
         .setValue(0)
         .setPosition(20 , height/5)
         .setSize(width/5,height/4)
         .setColorBackground(color(255,5,5))
         .setFont(createFont("arial",width/60))
         ;
    
      cp5.addButton("Pause")
         .setValue(0)
         .setPosition(width/3 , height/1.45)
         .setSize(width/11,height/7)
         .setColorBackground(color(0,5,112))
         .setFont(createFont("arial",width/60))
         ;
    
      cp5.addKnob("Vitesse")
         .setValue(value_vit)
         .setPosition(width/1.55 , height/8)
         .setSize(width/5,height/3)
         .setColorBackground(color(0,5,112))
         .setFont(createFont("arial",width/60))
         .setNumberOfTickMarks(20)
         ;
    
     cp5.addKnob("Inclinaison")
         .setValue(value_inc)
         .setPosition(width/1.55 , height/1.65)
         .setMax(360)
         .setSize(width/5,height/3)
         .setColorBackground(color(0,5,112))
         .setFont(createFont("arial",width/60))
         .setNumberOfTickMarks(20)
         .setViewStyle(Knob.ELLIPSE)
         .setColorForeground(color(255))
         .setColorBackground(color(255, 178, 34))
         ;
    
         //Console
    
      cp5.enableShortcuts();
    
      frameRate(500);
    
     //Début de connexion Bluetooth.
     bt.start();
     //Sélection de l'application.
     isConfiguring = true;
    
     //Couleur de fond
     fontMy = createFont("SansSerif", 40);
     textFont(fontMy);
     textSize(50);
      text("humanimer", 280, 55);
    
    }
    
    
    
    
    
    
    
    
    void draw () {
    
    //carré humanimer  
    fill(0,5,112);
    noStroke();
    rect(0,0,width/2,height/6);
    
    
    //ligne médiane vertical
    fill(0,5,112);
    noStroke();
    rect(width/2,0,width/90 ,height);
    
    //ligne médiane horizontal
    fill(0,5,112);
    noStroke();
    rect(0,height/2 ,width ,height/60);
    
    //ligne séparatrice carré gauche
    fill(0,5,112);
    noStroke();
    rect(width/4,0,width/90 ,height/2);
    
    //contour fenetre
    noFill();
    stroke(0,5,112);
    strokeWeight(width/75);
    rect(0, 0, width, height);
    
    //écriture nom
    fill (255);
    textSize(width/22);
    text("HUMANIMER", width/5, height/10);
    
    //écriture de vitesse(noeuds) 
    fill (0,5,112);
    textSize(width/40);
    text("Vitesse (Noeuds) ", width/1.5, height/15);
    
    //écriture inclinaison (degré)
    fill (0,5,112);
    textSize(width/40);
    text("Inclinaison (Degré) ", width/1.50, height/1.75);
    
    //écriture de activation
    fill (0,5,112);
    textSize(width/60);
    text("Etat du winch", width/3.2, height/7);
    
    //écriture commander le winch
    fill (0,5,112);
    textSize(width/40);
    text("Commander le winch ", width/8, height/1.75);
    
     //Si la sélection de l'application est valide.
     if (isConfiguring)
     {
      ArrayList names;
      klist = new KetaiList(this, bt.getPairedDeviceNames());
      isConfiguring = false;
     }
     else
     {
     //Affichage de la reception des données.
      noFill();
      noStroke();
      textAlign(LEFT);
      text(info, 20, 104);
     }
    }
    
    //gauche
    public void Gauche(int theValue) { 
     //Envoi de données de la liaison Bluetooth.
      byte[] data = {'g','a','u','c','h','e','\r'};
      bt.broadcast(data);
     //Affichage de la reception des données.
      noFill();
      noStroke();
      textAlign(LEFT);
      text(info, 20, 104);
    
    }
    //droite
    public void Droite(int theValue) { 
     //Envoi de données de la liaison Bluetooth.
      byte[] data = {'d','r','o','i','t','e','\r'};
      bt.broadcast(data);
     //Affichage de la reception des données.
      noFill();
      noStroke();
      textAlign(LEFT);
      text(info, 20, 104);
    
    }
    //Arret urgence
    public void Arret(int theValue) { 
     //Envoi de données de la liaison Bluetooth.
      byte[] data = {'a','r','r','e','t','\r'};
      bt.broadcast(data);
     //Affichage de la reception des données.
      noFill();
      noStroke();
      textAlign(LEFT);
      text(info, 20, 104);
    
    }
    
    //Pause
    public void Pause(int theValue) { 
     //Envoi de données de la liaison Bluetooth.
      byte[] data = {'p','a','u','s','e','\r'};
      bt.broadcast(data);
    
     //Affichage de la reception des données.
      noFill();
      noStroke();
      textAlign(LEFT);
      text(info, 20, 104);
    
    }
    
    void keyPressed() {
    
    }
    public void console(int theValue){
    
    }
    
    void onKetaiListSelection(KetaiList klist) {
     String selection = klist.getSelection();
     bt.connectToDeviceByName(selection);
     //Présence d'une Liste.
     klist = null;
    }
    
    
    //Méthode de gestion des évenements (dans la librairie Ketai), permettant de //recevoir les données. 
    void onBluetoothDataEvent(String who, byte[] data) {
     if (isConfiguring)
     return;
     //Réception.
     info += new String(data);
     //Effacer si le mot trop long.
     if(info.length() > 150)
     info = "";
    }
    
    public void controlEvent(ControlEvent theEvent) {
      println(theEvent.getController().getName());
      n = 0;
    

    } ``

  • Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.

    Kf

  • I am on smartphone today I do it tonight, in this code you can see knob it is them that I would like to evolve with a variable that I would send by bluetooth in this case the value of the potentiometer. This is for my end-of-year project in terminal

  • The edit is ok :)

Sign In or Register to comment.