G4P Library Processing with Arduino, ISIS Proteus and VSPE

edited May 2016 in Arduino

Hi,

I'm using G4P Library and I want to add Arduino code in my sketch but I can't. I'm using VSPE and Proteus for the Arduino UNO.


Can you help me to add this code to the win_draw1 ? It's for the temperature. I'm sorry for the french code, if you can help me with Skype (in live) it's cool.

Regards, Itachi

Answers

  • and I want to add that to the win_draw1

    You already have code in this method but assuming you want the output from the second sketch to appear in that window, try this.

    In the second Processing code block all the drawing is done in setup lines 26-77 so copy these lines into the win_draw1 method and prefix all the drawing commands with appc.

    // So
    stroke(0);
    // becomes
    appc.stroke(0);
    
  • edited March 2016

    That's what I do for the appc. ! Of course. How can I do to add the void serialEvent to the win_draw1 ?

    I can do screenshot if you want. The interface : http://prntscr.com/acd4fk ISIS Proteus : http://prntscr.com/acd4qx

    I want just to adapt the temperature to this code and when I up the temperature in Proteus, the temperature UP in the interface. It's so hard with G4P ^_^

    Thanks

  • Serial library searches for serialEvent() method from the passed PApplet instance parameter.

  • Like that : synchronized public void serialEvent (PApplet appc, GWinData data) ?

  • serialEvent()'s signature is always: void serialEvent(Serial).

  • edited March 2016

    How can I do to add the (Serial) and the (PApplet [...]) ? ^_^ for the win_draw1

  • If you change the serialEvent method then you don't need to add the serialEvent method to appc.

    So here is the modified method

    // Global variable created
    float f_temperature;
    
    //Traitements à réception d'une fin de ligne
    void serialEvent (Serial monPort)
    {
      //Récupération sur le port série de la tension sous forme de chaine de caractères
      String tensionCar = monPort.readStringUntil('\n');
      if (tensionCar != null)
      {
        tensionCar = trim(tensionCar); // Suppression des blancs au début et à la fin de la chaine de caractère
        int tensionNum = int(tensionCar);  // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
        f_temperature = ((500 * tensionNum) / (3.3 * 1024)) - 50.0;
      }
    }
    

    All the drawing code based on the temperature calculated (f_temperature) in the serialEvent method is now placed in win_draw1

    Notice I have created a new global variable (f_temperature) because you already have one called temperature although you don't appear to use it.

  • edited May 2016

    When I add the code to the win_draw1 I've got an error.

    "unexpected token: void"

    Can you adapt this code ? I have to do that with the humidity, If I see how you do the temperature, I can do the humidity alone.

    Thanks for you help

  • This code will be in the main sketch tab

    // Global variable created
    float f_temperature;
    
    void serialEvent (Serial monPort)
    {
      //Récupération sur le port série de la tension sous forme de chaine de caractères
      String tensionCar = monPort.readStringUntil('\n');
      if (tensionCar != null)
      {
        tensionCar = trim(tensionCar); // Suppression des blancs au début et à la fin de la chaine de caractère
        int tensionNum = int(tensionCar);  // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
        f_temperature = ((500 * tensionNum) / (3.3 * 1024)) - 50.0;
      }
    }
    

    This code is the win_draw1 in the gui tab.

    synchronized public void win_draw1(PApplet appc, GWinData data) { //_CODE_:window1:473254:
      appc.background(background2);
      appc.textFont(loadFont("Roboto-Light-20.vlw")); // police de caractère
      appc.fill(250);
      String s = String.valueOf(d); // jour
      appc.text(s, 632, 77);
      appc.text("/", 644, 77);
      s = String.valueOf(m); // mois
      appc.text(s, 652, 77); 
      appc.text("/", 665, 77);
      s = String.valueOf(y); // année
      appc.text(s, 673, 77);
      appc.text(+hour()+ ":"+minute()+":"+second(), 720, 77);
      // température
      appc.fill(250);
      appc.stroke(0);
      appc.strokeWeight(1);
      //appc.rect (90,20,180,500); // Thermometre
      appc.fill(255, 0, 0);
      appc.fill(0, 0, 255);
      appc.fill(50);
      appc.noStroke();
      appc.rect(210, 10, 20, 360); // rectangle barre
      appc.ellipse(220, 360, 40, 40); // ellipse barre
      // dessin du réservoir
      appc.ellipse(220, 360, 40, 40);
      appc.fill(#FF1008); // ROUGE
      appc.ellipse(220, 360, 40, 40);
      //Gradations et textes tous les 10 degrés
      fill(50);
      strokeWeight(2);
      stroke(50);
    
      //Traitements à réception d'une fin de ligne
    
      //Dessin des cadres -------------------------
      appc.stroke(0);
      appc.strokeWeight(1);
    
      //Dessin du thermomètre -----------------------
      appc.fill(50);
      appc.noStroke();
      //appc.rect(100,70,20,420);
      appc.ellipse(220, 360, 40, 40);
    
      // Dessin du réservoir
      appc.ellipse(220, 70, 20, 20);
      appc.fill(#FF1008); // ROUGE VIF
      appc.ellipse(220, 70, 20, 20);
    
      //Dessin temperature actuelle -----------------------
      appc.noStroke();
      appc.fill(#FF1008); // ROUGE VIF
      appc.rect(105, 476-(50+temperature)*4, 10, (50+temperature)*4);
      appc.fill(#F59300); // ORANGE 
      appc.rect(110, 476-(50+temperature)*4, 3, (50+temperature)*4);
    } //_CODE_:window1:473254:
    

    Notice that the variable f_temperature is modified in the serialEvent method and used in the win_draw1 method.

  • edited May 2016

    Nice, my sketch run.

    But now I'm testing if the temperature can UP or down with Isis Proteus (+ the code Arduino...) and she doesn't work.

    I have to rename the variable temperature for f_temperature in the Arduino code ?

  • Remove line 60, you are creating a local version of f_temperature which hides the global version.

  • edited March 2016

    Alternatively change line 55 to

    temperature = round(((500 * tensionNum) / (3.3 * 1024)) - 50.0);
    

    and delete all statements float f_temperature;

  • It works, really thank you. I'll try the side of moisture and ground now.

    Do you know what is the line I have to add to have the temperature value displayed on the curve is displayed in text, for example : 15 ° ?

  • Not sure what you mean by "on the curve" since I can't run your sketch to try it out. You have something close in line 109 which displays a temperature

  • Sorry, I mean : I want to display the temperature in text. Here it's the thermometer | Here the temperature : 15°

  • I don't know if this is what you mean -

    appc.text("Here the temperature : "+ temperature + "˚", poxX, posY);

    Where posX posY is the position on the curve

  • Yes, it's good thank you !

    How can I do to add a text to an image ? I tried several methods and I found nothing... Like that : http://prntscr.com/acqjp3

  • You can't add text to a PImage object.

  • Okay... I'm going to add this picture to the background. Thank's.

  • edited May 2016

    Hi,

    I have to display a value on my interface from a real Arduino assembly, or when I add value to A2, the A1 value appears, the problem come to my void serial Event or Arduino code ?

    **My Arduino code **:

    int temperature;
    int masse;
    int humidite;
    int comptage;
    
    void setup()
      {
        Serial.begin(9600);
      }
    
    void loop()
      {
    
        temperature = analogRead(A1);
        Serial.println(temperature);
        masse = analogRead(A2);
        Serial.println(masse);
        humidite = analogRead(A3);
        Serial.println(humidite);
        comptage = analogRead(A4);
        Serial.println(comptage);
        delay(1000);
      }
    

    Regards, Itachi

  • edited May 2016

    Do you have an exemple ?

    I have that :

    void serialEvent (Serial monPort)
    {
      //Récupération sur le port série de la tension sous forme de chaine de caractères
      String tensionCar = monPort.readStringUntil('\n');
      if (tensionCar != null)
      {
        tensionCar = trim(tensionCar); // Suppression des blancs au début et à la fin de la chaine de caractère
        int tensionNum = int(tensionCar);  // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
        temperature = round(((500 * tensionNum) / (3.3 * 1024)) - 50.0);
    

    And I want now to do that for the humidity but without the A1, I have in my Arduino code an others analogRead like A2, A3, A4...

    Regards,

  • edited May 2016

    I did several tests since your reply and that does not work. Can you help me to add a new value, I use potentiometer.

    My Arduino code :

    int temperature;
    int masse;
    int humidite;
    int comptage;
    int son;
    
    void setup()
      {
        Serial.begin(9600);
      }
    
    void loop()
      {
    
        temperature = analogRead(A1);
        Serial.println(temperature);
        masse = analogRead(A2);
        Serial.println(masse);
        humidite = analogRead(A3);
        Serial.println(humidite);
        comptage = analogRead(A4);
        Serial.println(comptage);
        son = analogRead(A5);
        Serial.println(son);
        delay(1000);
      }
    

    My Processing code :

    void serialEvent (Serial monPort)
    {
      //Récupération sur le port série de la tension sous forme de chaine de caractères
      String tensionCar = monPort.readStringUntil('\n');
      if (tensionCar != null)
      {
        tensionCar = trim(tensionCar); // Suppression des blancs au début et à la fin de la chaine de caractère
        int tensionNum = int(tensionCar);  // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
        temperature = round(((500 * tensionNum) / (3.3 * 1024)) - 50.0);
    

    As you can see, I do simulation for the temperature, now I want to add 4 others values. I don't know if I have to add new void serialEvent, I try with Firmata for Arduino but it doesn't work too. Can you help me to add 4 others values ? You can do an exemple for 2 values ? I think I can do for the others if I have a good exemple.

    Thanks for you help, it's for my project and I have to finish that for the 18/05.

    Regards.

  • I try with that :

    // Global variable created 
    void serialEvent (Serial monPort)
    {
      //Récupération sur le port série de la tension sous forme de chaine de caractères
      String listeInfo = monPort.readStringUntil('\n');
    
      if(listeInfo == null)
        return; //Aucune données reçues
    
      String[] tableauInfo = listeInfo.split(";"); //Chacun des 5 premières cases contient une info
    
      if (tableauInfo.length != 5)
        return; //Manque des données
    
        /*** TEMPERATURe ***/
        String tensionCar = trim(tableauInfo[0]); // Suppression des blancs au début et à la fin de la chaine de caractère
        int tensionNum = int(tensionCar);  // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
        temperature = round(((500 * tensionNum) / (3.3 * 1024)) - 50.0);
    
        /*** MASSE ***/
        String masse2 = trim(tableauInfo[1]);
        int tension2Num = int(masse2);
        masse = round(((500 * tension2Num) / (3.3 * 1024)) - 50.0);
    
        /*** HUMIDITE ***/ 
        String humidite = (tableauInfo[2]);
    
        /*** COMPTAGE ***/ 
        String comptage = (tableauInfo[3]);
    
        /*** SON ***/  
        String son = (tableauInfo[4]);
    
    
        //Suite du code...
    }
    

    I have the temperature and the height, but I want only the temperature when I'm in A0, and only the height when I'm in A1 with Arduino.

    My Arduino code :

    int temperature;
    int masse;
    int humidite;
    int comptage;
    int son;
    
    void setup()
      {
        Serial.begin(9600);
      }
    
    void loop()
      {
        //Lecture des données
        temperature = analogRead(A1);
        masse = analogRead(A2);
        humidite = analogRead(A3);  
        comptage = analogRead(A4); 
        son = analogRead(A5);
    
        //Écriture des données
        Serial.print(temperature);
        Serial.print(";");
        Serial.print(masse);
        Serial.print(";");
        Serial.print(humidite);
        Serial.print(";");
        Serial.print(comptage);
        Serial.print(";");
        Serial.println(son);
        Serial.print(";");
    
        delay(1000);
      }
    

    Thx ^_^

  • Answer ✓

    I don't think that the problem is with G4P any more, it is really about using Arduino. Perhaps it might be useful to either edit the discussion title or, because or ctreate a new discussion that focuses on this problem.

    Unfortunately I have never used Arduino so I can't really help.

  • No problem, I'm going to do a new thread.

Sign In or Register to comment.