Announcement

Collapse
No announcement yet.

How to get the Potentiometer value to display through arduino.

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

  • How to get the Potentiometer value to display through arduino.

    I am not able to view the Real time value of Potentiometer on the display. If I use serial print, I can see the values in serial monitor but i don't know how to display that value with LED digits.

    my example code:




    #include <genieArduino.h>


    //double = volt;
    unsigned int sensorPin = A11; // select the input pin for the potentiometer

    double sensorValue; // variable to store the value coming from the sensor
    double value;

    Genie genie;
    #define RESETLINE 4

    void setup()
    {
    Serial.begin(9600);
    genie.Begin(Serial);
    genie.AttachEventHandler(myGenieEvent); // Attach the user function Event Handler for processing events

    pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (Display Reset)

    digitalWrite(RESETLINE, 1); // Reset the Display via D4
    delay(100);
    digitalWrite(RESETLINE, 0); // unReset the Display via D4

    delay (3500);
    }

    void loop() {
    genie.DoEvents();

    }

    void myGenieEvent()
    {
    genieFrame Event;
    genie.DequeueEvent(&Event);
    sensorValue = ((5.0 * analogRead(sensorPin) * 100) / 1023);
    if (abs(sensorValue - value) > 0.03)
    {
    value = sensorValue;
    //Serial.println("sensorValue ");
    //Serial.println(sensorValue);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x00, sensorValue);
    }

    if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    {
    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)// If the reported message is from a Winbutton
    {
    if (Event.reportObject.index == 0) // If the reported message is from Winbutton1
    {
    if (genie.GetEventData(&Event) == 1) // If the data from the Button is a 1
    {
    Serial.println("Done"); // if i put this then only I am getting the Pot value after pressing the button.

    }
    }
    }
    }
    }

  • #2
    Hi,

    Maybe try moving the WriteObject routine to the main loop. I put a small delay in there also which you can adjust

    #include <genieArduino.h>


    //double = volt;
    unsigned int sensorPin = A11; // select the input pin for the potentiometer

    double sensorValue; // variable to store the value coming from the sensor
    double value;

    Genie genie;
    #define RESETLINE 4

    void setup()
    {
    Serial.begin(9600);
    genie.Begin(Serial);
    genie.AttachEventHandler(myGenieEvent); // Attach the user function Event Handler for processing events

    pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (Display Reset)

    digitalWrite(RESETLINE, 1); // Reset the Display via D4
    delay(100);
    digitalWrite(RESETLINE, 0); // unReset the Display via D4

    delay (3500);
    }

    void loop() {

    if (abs(sensorValue - value) > 0.03)
    {
    value = sensorValue;
    //Serial.println("sensorValue ");
    //Serial.println(sensorValue);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x00, sensorValue);
    }

    delay(10);

    genie.DoEvents();

    }

    void myGenieEvent()
    {
    genieFrame Event;
    genie.DequeueEvent(&Event);
    sensorValue = ((5.0 * analogRead(sensorPin) * 100) / 1023);


    if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    {
    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)// If the reported message is from a Winbutton
    {
    if (Event.reportObject.index == 0) // If the reported message is from Winbutton1
    {
    if (genie.GetEventData(&Event) == 1) // If the data from the Button is a 1
    {
    Serial.println("Done"); // if i put this then only I am getting the Pot value after pressing the button.

    }
    }
    }
    }
    }

    Best regards

    Paul

    Comment


    • #3
      Thank you for the response Paul. I also moved the sensorValue (line) to the main loop and its working fine.
      I have another question. I connected four Potentiometers to arduino and getting there values on 4D display. But there is a delay between turning the potentiometer and the value change on display. It takes some time for the display value to change.

      Can we reduce the delay?

      Here is my code:

      #include <genieArduino.h>


      //double = volt;
      unsigned int sensorPin = A8; // select the input pin for the potentiometer
      unsigned int sensorPin1 = A9;
      unsigned int sensorPin2 = A10;
      unsigned int sensorPin3 = A11;
      double sensorValue;
      double sensorValue1;
      double sensorValue2;
      double sensorValue3;// variable to store the value coming from the sensor
      double value;
      double value1;
      double value2;
      double value3;

      Genie genie;
      #define RESETLINE 4

      void setup()
      {
      Serial.begin(9600);
      genie.Begin(Serial);
      genie.AttachEventHandler(myGenieEvent); // Attach the user function Event Handler for processing events

      pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (Display Reset)

      digitalWrite(RESETLINE, 1); // Reset the Display via D4
      delay(100);
      digitalWrite(RESETLINE, 0); // unReset the Display via D4

      delay (3500);
      }

      void loop() {
      sensorValue = ((5.0 * analogRead(sensorPin) * 100) / 1023);
      if (abs(sensorValue - value) > 0.03)
      {
      value = sensorValue;

      //Serial.println("sensorValue ");
      //Serial.println(sensorValue);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x00, sensorValue);
      }
      sensorValue1 = ((5.0 * analogRead(sensorPin1) * 100) / 1023);
      if (abs(sensorValue1 - value1) > 0.03)
      {
      value1 = sensorValue1;

      //Serial.println("sensorValue ");
      //Serial.println(sensorValue);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x01, sensorValue1);
      }
      sensorValue2 = ((5.0 * analogRead(sensorPin2) * 100) / 1023);
      if (abs(sensorValue2 - value2) > 0.03)
      {
      value2 = sensorValue2;

      //Serial.println("sensorValue ");
      //Serial.println(sensorValue);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x02, sensorValue2);
      }
      sensorValue3 = ((5.0 * analogRead(sensorPin3) * 100) / 1023);
      if (abs(sensorValue3 - value3) > 0.03)
      {
      value3 = sensorValue3;

      //Serial.println("sensorValue ");
      //Serial.println(sensorValue);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x03, sensorValue3);
      }
      delay(10);

      genie.DoEvents();

      }

      void myGenieEvent()
      {
      genieFrame Event;
      genie.DequeueEvent(&Event);


      if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
      {
      if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)// If the reported message is from a Winbutton
      {
      if (Event.reportObject.index == 0) // If the reported message is from Winbutton1
      {
      if (genie.GetEventData(&Event) == 1) // If the data from the Button is a 1
      {
      Serial.println("Done"); // if i put this then only I am getting the Pot value after pressing the button.

      }
      }
      }
      }
      }

      Comment


      • #4
        Hi,

        glad that worked out for you.

        Can you please let me know which Arduino you are using.

        You need to remove or comment out this line

        Serial.println("Done"); // if i put this then only I am getting the Pot value after pressing the button. As you can't Serial print to the same serial port as genie as it will cause genie to go out of sync.

        And you can remove the delay(10);

        Best regards

        Paul

        Comment


        • #5
          Hello I am using Arduino mega 2560.
          Its still the same even after removing the delay and commenting serial.print.

          Comment


          • #6
            Hi,

            It might be best if you use Serial 1 on the Mega for the display and this will allow you to use the Serial monitor for Serial.print. The main serial port on the Mega, Serial 0, has a USB to Serial converter attached which can cause issues.

            You will need to physically connect the display to Serial 1 and then alter your code

            Serial.begin(9600);
            Seria1.begin(9600);
            genie.Begin(Serial1);

            You can then use Serial.print to help with debugging.

            I hope this helps

            Best regards

            Paul

            Comment

            Working...
            X