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

    Serials Communication with Arduino Uno?

    Scheduled Pinned Locked Moved Unsolved
    General Discussion
    8
    36
    2.8k
    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.
    • Adam - V3Dundefined
      Adam - V3D @oliof
      last edited by

      @oliof That only raises the question, how do I then connect the the USB port to the arudino?

      oliofundefined 1 Reply Last reply Reply Quote 0
      • Adam - V3Dundefined
        Adam - V3D @Sindarius
        last edited by

        @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?

        JadonMundefined 1 Reply Last reply Reply Quote 0
        • Gixxerfastundefined
          Gixxerfast
          last edited by Gixxerfast

          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 🙂

          Voron V2.4 (#1317) with Duet 3 Mini5+ Wifi and 1LC v1.1 Toolboard
          Voron V0.1 (#637) with Duet 3 Mini 5+ Wifi and 1LC v1.2 Toolboard
          Ender 3 Pro with BTT SKR-2 + RRF

          1 Reply Last reply Reply Quote 0
          • oliofundefined
            oliof @Adam - V3D
            last edited by

            @adam-v3d I was more thinking of using your PC that you already log data to and leaving out the Arduino.

            <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

            1 Reply Last reply Reply Quote 0
            • JadonMundefined
              JadonM @Adam - V3D
              last edited by JadonM

              @adam-v3d

              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.)

              1 Reply Last reply Reply Quote 0
              • Adam - V3Dundefined
                Adam - V3D
                last edited by

                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.

                Gixxerfastundefined 1 Reply Last reply Reply Quote 0
                • Adam - V3Dundefined
                  Adam - V3D
                  last edited by

                  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.

                  Sindariusundefined 1 Reply Last reply Reply Quote 0
                  • Gixxerfastundefined
                    Gixxerfast @Adam - V3D
                    last edited by

                    @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) ?

                    Voron V2.4 (#1317) with Duet 3 Mini5+ Wifi and 1LC v1.1 Toolboard
                    Voron V0.1 (#637) with Duet 3 Mini 5+ Wifi and 1LC v1.2 Toolboard
                    Ender 3 Pro with BTT SKR-2 + RRF

                    Adam - V3Dundefined 1 Reply Last reply Reply Quote 0
                    • Adam - V3Dundefined
                      Adam - V3D @Gixxerfast
                      last edited by

                      @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 - V3Dundefined 1 Reply Last reply Reply Quote 0
                      • Adam - V3Dundefined
                        Adam - V3D @Adam - V3D
                        last edited by

                        @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...

                        1 Reply Last reply Reply Quote 0
                        • Sindariusundefined
                          Sindarius
                          last edited by

                          @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 - V3Dundefined 1 Reply Last reply Reply Quote 0
                          • Sindariusundefined
                            Sindarius @Adam - V3D
                            last edited by

                            @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.

                            Sindariusundefined Adam - V3Dundefined 2 Replies Last reply Reply Quote 0
                            • Sindariusundefined
                              Sindarius @Sindarius
                              last edited by

                              I found an old SD card which had the config

                              ;Duet Mini5+
                              M575 P2 B57600 S0

                              1 Reply Last reply Reply Quote 0
                              • MintyTreborundefined
                                MintyTrebor @Adam - V3D
                                last edited by

                                @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..

                                9ab5fcdf-165d-4e08-8e4f-99ada01812e5-image.png

                                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).

                                NodeDSF - Native Node-Red integration with Duet boards.
                                BtnCmd - Customise DWC with user defined buttons/layouts/panels (DWC Plugin)
                                ReleaseMgr - Duet update info inside DWC.
                                Repo

                                Adam - V3Dundefined 2 Replies Last reply Reply Quote 0
                                • Sindariusundefined
                                  Sindarius
                                  last edited by

                                  Here's a short video that shows the project that I did. https://www.youtube.com/watch?v=WQDmI404N5k

                                  1 Reply Last reply Reply Quote 1
                                  • Adam - V3Dundefined
                                    Adam - V3D @Sindarius
                                    last edited by

                                    @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.

                                    1 Reply Last reply Reply Quote 0
                                    • Adam - V3Dundefined
                                      Adam - V3D @MintyTrebor
                                      last edited by

                                      @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.

                                      1 Reply Last reply Reply Quote 0
                                      • Adam - V3Dundefined
                                        Adam - V3D @Sindarius
                                        last edited by

                                        @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?

                                        Sindariusundefined 1 Reply Last reply Reply Quote 0
                                        • Adam - V3Dundefined
                                          Adam - V3D @MintyTrebor
                                          last edited by

                                          @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?

                                          MintyTreborundefined 2 Replies Last reply Reply Quote 0
                                          • Sindariusundefined
                                            Sindarius @Adam - V3D
                                            last edited by Sindarius

                                            @adam-v3d you mentioned you are using a duet 2 wifi but I didn’t see what firmware version you are running on the duet

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