Announcement

Collapse
No announcement yet.

First timer using 4D system and hoping for some help

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

  • John Kevin
    replied
    Hi,

    Thank you for the attached image.

    As mentioned above,
    However, if not digital writes must be reversed as Display Reset is Active Low.
    Since you are not using the 4D Arduino Adaptor Shield, change the reset routine to this:
    Code:
    // stuff related to screen start
    pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
    digitalWrite(RESETLINE, 0); // Reset the Display via D4
    delay(100);
    digitalWrite(RESETLINE, 1); // unReset the Display via D4
    Also, it seems that you are using Arduino Mega - which offers more Hardware Serial ports. You can utilize the Serial1 to communicate with the Display and use the Serial0 to debug your program. Note: Please make sure that you are using the same baud rates to establish communication
    Code:
    Serial.begin(9600);
    Serial1.begin(9600);
    genie.Begin(Serial1); // Use Serial1 for talking to the Genie Library, and to the 4D Systems display
    Based on your wiring, it seems that you got the TX and RX swapped. However, since you will be using the Serial1 to communicate with the Display, you can connect the two modules as follows:
    Display(TX) <--> Arduino Mega(RX1) - pin19
    Display(RX) <--> Arduino Mega(TX1) - pin18


    You are also missing the EventHandler in the setup() method
    Code:
    genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
    I assume i have to go on the 4d workshop and change the win button setting so OnChange = Report message for this to work. i put all the buttons on the same matrix so they can only achievate one at a time
    Yes, that is correct. You can then set the "Momentary" of the button to "No".

    I hope this helps.

    Best Regards,
    Kevin

    Leave a comment:


  • Adi_Soday
    replied
    thank you for your help - i think i have written code to the way its shown above. The text on it are static, so didnt think i need string based text; the only parts that are the gauge, cool gauge, and LED digits. so i have removed that line. Find attach the new version of the code with the changes u have shown me. also a picture of how i have connected up the screen to the board; i have get to test run it as i am still waiting on some of the bike parts to arrive but i guess since i now have an understanding i could try to right a rest code. I assume i have to go on the 4d workshop and change the win button setting so OnChange = Report message for this to work. i put all the buttons on the same matrix so they can only achievate one at a time
    Attached Files

    Leave a comment:


  • John Kevin
    replied
    Hi,

    Can I ask if you have successfully established the communication between the 4D Display and the Arduino? We do have an application note which can help you in connecting the Arduino to a 4D Display module, please check it out:
    AN-00017 ViSi Genie Connecting a 4D Display to an Arduino Host
    https://4dsystems.com.au/blog/4d-an-00017/

    Also, have you taken a look at the genieArduino_Demo? That example is used in conjunction with the above app note I mentioned above.

    Having a quick look at the attached Arduino file, are you using the 4D Arduino Adaptor Shield? If that is the case, then you are using the correct reset routine
    Code:
    // stuff related to screen start
    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
    However, if not digital writes must be reversed as Display Reset is Active Low.


    Code:
    //Write a string to the Display to show the version of the library used
    genie.WriteStr(0, GENIE_VERSION);
    Do you have a string object present in your project? Please ensure that you have otherwise, you are writing to a non-existent object in the display which may cause some issues.

    ​​​​​​​
    Code:
    genie.DoEvents();
    This line of code must be present on the loop function as this will loop to process the queued responses from the display

    ​​​​​​​
    Code:
    void myGenieEventHandler(void)
    This is the user's event handler function. It is called by genieDoEvents() when the following conditions are true

    If you are expecting a message from the display using the button. Please set the OnChanged Event of the Button to "Report Message". The event handler should be something like this:
    Code:
    void myGenieEventHandler(void)
    {
    genieFrame Event;
    genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below
    
    int button_val;
    
    //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
    if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    {
    if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) // If the Reported Message was from a Winbutton
    {
    if (Event.reportObject.index == 0) // If Winbutton0 (Index = 0)
    {
    button_val = genie.GetEventData(&Event); // Receive the event data from the WinButton0
    digitalWrite(13, button_val); //Turn on or off the LED
    }
    }
    }
    }
    ​​​​​​​
    I hope this helps.

    Best Regards,
    Kevin

    Leave a comment:


  • Adi_Soday
    started a topic First timer using 4D system and hoping for some help

    First timer using 4D system and hoping for some help

    Hi

    This is my first time programing on 4D system and need practice in arduino. I am making an E-bike and i wanted to use 4D to make interface; speedometer, battery level, change between different running modes for the DC motor. I am using GEN4-ULCD24PT screen. Please find attach a picture of the interface that i plan to us and the programming below. I have written next to which "if" i need the win button to activite but i cant figure out how to do that. I am not sure if have done the programming for the information going out correctly.

    The program none related parts to 4D system is almost finished complete, just requires another hall sensor for activation purpose only - need to figure out how to do that but the rest should be okay.

    Any help with any of these problem would be great - i am restruggling with the 4D to arduino on the arduino side.



    //pin in use Battery sensor A2, hall sensor for MPH pin 2, screen inputs reset pin 4 - pin 1 and 0 for TXD RXD.
    // pin for motor - enA 9, in1 6, in2 7
    // brake input – pin 10 11

    #include <genieArduino.h>

    Genie genie;

    unsigned long startMillis;
    unsigned long currentMillis;
    const unsigned long period=1;
    int magnetsense=0;
    int laststate=1;
    int rotDirection = 0;
    int pressed = false;
    int RightBrake = 10;
    int LeftBrake = 11;

    int sensPin=2;
    int counter=0;
    int analogInput = A1;
    int value = 0;

    #define RESETLINE 4
    #define enA 9
    #define in1 6
    #define in2 7

    float bikespeed;
    float MPH;
    float circumference= 0.44625;
    float volt = 0.0;
    float voltper = 0.0;



    void setup() {
    Serial.begin(9600);

    genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

    // stuff related to screen start
    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)
    genie.WriteContrast (1);
    genie.WriteStr (0, GENIE_VERSION);

    // stuff related to screen end

    pinMode(analogInput, INPUT);
    startMillis=millis();
    pinMode(sensPin, INPUT);

    //brake set up
    pinMode(RightBrake, INPUT);
    pinMode(LeftBrake, INPUT);

    // Motor setup start
    pinMode(enA, OUTPUT);
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
    // Set initial rotation direction
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    // Motor setup end

    }


    void loop() {

    beginningloop:

    // start of voltage reading
    value = analogRead(0);
    volt = (((value) * (5.0)) / (1024.0)) / (7500) / ((3000) + (7500)) ; // calculation for voltage
    voltper = ((volt) / (24)) * (100); // voltage reading to battery
    genie.WriteObject (GENIE_OBJ_GAUGE, 0x00, voltper) ;
    // end of voltage reading

    // start of speed reading
    currentMillis=millis();
    magnetsense=digitalRead(sensPin);

    if(magnetsense==0 && laststate==1){
    laststate=0;

    if(currentMillis-startMillis>=period && laststate==0){
    bikespeed=circumference/(currentMillis-startMillis)*1000;
    startMillis=currentMillis;
    counter++;
    MPH = bikespeed*3600;
    }
    }
    else{
    if(currentMillis-startMillis>=period && laststate==0){
    startMillis=currentMillis;
    laststate=1;
    }
    }

    genie.WriteObject (GENIE_OBJ_COOL_GAUGE, 0x00, MPH ) ;
    genie.WriteObject (GENIE_OBJ_LED_DIGITS, 0x00, MPH ) ;
    // end of speed reading

    //Start of motor control program
    if ((digitalRead(RightBrake) == HIGH) or (digitalRead(LeftBrake) ==HIGH)) { // braking system
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    rotDirection = 0;
    goto beginningloop;
    }

    if (voltper<10) { //battery to low
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    rotDirection = 0;
    goto beginningloop;
    }

    if () { // if input from winbutton 0, normal run mode
    if (MPH>35) { //slow down speed
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    rotDirection = 0;
    goto beginningloop;
    }

    if (voltper<20) {
    int potValue = analogRead(A0); // Read potentiometer value
    int pwmOutput = (map(potValue, 0, 1023, 0 , 255)/2); // Map the potentiometer value from 0 to 255
    analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
    goto beginningloop;
    }

    int potValue = analogRead(A0); // Read potentiometer value
    int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
    analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
    }

    if () { // if input from winbutton 1, reverse mode
    if (MPH>3) { //slow down speed
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    rotDirection = 0;
    goto beginningloop;
    }

    int potValue = analogRead(A0); // Read potentiometer value
    int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
    analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    rotDirection = 1;
    }

    if () { // if input from winbutton 2, test limit mode

    int potValue = analogRead(A0); // Read potentiometer value
    int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
    analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
    }
    //End of motor control program

    }
    Attached Files
Working...
X