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

    Sending GCode commands to duet3D Mini 5+ using python

    Scheduled Pinned Locked Moved
    General Discussion
    7
    29
    1.5k
    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.
    • Falcounetundefined
      Falcounet @shenouda13
      last edited by

      @marco13 Yes so that means it works to me.

      shenouda13undefined 1 Reply Last reply Reply Quote 1
      • shenouda13undefined
        shenouda13 @Falcounet
        last edited by shenouda13

        @Falcounet it gives me a wrong wi fi address ----> b'WiFi IP address 255.255.255.255\n' thou..

        Also, right now if I run :

        import serial
        ser = serial.Serial("/dev/ttyACM0", 115200)
        time.sleep(1)
        print('read')
        ser.write(b"G0 Y30 F50000\n")
        print('write')
        time.sleep(2)
        ser.close()

        the code it doesn't get stuck anymore but still cannot get the motor to rotate 😕

        also what does this line mean?

        b'Messages queued 244, send timeouts 242, received 0, lost 0, longest wait 0ms for reply type 0, free buffers 15\n'

        dc42undefined 1 Reply Last reply Reply Quote 0
        • dc42undefined
          dc42 administrators @Falcounet
          last edited by

          @Falcounet said in Sending GCode commands to duet3D Mini 5+ using python:

          The problem is the RTS control signal has to be raised after the serial connection is open.

          RRF on the Duet 3 Mini does not require the virtual RTS to be asserted for USB comms to work.

          Duet WiFi hardware designer and firmware engineer
          Please do not ask me for Duet support via PM or email, use the forum
          http://www.escher3d.com, https://miscsolutions.wordpress.com

          Falcounetundefined 2 Replies Last reply Reply Quote 0
          • Falcounetundefined
            Falcounet @dc42
            last edited by

            @marco13 If you do G0 Y30 F50000 in DWC console, does the motor moves ?

            The output displayed is the output of M122 command.
            Not sure why 255.255.255.255 is displayed as IP address but it is unrelated to python or serial connection problem.

            1 Reply Last reply Reply Quote 0
            • dc42undefined
              dc42 administrators @shenouda13
              last edited by

              @marco13 said in Sending GCode commands to duet3D Mini 5+ using python:

              also what does this line mean?
              b'Messages queued 244, send timeouts 242, received 0, lost 0, longest wait 0ms for reply type 0, free buffers 15\n'

              Those are statistics about CAN messages sent and received. You are running on old version of RRF, so they are less meaningful than in later versions.

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

              1 Reply Last reply Reply Quote 0
              • Falcounetundefined
                Falcounet @dc42
                last edited by Falcounet

                @dc42 From what I experienced, raising the RTS signal once the serial connection is open made the things to work.

                Opening a serial connection using picocom -c --imap lfcrlf /dev/ttyACM0 and issuing M122 doesn't get any output and I can't even close picocom (because it can't reset the tty, I believe).

                Opening a serial connection using picocom -c --raiserts --imap lfcrlf /dev/ttyACM0 and issuing M122 works.

                shenouda13undefined dc42undefined 2 Replies Last reply Reply Quote 0
                • shenouda13undefined
                  shenouda13 @Falcounet
                  last edited by

                  @Falcounet I was able to get the motor to rotate with your code:

                  import serial
                  with serial.Serial('/dev/ttyACM0') as ser:
                  ser.setRTS(True)
                  ser.write(b'\n')
                  ser.write(bG0 Y30 F50000\n')
                  eof = False
                  while not eof:
                  line = ser.readline()
                  if line == b'ok\n':
                  eof = True
                  print(line)

                  thank you very much!!!!!!!!

                  1 Reply Last reply Reply Quote 0
                  • dc42undefined
                    dc42 administrators @Falcounet
                    last edited by dc42

                    @Falcounet my guess is that it's a function of the Linux driver you are using that it requires RTS to be raised. Using YAT under Windows, I can set RTS and DTR to any states, and communication works.

                    RTS has no real meaning when the connection is USB from end to end, without a serial element, because flow control is handled by the USB protocol.

                    Duet WiFi hardware designer and firmware engineer
                    Please do not ask me for Duet support via PM or email, use the forum
                    http://www.escher3d.com, https://miscsolutions.wordpress.com

                    1 Reply Last reply Reply Quote 1
                    • shenouda13undefined
                      shenouda13 @Falcounet
                      last edited by

                      @Falcounet Is it possible to communicate back from the Duet to the Raspberry Pi such as if a condition is met stop the python code?
                      I would really appreciate your help again

                      Falcounetundefined 1 Reply Last reply Reply Quote 0
                      • Falcounetundefined
                        Falcounet @shenouda13
                        last edited by

                        @marco13 What you mean ? Was an exception raised and thus stopped your script running ?

                        shenouda13undefined 1 Reply Last reply Reply Quote 0
                        • shenouda13undefined
                          shenouda13 @Falcounet
                          last edited by shenouda13

                          @Falcounet I am performing some image classification in a loop on the RPi and based on that the duet will perform some actions. But sometimes the mechanism controlled by the duet gets jammed and the python code keeps running. So for each time the Rpi sends a command I would like the duet to be able to send back a signal/command in order for RPi to perform the next image classification.

                          Falcounetundefined 1 Reply Last reply Reply Quote 0
                          • Falcounetundefined
                            Falcounet @shenouda13
                            last edited by

                            @sarco13 Hard to help you more without code or details.
                            What commands are you sending ?
                            If you want to sync a macro and python code, you can maybe use a global variable that you increment on one side and check the value on another side. Something like that.

                            shenouda13undefined 1 Reply Last reply Reply Quote 0
                            • shenouda13undefined
                              shenouda13 @Falcounet
                              last edited by

                              @Falcounet I am calling macros to rotate motors and control sensors.
                              the code is something like this:

                              def send_command_duet(command):
                              with serial.Serial('/dev/ttyACM0') as ser:
                              ser.setRTS(True)
                              ser.write(b'\n')
                              ser.write(command)
                              eof = False
                              while not eof:
                              line = ser.readline()
                              if line == b'ok\n':
                              eof = True
                              print(line)

                              while True:
                              Capture image
                              classify image
                              send_command_duet(command) #perform action
                              receive signal from duet to go to next iteration

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post
                              Unless otherwise noted, all forum content is licensed under CC-BY-SA