I need send some information from PC using Serial communication to Arduino mega by its programing port, and send this information by the USB host shield using Serial communication too.
It must run like a bridge, I send information from pc this information passes through the board and it is sent through the USB host shield.
Doing a google search for the keywords “arduino mega serail bridge” does come up with the solution. It’s not that hard to find. But not the first hit. And the next ones you have to read the page/threads a bit to find how to do it. If you look at the code, you’ll find a recurring pattern. Basically, IF a byte is available (serial.availabe>0) in the buffer on one serial port, you send the byte that is first in line to the other serial port (serialWrite / serialRead). Obviously you do this in the loop function. And vice versa if the bridge is supposed to be a 2-way street.
Infact, the Arduino.cc learning wiki has a nice example:
p.s. the proper thread title would have been about how to program a serial bridge on the Arduino Mega. It’s not the USB host shield that you are trying to program.
Yes but I need the bridge use the USB shield port, the programs that I could find about a serial bridges only run with the serials pins of the board. You must indicate the pins that you want to use and it is all.
But I need use an USB port, because I only have access to the USB port of the other machine.
And why does the Arduino Mega with USB host shield need to be inbetween the PC and the other machine? Why can’t you plug the machine into the pc directly?
Without knowing anything about how the mysterious ‘other machine’ is operating it’s impossible to invent a program that drives the host shield. Does the “other machine” come with drivers that need to be installed? (not that this helps much) More details are needed. I lost my touch in waving my magic wand.
it is not a mysterious machine jeje. It an 3D printer.
I can’t connect it directly from PC because I only need send the information in some situations to the printer. My code has a function “if-else” that select when the information is sent to the printer and when not because I need work with this for other task.
Obviously I could do this distinction in the PC and connect both systems to it. But it is not the correct way, I if could find one way to do that as I told, would be better.
It is mysterious if it is unknown. Now you have started calling it a 3D printer you elevated it to the level of “vague machine”. Still not enough. Learn how to ask questions smartly. Nobody is going to help if you don’t provide concrete details of at least brand or model names, or links to it’s documentation. That’s not because they don’t want to, that because they can’t! (pull the answer out of their hat)
As it seems you would need to program some sort of driver on the Arduino to drive the USB host shield for this printer I won’t be able to help. That level is going to be way over my head.
P.S. Your Ebay link leaves a lot to be desired about usefull documentation on that USB host shield (read: none). This shop, or whatever it is, has a bit more in their “Documentation and Links” section for this product: (it seems to be the same one)
My advice: Don’t buy something until you know or have manuals how to operate with it. An unsupported product is useless if you cannot figure out how it works.
Ok I think that you are taking this in a bad way. If you can’t, or not understand, the question because I didn’t explain the this in the correct way for you, you can ask and I will always answer as well as I can, first at all because I am writing in a language that is no my language, is not necessary be rude. I am an engineer, I know perfectly how to do smart questions. If you don’t want to answer because I think that you are lose your time with me, I understand it, but not be rude
I didn’t say the machine before, because it is not relevant, work with simple serial communication, I did it in other systems, but It my first time with arduino and I don’t know how it work. For more information the printer has other arduino mega inside, the bridge would be:
Pc------------Arduino Mega 2560–USB host shield------------Arduino mega 2560
PS: I didn’t mean to be rude in my answer, but ,because is not my language, I think that is possible that it sound like that. Among other things because you are trying to help me
While I haven’t used the MAX3421E, you are looking for a CDC example as the Arduino in the printer shows up as a serial port when plugged into the PC. Google seems to find tons when searching for “usb host shield cdc”.
I don’t think I was rude, but others should judge that. I did get annoyed by the lack of information about all the parts that make up this communication link. That may have shown through in my choice of words. And as a result my patience ran out. But I really do not know enough about how to program on the USB protocol level. So I can’t help with that.