Welcome! Log In Create A New Profile

Advanced

talk to duet from a 2nd micro-controller?

Posted by shadowphile 
talk to duet from a 2nd micro-controller?
August 12, 2018 05:02AM
Hi. I am using Arduino board in my delta for miscellaneous functions like indicators, panic buttons, or jog controls, maybe a Home button..
These will be tied to the hardware buttons on a panel I printed out. I want to use those buttons to send Gcode from the Arduino to the Duet.
I can't tell from the schematics if there is even a port other than the USB. Is it possible to (easily) send commands through that port?
(I have the Duet Ethernet BTW)

On a similar subject, is it possible to set up the Duet to execute a Gcode whenever one of it's digital IO pins is toggled?
Re: talk to duet from a 2nd micro-controller?
August 12, 2018 07:35AM
Quote
shadowphile
Hi. I am using Arduino board in my delta for miscellaneous functions like indicators, panic buttons, or jog controls, maybe a Home button..
These will be tied to the hardware buttons on a panel I printed out. I want to use those buttons to send Gcode from the Arduino to the Duet.
I can't tell from the schematics if there is even a port other than the USB. Is it possible to (easily) send commands through that port?
(I have the Duet Ethernet BTW)

If you don't have a PanelDue connected to your Duet, then the simplest option is to use the PanelDue port. This is a standard async serial port using 3.3V signals levels (so you will need to level shift them if you want to connect it to an Arduino with 5V signal levels). You can send GCodes to this port. By default, the baud rate is 57600 and the commands must include line numbers and checksums for integrity checking; but you can use M575 in config.g to change these.

Quote
shadowphile
On a similar subject, is it possible to set up the Duet to execute a Gcode whenever one of it's digital IO pins is toggled?

Spare endstop pins can be used in this way. See the description of M581 in the GCodes page of the wiki either here or at duet3d.com.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
August 16, 2018 03:12PM
So if I am reading this correctly...

The PanelDue connector could be connected to a Raspberry Pi GPIO UART for serial communication, and using this, I could (at least in theory) use the Pi's HDMI/USB to replicate/enhance the PanelDue's functionality?

I see that the power pin on the Duet is labelled as 5V, I presume that's an output to power the PanelDue. What kind of current can it supply? (Enough to power up the Pi?)

The ability to use the Pi's HDMI output gives some good possibilities for status monitoring, since I happen to have a 7" 1024X640 HDMI touch LCD lying around not in use elsewhere (I was going to use it for a CarPi project, and ended up going with a 10" screen instead.)

