Unsolved Serials Communication with Arduino Uno?
-
@pcr already got a good bunch of stuff working on the arduino which i'd rather keep. I'll keep that in mind though If I can't get it working, thanks.
-
@oliof That only raises the question, how do I then connect the the USB port to the arudino?
-
@sindarius I've read through all your code and I think I can modify that to do exactly what I need. One question, did you need anything in the duet configuration to get this to work, or does it automatically respond on serial?
-
This might be irrelevant depending on what you need, but you can use for example an ESP32 to call the Duet board via WiFi (if your Duet board supports WiFi ofc) and request data via a REST GET call.
Non functional snippet just as an example
void getDuetStatus() { if((wifiMulti.run() == WL_CONNECTED)) { http.begin(HOSTNAME, 80, REQUEST_STATUS_1_PATH); //HTTP int httpCode2 = http.GET(); if(httpCode2 >= 0) { // file found at server if(httpCode2 == HTTP_CODE_OK) { StaticJsonDocument<2048> doc; DeserializationError error = deserializeJson(doc, http.getStream()); if (error) { Serial.print("deserializeJson() failed: "); Serial.println(error.c_str()); return; } const char* status = doc["status"]; // "I" JsonObject coords = doc["coords"]; JsonArray coords_axesHomed = coords["axesHomed"]; int coords_axesHomed_0 = coords_axesHomed[0]; // 1 int coords_axesHomed_1 = coords_axesHomed[1]; // 1 int coords_axesHomed_2 = coords_axesHomed[2]; // 1 ...
I don't know if it's recommended but it's possible.
Of course you don't need the ESP32 at all if you can execute the calls directly from the PC
-
@adam-v3d I was more thinking of using your PC that you already log data to and leaving out the Arduino.
-
This is another Neopixel project: https://github.com/mule1972/NeoPixelBLVmgn
I wrote the readme for the project a while ago, and I think it outlines the hardware part of the serial communication with the Duet well.
You do need to enable the serial port on the Duet. See the "Changes to your Duet Configuration" section of the readme.(Edit: I see you've already figured that out! It is a great read though.) -
I've been trying with the first neopixel code to get some response from the duet but it doesn't seem to send anything back at all. I've confirmed the TX is still working as i connected up a panel due and it worked just fine.
This is clearly well out of my skill level but i think ardunio to duet is still the best way to do this.
-
Whats confusing me at the moment is that in duet.h there is this:
private: void ProcessBuffer(); int bufferIdx; byte* buffer; DynamicJsonDocument doc; #ifdef SOFTWARESERIAL AltSoftSerial duetSerial; //Software serial on pins 8/9 on Arduino Uno. #endif };
Which is about the json called doc which should hold all the data from the duet.
At the bottom of this:
void DuetData::ProcessBuffer() { //Process the json data Status = DUET_STATUS::UNKNOWN; //Scan for invalid characters for (int i = 0; i < bufferIdx - 1; i++) { if (buffer[i] < 32 || buffer[i] > 126) { #ifdef DEBUG Serial.println("Throwing out buffer due to bad characters"); #endif return; } } DeserializationError error = deserializeJson(doc, buffer); if (error.code() != error.Ok) { Status = DUET_STATUS::ERROR; Serial.println("Error"); Serial.print(error.c_str()); Serial.println(error.f_str()); return; //There was an error deserializing the json } const char *status = doc["status"]; switch (status[0]) { case 'I': Status = DUET_STATUS::IDLE; break; case 'P': Status = DUET_STATUS::PRINTING; break; case 'M': Status = DUET_STATUS::SIMULATING; break; case 'B': Status = DUET_STATUS::BUSY; break; default: Status = DUET_STATUS::ERROR; break; } Progress = doc["fraction_printed"]; //Hotend Temp1 hotendTemp = doc["heaters"][1]; fanSpeed = doc["fanPercent"][0];
The hotendTemp and fanspeed look like they are getting 'extracted' from doc and assigned to variables. But when i print those, they are still just zero, or whatever they were initially assigned.
-
@adam-v3d I'm on a bit deep water here as I haven't played much at all with the Arduino Uno but I remember that when I used the Uno as a USB to serial bridge to flash an ESP32 I had to connect RX(0) to RX and TX(1) to TX. Not as one should expect. Are the Uno pin mislabeled or maybe only my board (Clone) ?
-
@gixxerfast Im using a genuine Arduino. I have two elegoo clones too, but they are all labelled the same.
I have discovered from doing this that the RX and TX dedicated pins (0 and 1) seem to be the same as what is used to communicate with laptop via USB so the connection to the duet is using AltSoftSerial which is a library that adds software serial connection using pins 8 and 9 on the arduino.
-
@adam-v3d Switching my connection on pins 8 and 9 has changed things. This might be whats going on. More errors now, but different ones at least...
-
@adam-v3d Sorry you have to open the comms in your config.g after you have wired the arduino to a serial capable IO using M575. I lost some of my notes when the computer I wrote that on crashed. The code you probably want to look at is where the comms is handled in /src/DuetData.cpp that handles talking back and forth with the duet.
this video shows it showing the print % progress on a simulated g-code file on a Duet 3 Mini5+
https://www.youtube.com/watch?v=OjPsP5I6l70 -
@adam-v3d In that code I use AltSoftSerial package which on an arduino uno forces the use of pins 8/9 on the arduino uno. If you use a different board you need to look up the required pins. There is a package bblanchon/ArduinoJson@^6.17.2 that takes the json data sent from the Duet and turns it into a document that you can look up the ObjectModel values.
-
I found an old SD card which had the config
;Duet Mini5+
M575 P2 B57600 S0 -
@adam-v3d If this helps as a backup/alternative ---
Because you are already planning to capture the data on a laptop, you can log data easily with node-red & nodeDSF:
For example - The screen shot below show a csv which logged T0 temp with a time stamp (millisecond) as it cooled down..
It took less than 5 mins to put together and gives you access to nearly the entire object model in almost real-time over the network (it uses the same connection methods as DWC).
-
Here's a short video that shows the project that I did. https://www.youtube.com/watch?v=WQDmI404N5k
-
@sindarius I think I kind of understood most of the code, only little bits of syntax I didn't understand. I turn on debugging and the end result was that it either paused completely after 500ms (first time it polled the duet) or ran mostly correctly but hotend temps and fan always showed the original values in the library of 10, 285 etc.
I guess this means there was no data coming from the Duet. Maybe wrong port number. I used M575 P1 B57600 S0 and connector to the RX and TX on the Panel due 4 pin connector next to the 4 pin probe connector.
-
@mintytrebor This is cool, I guess its easy when you know how. I've never used this before though and not sure how I would sync it up with the other data from the arduino.
-
@sindarius Oh i did get the thing with pins 8 and 9 after realising what the library was for and that the designated TX and RX pins are basically the same serial i'm using to connect to the laptop.
For connection, do you connect duet TX to pin 8, and duet RX to pin 9? -
@mintytrebor I've just installed and had a little look at this. I quite like it and might be more my speed but don't understand it really yet. It looks like it'll be capable of polling the arduino and duet at the same time and just merging them into a single file on the pc which could be useful. Maybe also a powerful option for when i'm adding more features later down the line.
Are you able to share details on what you showed here?