Hi, i'm beginner and have a question about serial communication.
I connected arduino and a serial device in two different pc usb ports, can I sent command from arduino to serial device or do I have to connect them together?
Thanks for help
In order to do that, you would need some software running on the PC which passed the serial data between the Arduino and the serial device.
You can skip the computer and connect them directly together. However, you can't connect them via the USB cables, since that requires a USB host to handle the USB communication, a capability most Arduino boards don't have. As for how you can connect them, that depends on the serial device. Note that the Arduino uses TTL serial levels. If your serial device is RS-232, that means it uses voltage levels for serial communication that will destroy your Arduino board if they are connected directly. In that case, you will need to convert the levels between the two devices. There are commonly available chips dedicated to this purpose like the MAX232, which are widely available on easy to use, low priced modules for the hobbyist market.
pert:
In order to do that, you would need some software running on the PC which passed the serial data between the Arduino and the serial device.You can skip the computer and connect them directly together. However, you can't connect them via the USB cables, since that requires a USB host to handle the USB communication, a capability most Arduino boards don't have. As for how you can connect them, that depends on the serial device. Note that the Arduino uses TTL serial levels. If your serial device is RS-232, that means it uses voltage levels for serial communication that will destroy your Arduino board if they are connected directly. In that case, you will need to convert the levels between the two devices. There are commonly available chips dedicated to this purpose like the MAX232, which are widely available on easy to use, low priced modules for the hobbyist market.
I have to control an amount of serial devices, so i can't connect these devices directly to arduino. So i need to connect them to a pc and controlling via Arduino. My question is : can i send data from arduino to devices using arduino IDE with command like "SerialN.write()"?
PS: N corrisponds to a number of COM port
Baldor:
can i send data from arduino to devices using arduino IDE
No. The Arduino IDE will have no place in this project, other than for use to write an upload the code that runs on the Arduino.
Baldor:
with command like "SerialN.write()"?
PS: N corrisponds to a number of COM port
No. The Arduino API does use this "SerialN" convention, but the N refers to the serial interface on the Arduino board. Some boards have multiple serial interfaces. The first one uses the Serial object, the second the Serial1 object, and so on. For example, the Arduino Mega has 4 hardware serial interfaces: Serial, Serial1, Serial2, and Serial3. However, only the first serial interface is connected to your computer. You could use separate hardware to connect the other serial interfaces to your computer, but that would serve no purpose towards your goal. You could connect 4 serial devices directly to the hardware serial pins on an Arduino Mega if you like. You can also add additional software serial interfaces on other pins, though there are some extra limitations on that:
https://www.arduino.cc/en/Reference/SoftwareSerial
It's also possible to add external hardware to allow the connection of multiple serial devices to the Arduino board.
What you're trying to accomplish is to specify which of the COM ports of the serial devices the communication with the Arduino should be routed to. You'd need to create a communications protocol where that information is encoded in the data, and then interpreted by the program running on the PC. For example, you could make it so that Serial.print("2:hello") sends "hello" to the serial device on COM2. Perhaps that would also set the incoming data stream as well, so that Serial.read() will receive the data from the device on COM2, until you specify another port to the application running on the PC.
Baldor:
I have to control an amount of serial devices, so i can't connect these devices directly to arduino.
Why not?
- What serial devices do you want to control?
- How many of them?
- What sort of messages need to be sent to (or received from) the different devices?
It is much easier to give useful advice when we can see the whole picture.
...R
Robin2:
Why not?
- What serial devices do you want to control?
- How many of them?
- What sort of messages need to be sent to (or received from) the different devices?
It is much easier to give useful advice when we can see the whole picture.
...R
Devices are 3 : one power supply, one electronic load and one electrolyzer that i can control via RS-232 protocol. Messages are a series of byte
Baldor:
Devices are 3 : one power supply, one electronic load and one electrolyzer that i can control via RS-232 protocol. Messages are a series of byte
You are making it very hard to help you.
I sorta guessed that there would be bytes involved.
How about giving details of the specific devices (links to their datasheets) and examples of the messages that the Arduino needs to send. Also important is whether the devices need to send data to the Arduino.
If you have just 3 devices then I suggest you use an Arduino Mega which has 3 spare HardwareSerial ports.
...R
pert:
No. The Arduino IDE will have no place in this project, other than for use to write an upload the code that runs on the Arduino.
No. The Arduino API does use this "SerialN" convention, but the N refers to the serial interface on the Arduino board. Some boards have multiple serial interfaces. The first one uses the Serial object, the second the Serial1 object, and so on. For example, the Arduino Mega has 4 hardware serial interfaces: Serial, Serial1, Serial2, and Serial3. However, only the first serial interface is connected to your computer. You could use separate hardware to connect the other serial interfaces to your computer, but that would serve no purpose towards your goal. You could connect 4 serial devices directly to the hardware serial pins on an Arduino Mega if you like. You can also add additional software serial interfaces on other pins, though there are some extra limitations on that:
https://www.arduino.cc/en/Reference/SoftwareSerial
It's also possible to add external hardware to allow the connection of multiple serial devices to the Arduino board.What you're trying to accomplish is to specify which of the COM ports of the serial devices the communication with the Arduino should be routed to. You'd need to create a communications protocol where that information is encoded in the data, and then interpreted by the program running on the PC. For example, you could make it so that Serial.print("2:hello") sends "hello" to the serial device on COM2. Perhaps that would also set the incoming data stream as well, so that Serial.read() will receive the data from the device on COM2, until you specify another port to the application running on the PC.
thanks a lot for advice and help.
Another question: can I use program like HyperTerminal or TeraTerm for communication between two ports?
Sorry, but I really don't know how to do that
Robin2:
You are making it very hard to help you.I sorta guessed that there would be bytes involved.
How about giving details of the specific devices (links to their datasheets) and examples of the messages that the Arduino needs to send. Also important is whether the devices need to send data to the Arduino.
If you have just 3 devices then I suggest you use an Arduino Mega which has 3 spare HardwareSerial ports.
...R
I linked two of them, the most importants.
Electronic Load : https://it.farnell.com/ea-elektro-automatik/ea-el-9080-400/electronic-load-80v-400a/dp/1886272?gclid=Cj0KCQjwtMvlBRDmARIsAEoQ8zRlwi3WC8jiepGY367vp84CxMyM7jE9bwEtrKmxm0jgxRnbfShO4-4aAiCzEALw_wcB&mckv=sVmb59Nk3_dc|pcrid|74427982818|kword|ea%20el%209080%20400|match|p|plid||slid||product||pgrid|11084760738|ptaid|kwd-49881300867|&CMP=KNC-GIT-GEN-SKU-MDC
Power supply: https://uk.farnell.com/ea-elektro-automatik/ea-ps-8080-170-3u/power-supply-1ch-80v-170a-adjustable/dp/1830426
The devices must answer a series of query in which I should be able to see the answers.
The messages are Made up of a series of bytes whose construction is provided by datasheet. For example:
SD: start delimiter byte
Object: the question to answer
Data
Checksum
Those are commercial test equipment.
If your PC does not have a RS232 port, you buy a USB-RS232 adapter.
Then you can use any software such as Python, C#, VB.NET, LabVIEW, Java, whatever you know how to program to query the instruments and get the response.
If it silly to use an Arduino for this.
.
ieee488:
Those are commercial test equipment.If your PC does not have a RS232 port, you buy a USB-RS232 adapter.
Then you can use any software such as Python, C#, VB.NET, LabVIEW, Java, whatever you know how to program to query the instruments and get the response.
If it silly to use an Arduino for this.
.
Yeah i know, but i need to do that with microcontroller right now
Baldor:
Yeah i know, but i need to do that with microcontroller right now
As I said earlier get yourself an Arduino Mega and an RS232 - TTL converter module (MAX232 is the usual) and connect to one of the devices using Serial1. Be aware that RS232 voltage levels can damage an Arduino.
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
...R
Baldor:
Yeah i know, but i need to do that with microcontroller right now
Why?
Baldor:
Another question: can I use program like HyperTerminal or TeraTerm for communication between two ports?
I don't know whether it's possible to "bridge" two ports using one of those programs. However, it's irrelevant, since you have more than two ports to deal with. Certainly those programs aren't going to be able to work for your situation of needing to coordinate communication between three serial devices and an Arduino board.