Problem:
I know for a fact (after testing with Raspberry Pi) that if I could just write bytes to USB serial, my printer would receive the bytes and work just fine. But Serial communication fails to start. If I skip the start, then the "write" function always returns 0 bytes sent.
Details:
I have a Thermal Printer that uses the same default settings as the default Arduino Serial. 8 bits, no parity, one stop bit.
I have used this printer in the USB port on a raspberry pi with these settings and it works completely fine.
When I try to start Serial USB communication on the Arduino like normal, it fails.
Non-solutions:
The Thermal Printer library uses TX/RX, I am using USB.
The USBHost library is obviously not built for this board. Regardless, when I was using the raspberry pi, all I had to do was write bytes to the USB Serial port and it worked fine.
I'm sure SPI might help. I can code in the baudrate myself. I can code in the parity bit. but the Serial library reads like utter gibberish to me. Please, does anyone know how I can just write raw bytes to the USB Serial port?
When you connect the pi to the printer, the pi is acting as a USB Host, just like any PC/laptop does. The printer is acting as a USB Device.
Most Arduino can only act as a USB Device. If you connect a USB Device to another Device, it won't work. One of them has to act as a Host.
You can get USB Host shields/adapters for some models of Arduino. Some Arduino can act as a USB Host, I don't know about MKRWAN1300. But even if it can do that, using Serial.write()/.print() won't work. Those functions only work when the Arduino is acting as a Device, as far as I know.
I have another project going on right now that uses the USBHost library for a Number Pad on this same board. Since the Numberpad acts as a keyboard, I can use the Keyboard class from the USBHost library for it. I know it shouldn't work since the library isn't built for SAMD architecture, but it does. I have the Arduino operating as a USBHost. I know there is a library for the SAMD architecture to act as a USB host, but it hasn't been updated in 4 years and it uses includes that don't exist.
On a side-note, when I plug the printer into a computer USB port it shows up as "Prolific USB-to-Serial Comm Port".
If possible could you answer these questions:
Why do I have to register it as a USB device before simply sending raw serial data? I don't even need to monitor what is received, I just need to put data onto the TX pin of the USB port.
If that doesn't have an answer, how do I write a class that uses the USBHost library to create my own USB device? I only see built-ins for a Keyboard and Mouse or something called an ADK.
I can use TTL communication in a worst case scenario, but it would set me back significantly. I'd much rather get this working.
I know enough to realise why your attempts so far have failed. Bad news is, I'm not expert enough to know how to achieve what you want.
The standard Arduino USBhost library can only work with keyboard and mouse like devices. From what you say, your printer appears as a USB-serial device. You need a version of or equivalent to USBhost library that can work with USB-serial devices. I don't know where to find that, or even if it exists, sorry.
Oh wow, it makes way more sense now that the device works. In the arduino page for the library it only says it works for the Arduino Due so I thought this was a bit of a fluke. Good to understand why it works.
Is there any direction you can point me for more information on the library and how it works? I know about the github, but I can't find any other information.
At the time that page was written, the Due was probably the only Arduino with a SAMD architecture. The page has not been updated since then. These days, there are quite a few Arduino models using SAMD chips. The Due was the first, later came the Arduino Zero and Arduino M0. That was a confusing period for everyone, where the Arduino corporation almost tore itself apart and the two opposing parts became rivals for a time. But things were sorted out eventually, and now there are quite a few Arduino models using SAMD chips.