-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work with printers without serial interface (USB Host Mode) #123
Comments
Never say never... In the meantime, this is where you can solder to the Creality mainboard: |
I tried to connect my esp8266 usb to mega usb (my printer). |
@probonopd thanks, I might try later with those pins. |
Actually there will be a new ESP32 chip version with USB host mode soon: ESP32-S2. I think I am gonna support this one if possible, once boards for it are cheaply available. Throwing in a USB host to serial chip is always an option of course, so this brings our options (at least) to:
|
Ever tried either of these chips? I'm a bit sceptical, I couldn't find any quick examples for most of the chips that'd be equivalent to what shall be accomplished here. |
No. But any chip that can convert serial-over-USB to serial should do, at least in theory. |
A Raspberry Pi Zero however doesn't run OctoPrint sufficiently smoothly... |
Who said OctoPrint? ;-) I wonder if we can get this to compile on https://github.com/epsilonrt/piduino. Probably the WLAN stuff would need to be ifdef'd away... since you know C++ quite well, would you like to give it a try? |
Well...
Did I mention one of these cheap RasPi clones melted an SD card and it took me an hour to figure out what was wrong? OctoPrint is great, if you have the right hardware to make use of all the features. However, if you can't, a small, energy-saving solution like WirelessPrinting is preferable. |
Agree! I was just wondering whether we can make it run on the 5 EUR Raspberry Pi Zero which has USB host mode... |
Maybe by making this app into a proper C++ library and then building two frontends, one for Arduino, one for Linux hosts. That's the easiest and most manageable way. |
A USB host solution by the way is also great for debugging, you don't have to solder to demonstrate this on arbitrary printers -> great for conferences. |
In September or so we will have ESP32-S2 👍 https://hackaday.com/2019/05/21/new-part-day-espressif-announces-esp32-s2-with-usb/ |
Blocked by epsilonrt/piduino#11 as it currently does not seem to support networking at all. |
Looks like the Geeetech 3D WiFi Module can do it. Looking at http://www.geeetech.com/firmware/Upgrade3DWF/config.txt the hardware is based on ESP8266 but the firmware is proprietary. I wonder what chip/electronics they are using for the USB host. |
Digging though their firmware gives https://www.st.com/en/embedded-software/stsw-stm32046.html
Intelligent guessing when digging through the firmware is fun:
So at this point I'd say that's the hardware they are using. Are they flashing the STM32F105xx from the ESP8266, or why does the STM32F105xx stuff show up in the ESP8266 firmware? Actually, the manual says under "Specs": CPU: STM32F107 + ESP8266 The available STM32F107 boards/modules are more expensive than the Geeetech 3D WiFi Module, so if you need a solution now, then Geeetech 3D WiFi Module may be it. |
ESP32-S2 seems still not to be available yet on eBay. |
Has this board ever been released? I don't see any of those in the respective shops. Regarding the combination of an STM32 and ESP8266, it's also a pretty cheap and very universal solution. Ideally, we could simply combine a bluepill board with a NodeMCU or WeMos D1 Mini. I think that such a solution would work out of the box, provided that the STM32 just bridges between the USB serial interface and its own UART pins. Edit: the vendor publishes a library which claims to support USB host mode for USB-CDC devices. This class is also used by the USB-to-RS232 bridges, which internally use chips from e.g., FTDI or (especially cheaper ones) Prolific. See https://www.st.com/resource/en/data_brief/stsw-stm32046.pdf for more information. Edit 2: hosting CDC devices is not available on cheaper boards like the bluepill, you need a specific chip which contains a USB host. |
Yes, unfortunately the Blue Pill is lacking the needed USB OTG/host functionality. The ESP32-S2 had been announced some time ago, but as far as I know there are no board with it on the market for sale yet. And also no code for the Arduino framework to use it as a USB OTG/host device yet. |
I've found some USB host shields for ~8USD, that still exceeds a RasPi Zero's price. Perhaps this repository should be split up and modularized so that it's easier to build frontends for e.g., embedded devices, but also native ones? Some hardware abstraction wouldn't be too hard to implement, C++ makes it really easy (adding an abstract class which defines the serial communication interface as well as two or more implementations for the ESP8266/ESP32, Linux (for the RasPi Zero but also development machine), and in the future perhaps even a simple Arduino Nano (should work for LAN, see #125)). Another advantage is that you can develop on your computer to debug non-hardware-related problems, e.g., the communication protocols. Unit testing also becomes a lot easier. |
...or we just wait a bit more, then we will get Linux capable modules for the price of an ESP8266. It's only a question of time :-) |
Linux is not a real-time system. But I guess that doesn't really matter here, since we just forward commands to an actual real-time system. |
Yes. Actually, we can send a few lines "in advance" to what is being printed; hence the exact timing should not matter too much. |
I ordered an STM32F4 for evaluation, which could be combined with a WirelessPrinting device, serving as a bridge between a USB CDC device and UART. |
Which one did you order? Seems like STM32F401CCU6 boards are becoming cheaply available, but with that dreaded USB Type C plug (despite the chipset having USB 2.0 OTG FS). Also note that not all printer boards implement USB CDC; some have chip-proprietary implementations like FTDI, Silabs, Prolific, WCH-IC CH340, etc., all of which you need host drivers for. Does STM32CubeMX contain all of those or "just" CDC? |
ESP32-S2 support is beginning to trickle into the libraries... hathach/tinyusb@2ff3f76. Unfortunately,
And is likely missing the CDC/other serial modes. |
Someone mentioned the ESP32-S2? http://invidio.us/watch?v=L6IoSVdKwNM Looks like a nice device, let's hope for the best. The thing has just one core, but it's fine for WirelessPrinting, nothing time critical running really. What's a bit annoying is the need for an external SPI MicroSD interface. Maybe it's even a bit cheaper than the ESP32, that would be nice, too. |
I am interested in developing a pcb with either ESP32-S2 or maybe a USB-Hostcontroller chip like MAX3421 and make it especially for this library with onboard sd-card reader or larger onboard volatile memory if that is better. Has any tests been made with ESP32-S2 as USB-Host? Looking at this example makes me think that doing this with an ESP32-S2 will actually work. Atleast there is examplecode for arduino here but should also work in PlatformIO. Does not take much time or money to get a develop-pcb up and running so I think I will give it a shoot |
https://www.winbond.com/hq/product/code-storage-flash-memory/qspinand-flash/?__locale=en might be a better choice, each chip contains 1 Gb of NAND flash (128 MB). Perhaps one could add as many chips as needed? |
Just for starting to think about it I created this miniboard with onboard memory. But I am quite pleased with this. Would be really easy for anyone wanting their printer to be wireless :) Price for this one is completely different. Again if you just order 5 of them it will be about $10 for each depending on what price you get on the ESP32-S2. The reason I am looking at this is that I run a small electronics business and look for projects and be a little like adafruit that provide everything opensource for them who like to do it themselves but also provide finished boards for the bigger crowd. |
For the record, I'd include the option to add some control buttons (e.g., by including pin headers). Most important button IMO is "abort print", that should trigger some "move print head away and turn off heaters" G-Code. |
That is a good idea. The first step is to ofcourse just see if it is possible at all to do it with the ESP32-S2. I do have a small board with the USB-port connected to a ESP32-S2 somewhere so think I will start there just to test. The construction exercise was just to see if it is viable at all for me to spend my time on (More seriously) and because it was fun to attempt to do something as little as possible :) But what I see could be possible when compared to other options is:
|
I just thought about your second proposal. I think you shouldn't add a specific connector (or do different boards for different types of USB connectors). The Ender-2, the printer I mentioned in the original post, wouldn't allow fitting a board right on the USB connector, which is exposed to the front through a little cutout in the acrylic cover. I always wanted to use a cable and mount the wireless interface in some place it fits into. Some printers might not even have space for such a board, so you'd have to mount it on the outside anyway. Your first prototype with the female USB type A looks most promising therefore. Just add a suitable (maybe even angled) USB A-to-[printer connector] cable and you're set. Re. SD card vs. onboard flash: in the long term, SD cards will be the better option. You can just swap it for another one on failures, for example. Also, there's virtually no size limitation. The cards are really cheap, and I think many people have some old ones for such a purpose (I do have some 2-8 GiB ones I don't use, for instance, which could perfectly work as a cache for such a board). Also, with an SD card, some old g-code could even be kept for quick reprints (I'd like to have such a feature, also has some use in print farms for instance; of course that'd likely require a little display to be hooked up to the ESP). I think the board should be discussed in a new repository. This issue is about adding support to @probonopd's firmware. Hardware questions are out of scope. |
I agree totally with this. I think I was focusing to much on my own printers (Creality Ender 3 v2 and Creality CR-10s pro) Where the minimialistic design would work really well. I will also create another repository for it when I get into that project more. |
There are now very inexpensive ESP32-S2 based boards called the S2 Mini. Photo credits: @smartin015 They have a USB-C port which a 3D printer can be plugged in using a USB-A to USB-C adapter. And Espressif seems to have a USB host mode driver for serial bridges and for CDC class compliant devices.
So possibly it could be done now. Actually, someone has done almost exactly what we have in mind: But that code doesn't use a microSD card to store the GCode; instead it opens a socket over the network. But it should be possible to port it over... Code: https://github.com/smartin015/esp32-tcp-serial Volunteers? Cross-reference: |
Heya! That was a quick demo, more just to prove the concept than to be used in a "production" setup. I'm glad it caught your attention though, I'd be happy to help contribute here as this project is way further along. The examples I pull from all use the ESP-IDF framework. I expect building compatibility between the IDF stuff and your Arduino framework code would be step 0 here. WDYT? |
Indeed, porting what you have to the Arduino framework would be tremendous. 👍 |
Just a heads up that I started the port work today - successfully builds with VCP idf components included and imported into ESP8266WirelessPrintAsync.ino. I haven't yet tried using the VCP components or even running the firmware, but things are looking good so far. WIP is in https://github.com/smartin015/WirelessPrinting/tree/esp32s2_usb_host. Note on what it took to combine ESP-IDF and Arduino: it appears there are two recommended ways of combining them.
I'm much more in favor of (1) and have used that approach when building as it's easier to debug compile-time errors and add more cross-platform stuff later on. Additionally, I had to exclude the OTA library as I was running into the 1MB FLASH memory limit. Unsure if there's something less impactful I can cut down on, but I'm proceeding with that for now out of convenience. |
Wow, that is awesome news! Very exciting. :+1
Don't we have 4 MB flash on those lolin_s2_mini boards that we want to use for USB host mode? We can do without the ElegantOTA library (in fact I wanted to remove it anyway), but we do need a way to update via the web interface (I have no physical access to the ESPs built into my 3D printers). Have a look at #175. We had web based updates working before we added the ElegantOTA library. The ElegantOTA library is purely cosmetical. Before the PR that added the ElegantOTA library, we had a simple (not so graphically nice but leaner) way of updating via the web interface, which hopefully doesn't need as much memory. Maybe you can add the original update mechanism back in, essentially reversing #118? I hope we can keep SD card functionality for the lolin_s2_mini. What is very important to me is that CI builds work. |
Good catch, indeed we do - apparently the default partition config for the S2 mini reserves ~1M for the app, 1.5M for SPIFFS and the rest for OTA. I was able to minimize the SPIFFS and fit it all without disabling OTA.
Shouldn't be a problem now :)
I'm still splicing things together - will enable CI once I'm ready to submit a PR. FWIW I've progressed to sending/receiving some USB serial data while the embedded server/telnet are up, but I'm hitting a snag with command interpretation (apparently my printer doesn't send an EDIT: I seem to be running into problems with corruption in the Arduino |
Great that you ae working on this! I have made a prototype hardware that I have at home now available for testing. I did do some mistakes in it but with some modifications it works so I can do testing when you have something that is being able to run. I did go with the S2_mini cpu but a completely custom pcb around it just to keep cost down and make it easy to just plugin. Unfortunately it does seem like atleast creality printers that I use does not provide a 5V source thru USB as standard as my original idea was to just use the board and have a microusb male contact on it and just mount it on the printer directly on the usb-port. Would be really elegant but sadly I needed to provide my own +5V and powerbrick... |
Neat that you're making a custom board! And yeah, I had to power mine externally as well as I don't think there's anything in the USB spec about supplying any amount of voltage from the non-host device. Did you try my original code on it to confirm the VCP stuff is working? I think there could still be a pretty elegant solution that turns the S2 into a little bump on a "USB cable", something like USB A to power the S2 on one end and USB micro to connect to the printer on the other end. One could buy and hack apart a standard USB micro cable to put it inline as well. |
No I havent got around to testing anything yet more than solving the issues I had with the PCB. I currently work on another project taking up all my time so will need to pause this until after May. I just cant start more projects right now. But yeah I have been thinking about the same thing but I am thinking of just having a type A usb for communication with printer and then a micro-usb for power. But it will be really small atleast. |
Another update on my end: code is still quite hacked together, but I've managed to get
Video of all this working here: https://youtu.be/9qLVEFzK7UQ @probonopd before I actually submit my draft PR and run the CI builds, I'd like your input on a few things:
In other news, I'm pausing development for around ~2wks as I've got some other projects that need attention. My PR should build and run just fine on an S2 mini however, so if anyone wants to pick it up and work on it they're more than welcome to keep going :) |
Well, the printer is a device. The USB host needs to provide USB power. And in this case, this is the ESP. |
@smartin015 congratulations, I watched your video, this is awesome progress. 👍 A real breaktrough. Regarding your questions:
|
Okay - I should have time this week to make some additional progress here. I'll
|
Would it be possible to get the fixes into those libraries upstream? I think that would be the cleanest solution... |
https://github.com/luc-github/esp32-usb-serial is now available, which adds support for
to ESP32S3 and (untested) ESP32S2. Maybe someone would like to integrate it here? |
Hey @probonopd - long time no update from me. Apologies for leaving things half finished, life got busy. I make no guarantees on additional work, but I did poke at the new arduino library you linked today. It builds with pio for esp32s2 (see https://github.com/smartin015/esp32-usb-serial-pio/) but I ended up submitting a PR to the original library as it was complaining about missing non-static members (see luc-github/esp32-usb-serial#1). Also had to specifically set the C++ version in Haven't tested on a device yet; just wanted to leave some breadcrumbs in case another person wants a head start. |
Thanks for the update @smartin015. I don't think anyone besides you is currently working on this topic, so in case you ever get it to work with WirelessPrinting, we'd certainly appreciate a pull request. |
Hi, I've now looked at your code and augmented it a bit to work with the printer. The problem came out that the processing speed in Arduino-IDE is not enough, I haven't tested it with ESP-IDF (I don't know it). Do you have any ideas how to speed up your code with Arduino-IDE? |
Overclock the microcontroller maybe? |
I'm a layman in these things, but I checked my code for delays sending and processing a received message takes >500 microseconds. When testing with the printer via PC and Arduino IDE Port Monitor, the printer sends a response to the command almost instantly > 1 second, and if you send the message via ESP32-S3, the delay is about 10 seconds. If someone has tested this code, but on ESP-IDF, I would be grateful if you could write your conclusions on delays. So that I can understand if I should learn a new language:) |
According to luc-github/ESP3D#851, ESP3D seems to have this feature now. I haven't tested it yet. Could it be ported here? |
Some printers' boards, such as for instance the Creality Ender 2, don't have RX/TX GPIOs for serial communication, which means this project cannot be used with them. As these are mostly inexpensive printers, using OctoPrint with more expensive hardware is annoying due to the price.
The printers however mostly have USB sockets which can be used for serial communication. Therefore the question is: can an ESP board communicate via USB with those?
My hope is there's a USB-to-serial sort of adapter that provides a USB host and translates the USB stuff into raw serial again. The cheap UART adapters you can find online are functionally equivalent to the stuff in the printer board, they lack the host feature and cannot be used.
I know some Mega2560 based Arduino boards can provide a USB host feature and might do the translation, however they're quite bulky and also expensive. It might be cheaper to get something like an Orange Pi or so and try to run OctoPrint on there (UI won't run very well, I hope there will be a completely headless version in the future).
Perhaps there's a kind of USB host chip to do the translation which doesn't require a complex circuit that needs to be soldered on a PCB, as most people don't have access to the tools to realize that.
The text was updated successfully, but these errors were encountered: