Go Down

Topic: Communication between Uno board and sealing device (Read 338 times) previous topic - next topic

MRutger

Jan 23, 2019, 10:41 pm Last Edit: Jan 24, 2019, 10:47 am by MRutger
Dear reader,

First of all I would like to clarify that I'm pretty new to arduino and that I don't really have that much experience with electronics and their way of communication. I know that my laptop and the arduino board can communicate with each other by opening the serial monitor and using the serial.print() commands. However for a current project I was wondering if it's possible to have the arduino communicate and send ASCII commands to another device without the serial monitor.

This device is a sealing device of which i don't have the specs. When connecting it to my laptop directly using USB i can send commands using the serial monitor of arduino or other serial terminal programs. But since i don't want to have my laptop connected to it the whole time, i was thinking of using my uno board to send the commands instead. But when i connect my board (with external battery) to the sealer using the USB port I can't make it communicate with the sealer and it doesn't seem to react to the uno board. The TX led doesn't blink either when using serial.print(). I had to use a Female USB A to Male USB B Adapter to connect them, but I don't know if this is allowed.

The code I've been using is the following. I intended to send the command, which i normally do using the serial monitor, by using the serial.print() function as soon as a button was pressed, hence the input on pin 2.

Code: [Select]
int switchState = 0;
int valuex = 0;
int gelezen = 0;
char chrValue = 119;

void setup() {
 Serial.begin(9600);
pinMode(2,INPUT);
}

void loop() {
  switchState = digitalRead(2);
if(switchState == HIGH){
  valuex = valuex+1;
  digitalWrite(3,HIGH);
}
else{
  valuex = 0;
  gelezen = 0;
 digitalWrite(3,LOW);
  }
 
if(valuex>0 && gelezen==0)
{Serial.write(chrValue);
gelezen = gelezen+1;
}
delay(100);
}


As said before I barely know anything about device communication, master-slave relations, handshaking and such. But seeing how such amazing things can be accomplished with the arduino boards there has to be a way to make it send a single command to another device through it's serial port. Perhaps it might be something simple that I'm overlooking. I hope somebody can help me. Thank you in advance.

pylon

Quote
But when i connect my board (with external battery) to the sealer using the USB port I can't make it communicate with the sealer and it doesn't seem to react to the uno board.
The USB connection is not the same as a UART connection. In the USB world you have a host which controls the complete USB. All connected devices (for a PC usually mouse, keyboard, printer, etc.) are only slaves and only answer requests sent by the host. In your case the sealing device is a slave as well as the UNO (as both connect to the PC). But they cannot be connected directly as both are slave devices, so none of them is requesting anything, both are waiting until the host is asking for a service.
You get similar problems if you try to connect two hosts (connect one PC to the other), but there you have not only logical problems you also get electrical problems as both are providing power to the USB, so never try that in reality.

You have the imagination of the USB to be equally to the former RS-232 connection. There both ends are on the same level and can be exchanged, although usually there also one side is asking for some service and the other one is answering, this is just by convention and not part of the standard.

The serial port you see on the PC is just an emulation on the USB layer. On the Arduino side the UNO has a coprocessor (ATmega16U2) that is handling the USB side and provides a UART layer to the UNO's main processor (ATmega328p).

If you provide more information about the device you're trying to communicate with we might find a solution. You might put a USB Host Shield to the UNO to give it host capabilities but you must have a driver for the shield that correspond with the connected device (as you have to do on the Windows machine, if you connect the UNO the first time you have to install a driver to enable the virtual serial interface). For some often used USB-to-serial chips such drivers exist but there are many other chips on the market, that are not supported and if the sealing device is handling USB directly you will fail to find a driver surely.

MRutger

#2
Jan 25, 2019, 09:32 am Last Edit: Jan 25, 2019, 03:47 pm by MRutger
Thank you for your reply and simple explanation. Like i said before, i don't really now all that much about device communication so your explanation was a big help. I thought that USB and UART were the same thing given the explanation about serial on one of the arduino pages. If a RS-232 connection (which are the TX and RX pins?) would solve the host-slave problem, perhaps i should try to find a way to connect them that way?

If you provide more information about the device you're trying to communicate with we might find a solution.
At the moment i don't have that much information about the device i want to connect with, but i can try to find out some more. What kind of information do we need? What i can already tell is that when using the laptop and USB connection I also had to use a redcom usb-rs485 adapter in between the laptop and the device.

You might put a USB Host Shield to the UNO to give it host capabilities
I was under the impression that USB Host shields could only be used to read out data, not send commands?

pylon

Quote
If a RS-232 connection (which are the TX and RX pins?) would solve the host-slave problem, perhaps i should try to find a way to connect them that way?
RS-232 is not the same as a TTL UART, connecting RS-232 directly to Arduino pins probably fry them. You may use driver chips (MAX232) to adapt the voltage levels (as the logic is the same) but all that stuff we must have detailed information about that other sealing device.

Quote
What i can already tell is that when using the laptop and USB connection I also had to use a redcom usb-rs485 adapter in between the laptop and the device.
That gives the important information that your sealing device uses RS-485 for the communication. There are RS-485 adapter on the net that can be used for Arduino too.
Do you have a photo of the device? Do you have type and model information? Maybe the link to a manual or something similar?

Quote
I was under the impression that USB Host shields could only be used to read out data, not send commands?
Theoretically USB host shields can do the same as a PC can. In reality this often fails because you get a USB driver for Windows for the device in question but no information about how the USB communication is structured, so a corresponding driver for the USB host shield cannot be implemented. Even if the information is available, there must be someone that develops such a driver. As this task needs quite some knowledge about USB and it's internals that someone is often not found.

MRutger

Dear Pylon,

Sorry for the long absence. I've been trying to gather more info about the device itself, but apparently it was custom made and I can't get in touch with the manufacturer. I did find out however that the device uses a ST1480AC transceiver for RS485/422. (I've added the datasheet of the manufacturer as attachement). It might be a stupid question but do you think it is possible to bypass this transceiver and just connect the arduino directly to the receiver output of this transceiver? I'm not really sure how such a transceiver works but my guess was that the RO pin equals the Rx pin and the DI equals the Tx pin? Guess I'm seeing it to simplistic and am missing some important insights.

pylon

Quote
I'm not really sure how such a transceiver works but my guess was that the RO pin equals the Rx pin and the DI equals the Tx pin?
No, bad idea, this chips is running on 3V3 but your UNO runs on 5V, you might destroy any of it or both.

Why don't you buy an RS-485 adapter for the Arduino (costs a few buck) and connect it using that? I guess the A/B connectors are marked correctly on the device.

MRutger

Why don't you buy an RS-485 adapter for the Arduino (costs a few buck) and connect it using that? I guess the A/B connectors are marked correctly on the device.
But will this solve the slave-slave problem however? Or is this only important for the USB connection and not if you're using the RS-485?

Also I've bought a USB host shield before for my arduino, but after contacting support they told me my UNO WIFI Rev 2 board wasn't compatible with it although it was the official USB host shield and said to be compatible with the UNO series. So kinda suspicious about buying shields for my board now.

pylon

Quote
But will this solve the slave-slave problem however? Or is this only important for the USB connection and not if you're using the RS-485?
For the RS-485 connection this doesn't apply. Both sides can send and receive.

Quote
Also I've bought a USB host shield before for my arduino, but after contacting support they told me my UNO WIFI Rev 2 board wasn't compatible with it although it was the official USB host shield and said to be compatible with the UNO series. So kinda suspicious about buying shields for my board now.
Unfortunately the UNO WiFi is not an UNO, despite it's rather bad chosen name. The UNO is based on a ATmega328p processor while the UNO WiFi is based on a ATmega4809. There are many things that won't work on the UNO WiFi that is designed to work on a UNO. Most shields that work on a Mega2560 and on an UNO will probably also work on the UNO WiFi though.

I would not buy an RS-485 shield anyway, a cheap RS-485 module will do the job as well.

MRutger

Hello Pylon,

me again sorry. I bought that TTL-RS485 module as you recommended and wired it the following way:

Arduino                 Module                  Sealer
GND                         GND                      GND
5V                            VCC
TX                             DI
RX                             RO
                                 A                           D+
                                 B                           D-

Now I wasn't entirely sure about that those last 2 rows so i did try to switch them in case I'd mistaken D+ and D- but neither case did the sealer react nor the arduino's TX led blink.
I've also tried it with placing 5V at the DE pin of the module and the GND at the RE pin but this didn't seem to have any effect. Any idea why this wouldn't work? I thought perhaps i fried the TX and RX pins on the arduino during one of the previous attempts so i was thinking of trying the software serial function. What do you think?

MRutger

Just to let you know i've tried doing it with the software serial function and i was finally able to make it seal something. Can't thank you enough pylon, you've been a great help.

Go Up