ID | Description | Logical value | Actual voltage |
---|---|---|---|
i | idle signal | 1 | -ve |
0 | start bit | 0 | +ve |
a..h | the data bits (LSB to MSB) | 0=0,1=1 | 0=+ve, 1=-ve |
1 | the stop bit | 1 | -ve |
Number of 0 data bits | Data value | Total 0 bits (Inc start bit) | Pulse duration | Notes | |
---|---|---|---|---|---|
At 4800 baud, 1 bit takes 208.33us so: | |||||
3 | 0xF8 | 4 | 0.83333 ms | Same as 2400 baud 0xFE | |
4 | 0xF0 | 5 | 1.04166 ms | ||
5 | 0xE0 | 6 | 1.25000 ms | Same as 2400 baud 0xFC | |
6 | 0xC0 | 7 | 1.45833 ms | ||
7 | 0x80 | 8 | 1.66666 ms | Same as 2400 baud 0xF8 | |
8 | 0x00 | 9 | 1.87500 ms | ||
At 2400 baud, 1 bit takes 416.66us so: | |||||
1 | 0xFE | 2 | 0.83333 ms | Same as 4800 baud 0xF8 | |
2 | 0xFC | 3 | 1.25000 ms | Same as 4800 baud 0xE0 | |
3 | 0xF8 | 4 | 1.66666 ms | Same as 4800 baud 0x80 | |
4 | 0xF0 | 5 | 2.08333 ms | ||
5 | 0xE0 | 6 | 2.50000 ms |
GND-----|>|----+
+
PWR-----|<|----+
+ +----+
Control -------+---+ +--- TX data from RS232
+----+
If your are using a 9-pin connector for the RS232, then TX is Pin 2, GND is Pin 5. I tied 7+8 together. Then 1+4+6 together. This avoids handshaking issues.
# First set permissions
sudo chmod 777 /dev/ttyS0
# Then set baud rate
stty -F /dev/ttyS0 2400
# 0xFE at 2400 baud = 0.83333 ms
echo -ne '\xFE' > /dev/ttyS0
# 0xF8 at 2400 baud = 1.66666 ms
echo -ne '\xF8' > /dev/ttyS0
# 0xE0 at 2400 baud = 2.50000 ms
echo -ne '\xE0' > /dev/ttyS0
Note: Setting the port to all access seems to work, trying to sudo the individual commands, generates extra characters on the serial port.
./rs232-servo 0
./rs232-servo 1
./rs232-servo 2
./rs232-servo 3
./rs232-servo 4
./rs232-servo 5
./rs232-servo 6
./rs232-servo 7