No announcement yet.

4Duino system and code.

  • Filter
  • Time
  • Show
Clear All
new posts

  • sherwin4D
    Hi Greco,

    I believe this is the information that you are seeking:

    Please do let me know if you have further question on this matter.

    Thanks and regards,

    Leave a comment:

  • greco
    here is the attached code.
    // NB! This is a file generated from the .4Dino file, changes will be lost
    // the next time the .4Dino file is built
    // Define LOG_MESSAGES to a serial port to send SPE errors messages to. Do not use the same Serial port as SPE
    //#define LOG_MESSAGES Serial

    //#define RESETLINE 30
    //#define DisplaySerial Serial0
    #define DisplaySerial Serial1
    //#include "Display_v1Const.h" this may be needed later
    #include "genieArduino.h"
    #include "Picaso_Serial_4DLib.h"
    #include "Picaso_Const4D.h"
    #include <genieArduino.h>
    #include <SoftwareSerial.h>
    // Picaso_Serial_4DLib Display(&DisplaySerial 1 );

    Genie genie;

    // Use software serial on pins 10 and 11, which means set the RX and TX jumpers on
    // the Arduino breakout board to use D10 and D11.
    SoftwareSerial serial(10, 11);

    String inputString = ""; // a string to hold incoming data
    boolean stringComplete = false; // whether the string is complete

    Uncomment to use ESP8266
    #define ESPRESET 17
    #include <SoftwareSerial.h>
    #define ESPserial SerialS
    SoftwareSerial SerialS(8, 9) ;
    Uncomment next 2 lines to use ESP8266 with ESP8266 library from
    #include "ESP8266.h"
    ESP8266 wifi(SerialS,19200);


    was used but stopped for testing====================================================================
    int loops = 0 ;
    String ATresponse ; // response from last AT command, does not include "OK" or "ERROR" and will be partial if command timed out

    routine to handle Serial errors
    void mycallback(int ErrCode, unsigned char Errorbyte)
    #ifdef LOG_MESSAGES/ const char *Error4DText[] = {"OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0"} ;
    LOG_MESSAGES.print(F("Serial 4D Library reports error ")) ;
    LOG_MESSAGES.print(Error4DText[ErrCode]) ;
    if (ErrCode == Err4D_NAK)
    LOG_MESSAGES.print(F(" returned data= ")) ;
    LOG_MESSAGES.println(Errorbyte) ;
    LOG_MESSAGES.println(F("")) ;
    while (1) ; // you can return here, or you can loop
    Pin 13 has an LED connected on most Arduino boards. Just give it a name

    // turn this off for testing====================================================================================
    #define led 13
    while (1)
    digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(200); // wait for a second
    digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
    delay(200); // wait for a second
    // end of routine to handle Serial errors
    // Assign I/O pins
    //int sensor1Pin = A0;
    //int sensor2Pin = A1;
    //int widebandPin = A3;
    //int voltPin = A2;

    int pump1Pin = 13; // all pins below will need to be changed to be correct pin 13 is for testing only
    int temp1Pin = 12;
    int oilFan1Pin = 10;
    int coolFan1Pin = 9;
    int resPin = 4;

    // Variables
    int flag = 0; // i may need to use this but unsure
    //int oilMeter1 = 0;
    //int fuelMeter2 = 0;
    //int widebandMeter = 0;
    //float voltLED = 0;
    //float voltReading = 0;
    //float wideBand = 0;
    //float temp1F;
    //float temp2F;
    //int temp1Gauge;
    //int temp2Gauge;
    //int temp3Gauge;
    //int temp4Gauge;
    //int temp5Gauge;
    //int temp6Gauge;
    int relay1 = 0;
    int relay2 = 0;
    int relay3 = 0;
    int relay4 = 0;
    //int tempHigh = 0;
    //int tempLow = 0;
    //int widebandScope = 0;
    //int wideBandI = 0;
    //int wideBandDecimal = 0;

    void setup()

    Serial.begin(9600); // Serial0 @ 200000 (200K) Baud
    serial.begin(9600); //
    genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display
    genie.Begin(serial); // Use the software serial port to communicate with the display module
    genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events

    pinMode(pump1Pin, OUTPUT);
    digitalWrite(pump1Pin, LOW);
    pinMode(temp1Pin, OUTPUT);
    digitalWrite(temp1Pin, LOW);
    pinMode(oilFan1Pin, OUTPUT);
    digitalWrite(oilFan1Pin, LOW);
    pinMode(coolFan1Pin, OUTPUT);
    digitalWrite(coolFan1Pin, LOW);
    pinMode(resPin, OUTPUT);
    // Reset Display
    digitalWrite(resPin, 0);
    digitalWrite(resPin, 1);
    delay (3500);

    //------------------------------------------- This is the start of the Loop --------------------------------------------------------------------------
    void loop()
    static long waitPeriod = millis();

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

    if (millis() >= waitPeriod)
    if(flag ==1){

    if (relay1 == 0)
    digitalWrite(pump1Pin, HIGH);
    genie.WriteObject(GENIE_OBJ_USER_LED, 0, 1);
    //digitalWrite(pump1Pin, LOW);
    genie.WriteObject(GENIE_OBJ_USER_LED, 0, 0);
    if (relay2 == 0)
    //digitalWrite(temp1Pin, HIGH);
    genie.WriteObject(GENIE_OBJ_USER_LED, 1, 1);
    //digitalWrite(temp1Pin, LOW);
    genie.WriteObject(GENIE_OBJ_USER_LED, 1, 0);
    if (relay3 == 1)
    // digitalWrite(oilFan1Pin, HIGH);
    genie.WriteObject(GENIE_OBJ_LED, 2, 1);
    //digitalWrite(oilFan1Pin, LOW);
    genie.WriteObject(GENIE_OBJ_LED, 2, 0);
    if (relay4 == 1)
    // digitalWrite(coolFan1Pin, HIGH);
    genie.WriteObject(GENIE_OBJ_LED, 3, 1);
    // digitalWrite(coolFan1Pin, LOW);
    genie.WriteObject(GENIE_OBJ_LED, 3, 0);
    else if(flag ==0){
    genie.WriteObject(GENIE_OBJ_USER_LED, 0, 0);
    genie.WriteObject(GENIE_OBJ_USER_LED, 1, 0);
    genie.WriteObject(GENIE_OBJ_USER_LED, 2, 0);
    genie.WriteObject(GENIE_OBJ_USER_LED, 3, 0);
    genie.WriteObject(GENIE_OBJ_USER_LED, 4, 0);
    genie.ReadObject(GENIE_OBJ_4DBUTTON, 14);
    genie.ReadObject(GENIE_OBJ_4DBUTTON, 15);
    genie.ReadObject(GENIE_OBJ_4DBUTTON, 16);
    genie.ReadObject(GENIE_OBJ_4DBUTTON, 17);
    waitPeriod = millis() + 20;
    //==================================================================================================== =========================================
    void myGenieEventHandler(void)
    genieFrame Event;

    int rockersw3_val;
    int rockersw2_val;
    int rockersw1_val;
    int rockersw0_val;

    //Evaluate the event
    if (genie.EventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_4DBUTTON, 17)){ //if the event is a REPORT_OBJ from 4DBUTTON17
    rockersw3_val = genie.GetEventData(&Event); //extract the MSB and LSB values and pass them to rockersw_val
    if (rockersw3_val == 0) //if Rockerswitch is off
    relay4 = 0; //"Switch audio input to HD Radio"
    else if (rockersw3_val == 1) //if Rockerswitch is on
    relay4 = 1; //"Switch audio input to SAT Radio"
    if (genie.EventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_4DBUTTON, 16)){ //if the event is a REPORT_OBJ from 4DBUTTON16
    rockersw2_val = genie.GetEventData(&Event); //extract the MSB and LSB values and pass them to rockersw_val
    if (rockersw2_val == 0) //if Rockerswitch is off
    relay3 = 0; //"turn off" system"
    else if (rockersw2_val == 1) //if Rockerswitch is on
    relay3 = 1; //"turn on" system"
    if (genie.EventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_4DBUTTON, 15)){ //if the event is a REPORT_OBJ from 4DBUTTON15
    rockersw1_val = genie.GetEventData(&Event); //extract the MSB and LSB values and pass them to rockersw_val
    if (rockersw1_val == 0) //if Rockerswitch is off
    relay2 = 0; //"turn off" Relay2"
    else if (rockersw1_val == 1) //if Rockerswitch is on
    relay2 = 1; //"turn on" Relay2"
    if (genie.EventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_4DBUTTON, 14)){ //if the event is a REPORT_OBJ from 4DBUTTON14
    rockersw0_val = genie.GetEventData(&Event); //extract the MSB and LSB values and pass them to rockersw_val
    if (rockersw0_val == 0) //if Rockerswitch is off
    relay1 = 0; //"turn off" Relay1"
    else if (rockersw0_val == 1) //if Rockerswitch is on
    relay1 = 1; //"turn on" Relay1"
    SerialEvent occurs whenever a new data comes in the
    hardware serial RX. This routine is run between each
    time loop() runs, so using delay inside loop can delay
    response. Multiple bytes of data may be available.
    void serialEvent() {
    while (Serial.available()) {
    // get the new byte:
    char inChar = (char);
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
    stringComplete = true;


    Attached Files

    Leave a comment:

  • greco
    started a topic 4Duino system and code.

    4Duino system and code.

    I am looking for any help that can be given. I am new to this and coding but i do understand some.Here is what i have done so far. I Used the program Visi-Genie and created a multi form display. all the switch and gauges were set and linked. i can change pages in the 4d workshop and use the GTX program to test all functions which work with no issues. The program is connected this to the arduino board. i have looked for code but can not find any to connect the user-buttons to the display. i am just trying to use switches to turn on/off items. ( currently using the LED on pin 13 for)
    I wrote the same display in the Arduino extended and can make the buttons work on the main form but can not change to a second form. so the help i need is code to connect the display to arduino and a way to test or code to change to a form and uses the buttons on this new form. any help of a direction to look would be greta.