4D systems LCD display reporting integers to Arduino

I am having trouble finding an example code that shows how to read an ledDigit0 widget from a 4D systems LCD that will correspond with an int value in my Arduino code.

I need to adjust an integer to be used as a set point in my arduino code for a function such as:

if (sensorValue > ledDigits0)
{
digitalWrite (outputPin, HIGH); 
}
else
{
digitalWrite(outputPin, LOW);
}

Any help here would be greatly appreciated! I can successfully report data TO the ledDigits0, but receiving the data from a separate ledDigits2 is something I am having trouble figuring out.

Post your code (all of it) and a link to the library, or libraries, you are using, if you really want help.

My code is quite long so it will take time to make it fit in a post. I am just looking for an example code so I can figure out this one bit of communication. I don't need help with the rest of my code, thanks

My code is quite long so it will take time to make it fit in a post.

It would take 10 seconds to click the Additional Options link, and attach your code.

I am just looking for an example code so I can figure out this one bit of communication. I don't need help with the rest of my code, thanks

I don't have one of those devices, but I'm pretty good at reading libraries, and figuring things out. But, if that's not what you want, I'm OK with that.

Best idea is to post on their forum, might get faster support and people who are familiar with the technology helping.

That said...

You need to do the following in your loop() at whatever interval or conditions you want (dont do it every loop).

genieReadObject(GENIE_OBJ_LED_DIGITS, 2); // Trigger a manual read to leddigits2

You then need to set up your event handler to catch these Reported Objects (genieReadObject), as they don't return immediately in the same line of code, they come in via the event handler and get captured that way.

for example:

void myGenieEventHandler(void) 
{
  genieFrame Event;
  genieDequeueEvent(&Event);

  //If the cmd received is from a Reported Object, which occurs if a Read Object is requested in the main code, reply processed here.
  if(Event.reportObject.cmd == GENIE_REPORT_OBJ)
  {
    if (Event.reportObject.object == GENIE_OBJ_LED_DIGITS)                // If the Reported Message was from leddigits
    {
      if (Event.reportObject.index == 2)                              // If Leddigits2 
      {
        leddigits_val = genieGetEventData(&Event);  // Receive the event data from the Leddigits2 
      }
    }
  }
}

Just to give you an idea.

This is actually present in the demo they provide with the library...

Hope that helps

Thank you WanaGo for your input! I have been studying that demo code a lot and the only part I don't understand is how to label that reported int from the screen in order to use it in an if statement within the main loop.

example: the part in ??s is what I don't understand.

if ( ??ledDigits2?? > sensor1)
{
outputPin HIGH
}

Well in this case, its just the variable that is being set in the Event Handler function

if ( leddigits_val > sensor1)
{
digitalWrite(outputPin, HIGH);
}

If you look in the event handler, you will see this:
leddigits_val = genieGetEventData(&Event);

This is just saying, get the Data from the particular event which you have filtered out, and put the value into leddigits_val, or whatever variable you want.

@WanaGo Thanks for all your help! I just have one last question as I am not sure what I'm doing wrong... The code compiles fine, am I missing something obvious?
Where in the code do I place my outputPin if statements? information coming from the screen seems to be being ignored. The relay does not respond to the changes in temperature and the LED set point.

Here is my full completed code:

#define CHANNEL1 8//RelayIN

#include <genieArduino.h>
#include "DHT.h"

#define DHTTYPE DHT22  // DHT 22  (AM2302)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

int sensePin = 2; //DHT sense pin
DHT dht(sensePin, DHTTYPE);

