Announcement

Collapse
No announcement yet.

Declaring cool gauges on arduino ide

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declaring cool gauges on arduino ide

    Hi i used the 4D IDE to declare 3 cool gauges on 2 forms for my uLCD-32ptu display. But im unable to understand how to declare 3 gauges with different gaugeVal in the arduino IDE with this sample code i took from the genieArduino_demo sketch.

    void loop()
    {
    static long waitPeriod = millis();
    static float gaugeAddVal = 1;
    static float gaugeVal = roll;

    genie.DoEvents(); // This calls the library each loop to process the queued responses from the display

    if (millis() >= waitPeriod)
    {
    // Write to CoolGauge0 with the value in the gaugeVal variable
    genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x00, gaugeVal);
    gaugeVal += gaugeAddVal;
    if (gaugeVal == 90) gaugeAddVal = -1;
    if (gaugeVal == -90) gaugeAddVal = 1;


    waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
    }
    }
    Last edited by Ahmit; 19 December 2014, 04:45 PM.

  • #2
    Hi Ahmit,

    I've attached a sample arduino program and ViSi-Genie program for you. This sample contains 3 Cool Gauge that increments one after the other.

    Hope this helps.
    Attached Files
    Symon

    Comment


    • #3
      Oh whow thanks alot! One more question thou, how can i display a sensor's value which is connected to the arduino, as the 2 decimal point value itself on the display screen using the strings label in the 4D IDE?

      Comment


      • #4
        You can do that by converting you floating point value to a character array. In page 6 of this application note ViSi-Genie Writing to Genie Objects Using an Arduino host: http://www.4dsystems.com.au/appnote/4D-AN-00018/ you can learn how to write to a string object.
        Symon

        Comment


        • #5
          Thanks again
          Am i doing it right?

          void loop()
          {
          char array[10] = {altitude};
          sprintf(array, "%f", altitude);
          genie.DoEvents();
          static long waitPeriod = millis();

          {
          {
          genie.WriteStr(0, array);
          }

          for(int roll = 0; roll<91; roll++) //x is the value to be written to the first coolgauge
          {
          genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x00, roll); //0x00 is the index of Coolgauge0
          }
          for(int pitch = 0; pitch<91; pitch++)//y is the value to be written to the second coolgauge
          {
          genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x01, pitch); //0x01 is the index of Coolgauge1
          }
          for(heading = 0 ; heading<100; heading++)//z is the value to be written to the third coolgauge
          {
          genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x02, heading);//0x02 is the index of Coolgauge2
          }
          waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
          }

          }

          Comment


          • #6
            Can you send the whole updated arduino code and the genie program? So I can test it here.
            Symon

            Comment


            • #7
              sketch_dec05 is the main sketch which contains the various combined setup and loop functions of the sensors and the display, and it has to be uploaded with the other 6 sketches which help provide pitch and roll data. The attitude and heading values can be displayed in the serial monitor if the void setupdisplay and void loopdisplay functions for the display is not uploaded together.
              Attached Files

              Comment


              • #8
                these are part of the 6
                Attached Files

                Comment


                • #9
                  Hi Ahmit,

                  Can you also send your genie program? I will only test the code snippet you pasted.

                  Thanks again
                  Am i doing it right?

                  void loop()
                  {
                  char array[10] = {altitude};
                  sprintf(array, "%f", altitude);
                  genie.DoEvents();
                  static long waitPeriod = millis();

                  {
                  {
                  genie.WriteStr(0, array);
                  }

                  for(int roll = 0; roll<91; roll++) //x is the value to be written to the first coolgauge
                  {
                  genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x00, roll); //0x00 is the index of Coolgauge0
                  }
                  for(int pitch = 0; pitch<91; pitch++)//y is the value to be written to the second coolgauge
                  {
                  genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x01, pitch); //0x01 is the index of Coolgauge1
                  }
                  for(heading = 0 ; heading<100; heading++)//z is the value to be written to the third coolgauge
                  {
                  genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x02, heading);//0x02 is the index of Coolgauge2
                  }
                  waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
                  }

                  }
                  do you mean the writing to string part?
                  Symon

                  Comment


                  • #10
                    Hi Symon, i cant seem to upload any genie files as it says its an invalid file type whenever i try to upload. Ill attach images of my genie program as it is rather straightforward, sorry about this.
                    Attached Files

                    Comment


                    • #11
                      Hi Ahmit,
                      After compiling/saving your file, In workshop, go to 'File' then 'Zip Project' under 'Save As'. Then attach the zip file here.
                      Symon

                      Comment


                      • #12
                        Oh alright haha, thanks!
                        Attached Files

                        Comment


                        • #13
                          Hi this sample should help you understand writing float value to a string object

                          Code:
                          #include <genieArduino.h>
                          Genie genie;
                          #define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below)
                          
                          void setup()
                          {
                          
                            // NOTE, the genieBegin function (e.g. genieBegin(GENIE_SERIAL_0, 115200)) no longer exists. Use a Serial Begin and serial port of your choice in
                            // your code and use the genie.Begin function to send it to the Genie library (see this example below)
                            // 200K Baud is good for most Arduinos. Galileo should use 115200. 
                            Serial.begin(9600); // Serial0 @ 200000 (200K) Baud
                            genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display
                          
                            // genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
                          
                            // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)
                            // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC
                            // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and
                            // the 4D Arduino Adaptors invert this signal so must be Active High. 
                            pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
                            digitalWrite(RESETLINE, 1); // Reset the Display via D4
                            delay(100);
                            digitalWrite(RESETLINE, 0); // unReset the Display via D4
                          
                            delay (3500); //let the display start up after the reset (This is important)
                          
                            //Turn the Display on (Contrast) - (Not needed but illustrates how)
                            // genie.WriteContrast(1); // 1 = Display ON, 0 = Display OFF.
                            //For uLCD43, uLCD-70DT, and uLCD-35DT, use 0-15 for Brightness Control, where 0 = Display OFF, though to 15 = Max Brightness ON.
                          
                            //Write a string to the Display to show the version of the library used
                            // genie.WriteStr(0, GENIE_VERSION);
                          }
                          
                          
                          void loop()
                          {
                            float altitude = 1.75;
                            float heading = 2.00;
                            char array[10];
                            dtostrf(altitude, 4, 3, array);// converts float to character array
                          
                              genie.DoEvents();
                            static long waitPeriod = millis();
                          
                            {
                              {
                                genie.WriteStr(0, array);
                              }
                          
                              for(int roll = 0; roll<91; roll++) //x is the value to be written to the first coolgauge
                              {
                                genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x00, roll); //0x00 is the index of Coolgauge0
                              }
                              for(int pitch = 0; pitch<91; pitch++)//y is the value to be written to the second coolgauge
                              {
                                genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x01, pitch); //0x01 is the index of Coolgauge1
                              }
                              for(heading = 0 ; heading<100; heading++)//z is the value to be written to the third coolgauge
                              {
                                genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0x02, heading);//0x02 is the index of Coolgauge2
                              }
                              waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
                            }
                          
                          }
                          Symon

                          Comment


                          • #14
                            I applied the changes and uploaded my code but it does not display any data on the gauges nor can i switch between the forms. What could be causing this?

                            Comment


                            • #15
                              Hello,

                              What you have posted is very difficult to read. Instead of just pasting in the code in the main window, please use the CODE box, which is available by clicking the A in the top right corner of the box you type in, and then select the CODE box from there. Paste directly from your Arduino IDE and it will retain the formatting and spacing.

                              Even better however, attach your ino file and your WS4 project as a ZIP, so we can just take your files and run them.

                              Regards
                              James

                              Comment

                              Working...
                              X