Can I plug a USB device into an Arduino by using a USB-TTL converter?

I have an MKRWAN 1300.

I managed to get it set up as a USBHost and got it to work with a keyboard, but it only works if you press buttons on the keyboard during startup. It also only works for a keyboard or a mouse, but I have a thermal printer with a USB port I also need to set up.

Basically, I want to bypass USB protocol and just read/write raw data.

Can a USB-TTL converter allow me to bypass the protocol or are they only designed for data to flow from TTL to USB?

Your question doesn't make sense as it now stands, due to vague or undefined terms and language. What does it mean to "bypass the USB protocol"? USB hardware can't possibly work without following its defined data and control protocol.

Unless you rip open the printer and replace or reprogram its controller, it will speak USB only. Even if you could do that, how would you know the (I assume) proprietary internal workings of the printer that I would need to know, to customize it with this direct interface that you propose?

It's even hard to understand what hardware connection you are talking about. Do you want to communicate with the printer via serial instead of USB?

I would suggest if you want to hook it to a printer, you look at one of these, designed to be used with a microcontroller. You're going to have more luck with a serial device instead of one that uses USB.

USB protocol is the pre-determined need for the master-slave architecture of USB devices to USB hosts. This is a protocol I have not seen in other forms of communication such as TTL or radio signals.

Bypassing the USB protocol would mean that some third device could act as a psuedo-USB Host and send raw data received from a USB Device to my Arduino in the form of Serial TTL communication on the RX/TX pins (obviously with a logic level converter). I was wondering if a USB-TTL converter, something typically used to allow a microcontroller to be treated as a USB Device, could fill that role. The reason is that my keyboard does not work correctly all the time and my printer does not work at all.

I hope this brings a bit of clarity. I assume, by your tone, that this is not possible?

Not impossible. I'm just asking you how you would do it.

The problem is, a USB connection observes the protocol on both ends. So a USB host to USB client device like a printer would need two translations to pass through serial:

e.g.
host USB -> serial ... (raw data over comm line)... serial -> USB

Understand? This is the only way to make a connection where the data protocol is unknown. But serial is way slower than USB so both USB devices firmware stack would have to tolerate huge delays.

1 Like

It's just disappointing that the USBHost library has so little explanation of how it does the things it does. It only works for keyboards and mice. The printer is identified as a USB-to-Serial Device when I plug it into my computer. I'd happily add to the library if I could understand anything about it to begin with.

This is almost entirely because most USB peripherals have proprietary interfaces, they don't and won't publish interface details.

You're looking in the wrong place for the key. It's in the printer interface spec, nothing to do with the Arduino library. Just try getting that out of the manufacturer!

2 Likes

Did you look at the source code?

and...
How much did you pay for it?

When you connect a printer to your PC you have to download a driver from the manufacturer. That is how your computer knows how to communicate with the printer.

What are you expecting your microcontroller to be able to print out anyway? With only 256K of flash and 32K of RAM, you're not going to be able to hold very large documents in memory anyway.

1 Like

Windows hides the proprietary nature of drivers, making them appear plug and play. But in fact, MS works behind the scenes with manufacturers to allow Windows to auto-install them.

Other OS like Linux, have to beg, plead and hack to get the information. It's always been a problem.

Begging, pleading and hacking are introduced in Reverse Engineering 1.01.

Begging and pleading are subsets of an also important branch of the field, Social Engineering.

a7

Postscript was supposed to open up printers by defining a stream interface. It works quite well, but not too many printers support it. Even so, the problem of how to fit a printer driver in the limited memory footprint of an Arduino remains.

I'm gonna explain a couple more things about my situation.