Does the Duet just update the PanelDue, or does the panel have to poll the board for information? Where do i find computational information to provide line checksums? (I'm actually kind of excited about this as a possibility.)


MBot3D Printer
MakerBot clone Kit from Amazon
Added heated bed.

Leadscrew self-built printer (in progress)
Duet Wifi, Precision Piezo parts
Re: talk to duet from a 2nd micro-controller?
August 17, 2018 07:47AM
Quote
SupraGuy
So if I am reading this correctly...

The PanelDue connector could be connected to a Raspberry Pi GPIO UART for serial communication, and using this, I could (at least in theory) use the Pi's HDMI/USB to replicate/enhance the PanelDue's functionality?

Yes.

Quote
SupraGuy
I see that the power pin on the Duet is labelled as 5V, I presume that's an output to power the PanelDue. What kind of current can it supply? (Enough to power up the Pi?)

The maximum you should draw from that is 1.5A, which is probably not enough to power a Pi + 7" screen.

Quote
SupraGuy
Does the Duet just update the PanelDue, or does the panel have to poll the board for information? Where do i find computational information to provide line checksums? (I'm actually kind of excited about this as a possibility.)

It polls the Duet using M408 commands, however when waiting for heating to complete polling is suspended so the Duet keeps sending M408 responses. See the GCodes wiki page for details of the checksums.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
August 18, 2018 02:09AM
Quote

(I'm actually kind of excited about this as a possibility.)

Has anyone tried to port DuetWebControl to a RasPi? That's the more elegant way to set communication IMHO.
Integrating the RasPi-camera would be the icing, but common USB-cams will do too, I guess.
Re: talk to duet from a 2nd micro-controller?
August 25, 2018 06:54PM
I've successfully sent gcodes through the paneldue port make things happen.
However, I'm having problems reading responses like M408 or M105; I get no chars, except under conditions I have yet to determine.
It seems like there is a control issue between the commands I send to the paneldue port, and commands from the web interface. at some point I can't connect anymore from the webpage.
can you explain how duet responds to requests from both serial ports and where the answers go?
thanks
Re: talk to duet from a 2nd micro-controller?
August 26, 2018 01:37AM
Responses to commands are sent to the channel that the command was received from.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
September 02, 2018 06:12PM
thanks for the feedback. I've been talking and getting replies for a while now and trying to decode the messages.
At some point recently I Iost the ability to send messages.
-I set checksum option to off (which is why it started working)
-The PanelDue serial port is receiving signals fine right at the pin. But the messages are not getting through. I set the code to send continuous 'allow cold' extrudes then disabled cold extrudes with a command through webcontrol. It does not revert back when I check the status.
-Serial settings have been confirmed for the panel due port using webcontrol GUI.
-I can send a message through the paneldue port ok, using the M118 command.

Today I updated the firmware to the latest. No change.

I'm afraid I may have blown the receiving pin on the SAM IC.
Is there anything else I can look at or try before concluding I'm screwed? (too bad there isn't a third serial port on the duet to try)

Edited 1 time(s). Last edit at 09/02/2018 09:31PM by shadowphile.
Re: talk to duet from a 2nd micro-controller?
September 03, 2018 01:54AM
You can connect a PC via USB and send M111 S1 P3. That will cause all received GCode commands to be echoed to USB, so you will be able to see if anything has been received.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
September 03, 2018 07:00PM
Now that is an obscure command! thanks. (although I can't think of why my dummy command running in loop would not immediately reset a different setting for that command sent from web control console.)
I don't normally use the USB port except in the early days when that was the only way to update the firmware.
Can I just use a simple terminal program like Hyperterminal to test out the debug, assuming the USB looks like a comm port on the pc? (if so the serial port settings would be useful)
Re: talk to duet from a 2nd micro-controller?
September 04, 2018 02:44AM
Yes you can use a terminal program. I use YAT. Set it to no flow control, and LF-only as the line ending.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
September 04, 2018 04:09PM
baud rate?
Re: talk to duet from a 2nd micro-controller?
September 04, 2018 05:28PM
Quote
dc42
If you don't have a PanelDue connected to your Duet, then the simplest option is to use the PanelDue port. This is a standard async serial port using 3.3V signals levels (so you will need to level shift them if you want to connect it to an Arduino with 5V signal levels). You can send GCodes to this port. By default, the baud rate is 57600 and the commands must include line numbers and checksums for integrity checking; but you can use M575 in config.g to change these.

On the other hand, int he getting started guide at [duet3d.dozuki.com]
It indicates that when you connect to the USB serial device to use 9600BPS, no parity, 8 bits, 1 stop bit for Windows. It appears that the connection for Mac was to use 115200BPS. I'm actually pretty sure that I connected at 115200BPS using Putty from Windows, and it worked fine. I suspect that the USB serial port isn't actually picky about the BPS rate.
Re: talk to duet from a 2nd micro-controller?
September 04, 2018 06:08PM
DC42's reply addressed the non-USB port. I did not assume the same settings for the USB since it is used in different contexts.
Now that I think about it the M575 can address the USB as well so...pick my own speed I suppose.
Re: talk to duet from a 2nd micro-controller?
September 20, 2018 01:16PM
Okay, I'm trying a little experiment...

It's just the bare Duet board, connected tot he GPIO serial port on the Pi.\

I banged together a little python script:
#!/usr/bin/python

# Test to interface to a Duet Wifi over the serial port, hopefully able to read
# some keyboard information, (Later have mouse clicks and other inputs) and send
# simple gcode to the Duet serial port and read back responses

import serial
import time

portDuet = serial.Serial("/dev/serial0", baudrate=57600, timeout=1.0)

iLineNumber=1

# Calculate line checksums
def fnCheckSum(strString):
    iCS = 0;

    for chrChar in strString:
        iCS = iCS ^ ord(chrChar);

    return(iCS);


# Add Line numbers and checksums to strings
def fnVetLine(strString):
    if len(strString) == 0:
        return(strString);

    strString = "N" + str(iLineNumber) + " " + strString;
    iCheckSum = fnCheckSum(strString);
    strString += "*" + str(iCheckSum);
    return(strString);



# Read a NL terminated line from the serial port
def fnReadLine(portPort):
    strRV = "";
    while True:
        chrChar = portPort.read();
        strRV += chrChar;
        if chrChar != "":
            if ord(chrChar) == 10 or ord(charChar) == 13:
                return(strRV);
        else:
            return(strRV);



strGCode = "M552";
strSendCode = fnVetLine(strGCode);
print strSendCode;
portDuet.write(strSendCode);
strResponse=fnReadLine(portDuet);
print strResponse;

This was longer before, but has been trimmed down to just send the one command ("N1 M552*32") and wait up to 1 second (Or until a newline) for a response.
I was really hoping to get a response of:
WiFi module is connected to access point SupraGuyWiFi, IP address 10.1.2.3

Nope. I get nothing. And I get no indication on the USB port that any command was received on any channel.

I don't think that I have it connected wrong. I know that hte black, red, black, red wires are confusing, I just used a couple of 2 pin DuPont wires that I| had around. They are connected +5V to +5V, ground to ground, URXD0 to BCM14/TXD, and UTXD0 to BCM15/RXD. Given that the Duet doesn't have any hardware RTS/CTS/CS lines, none are connected or should be expected on the Pi.

I have tested that the Pi serial port is enabled and am able to send and receive text from another Pi, since I don't have a handy 3.3V level shifter around.

Edit: Whoops! Forgot to add a carriage return to the sent line. It worked with the Pi to Pi test because it just sent characters one by one from the keyboard.

More work to do on reading and parsing the responses, but so far, so good.

Edited 1 time(s). Last edit at 09/20/2018 01:29PM by SupraGuy.


MBot3D Printer
MakerBot clone Kit from Amazon
Added heated bed.

Leadscrew self-built printer (in progress)
Duet Wifi, Precision Piezo parts
Re: talk to duet from a 2nd micro-controller?
September 21, 2018 12:23PM
Hmmm. One of the things that I was hoping to grab/display with the pi is its IP address, but when I send M552 (Well, N1 M552*32 actually) it doesn't respond with the expected line of "WiFi module is connected to access point SupraGuyWiFi, IP address 10.1.2.3" I get a null response. On the USB serial port, I am getting back: "aux: M552" so I know that the command was received.

I've been doing this at work, so I haven't made much progress on it. So far I've managed to parse out relevant information from some of the M408 commands Heater temperatures are always 2000 with no thermistors, and position is always zeros, so far, but I believe that it's reading correctly, so long as the reported coordinates are in the order specified by "axisNames" in the M408 S1 response. The wiki indicates that the temperatures are the bed first, then the tools in order. (I only have one, so I don't know that I'll worry about more of them.)

So far I'm doing all of this in python on the Pi, but as you may see from all of those unnecessary semicolons in my code, it's not my main programming language. I'm concurrently doing pretty much the same thing in the Arduino IDE, and looking for the code to use a repRapDiscount 2004 controller. the Discount controller and a Mega2560 clone is dirt cheap (Even if you get it with a RAMPS 1.4 shield), and I have several spares already. I don't think it'll be nearly as capable as the Panel|Due, but implementing some basic display on the 20X4 screen, (Coordinates and temperatures) some query functions (Machine name, IP address, Job percent) and some preparation functions (Preheat, home axis, mesh level, jog axes) should be enough to supplement the DWC.

Well, If I don't use the 2004 Discount controller for this, I have a couple of car projects that I'd love to use it for, too.


MBot3D Printer
MakerBot clone Kit from Amazon
Added heated bed.

Leadscrew self-built printer (in progress)
Duet Wifi, Precision Piezo parts
Re: talk to duet from a 2nd micro-controller?
September 21, 2018 12:27PM
The M552 response will be in the "msg" field of the response to the next M408 command that you send.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
September 24, 2018 11:52AM
I see a msg|Box.mode which has a value of "-1", but I don't see a way to read any message data in it.

My code is sending:

M408 S1
It then parses the machine name, Axis number/names, and primes things like machine coordinates,
The it sends the M552
I wanted to parse the SSID and IP address.
So I added another M408 command. I've tried it with no argument, and with an S0 argument. In both cases, I get exactly the same response (Which I did expect)
{"status":"I","heaters":[2000.0,2000.0],"active":[0.0,0.0],"standby":[0.0,0.0],"hstat":[0,0],"pos":[0.000,0.000,0.000],"machine":[0.000,0.000,0.000],"sfactor":100.00,"efactor":[100.00],"babystep":0.000,"tool":-1,"probe":"0","fanPercent":[30.00,100.00,100.00,0.00,0.00,0.00,0.00,0.00,0.00],"fanRPM":0,"homed":[0,0,0],"msgBox.mode":-1}

I get a few more pieces appended onto the response with the "S1" parameter, geometry, axes, axisNames, volumes, numTools, myName, and firmwareName, No message text, even if I send the M552 first.

EDIT: Ah I see. If I ask for S4, then I get the response I'm looking for.

I also have a question about the position response. There seems to be 2 sets "pos" and "machine" I've been working under the assumption that "pos" is the position that the software has been told to go to, and "machine" is the actual position which may be en route during a move. probably for my purposes the difference isn't too important, but it would be good to know.

Edited 1 time(s). Last edit at 09/24/2018 11:57AM by SupraGuy.


MBot3D Printer
MakerBot clone Kit from Amazon
Added heated bed.

Leadscrew self-built printer (in progress)
Duet Wifi, Precision Piezo parts
Re: talk to duet from a 2nd micro-controller?
September 25, 2018 03:07PM
Quote
SupraGuy
I also have a question about the position response. There seems to be 2 sets "pos" and "machine" I've been working under the assumption that "pos" is the position that the software has been told to go to, and "machine" is the actual position which may be en route during a move. probably for my purposes the difference isn't too important, but it would be good to know.

That's correct. "pos" is the position requested by the GCode, "machine" is the translation of that position after accounting for coordinate system selection, tool offset, skew compensation, bed compensation, firmware retraction, and baby stepping.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: talk to duet from a 2nd micro-controller?
September 26, 2018 06:21PM
Cool.

Next question. What does status "O" mean? It's not listed in the gcode wiki. My spare board started coming back with this lately instead of the expected status "I" (I have a translation for all of the expected status codes
Quote
RepRap Wiki
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


MBot3D Printer
MakerBot clone Kit from Amazon
Added heated bed.

Leadscrew self-built printer (in progress)
Duet Wifi, Precision Piezo parts
Re: talk to duet from a 2nd micro-controller?
September 27, 2018 02:33AM
Status O means that the Duet is on standby because there is no VIN power.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Sorry, only registered users may post in this forum.

Click here to login