Duet 3D and Raspberry Pi connection



  • Hello,

    I am building a custom GUI on Raspberry Pi and need it to communicate with the Duet Ethernet. How can I send specific data such as motor control and temperature readings from the Duet to the Raspberry Pi? I want to fully read information and control the Duet using my custom Raspberry Pi GUI. Would connecting through either Ethernet, USB or pins work?

    All the help is appreciated.

    Thanks!


  • administrators

    You can have the RPi send M408 command to the Duet (by USB or HTTP) to get the full status.



  • @blandified, do you plan to release your RPi-based GUI as free software?


  • administrators

    @blandified:

    Hello,

    I am building a custom GUI on Raspberry Pi and need it to communicate with the Duet Ethernet. How can I send specific data such as motor control and temperature readings from the Duet to the Raspberry Pi? I want to fully read information and control the Duet using my custom Raspberry Pi GUI. Would connecting through either Ethernet, USB or pins work?

    All the help is appreciated.

    Thanks!

    You might find it easiest to connect over the network then you can use all the http requests that Duet Web Control uses:

    https://github.com/chrishamm/DuetWebControl/blob/master/README.md



  • @blandified, (T3P3Tony: My thoughts too).. If you do not want a serial connection then you may want to look at the http requests (including gcode commands) you can send to the firmware. See the readme at https://github.com/chrishamm/DuetWebControl and beyond.

    Otherwise use a USB serial link in the normal manner; I toyed with the idea of using the UARTs on both the Pi and Duet to make a low-level serial link via the gpio ports, but it seemed like an awful lot of effort for marginal benefit.

    Edit: Ninja'd



  • @dc42:

    You can have the RPi send M408 command to the Duet (by USB or HTTP) to get the full status.

    Thank you for input! Just to clarify, HTTP means ethernet connection, correct?

    We were reading somewhere that ethernet might be the better connection between the Rpi and Duet because we would have more access to sending more commands. Would USB be lacking in any way on what communication can happen?

    We essentially plan to have the SD card (with the gcode file of what we want to print) inserted into the Rpi, and then the Rpi through a GUI will send that gcode file to the Duet.



  • @fma:

    @blandified, do you plan to release your RPi-based GUI as free software?

    As for now, the Rpi GUI is just for us due to possible legal reasons, but if everything goes smoothly we would like to open source it as free software. Do you have any experience with this?



  • @T3P3Tony:

    @blandified:

    Hello,

    I am building a custom GUI on Raspberry Pi and need it to communicate with the Duet Ethernet. How can I send specific data such as motor control and temperature readings from the Duet to the Raspberry Pi? I want to fully read information and control the Duet using my custom Raspberry Pi GUI. Would connecting through either Ethernet, USB or pins work?

    All the help is appreciated.

    Thanks!

    You might find it easiest to connect over the network then you can use all the http requests that Duet Web Control uses:

    https://github.com/chrishamm/DuetWebControl/blob/master/README.md

    We are leaning towards the ethernet/HTTP due to the reason you listed above!

    For the link that you posted, are these the only HTTP commands or can we build our own?

    Thanks!



  • @EasyTarget:

    @blandified, (T3P3Tony: My thoughts too).. If you do not want a serial connection then you may want to look at the http requests (including gcode commands) you can send to the firmware. See the readme at https://github.com/chrishamm/DuetWebControl and beyond.

    Otherwise use a USB serial link in the normal manner; I toyed with the idea of using the UARTs on both the Pi and Duet to make a low-level serial link via the gpio ports, but it seemed like an awful lot of effort for marginal benefit.

    Edit: Ninja'd

    Thank you for the input!

    One thing that just now came to our minds:

    So the DuetWebControl software is the communication link between the web interface and the Duet board. Does this mean that we download the DuetWebControl software onto the Rpi to allow communication between the Rpi and Duet board through ethernet? (Since we will be using the Rpi instead of the web interface)



  • The Duet Web Control does not need to be loaded onto your Pi. Whatever GUI you write on your Pi needs to make the same calls. The calls are so simple they can be made from a browser. Or Curl. Or whatever.

    Example, from a browser: (Click to enlarge)

    Second example, from command line:

    curl http://192.168.86.110/rr_status?type=3
    {"status":"I","coords":{"axesHomed":[0,0,0],"extr":[0.0],"xyz":[0.000,0.000,625.246]},"currentTool":0,"params":{"atxPower":0,"fanPercent":[0.00,100.00,50.00,0.00,0.00,0.00,0.00,0.00,0.00],"speedFactor":100.00,"extrFactors":[100.00],"babystep":0.000},"seq":6,"sensors":{"probeValue":1000,"fanRPM":0},"temps":{"current":[2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0],"state":[0,3,0,0,0,0,0,0],"heads":{"current":[2000.0],"active":[0.0],"standby":[0.0],"state":[3]},"tools":{"active":[[0.0]],"standby":[[0.0]]},"extra":[{"name":"MCU","temp":41.6}]},"time":53212.2,"currentLayer":0,"currentLayerTime":0.0,"extrRaw":[0.0],"fractionPrinted":0.0,"firstLayerDuration":0.0,"firstLayerHeight":0.00,"printDuration":0.0,"warmUpDuration":0.0,"timesLeft":{"file":0.0,"filament":0.0,"layer":0.0}}

    Any piece of code that can send and receive HTTP can interact with the Duet, completely replacing the DWC http/css/js with whatever you code.



  • Another command line example:

    curl http://192.168.86.110/rr_filelist?dir=sys
    {"dir":"sys","files":[{"type":"f","name":"bed.g","size":1709,"date":"2017-08-14T16:56:09"},{"type":"f","name":"cancel.g","size":59,"date":"2017-08-14T17:00:18"},{"type":"f","name":"config.g","size":3857,"date":"2018-02-15T08:55:06"},{"type":"f","name":"DuetWiFiServer.bin","size":245264,"date":"2017-11-06T13:50:22"},{"type":"f","name":"homedelta.g","size":743,"date":"2017-08-14T17:08:09"},{"type":"f","name":"iap.bin","size":60904,"date":"2017-08-15T09:07:10"},{"type":"f","name":"iap4e.bin","size":61424,"date":"2017-11-06T14:22:10"},{"type":"f","name":"pause.g","size":221,"date":"2017-08-14T16:32:10"},{"type":"f","name":"resume.g","size":206,"date":"2017-08-14T16:30:26"},{"type":"f","name":"sleep.g","size":54,"date":"2017-08-14T16:27:02"},{"type":"f","name":"stop.g","size":86,"date":"2017-08-14T16:27:02"},{"type":"f","name":"tfree0.g","size":136,"date":"2017-08-14T16:27:02"},{"type":"f","name":"tpost0.g","size":196,"date":"2017-08-14T16:27:02"},{"type":"f","name":"tpre0.g","size":139,"date":"2017-08-14T16:27:02"},{"type":"f","name":"config.g.bak","size":3844,"date":"2018-02-15T08:44:10"}]}



  • Oh, and you can certainly have your Gcode file on the Pi, and feed it one command at a time over the network to the Duet. With

    rr_gcode?gcode=XXX

    However, since the Duet has a file upload facility, and can print from that uploaded file residing on its own SD card, sending the file in pieces from the Pi certainly seems like "re inventing the wheel" and a serious step backwards in reliability.

    🙂



  • In fact, I'm a little curious what the real role of the Pi will be in your proposed design.

    When you say "building a custom GUI on the Pi", building in what? Will it run on the Pi and display on the Pi's physical console, the HDMI connection? If so, in what languages or "tech stack"?

    Or does it work some other way? Does the Pi talk to a browser?

    What is the "overall flow" intended?



  • @Danal:

    Oh, and you can certainly have your Gcode file on the Pi, and feed it one command at a time over the network to the Duet. With

    rr_gcode?gcode=XXX

    However, since the Duet has a file upload facility, and can print from that uploaded file residing on its own SD card, sending the file in pieces from the Pi certainly seems like "re inventing the wheel" and a serious step backwards in reliability.

    🙂

    1.) We are using the Rpi to allow a HD touchscreen and further expansion of the project (paneldue is too low resolution and not many options for customization).

    2.) We are building the GUI with Python. It will be running on the Rpi and the touchscreen will be connected via HDMI.

    3.) The Rpi will be talking to the Duet via ethernet (potentially octoprint). We might also use HTTP protocol client to send and request info to the Duet USING the GUI.

    So just to summarize our plan: The Duet is connected to the Rpi using ethernet and the Rpi is connected to our touchscreen. The touchscreen will display the GUI and also have the accessible SD card slot.

    To clarify, the HTTP command "rr_gcode?gcode=XXX" only passes 1 gcode command at a time? So say we have the gcode on a SD card on the Rpi's touchscreen, can we use the HTTP command "rr_upload?name=XXX&time=YYY" to pass the whole gcode file to the Duet?

    So… say we have this line of pseudocode HTTP commands sent from the Rpi to the Duet:

    host = 192.xxx.xxx.xx // address for the the duet
    sendfile = "rr_upload?name=XXX&time=YYY" // specify the gcode file to send
    send(host, sendfile) // send the entire gcode file to the duet

    If this is the case, where exactly on the Duet does this gcode file go? The onboard SD card?

    Thank you in advance!


  • administrators

    Yes it would upload to the SD card. You would then need to send a GCode command to print the file you just uploaded.



  • @dc42:

    Yes it would upload to the SD card. You would then need to send a GCode command to print the file you just uploaded.

    Thank you very much! We are done with the first draft of the GUI and how it will send the gcode file to the Duet's SD card.

    Here's another challenge: So the Rpi and the Duet are connected via Ethernet. How does the DWC factor in? Do we need to do some installing/setting up or will the Duet and Rpi automatically connect via the DWC?

    Thanks!


  • administrators

    DWC runs in the web browser, so in your setup using a RPi you would need to replicate whatever DWC functions you want to use on the RPi, for example in Octoprint.



  • @dc42:

    DWC runs in the web browser, so in your setup using a RPi you would need to replicate whatever DWC functions you want to use on the RPi, for example in Octoprint.

    Thanks for the speedy response! We might end up switching to Raspian due to somethings coming up with the GUI, just wanted to check that the process would be the same 🙂 Any idea on this? Thanks in advance!



  • I am using RPi to monitor print progress as I keep print progress updated in a sql database from each of my printers – and others are updated via octoprint -- I have a process which sends commands to DWC via http requests (basically a REST api) and get back a json object with all the information I'd need to build a full fledged UI, I only take the information I need to get progress, and estimation to completion as that's all I display on a rolling ticker LCD which shows progress of all print jobs. There are a handful of supported commands which are documented in DWC, some give more information than others, you can also execute gcode commands if necessary.



  • @kazolar:

    I am using RPi to monitor print progress as I keep print progress updated in a sql database from each of my printers – and others are updated via octoprint -- I have a process which sends commands to DWC via http requests (basically a REST api) and get back a json object with all the information I'd need to build a full fledged UI, I only take the information I need to get progress, and estimation to completion as that's all I display on a rolling ticker LCD which shows progress of all print jobs. There are a handful of supported commands which are documented in DWC, some give more information than others, you can also execute gcode commands if necessary.

    If I can pick you brain real quick: We have an Rpi3 running Raspbian and want to connect to Duet using ethernet and send HTTP requests to send gcode and print. Do we connect using the DWC? If so, how do we get DWC on the Rpi? Do we treat the Rpi like a computer and access it that way?



  • The very best thing to do is look at DWC on Github for examples.

    There was a topic in a different forum discussion about having a "multi printer" monitor, and, by looking at DWC, I was able to have a draft in a day, and a workable product in about three. With only a couple of hours per day. And having never looked at DWC before.

    This is in no way a brag on me. I'm medium skilled web person at best.

    It is pointing out how much can be done, and how quickly, through the existing APIs, and how much those APIs can be understood by looking at functions in DWC.


  • administrators

    @blandified:

    If I can pick you brain real quick: We have an Rpi3 running Raspbian and want to connect to Duet using ethernet and send HTTP requests to send gcode and print. Do we connect using the DWC? If so, how do we get DWC on the Rpi? Do we treat the Rpi like a computer and access it that way?

    If you are connecting to the Duet and sending http from.another application (like some software you are running in the Raspi), rather than a web browser, then you can send http request formatted in the same.way as DWC formats http requests.

    Look at the DWC github readme:

    https://github.com/chrishamm/DuetWebControl/blob/master/README.md

    You will see commands like:

    [[language]]
    rr_gcode?gcode=XXX
    
    

    To send a gcode. It's worth reading that whole readme as it explains how to establish a session and gives some examples.of the AJAX that the Duet returns.



  • I send
    rr_status?type=[1-3]

    depending on what I want to get from duet

    so let's say your duet address is 192.168.0.100 you'd send an http request
    http://192.168.0.100/rr_status?type=1

    and you'll get back a json payload and you then read it into your app and display it as you see fit.

    treat the duet as you'd treat any REST host – you send commands to the DWC from the Pi and get back information.
    You can do that inside a web app, a python script, or a Java web service as I am doing.



  • @dc42:

    DWC runs in the web browser, so in your setup using a RPi you would need to replicate whatever DWC functions you want to use on the RPi, for example in Octoprint.

    Hey dc42, we are having trouble with using "rr_upload?name=XXX&time=YYY."

    Using a web browser on the Rpi, we are able to use "rr_gcode?gcode=XXX" to select the gcode file and print it out, but this only works on a gcode file that is already on the SD card.

    Example:

    _> [IP address of Duet]/rr_gcode?gcode=M23 [filename].gcode

    [IP address of Duet]/rr_gcode?gcode=M24_

    But once again, this only works with gcode files that are already on the SD.

    When we try to use the rr_upload, we don't know how to specify the gcode file that needs to be uploaded:

    So looking at the HTTP command:

    > rr_upload?name=XXX&time=YYY

    According to the documentation, XXX is the folder we want to save the gcode file to, so here:

    > rr_upload?name=gcodes/[filename].gcode

    However, how do we SELECT the gcode we want to upload TO that folder?

    So say we have a gcode file "zTest.gcode" that is on the Rpi and we want to send that gcode file to the SD card.

    How do we do this?



  • You can't use a browser to upload, because a browser does a "get" request with what you type into the address bar.

    The "rr_upload…" has to be a "post" request. The direct answer to your question "Which file is sent" is "the file you encode and send in the post request".

    See https://github.com/chrishamm/DuetWebControl/blob/master/core/js/upload.js for details.


Log in to reply