Arduino Delphi Serial Communication Rs232
- Arduino Rs232 Serial Communication Example
- Arduino To Arduino Serial Communication
- Arduino Rs232 Communication
My project goal is to read the serial signal which is supplied by the P1 port of a Smart Meter (ISKRA type MT382-D2A52-M2K0agnZ) with an Arduino MEGA 2560 @ 9600 Baud rate. Many before me have succeeded, however I don't seem to manage. Before the Arduino can 'read' the signal from the P1 port, the signal requires to be inverted.
Arduino Rs232 Serial Communication Example
The Question and Setup
I'm trying to have my Arduino Pro Mini (w/ ATmega328) communicate with a serial device via RS232. Specifically, I want the arduino to eventually communicate with a BKPrecision 1785B power supply and control its voltage, current, etc.
One caveat. I'm using my computer (via the only RS232 hookup on the arduino) to program and debug the code, and my arduino only has one serial port. Therefore, I decided to use the SoftwareSerial library to setup an additional software RS232 port (on digital pins) for communicating with the power supply.
Arduino To Arduino Serial Communication
What I've done to date
Arduino Rs232 Communication
I tried implementing the above, but the BK1785 didn't show any sign of receiving or understanding the commands. I then plugged in a second computer into the SoftwareSerial port (instead of the power supply) to monitor communication and make sure that the commands were properly sent. The second computer (using Docklight as a serial monitor) noticed that information was being received, but it didn't match what was sent (see below). I can only assume that the I haven't set up the adruino to communicate correctly. It seems most likely that it must be either 1) the Software serial setup or 2) me incorrectly broadcasting the data.
Additional info
The power supply requires a packet of 26 bytes.
Docklight is setup as 9600, 8N1 (edit#1)
Arduino Code
This is the simplified code that I'm running on the Arduino.
Output and Input
I'm broadcasting the following 26 bytes (shown below in dec. format) from the arduino (see code above) through the SoftwareSerial port:170, 0, 32, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 203
My second computer (connected to the SoftwareSerial port of the arduino) is receiving the following 25 (not 26) bytes (also shown in dec. format):149 191 253 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 105
Final thoughts
I've tried using both the write and print commands in the arduino, but neither appear to work. Honestly, I have no idea if using the for loop to send the 26 bytes is the correct way to send information like that. Is there a better method for sending a packet of bytes? I poked around on the internet, but I couldn't mind a similar example.I would appreciate any feedback for the community. Thanks!
Edit#2
I replaced the for loop in my code with the following line:
and received a the identical set of 25 bytes:149 191 253 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 105
Edit#3
I'm trying to post images of my oscilloscope traces, but I don't have 10 reputation points yet.
Is the serial communication receive line supposed to be high when there is no data sent?
1 Answer
Given that you are getting mostly 1's where you want 0's, maybe you've got the high-low levels wrong. If the hardware connections look right, try the undocumented 'inverse_logic' flag in the SoftwareSerial()
constructor.
See https://github.com/arduino/Arduino/blob/master/libraries/SoftwareSerial/SoftwareSerial.cpp, line 335
AShellyAShellyNot the answer you're looking for? Browse other questions tagged serial-portarduino or ask your own question.
Description
Used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART), and some have several.
Board | USB CDC name | Serial pins | Serial1 pins | Serial2 pins | Serial3 pins |
---|---|---|---|---|---|
Uno, Nano, Mini | 0(RX), 1(TX) | ||||
Mega | 0(RX), 1(TX) | 19(RX), 18(TX) | 17(RX), 16(TX) | 15(RX), 14(TX) | |
Leonardo, Micro, Yún | Serial | 0(RX), 1(TX) | |||
Uno WiFi Rev.2 | Connected to USB | 0(RX), 1(TX) | Connected to NINA | ||
MKR boards | Serial | 13(RX), 14(TX) | |||
Zero | SerialUSB (Native USB Port only) | Connected to Programming Port | 0(RX), 1(TX) | ||
SerialUSB (Native USB Port only) | 0(RX), 1(TX) | 19(RX), 18(TX) | 17(RX), 16(TX) | 15(RX), 14(TX) | |
101 | Serial | 0(RX), 1(TX) |
On Uno, Nano, Mini, and Mega, pins 0 and 1 are used for communication with the computer. Connecting anything to these pins can interfere with that communication, including causing failed uploads to the board.
You can use the Arduino environment’s built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin()
.
Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board). Don’t connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board.
To use these extra serial ports to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground.