• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

Duet2 Wifi PanelDue serial passthrough with Arduino Due

Scheduled Pinned Locked Moved
PanelDue
5
21
911
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    Olivimages
    last edited by 28 Jun 2020, 09:51

    Hello guys,

    I wanted to make a CNC Pendant. I have a PaneDue connected to Duet2 Wifi.
    For that i use a Arduino Due in 3,3v. For now it's working sending GCode through PanelDue port.
    But i wanted to have also PanelDue working.

    I use that code to make a PanelDue serial passthrough :

    void loop() {
        // read from port 1, send to port 2, transmit from Duet to PanelDUE
    while (Serial1.available() > 0) {
        int inByte = Serial1.read();
        Serial2.write(inByte);
        Serial.print(char(inByte)); // echo to Serial Monitor
    }
      // read from port 2, send to port 1, transmit from PanelDUE to Duet 
    while (Serial2.available() > 0) {
        int inByte = Serial2.read();
        Serial1.write(inByte);
        Serial.print(char(inByte)); // echo to Serial Monitor
    }
    

    I see PanelDue sending its M408 to Duet but have no response from the other side.
    Move buttons on the PanelDue are functioning, the Gcode are sent via passthrough but the "Macros" and "SD Card jobs" page are not populated. It seems that there is no communication from Duet.

    N40 M408 S0*88
    N41 M408 S0*89
    N42 M408 S0*90
    N43 M408 S0*91
    N44 M408 S0*92
    N45 M408 S0*93
    N46 M408 S0*94
    

    Have you any ideas about that ?

    Thanks
    Olivier

    1 Reply Last reply Reply Quote 0
    • ?
      A Former User
      last edited by 28 Jun 2020, 10:25

      have you seen https://github.com/Duet3D/CNC-Pendant-Firmware ?

      undefined 1 Reply Last reply 28 Jun 2020, 11:57 Reply Quote 0
      • undefined
        FelixH
        last edited by 28 Jun 2020, 10:51

        In addition to @bearer here is the topic where all originated:

        https://forum.duet3d.com/topic/11389/cnc-style-pendant

        I have one of these with a modified Arduino Nano (a SMD resistor has to be changed) working together with the Panel Due. It makes a world of a difference how easier it is now to jog around...

        1 Reply Last reply Reply Quote 0
        • undefined
          Olivimages @A Former User
          last edited by Olivimages 28 Jun 2020, 11:57

          @bearer
          Yes i read this topic many many times, tried to understand the "passthrough" code but a bit too complicated for me.
          I have build a pendant with joystick and buttons that works.
          The only thing that doesn't work is the passthrough for continuing to use the PanelDue.
          I also tried to weld the Duet_TX to Panel_RX (so bypassing the Arduino), it is better but have no correct return (current position, etc) so i would to implement the thing using code to be transparent.

          undefined 1 Reply Last reply 28 Jun 2020, 12:00 Reply Quote 0
          • undefined
            FelixH @Olivimages
            last edited by 28 Jun 2020, 12:00

            @Olivimages when you say "it doesn' work", what do you mean exactly? it does not move? it moves erratically?

            Could you eventually post a wiring diagram of what you have done as well as the code? otherwise, we will be trying to troubleshoot a black box...

            undefined 1 Reply Last reply 28 Jun 2020, 12:37 Reply Quote 0
            • undefined
              Olivimages @FelixH
              last edited by Olivimages 28 Jun 2020, 12:37

              @FelixH
              Sorry, i found that a wire was broken, so now everything work perfectly 🙂

              Here is the wiring
              Duet PanelDUE.jpg

              And the complete code, simplified to make first the passthrough functioning before adding the joystick code. I will post the complete code with a photo of the joysticks when it will be finished.

              /*
                Workbee pendant
              */
              
              void setup() {
                Serial1.begin(57600);
                Serial2.begin(57600);
                Serial1.print("M111 S1 P3\n"); // Start debug mode on USB
                Serial1.print("M575 P1 B57600 S0\n"); // Serial port without checksum
                Serial.begin(57600); // echo to Programming port for Serial Monitor
              }
              
              void loop() {
                  // read from port 1, send to port 2, transmit from Duet to PanelDUE
              while (Serial1.available() > 0) {
                  int inByte = Serial1.read();
                  Serial2.write(inByte);
                  Serial.print(char(inByte)); // echo to Serial Monitor
              }
                // read from port 2, send to port 1, transmit from PanelDUE to Duet 
              while (Serial2.available() > 0) {
                  int inByte = Serial2.read();
                  Serial1.write(inByte);
                  Serial.print(char(inByte)); // echo to Serial Monitor
              }
              
              }
              
              undefined 1 Reply Last reply 28 Jun 2020, 13:41 Reply Quote 0
              • undefined
                FelixH @Olivimages
                last edited by 28 Jun 2020, 13:41

                @Olivimages said in Duet2 Wifi PanelDue serial passthrough with Arduino Due:

                @FelixH
                Sorry, i found that a wire was broken, so now everything work perfectly 🙂

                I was just comparing codes here... ☺ glad you sorted it out. Something like that happened to me more than once!

                1 Reply Last reply Reply Quote 0
                • undefined
                  Olivimages
                  last edited by 28 Jun 2020, 19:35

                  I tried this code, without storing the data in a variable it appears to react faster than before.

                  void loop() {
                      // read from port 1, send to port 2, transmit from Duet to PanelDUE
                  while (Serial1.available() > 0) {
                       Serial2.write(Serial1.read());
                  }
                    // read from port 2, send to port 1, transmit from PanelDUE to Duet 
                  while (Serial2.available() > 0) {
                      Serial1.write(Serial2.read());
                  }
                  
                  undefined 1 Reply Last reply 28 Jun 2020, 20:29 Reply Quote 0
                  • undefined
                    zapta @Olivimages
                    last edited by 28 Jun 2020, 20:29

                    @Olivimages said in Duet2 Wifi PanelDue serial passthrough with Arduino Due:

                    I tried this code, without storing the data in a variable it appears to react faster than before.

                    Possibly it's faster because you don't echo it and not because of the variable.

                    1 Reply Last reply Reply Quote 0
                    • ?
                      A Former User
                      last edited by 28 Jun 2020, 20:34

                      to increase the speed further skip past the arduni serial and write good old avr fashioned code in its place.

                      also having a while loop process all the bytes in the queue would favour one direction of the link, putting a limt on the number of bytes in each loop might balance things out?

                      1 Reply Last reply Reply Quote 0
                      • undefined
                        dhusolo
                        last edited by 30 Jun 2020, 20:37

                        Not to hijack but I'm working on something similar. I have a Duet 2 Wifi, Panel Due and 5 inch screen with firmware 2.04. I want to make a G Code Sender with a simple 16 button keypad. Each button will have an assigned G Code to send to the printer. I have spare Arduino Nano, Mini, and ESP8266 so I have some options.

                        undefined 1 Reply Last reply 1 Jul 2020, 07:21 Reply Quote 0
                        • undefined
                          FelixH @dhusolo
                          last edited by 1 Jul 2020, 07:21

                          @dhusolo if you have a PanelDue, why don't you just create macros??

                          undefined 1 Reply Last reply 1 Jul 2020, 14:08 Reply Quote 0
                          • undefined
                            dhusolo @FelixH
                            last edited by 1 Jul 2020, 14:08

                            @FelixH I've tried that but with the number of macros needed it would clutter the screen. I feel this would be easier during troubleshooting and I think it'll be pretty useful to others if I can get it working right.

                            undefined 1 Reply Last reply 1 Jul 2020, 14:13 Reply Quote 0
                            • undefined
                              FelixH @dhusolo
                              last edited by 1 Jul 2020, 14:13

                              @dhusolo said in Duet2 Wifi PanelDue serial passthrough with Arduino Due:

                              @FelixH I've tried that but with the number of macros needed it would clutter the screen. I feel this would be easier during troubleshooting and I think it'll be pretty useful to others if I can get it working right.

                              I have plenty of macros on my Duet CNC. I de-clutter them by using folders and sub-folders. Not to discourage you ore anything, but your problem has a much easier solution than an external Arduino Gcode sender.

                              undefined 1 Reply Last reply 1 Jul 2020, 16:52 Reply Quote 0
                              • undefined
                                dhusolo @FelixH
                                last edited by 1 Jul 2020, 16:52

                                @FelixH I completely agree, there's an easier way of doing it. Just sometimes it'd be easier if i had a handheld controller vs having to navigate the touchscreen

                                undefined 1 Reply Last reply 1 Jul 2020, 17:08 Reply Quote 0
                                • undefined
                                  FelixH @dhusolo
                                  last edited by 1 Jul 2020, 17:08

                                  @dhusolo said in Duet2 Wifi PanelDue serial passthrough with Arduino Due:

                                  @FelixH I completely agree, there's an easier way of doing it. Just sometimes it'd be easier if i had a handheld controller vs having to navigate the touchscreen

                                  You can always have a look here:

                                  https://forum.duet3d.com/topic/11389/cnc-style-pendant/122?_=1593623248420

                                  remove all the code regarding the pendant (encoders, buttons, etc.) and just set what you want to do. Should be quite doable...

                                  1 Reply Last reply Reply Quote 0
                                  • undefined
                                    Olivimages
                                    last edited by 21 Jul 2020, 11:10

                                    Hi all,

                                    Here is the completed pendant/joystick
                                    IMG_0441.JPG
                                    The potentiometer sets the feed speed for manual move
                                    Left joystick for X and Y
                                    Right Joystick for Z (up and down) and baby step Z (left and right)
                                    Button on left joystick set work coordinate X Y to 0 while right joystick button set Z to 0.
                                    Manual move occurs only when status is "Idle" and not processing.
                                    Cable used is an ethernet cable with 8 wires, that insert between PanelDue and Duet, so Arduino is powered by Duet 5V.

                                    I have searched a lot for smooth movements. Pushing maximum joystick sends 5mm move at maximum feed speed.
                                    Pushing just a bit moves % (from 0 to 100%) of 5mm move and feed speed.
                                    There is a calculation for the move duration, and send only a new G1 code only when previous move is terminated.
                                    I can post the code but i need to clean it before.

                                    undefined 1 Reply Last reply 22 Jul 2020, 01:15 Reply Quote 2
                                    • undefined
                                      dhusolo @Olivimages
                                      last edited by 22 Jul 2020, 01:15

                                      @Olivimages That's pretty cool. Great job! are you planning on sharing the sketch and wiring diagram? I built a CNC pendant but I'd like to incorporate some of your features into mine.

                                      1 Reply Last reply Reply Quote 0
                                      • undefined
                                        Olivimages
                                        last edited by 22 Jul 2020, 08:22

                                        Here is the sketch, need to be fine tuned but working very good already.
                                        The wiring for serial is on this topic just above, wiring of joystick are on the Analog pins of arduino and buttons on Digital pins.
                                        @dhusolo Let me know if you have remarks or improvement on the code, and show us your project.

                                        #include <LiquidCrystal_I2C.h>
                                        #include <Wire.h>
                                        #define COLUMS           20
                                        #define ROWS             4
                                        #define LCD_SPACE_SYMBOL 0x20  //space symbol from the LCD ROM, see p.9 of GDM2004D datasheet
                                        LiquidCrystal_I2C lcd(PCF8574_ADDR_A21_A11_A01, 4, 5, 6, 16, 11, 12, 13, 14, POSITIVE);
                                        
                                        /*
                                          Workbee CNC pendant
                                          Duet3d and PanelDue7i
                                          Olivier Dessy
                                        */
                                        
                                        int PotX = 0;  // Joystick X reading
                                        int PotY = 0;  // Joystick Y reading
                                        int PotZ = 0;  // Joystick Z reading
                                        int PotZB = 0;  // Joystick Z babystep reading
                                        int PotF = 0;  // Potentiometer Feed reading
                                        bool ButtonX = 0;  // Button X joystick
                                        bool ButtonZ = 0;  // Button Z joystick
                                        bool Button1 = 0;  // Button 1
                                        bool Button2 = 0;  // Button 2
                                        bool Button3 = 0;  // Button 3
                                        bool Button4 = 0;  // Button 4
                                        bool Button5 = 0;  // Button 5
                                        float X = 0.2; // X move
                                        float Y = 0.2; // Y move
                                        float Z = 0.200; // Z move
                                        float ZB = 0.002; // Z babystep move
                                        int F = 0;
                                        int PotFlcd = 0;
                                        String Buffer ="";
                                        String Move =""; // Instruction GCODE
                                        String Message ="";
                                        String Status ="";
                                        // I=idle, P=printing from SD card, S=stopped (i.e. needs a reset), C=running config file (i.e starting up), A=paused, D=pausing, R=resuming from a pause, 
                                        // B=busy (e.g. running a macro), F=performing firmware update, O=Vin power low
                                        unsigned long startMillis;
                                        unsigned long currentMillis;
                                        unsigned long period=500;
                                        
                                        void setup() {
                                          pinMode(22, INPUT);
                                          pinMode(23, INPUT);
                                          pinMode(24, INPUT);
                                          pinMode(25, INPUT);
                                          pinMode(26, INPUT);
                                          pinMode(27, INPUT);
                                          Serial1.begin(57600); // Serial port to Duet3d
                                          Serial2.begin(57600); // Serial port to PanelDue
                                          //  Serial1.print("M111 S1 P3\n"); // Start debug mode on USB
                                          Serial1.print(F("M575 P1 B57600 S0\n")); // Serial port without checksum for GCode commands
                                          Serial.begin(57600); // Programming port of Arduino Due for debug
                                          lcd.begin(16,4);
                                          lcd.setCursor(0,0);  
                                          lcd.print("Feed : ");
                                          startMillis=millis(); // Start time
                                        }
                                        
                                        void loop() {
                                            if (Buffer.substring(2,8) == "status") { // If status received, extract status
                                                Status = Buffer.substring(11,12);
                                            }
                                            Serial.print(Buffer); // Print received message from Duet3d for debug
                                            Buffer="";
                                            Readsensor(); // read the value from the sensor:
                                            period=(abs((max(abs(X),max(abs(Y),abs(Z+ZB)))/(F)*60.00*1000.00)*0.8)); // Wait for move to be terminated in ms
                                            if (abs(PotF-PotFlcd)>25) { // LCD Anti flickering, display only once when changed
                                              PotFlcd = PotF;
                                              Serial.print(String(PotFlcd));
                                              lcd.setCursor(7,0);  
                                              lcd.print(String(PotFlcd)+" mm/'   ");
                                            }
                                            currentMillis=millis();
                                        
                                            if ((abs(PotX) > 8 || abs(PotY) > 8 || abs(PotZ) > 15 || abs(PotZB) > 15) && (Status !="P") ) { // If one joystick is moved and machine not processing/printing
                                                F = PotF*(max(abs(PotX),max(abs(PotY),abs(PotZ)))/512.00); // Feed from 4% to 100% of F proportionnal to PotX 
                                                if (F < 150) { F=150; } // Avoid divide by 0  // Feed min 150mm/min max 3500mm/min, from 4% to 100% of F proportionnal to PotX 
                                                X = int((PotX)/100.00*10.00)/10.00; // Max potentiometer 512/100 -> X Y move of 5.12 mm max
                                                Y = int((PotY)/100.00*10.00)/10.00; 
                                                Z = int((PotZ)/5000.000*1000.000)/1000.000; // Max potentiometer 512/5000 -> Z move of 0.10 mm max
                                                ZB = int((PotZB)/100000.000*10000.000)/10000.000; // Max potentiometer 512/100000 -> ZB move of 0.005 mm max
                                                period=(abs((max(abs(X),max(abs(Y),abs(Z+ZB)))/(F)*60.00*1000.00)*1)); // Wait for move to be terminated in ms
                                                if (currentMillis-startMillis>=period) { // Start new move only when move is finished
                                                  String Move = "G91 G1 X"+String(X)+"Y"+String(Y)+"Z"+String(Z+ZB)+" F"+String(F)+"\n" ;
                                                  Serial1.print(F("G91\n"));
                                                  Serial1.print(Move); // GCODE send
                                                  Serial.println(Status+" start="+String(startMillis)+" current="+String(currentMillis)+" delay="+String(period)+" PotF="+String(PotF)+" Move="+String(Move)); // Debug print
                                                  startMillis=currentMillis; // Reset delay count for next move
                                                }
                                            }
                                            else {  // If no joystick is moved do serial passthrough between Duet3d and PanelDue
                                               // read from port 1, send to port 2, transmit from Duet to PanelDUE
                                              while (Serial1.available() > 0) {
                                                Buffer = Serial1.readString();
                                                Serial2.print(Buffer);
                                              }
                                              // read from port 2, send to port 1, transmit from PanelDUE tu Duet 
                                              while (Serial2.available() > 0) {
                                                //    Serial.print(char(Serial2.peek()));
                                                Serial1.write(Serial2.read());
                                              }
                                            }
                                        
                                        // Read buttons and execute macros    
                                        if (ButtonX == LOW ) {
                                        Serial1.println("M98 P""0:/macros/Set work X0 Y0""");
                                        lcd.setCursor(0,1);
                                        lcd.print("Set work X0 Y0  ");
                                        delay(1000);
                                        lcd.setCursor(0,1);
                                        lcd.print("                ");
                                        }
                                        if (ButtonZ == LOW ) {
                                        Serial1.println("M98 P""0:/macros/Set work Z0""");
                                        lcd.setCursor(0,1);
                                        lcd.print("Set work Z0     ");
                                        delay(1000);
                                        lcd.setCursor(0,1);
                                        lcd.print("                ");
                                        }
                                        if (Button1 == HIGH ) {
                                        Serial1.println("M98 P""0:/macros/Probe XYZ Left Front 6,35 tool""");
                                        lcd.setCursor(0,1);
                                        lcd.print("Probe XYZ 6,35  ");
                                        delay(2000);
                                        lcd.setCursor(0,1);
                                        lcd.print("                ");
                                        }
                                        if (Button2 == HIGH ) {
                                        Serial1.println("M98 P""0:/macros/Probe Z""");
                                        lcd.setCursor(0,1);
                                        lcd.print("Probe Z         ");
                                        delay(2000);
                                        lcd.setCursor(0,1);
                                        lcd.print("                ");
                                        }
                                        if (Button3 == HIGH ) {
                                        Serial1.println("M98 P""pause.g""");
                                        lcd.setCursor(0,1);
                                        lcd.print("Pause           ");
                                        delay(2000);
                                        lcd.setCursor(0,1);
                                        lcd.print("                ");
                                        }
                                        if (Button4 == HIGH ) {
                                        Serial1.println("M98 P""stop.g""");
                                        lcd.setCursor(0,1);
                                        lcd.print("Stop            ");
                                        delay(2000);
                                        lcd.setCursor(0,1);
                                        lcd.print("                ");
                                        }
                                        }
                                        void Readsensor() {
                                          PotX = map(analogRead(A0),0,1023,-512,512)-8; // Offset of -8 joystick not at 0 at center
                                          PotY = map(analogRead(A1),0,1023,-512,512)-5;
                                          PotZ = map(analogRead(A2),0,1023,-512,512)+7;
                                          PotZB = map(analogRead(A4),0,1023,-512,512);
                                          PotF = map(analogRead(A3),0,1023,3500,150); // Feed min 150mm/min max 3500mm/min
                                          ButtonX = digitalRead(22);
                                          ButtonZ = digitalRead(23);
                                          Button1 = digitalRead(24);
                                          Button2 = digitalRead(25);
                                          Button3 = digitalRead(26);
                                          Button4 = digitalRead(27);
                                        }
                                        
                                        undefined 1 Reply Last reply 20 Aug 2020, 23:23 Reply Quote 1
                                        • undefined
                                          dhusolo @Olivimages
                                          last edited by 20 Aug 2020, 23:23

                                          @Olivimages Are you using a normal pot(like a 10K/20K) or a rotary encoder?

                                          undefined 1 Reply Last reply 21 Aug 2020, 08:18 Reply Quote 0
                                          • First post
                                            Last post
                                          Unless otherwise noted, all forum content is licensed under CC-BY-SA