void setup() 
{ 
 // pinMode(outputPin, OUTPUT);
   pinMode(CHANNEL1, OUTPUT);
  
  digitalWrite(CHANNEL1, HIGH);
  delay (500);
  digitalWrite(CHANNEL1, LOW);
  
  genieSetup(9600); //Make sure this is the same baud rate of the LCD and the genieBegin command.
  
  dht.begin();
  //sensors.begin();
  //sensors.setResolution(insideThermometer, 10);

  //pinMode(CHANNEL2, LOW);//Relay for Water Pump

  genieBegin (GENIE_SERIAL, 9600);  //Serial1

  //genieAttachEventHandler(myGenieEventHandler);

  //Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)
  pinMode(4, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
  digitalWrite(4, 1);  // Reset the Display via D4
  delay(100);
  digitalWrite(4, 0);  // unReset the Display via D4
  
  delay (3500); //let the display start up
}
////////////////////////////////////////////////////////////////////////////////////////////////

void loop()
{
 
  genieDoEvents(); // Do this every loop, checks the input buffer for data from the display and runs myGenieEventHandler()
  
  int leddigits2_val = 0;
 
  float humidity = dht.readHumidity();
  float t = dht.readTemperature();

  float temp = (t * 1.8) + 32; //Convert *C to *F.  
 
  static long waitPeriod = millis();
  
  //Read from sensor every 100ms and write to the display
  if (millis() >= waitPeriod) 
  {
    // PUT YOUR CODE HERE FOR TEMP SENSORS
    if(humidity < 100) humidity++; // replace with where you get your data from
    else humidity = 0;
    
    genieWriteObject(GENIE_OBJ_LED_DIGITS, 0, humidity); // write insideTempSensor value to LedDigit0
    
    //insideTempSensorF = ((temp * 9) / 5) + 32; // Convert to Degress F
    genieWriteObject(GENIE_OBJ_LED_DIGITS, 1, temp); // write insideTempSensorF value to LedDigit1
    
    genieWriteObject(GENIE_OBJ_THERMOMETER, 0, temp); // write insideTempSensor value to Thermometer
    genieReadObject(GENIE_OBJ_LED_DIGITS, 2); //in theory.. this reads the number on LedDigit2  
    genieReadObject(GENIE_OBJ_LED_DIGITS, 3);
    waitPeriod = millis() + 100; // rerun this code in another 100ms time. 
  ///////////////////////////////////////////////////////////

}


  if(leddigits2_val > temp)
{
  digitalWrite(CHANNEL1, HIGH);
}
else
{
  digitalWrite(CHANNEL1, LOW);
}
}


 void myGenieEventHandler(void)
{
  float humidity = dht.readHumidity();
  float t = dht.readTemperature();

  float temp = (t * 1.8) + 32; //Convert *C to *F.  
 // int setTemp = 80; //set temp for the relay
 
  static long waitPeriod = millis();
  
  //Read from sensor every 100ms and write to the display
  if (millis() >= waitPeriod) 
  {
    
    // PUT YOUR CODE HERE FOR TEMP SENSORS
    if(humidity < 100) humidity++; // replace with where you get your data from
    else humidity = 0;
    
    genieWriteObject(GENIE_OBJ_LED_DIGITS, 1, humidity); // write insideTempSensor value to LedDigit0
    //insideTempSensorF = ((temp * 9) / 5) + 32; // Convert to Degress F
    genieWriteObject(GENIE_OBJ_LED_DIGITS, 0, temp); // write insideTempSensorF value to LedDigit1
    genieWriteObject(GENIE_OBJ_THERMOMETER, 0, temp); // write insideTempSensor value to Thermometer0
    genieReadObject(GENIE_OBJ_LED_DIGITS, 2);
   

    waitPeriod = millis() + 100; // rerun this code in another 100ms time. 
  ///////////////////////////////////////////////////////////
   
  genieFrame Event;
  genieDequeueEvent(&Event);

  //int leddigits3_val = 0;
  int leddigits2_val = 0;
  leddigits2_val = genieGetEventData(&Event);
  

  //If the cmd received is from a Reported Object, which occurs if a Read Object is requested in the main code, reply processed here.
  if(Event.reportObject.cmd == GENIE_REPORT_EVENT)
  {
    if (Event.reportObject.object == GENIE_OBJ_LED_DIGITS)                // If the Reported Message was from a LED digits
    {
      if (Event.reportObject.index == 2)                              // If LED Digits 2
      {
       leddigits2_val = genieGetEventData(&Event);                    // Receive data from led digits 3 
      }
    }
  }

 }

}

Hi Gustermaximus,

Lots of things wrong in your code... to put it simply

genieSetup(9600); //Make sure this is the same baud rate of the LCD and the genieBegin command.

Gee that is going back a bit... why do you have that?

You then have this:

genieBegin (GENIE_SERIAL, 9600); //Serial1

comment is wrong, but other than that its correct. Does the same thing as the genieSetup above, but the genieSetup was from the very initial version of the library. Are you copying code from various places, or did you find that in the library?
You then have this

//genieAttachEventHandler(myGenieEventHandler);

Why is that commented out? You are not telling the genieArduino library which function it is to call when an event comes in, so nothing in your void myGenieEventHandler(void) function is going to happen...

Your myGenieEventHandler has some weird things going on in there too...

//Read from sensor every 100ms and write to the display
if (millis() >= waitPeriod)
{

Why is all of that code in your myGenieEventHandler function?
Is that just a copy paste issue or is that your actual code?
Looks like you are missing a bracket after that... and if not, then you are calling your events to be unloaded only once every 100ms which is not going to work well...

You also have this, just sitting out in the open, not inside some filtering if statments:
leddigits2_val = genieGetEventData(&Event);

Think you need to pause for a moment and read your code and think about what you are trying to do. The things mentioned above are going to stop most of what you want to achieve from working. After that however, the code in your handler needs some serious changes. Some serious errors/issues going on in there.

Have another go and post again, happy to help but have a think yourself too...

Regards
WanaGo