The keyboard I have is technically a keypad, but the computer identifies it as a keyboard.
The printer, interestingly enough, is identified as a "USB-to-Serial Device."
The printer is capable of TTL communication too, however...
If I don't press my keypad buttons in the 10-20 seconds after I power my microcontroller, USBHost sometimes fails to start up for some unknown reason.
I'm also making several copies of this device and already have parts coming in (an error on my part), so I'm hoping to use what I have for multiple reasons.
Since both are currently set up to be USB Devices I'd have to order a whole new set of keypads to change out of USB communication and solve the failure to start up.
There are a few other, less important reasons why I don't want to have to change parts I already am getting.

I was hoping for a solution that would allow me to use what I have.

I see by what you're saying though that the problem is much more multi-layered than I thought. The one perk here is that my printer is TTL-compatible, so I only have to buy cables to solve that problem.

The issue of the keypad failing on my Arduino is a much more brutal one that will cost a decent chunk of change.

As for the library, I really just don't understand what I'm looking at. The use of classes and external definitions feels like following a trail of breadcrumbs that is constantly splitting into smaller and smaller trails. For instance, the Keyboard Controller is literally just a class definition while the hdiboot file contains definitions required to parse keyboard input. A simple md file or even a flow chart would be a life saver to figure out why the hosting fails if the keyboard isn't interacted with early enough.

It might better focus the discussion if you were to identify the printer make and model.

If, as you say, it has a serial interface it may very well do something useful if one simply sends the characters one wants to print over the serial interface.

I'm with you on that. I haven't seen that one, but a lot of them are severely under-documented.

1 Like

People continue to mention the printer. I think it was my mistake for bringing the printer up. I must have been pretty unclear about what information I was looking for out of the post.

I made this post because I want my Arduino to be able to get data from USB devices without plugging them into the USB port. Whether that be by simply converting the signal, having a dummy USB host that only pretends to be hosting and actually converts to TTL, even a cheap dedicated USB host device on the side.

There are two USB devices, the printer never worked but the keyboard only usually works.

What I'm looking for is a universal solution to the problems I'm having with both devices by skipping the need to plug the USB device into the USB port.

Not to be too pointed, but your wishes simply don't align with reality. I'm surprised you can look past the obvious fact that most consumer devices are black boxes and will only work with the interfaces that are provided. Those interfaces often have months or years of costly R&D behind them and really, do you have the ability and time to duplicate them, also considering that you have no access to the proprietary information that was passed to the manufacturer by its suppliers and design partners?

You seem to want to pretend that USB is "just a plug". It's not. It's a sophisticated interface.

1 Like

A USB-TTL converter is a device that plugs into the USB port of a USB master and "speaks" serial TTL to some other device. Your keyboard and printer are USB slaves, so a USB-TTL converter won't plug in and be recognized by the slave device.

One could conceivable build a device which is a USB master connected to the USB slave that talks to the microcontroller via serial with some suitable translation. e.g. a PC or Raspberry Pi could do this. At this point, however, one wonders what functionality the microcontroller is doing that the Raspberry Pi couldn't do just as well.

The thread seems to be an instance of an XY_problem in that you're asking about an attempted solution, "How do I interface with a USB device without using USB?", without having described the root goal of the project.

1 Like

Perhaps by using this software, the OP can begin to work on a solution to his problem.

1 Like

The project involves a Keypad at one end, a Thermal Printer at the other, and Radio communication between the two. I need my parts to be easily purchased in bulk.

I've already finished this project with Raspberry Pis, but I can't use the Raspberry Pis in the final iteration. The chip shortage is making the cost ridiculous. It should be around $40 apiece but right now (and for the past year at least) you're lucky to find it for cheaper than $120 if you can find them being sold at all. A microprocessor is not an option for me, cost-wise.

I'm not sure the XY-problem applies here. I have parts I don't want to waste, I'm hoping for a relatively cheap solution, but I'm open to any solutions within those constraints. The USBHost library doesn't fulfill all the needs I have for USB Devices so I want to separate the Hosting from the Arduino and I wanted to know what that would entail.

I've gotten a lot of really helpful information from everyone (especially aarg) despite my apparent inability to provide all the necessary information. Even if the resulting answer is "it can't be done", it's very helpful to understand why that is.