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

New M-code to send a network request

Scheduled Pinned Locked Moved
Firmware wishlist
15
51
6.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.
  • undefined
    fma @Nightreaver
    last edited by 21 May 2019, 08:58

    @nightreaver said in New M-code to send a network request:

    And as other already said, why do i have need to have another device for much simpler things when i already have a 179$ duet in place.

    Well, I like the idea to have multiple simple systems doing specific tasks, and doing them well, rather than heavy things doing badly a lot of stuffs... Maybe RRF needs a good hooks system, with a simple and powerfull com design, to allow us to expand its capabilities without the need to modify the firmware, introducing complexity and potential unstability...

    Feels like fixing my porsche with cheap volvo parts...

    What a waste of Volvo parts 😉

    Frédéric

    undefined 1 Reply Last reply 21 May 2019, 13:25 Reply Quote 0
    • undefined
      dc42 administrators
      last edited by 21 May 2019, 13:24

      I have it on the list for RRF3 for the Duet to be able to send network messages. Whether we support sending via HTTP or MQTT or something else has not been decided yet.

      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

      undefined 1 Reply Last reply 21 May 2019, 18:46 Reply Quote 4
      • undefined
        dc42 administrators @fma
        last edited by dc42 21 May 2019, 13:25

        @fma said in New M-code to send a network request:

        ... Maybe RRF needs a good hooks system, with a simple and powerfull com design, to allow us to expand its capabilities without the need to modify the firmware, introducing complexity and potential unstability...

        That's hard to do on Duet 2, but it will be provided on Duet 3 right from the start.

        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
        • undefined
          Nightreaver @dc42
          last edited by 21 May 2019, 18:46

          @dc42 said in New M-code to send a network request:

          I have it on the list for RRF3 for the Duet to be able to send network messages. Whether we support sending via HTTP or MQTT or something else has not been decided yet.

          IMHO is MQTT THE IoT protocol.

          Other opinions ( "mqtt vs http" ) :

          https://medium.com/mqtt-buddy/mqtt-vs-http-which-one-is-the-best-for-iot-c868169b3105
          https://www.linkedin.com/pulse/internet-things-http-vs-websockets-mqtt-ronak-singh-cspo
          https://cloud.google.com/blog/products/iot-devices/http-vs-mqtt-a-tale-of-two-iot-protocols

          I'd probably not go, an reinvent the wheel with "something else". But im biased 🙂

          1 Reply Last reply Reply Quote 1
          • undefined
            Nightreaver @fma
            last edited by 21 May 2019, 18:51

            @fma said in New M-code to send a network request:

            Why not just use a little RPi Zero W, and connect it to the Duet via I²C? RRF can send I²C commands, so once the RPi is set up, you can do whatever you want (up to cmplex tasks). An ESP8266/32 could also do the job.

            So how would I utilize I²C on duet? I mean.. in need something while no solution is there.

            I'd like to get:

            • power on/off before/after print
            • print status / filament status

            I think if you can point me to any of these, I can figure out everything else

            1 Reply Last reply Reply Quote 0
            • undefined
              fma
              last edited by 21 May 2019, 21:07

              M260 can send data over I²C bus:

              https://duet3d.dozuki.com/Wiki/Gcode#Section_M260_i2c_Send_and_or_request_Data

              On the I²C slave, just mimic some registers you will write from Duet to take the actions you need.

              I recently developped a project using an ATtiny841 as I²C slave (this chip as a hardware I²C slave implementation), working this way. See:

              https://framagit.org/fma38/Servo_Node

              This is for an hexapod (I will use 6 of them, to control the 4 servos of each leg). But I will certainly use this chip for other projects, like here.

              Code in Arduino/ dir is a master example; the real master will be a RPi, running my framework Py4bot: https://framagit.org/fma38/Py4bot

              Frédéric

              undefined 2 Replies Last reply 23 May 2019, 14:44 Reply Quote 2
              • undefined
                Nightreaver @fma
                last edited by 23 May 2019, 14:44

                @fma can i also get a hook in power on/off before and after a print?

                Also is there a way to get serial through not usb?

                1 Reply Last reply Reply Quote 0
                • undefined
                  fma
                  last edited by 23 May 2019, 18:14

                  You can send I²c commands from your start and stops scripts.

                  You can drive the Duet from the LCD connector instead of USB port (This is a serial TTL, you need a TTL-RS232 converter to hook it to a PC serial port).

                  Frédéric

                  1 Reply Last reply Reply Quote 0
                  • undefined
                    Nightreaver @fma
                    last edited by 25 May 2019, 18:34

                    @fma I want to use a WemosD1 because I got a couple for cheap. Im currently struggleing getting the I2C connection working (total noob on arduion and I²C)

                    The wemos is a 3v3 device, so I can use without a level shifter. Ive use the pins of the expansion board.
                    0_1558808799959_945279ed-cd99-48cd-9302-b77d6e3c201a-image.png

                    I assume sda is TWD, and scl is TWCK ?

                    What else do I need?

                    I'm giving my device a 0x08 address and send the following from the duet: M260 A"x08" B99 or M260 A8 B99
                    But I cant see anything happening tho.

                    Did I miss something or is it just a coding/cabling issue? The wires are ~10cm

                    undefined 1 Reply Last reply 26 May 2019, 02:38 Reply Quote 0
                    • undefined
                      Danal @Nightreaver
                      last edited by Danal 26 May 2019, 02:38

                      @nightreaver said in New M-code to send a network request:

                      I assume sda is TWD, and scl is TWCK ?

                      ESP8266s do I2C in firmware, not hardware. Whatever pins you assign in the wire.begin() will work, with very few exceptions. I do encourage you to use "Dn" format, vs. just a number, the Dn are defined to map properly to the silkscreen on the board. Also, as far as I know, and ESP8266 can be an I2C master, but not a slave.

                      And... this may help your efforts. This sketch scans the I2C bus and tells you the addresses of all slaves that respond. I've tried it, and it does work. I don't remember where I got it, and its own header comments don't say.

                      /*
                      * Wire - I2C Scanner
                      *
                      * The WeMos D1 Mini I2C bus uses pins:
                      * D1 = SCL
                      * D2 = SDA
                      */
                      #include <Wire.h>
                      const int sclPin = D1;
                      const int sdaPin = D2;
                      void setup()
                      {
                      Wire.begin(sdaPin, sclPin);
                      Serial.begin(115200);
                      Serial.println("I2C Scanner");
                      }
                      void loop()
                      {
                      byte error, address;
                      int nDevices;
                      Serial.println("Scanning...");
                      nDevices = 0;
                      for (address = 1; address < 127; address++)
                      {
                      // The i2c scanner uses the return value of
                      // the Write.endTransmisstion to see if
                      // a device did acknowledge to the address.
                      Wire.beginTransmission(address);
                      error = Wire.endTransmission();
                      if (error == 0)
                      {
                      Serial.print("I2C device found at address 0x");
                      if (address < 16) {
                      Serial.print("0");
                      }
                      Serial.print(address, HEX);
                      Serial.println(" !");
                      nDevices++;
                      }
                      else if (error == 4)
                      {
                      Serial.print("Unknown error at address 0x");
                      if (address < 16) {
                      Serial.print("0");
                      }
                      Serial.println(address, HEX);
                      }
                      }
                      if (nDevices == 0) {
                      Serial.println("No I2C devices found\n");
                      }
                      else {
                      Serial.println("Done.\n");
                      }
                      delay(2000);
                      }

                      Delta / Kossel printer fanatic

                      undefined 1 Reply Last reply 26 May 2019, 04:33 Reply Quote 0
                      • undefined
                        Nightreaver @Danal
                        last edited by 26 May 2019, 04:33

                        @danal Hey, i found that scetch on github yesterday. I assume it's the esp sample library. Nonetheless I tried it and didn't work for me. I also changed to pins in the firmware, so i assume the pins on the duet i use are wrong, or i missed a cable.
                        Are the marked pins good for i2c communication on the duet? Do i need any more wires or connections?

                        undefined undefined 2 Replies Last reply 26 May 2019, 09:48 Reply Quote 0
                        • undefined
                          dc42 administrators @Nightreaver
                          last edited by 26 May 2019, 09:48

                          You need to add pull up resistors between each of the I2C lines and +3.3V.

                          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

                          undefined 1 Reply Last reply 26 May 2019, 16:43 Reply Quote 0
                          • undefined
                            fma
                            last edited by 26 May 2019, 13:20

                            Are not pullups already on the Duet?

                            Frédéric

                            1 Reply Last reply Reply Quote 0
                            • undefined
                              Nightreaver @dc42
                              last edited by 26 May 2019, 16:43

                              @dc42 said in New M-code to send a network request:

                              pull up resistors

                              On https://forum.duet3d.com/topic/7269/duet-sometimes-really-slow-i2c-error-or/58 you said, between 1.3k and 2.2k, that works with Duet3d Wifi as well?

                              @fma Idk, I find it also a bit frustrating why there is no collection about I2C basics anywhere, I have to collect all the information I need to get started one by one... ☹

                              1 Reply Last reply Reply Quote 0
                              • undefined
                                dc42 administrators
                                last edited by dc42 26 May 2019, 16:54

                                If you have only the Duet and your I2C device on the I2C bus, and your I2C device doesn't itself have any pullup resistors, then you can go as low as 1K.

                                I2C isn't particular to the Duet, and there are plenty of pages about I2C on the web. What matters is that somewhere on the I2C bus you have pullup resistors, and they are not too strong that the I2C devices can't handle them, and not too weak that the capacitance on the I2C bus makes the rise time too long. Pullup resistors of 4K7 are commonly used with I2C, but lower value give better rise times and noise immunity.

                                The Duet does not have any pullup resistors on the I2C lines, because if you are not using I2C you could use them as general purpose I/O pins. The DueX2 and DueX5 do have pullup resistors, with value 1K on recent production and 4K7 on older boards.

                                Note, I2C was intended for connecting chips together on a single circuit board. It was not designed to work over any length of cable.

                                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
                                • undefined
                                  Danal @Nightreaver
                                  last edited by Danal 27 May 2019, 01:31

                                  @nightreaver said in New M-code to send a network request:

                                  @danal Hey, i found that scetch on github yesterday. I assume it's the esp sample library. Nonetheless I tried it and didn't work for me. I also changed to pins in the firmware, so i assume the pins on the duet i use are wrong, or i missed a cable.
                                  Are the marked pins good for i2c communication on the duet? Do i need any more wires or connections?

                                  It may very well be working, if it is reporting zero slaves found, if you have wired ESP<I2C>Duet. There are two possible reasons for this:

                                  1. The Duet is a MASTER. It will never report to this script because the ESP is also a master when running this script. I pointed out the script only for general debugging... for example, if you have another I2C device with which to test, or take an arduino and load an example slave script, then use this polling script in the ESP, etc, etc. That script can be very helpful in general experimentation with I2C.

                                  2. As mentioned, all I2C busses need pullups somewhere. It doesn't matter if the resistors are on the master or slave, M/S is a software concept. In fact, in certain circumstances, resistors in multiple places can be OK. This is because the I2C hardware protocol specification works by whomever is transmitting at that moment "pulling down" the lines. Therefore, a resistor is needed to pull them up when no one is transmitting.

                                  Back to point (1) above: There seems to be no easy way to use an ESP8266 connected I2C with Duet. They both want to be master. I've seen some solutions floating around that MIGHT make an ESP work as a slave... but the postings are ALL sort of ambiguous around whether anyone got it to work. For sure, the standard "Arduino core on ESP" I2C library will not work as a slave.

                                  Delta / Kossel printer fanatic

                                  1 Reply Last reply Reply Quote 0
                                  • undefined
                                    Danal
                                    last edited by Danal 27 May 2019, 01:40

                                    So, having said all of that, the origin of this thread was "M code to send a network request".

                                    An ESP8266 could be very good at sending the network request... Tons of different libraries for every protocol under the sun, and the ESP can be a WiFi client, Access-Point, or both at the same time. Very capable little IOT network device.

                                    I know it bothers people to have to add something to the already very capable Duet... but... come on, ESPs are easy to get for $4 to $6 US, even in low quantities, and can be had for even less if you are willing to order in quantity and wait for a direct Asian shipment. Anyway...

                                    A Duet to ESP connection would work over TTL serial, very easily.

                                    A Duet to ESP I2C might be made to work, if someone can find a library or whatever that makes the ESP work as an I2C slave. At this moment, I don't know of any that are proven to work.

                                    Delta / Kossel printer fanatic

                                    undefined 1 Reply Last reply 27 May 2019, 08:26 Reply Quote 0
                                    • undefined
                                      fma
                                      last edited by 27 May 2019, 05:13

                                      There are some examples of I²C slave with the ESP8266 Arduino package, so I think it can work.

                                      Frédéric

                                      1 Reply Last reply Reply Quote 0
                                      • ?
                                        A Former User
                                        last edited by 27 May 2019, 05:41

                                        Seems ESP8266 as a slave is limited to 14khz with the current software implementation and it lacks proper hardware support. People report success between two ESP8266 but not with a non ESP master. Hoping to verify during the week

                                        1 Reply Last reply Reply Quote 0
                                        • undefined
                                          Nightreaver @Danal
                                          last edited by 27 May 2019, 08:26

                                          @dc42 Yes, I didnt mean infos about I²C in general, but related to the duet. But at one point everything will be discussed in the forums anyways.

                                          @danal Yes ESP are cheap to get, i got 5 WemosD1 for 12$ ? they have the cheaper CH340 chipset, but that still works well after you installed the driver.

                                          So you can get the high quality wemos here:
                                          https://www.aliexpress.com/item/WeMos-D1-mini-PRO-analog-WiFi-D1-mini-PRO-integration-of-ESP8266-32Mb-flash-and-USB/32806566263.html

                                          cheaper bulk wemos:
                                          https://www.aliexpress.com/item/5pcs-D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/32832024575.html

                                          or the ESP32 wroom:
                                          https://www.aliexpress.com/item/ESP-32S-ESP-WROOM-32-ESP32-ESP-32-Bluetooth-and-WIFI-Dual-Core-CPU-with-Low/32864722159.html

                                          secondly:
                                          afer adding the resisors (1k each) i was able to get at least an exception when i have scl/sda wrong way, so i think in general it "works"...

                                          So even tho it doesnt work, i also thought about grabbing serial from the duet and build something around that.
                                          But I dont really wanna sacrifice the usb for that. I have some USB-TTL laying around as well... just didnt check them for wiring on the duet/esp yet.

                                          @bearer that is limited to ESP8266? and what about that ESP32? looks like a bigger package...

                                          @fma I will check to figure something about the slave/master thing. General communication wasn't working yesterday... so i gave up at one point

                                          ? 1 Reply Last reply 27 May 2019, 08:56 Reply Quote 0
                                          31 out of 51
                                          • First post
                                            31/51
                                            Last post
                                          Unless otherwise noted, all forum content is licensed under CC-BY-SA