Announcement

Collapse
No announcement yet.

Changing to a uLCD 43DT to control a stepper motor driven macro rail

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

  • Changing to a uLCD 43DT to control a stepper motor driven macro rail

    Hi, I have a macro rail setup that comprises an Arduino Mega 2560, an EasyDriver stepper driver and a 16 x 2 LCD display that I use to set the number of images i wish to capture, over what distance the stepper should move between images and a pause to activate the shutter release before progressing to the next image.
    I wold like to replace the 16 x 2 LCD with the uLCD 43DT that I have been playing with but need some help on where to start, I have attached the sketch i need to modify, any help and support would be greatly appreciated.
    Attached Files

  • #2
    going from a serial lcd to a microcontroller lcd requires most of that code redone. Take a look at some examples in Workshop to get an idea on how the display works with your arduino mega before rewriting your code.

    Comment


    • #3
      Hi Techno

      tonton81 is correct, changing from a serial LCD to a intelligent microcontroller lcd does not work the same way. To give you a better idea on how our uLCD module works and how you can program it using the Arduino, please download and read these application notes:

      ViSi-Genie Getting Started - First Project for Diablo16 Display Modules
      http://www.4dsystems.com.au/appnote/4D-AN-00106/

      ViSi-Genie Connecting a 4D Display to an Arduino Host
      http://www.4dsystems.com.au/appnote/4D-AN-00017/

      Best Regards,

      Comment


      • #4
        Hello Mark and tonton81
        Thank you for your responses they are really appreciated. I have connected my Arduino Mega 2560 with the latest 4D shield, designed a very simple dashboard to prove the connection and wrote again a very simple sketch to go with the dashboard. The idea is to move the slider, which on changed reports a message to my Arduino and upon receipt the Arduino sets the LED Digits. Guess what! it does not work.
        The display was disconnected when i uploaded the verified sketch, the Visi Genie program was saved to the uSD card and the display reconnected successfully. could you have a look at the attached and tell me where i am going wrong please.
        Many thanks
        Techno
        Attached Files

        Comment


        • #5
          you forgot to add this to the setup function:

          Code:
            genie.AttachEventHandler(myGenieEventHandler);
          Your code works as is if you include the above correction.
          Also, your using an arduino mega2560, use serial for debugging purposes and move genie to Serial1, that way you'll have no problem reprogramming arduino without disconnecting the lcd. Also use 200000 baud since you have the diablo processor, fix that in the workshop IDE and arduino (Serial1.begin(200000));

          Tony
          Last edited by tonton81; 15th November 2016, 05:36 AM.

          Comment


          • #6
            Thanks Tony, I missed what should have been so obvious, I will now attempt adding additional functions and attempt to absorb the language required to facilitate these in the correct order, slowly but surely seems to be the way to go.

            Comment


            • #7
              Hi Techno,

              In the GenieArduino library, there is an example code that you can refer to. You can also visit our website and go through the app notes tab to check on more application notes for the Arduino tutorials.

              Comment


              • #8
                Hi Guys
                My next problem is sending an instruction to my Arduino via a win button to set a digital pin high, would you help me in looking where I have gone wrong please.
                Attached Files

                Comment


                • #9
                  Hi Techno,

                  Try changing the Momentary: Yes to Momentary: No on the Object Inspector of your ViSi-Genie

                  Momentary: No basically gives you 2 states of the button, ON and OFF

                  You can learn more of this through this application note:
                  http://www.4dsystems.com.au/download...0004_R_1_0.pdf

                  Comment


                  • #10
                    Hi Guys

                    Need your help again please, I have built a display for controlling my macro rail and I am working my way very slowly through the controls trying to learn as i go. I have a problem when pressing the Winbutton0, i need to set 2 pins at the same time but it will not work, if i specify a single pin it is okay, can you tell me where i am going wrong please.
                    Attached Files

                    Comment


                    • #11
                      Hi Techno

                      Wrong location of brackets in your myGenieEventHandler I think

                      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 we received an event from Winbutton0
                            {
                              button_val = genie.GetEventData(&Event);           // extract the data from the event
                      
                              if (button_val == 0)                               // evaluate the data and do something
                              {
                                digitalWrite(dir_pin, LOW);
                                digitalWrite(drive_pin, LOW);
                              }
                      
                              else if (button_val == 1)
                              {
                                digitalWrite(dir_pin, HIGH);
                                digitalWrite(drive_pin, HIGH);
                              }
                            }
                          }
                        }
                      }
                      Try that
                      James

                      Comment


                      • #12
                        Hi James
                        A curly bracket after the if statement! would you believe it, guess I was looking for a more complicated fix and missing the obvious.

                        Thank you so much for your continued support it really is appreciated.

                        Regards

                        Comment


                        • #13
                          Hi Guys
                          I need your help again please.
                          I am trying to rough set the Led digits for "No of Images" and "Distance" using the sliders, then fine tune them using the "Increase" and "Decrease" 4D buttons that sit next to the sliders. I cannot get this to work and was hoping you could point me in the right direction please. All relevant files are attached.
                          Thank you in anticipation.
                          Andy
                          Attached Files

                          Comment


                          • #14
                            Hi Techno,

                            I have modified your code a little bit. I tested it at 9600 baud. You might want to change the baud to 200,000.

                            - moved the ledDigit_val variables above at declaration to prevent it from resetting.
                            - grouped all 4dbuttons in a single report event
                            - included the slider below and linked its value to the leddigits value.

                            You might also want to change the momentary property of 4Dbutton 0 and 1 to no. At the moment, it results into being read twice in the Arduino code so it increment/decrement the values by 2.

                            Code:
                            #include "genieArduino.h"
                            Genie genie;
                            #define RESETLINE 4
                            
                             int ledDigit0_val = 0;   // moved in here
                             int ledDigit1_val = 0;   // moved in here
                            
                            void setup() {
                            
                              Serial1.begin(9600);            // Serial1 @ 200000 (200K) Baud,  changed
                            
                              genie.Begin(Serial1); // Use Serial1 for talking to the Genie Library, and to the 4D Systems display leaving Serial0 for the Arduino.
                              genie.AttachEventHandler(myGenieEventHandler);
                              pinMode(RESETLINE, OUTPUT);
                              digitalWrite(RESETLINE, 1);
                              delay(100);
                              digitalWrite(RESETLINE, 0);
                              delay (3500);
                              genie.WriteContrast(15);
                            
                            }
                            
                            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)
                              {
                                waitPeriod = millis() + 50; // rerun this code to update in another 50ms time.
                              }
                            }
                            
                            void myGenieEventHandler(void)
                            {
                              genieFrame Event;
                              genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below
                            
                             // int ledDigit0_val = 0;  // moved
                             // int ledDigit1_val = 0;  // moved
                            
                                genie.DequeueEvent(&Event); //If the cmd received is from a Reported Event
                                if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
                                {
                                  if (Event.reportObject.object == GENIE_OBJ_4DBUTTON) // If the Reported Message was from a 4Dbutton
                                  {
                            
                                   // ----------------------------
                            
                                    if (Event.reportObject.index == 2) // If 4Dbutton2 (INCREASE Slider0 and Leddigit0 value by 1 each button press)
                                    {       
                                      if (ledDigit0_val < 100) // 100 assumed to be the max, may need to change it
                                      {
                                        ledDigit0_val++; // Increment value by 1
                                        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, ledDigit0_val); // Write value to LED Digits 0 object
                                        genie.WriteObject(GENIE_OBJ_SLIDER, 0, ledDigit0_val); // Write same value to the Slider 0 Object
                                      }
                                    }
                            
                                    // ----------------------------
                            
                                    if (Event.reportObject.index == 1) // If 4Dbutton1 (SUBTRACT Slider0 and Leddigit0 value by 1 each button press)
                                    {       
                                      if (ledDigit0_val > 0) // 0 assumed to be the min, may need to change it
                                      {
                                        ledDigit0_val--; // Decrement value by 1
                                        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, ledDigit0_val); // Write value to LED Digits 0 object
                                        genie.WriteObject(GENIE_OBJ_SLIDER, 0, ledDigit0_val); // Write same value to the Slider 0 Object
                                      }
                                    }
                            
                                    // ----------------------------
                            
                                    if (Event.reportObject.index == 4) // If 4Dbutton2 (INCREASE Slider0 and Leddigit0 value by 1 each button press)
                                    {
                                      if (ledDigit1_val < 100) // 100 assumed to be the max, may need to change it
                                      {
                                        ledDigit1_val++; // Increment value by 1
                                        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, ledDigit1_val); // Write value to LED Digits 0 object
                                        genie.WriteObject(GENIE_OBJ_SLIDER, 01, ledDigit1_val); // Write same value to the Slider 0 Object
                                      }
                                    }
                            
                                    // ----------------------------
                            
                                    if (Event.reportObject.index == 3) // If 4Dbutton1 (SUBTRACT Slider0 and Leddigit0 value by 1 each button press)
                                    {
                                      if (ledDigit1_val > 0) // 0 assumed to be the min, may need to change it
                                      {
                                        ledDigit1_val--; // Decrement value by 1
                                        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, ledDigit1_val); // Write value to LED Digits 0 object
                                        genie.WriteObject(GENIE_OBJ_SLIDER, 1, ledDigit1_val); // Write same value to the Slider 0 Object
                                      }
                                    }
                            
                                 } // ---- end of 4dbutton
                            
                                 if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a 4Dbutton
                                  {   
                                    if (Event.reportObject.index == 0)      // slider 0
                                    {
                                      ledDigit0_val = genie.GetEventData(&Event);
                                    }
                            
                                    if (Event.reportObject.index == 1)      // slider 1
                                    {
                                      ledDigit1_val = genie.GetEventData(&Event);
                                    }
                            
                                  } // end of slider
                            
                                } // end of report event 
                            }
                            Best Regards,

                            Comment


                            • #15
                              Hi Guys
                              It has been a long time since my last problem but i have learned a lot and nearly completed my project. I do have a problem though that is stopping me from drawing this to a close.
                              1) On my display I have 2 forms, Form0 contains the Jogger control and the other has the imaging settings. On the Jogger form, when i press the FWD or BWD button the stepper motor rotates okay, when i press the STOP button the stepper stops, however, there is a delay of about 4 seconds before I can rotate the stepper motor again.
                              2) Form1 has the image settings, there is a reset button that should reset the Arduino and the LCD when pressed, this works during the process of imaging but only after the image being taken has completed its cycle and not immediately which is what i need, any help would be appreciated.
                              Attached Files

                              Comment

                              Working...
                              X