Announcement

Collapse
No announcement yet.

Arduino not exiting genie handling loop??

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

  • Arduino not exiting genie handling loop??

    I have a 70DT display I am using for an interface to control a heat exchanger using the Visi-genie environment. Basic goal being have 3 4D buttons control 3 GPIO pins on the host Arduino Uno to latch 1 of 3 solenoids at a time. Also on the display will be 2 angularmeters that will receive data from the host as it reads a square wave input with the pulseIn function from the flow sensors. First I had the angularmeter responding to various frequency square wave inputs to the host and it was working pretty good, a little slow reacting but could be a timing issue that I need to work out in the end. Next I moved to programming the 4D buttons and was able to get the genie event handler working to control 3 IO pins on the host based on the activation of the buttons on the display. However now that the buttons are reporting back to the host and controlling the pins, the angularmeter has stopped responding the the input from the host controller. I am not sure whether I am getting stuck in the event handler and not getting back into main loop to handle the pulseIn function or if I am just way off somehow. This is my first VisiGenie project and only done a few previous microntroller projects so I am still on the learning curve. Any help is appreciated, code is posted below for any help debugging.


    Code:
    #include <genieArduino.h>
    
    Genie genie;
    #define RESETLINE 4
    int sensorA = 3;
    int solenoidA = 7;
    int solenoidB = 8;
    int solenoidC = 13;
    float duration;
    float frequency;
    
    
    
    
    void setup()
    {
    
    Serial.begin(9600);
    genie.Begin(Serial);
    
    genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
    
    //Routine to reset display to sync to Arduino
    pinMode(RESETLINE, OUTPUT);
    digitalWrite(RESETLINE, 1); //invert logic if not using the shield
    delay(100);
    digitalWrite(RESETLINE, 0); //invert logic if not using the shield
    delay (5000);
    
    pinMode(sensorA, INPUT); //flow sensor square wave input
    pinMode(solenoidA, OUTPUT); //relay driver pin for latching water solenoid
    pinMode(solenoidB, OUTPUT); //relay driver pin for latching water solenoid
    pinMode(solenoidC, OUTPUT); //relay driver pin for latching water solenoid
    
    }
    
    
    
    
    
    void loop() {
    
    genie.DoEvents();
    
    
    
    
    
    
    
    
    
    
    
    
    duration=pulseIn(sensorA,HIGH);
    
    frequency=1/(2*duration/1000000); //convert HIGH duration of pulse to frequency of square //wave, displayed in Hz
    
    /*Serial.println(frequency);
    delay(500);*/
    
    genie.WriteObject(GENIE_OBJ_ANGULAR_METER, 0, frequency);
    
    delay(100);
    
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    void myGenieEventHandler(void)
    {
    genieFrame Event;
    genie.DequeueEvent(&Event);
    
    
    if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    {
    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)
    {
    if (Event.reportObject.index == 2)
    {
    if (genie.GetEventData (&Event) == 1)
    {
    digitalWrite (solenoidA, HIGH);
    digitalWrite (solenoidB, HIGH);
    digitalWrite (solenoidC, LOW);
    
    }
    
    }
    else if(Event.reportObject.index == 1)
    {
    if (genie.GetEventData (&Event) == 1)
    {
    digitalWrite (solenoidA, HIGH);
    digitalWrite (solenoidB, LOW);
    digitalWrite (solenoidC, HIGH);
    
    }
    }
    }
    
    }
    return;
    }

  • #2
    Hello,



    Welcome to the forum!

    Thank you for the information.




    Have you tried to use millis(...) function than delay(...) function? it is not recommended to use a blocking function like delay(...) function when timing is a concern.

    The advantage of utilizing millis(...) function are an accurate timing and non-blocking (it doesn’t block the rest of the program)

    Below is a code snippet of implementing the millis(...) function into your Arduino sketch:

    Code:
    unsigned long previousMillis = 0;
    const long interval = 100;           // interval(milliseconds)
    
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
      genie.DoEvents();
    
      duration = pulseIn(sensorA, HIGH);
      frequency = 1 / (2 * duration / 1000000);
    
      unsigned long currentMillis = millis();
      
      if (currentMillis - previousMillis >= interval) {
        previousMillis = currentMillis;
        
        // Update the angular gauge here
        
      }
    
    }

    Hopefully, this will help you.


    Best regards,
    Kayven

    Comment


    • #3
      Yes I believe the blocking of "delay" was the issue. I commented it out during debugging and the sketch runs seamlessly now. I may implement the millis function though to see if I notice any change/improvement. Thank you for the helpful response.

      Regards,
      JM

      Comment


      • #4
        You're welcome JM!


        Please let me know if there is a progress with your project.
        ​​​​

        Have a nice day!

        Best regards,
        Kayven

        Comment

        Working...
        X