Arduino can be used as a master controller and issue serial commands and queries to Roboteq controller by using its serial port. One thing to notice is the different signal levels between Arduino and Roboteq controller. Arduino uses TTL logic level on its serial port and the Roboteq controller serial port is RS-232. Besides the different logic level between the two ports, the two signals are also inverted. For those reasons, some additional circuitry is needed between the two devices to achieve communication. At this tutorial we will use an FBL2360T controller, an Arduino Uno board and a TTL to RS-232 adapter.
This tutorial will cover three points:
- Testing controller’s and adapter’s functionality by using an oscilloscope
- Confirming that the Arduino can read the transmitted data from Roboteq
- Confirming that the Roboteq controller can receive serial commands from Arduino
1. Testing controller and adapter by using an oscilloscope
Note: This step can be skipped if the communication between the two sides is conducted without problem.
At this first step, the correct operation of the TTL adapter and controller’s RS-232 port will be confirmed by using an oscilloscope. A script will be used to send some data through RS-232 and the user by using the oscilloscope can confirm that the waveforms of the controller and adapter are correct. For this initial test only the Roboteq controller and the Adapter will be used. The Adapter can be powered from Roboteq or Arduinos 5V.
To proceed follow the below steps:
1.1. Configure the Roboteq RS-232 port Baud Rate
For this test any baud rate would do since the Arduino’s RS-232 port will not be connected. The baud rate used in that example is 9600.
1.2. Set the script output to “RS-232”
At this test, we will send some data through RS-232 port by using script. By default, script prints at console tab, but there is also the option to use RS-232 port. The following command needs to be sent to change the script output:
The controller will reply with +
1.3. Write a small script that prints some data in a loop.
Send the below script to device and click run. The Roboteq controller will start printing “Hi” on its serial port, every 1 ms.
start:
print("Hi\n")
wait(1)
goto start
1.4. Confirm that the waveforms are correct by using the oscilloscope
The RS232 signal at controllers RS-232 Tx pin should be centered at 0 V and have positive and negative values. At this setup with the FBL2360T controller, the Tx signal has a minimum of -5 V and a maximum of 5. Also, the idle state of the line that is equivalent to no bit transmission is HIGH (5 V).
At the other side of the converter, the signal should be inverted (at no bit transmission it should be LOW) and the signal should have values from 0 to 5 V. The correct operation is shown in the next image.
This test will prove that the Tx pin of the controller and Rx out of the adapter work and have the correct signals. If the signals are correct on these pins, then it is most possible that the Rx and Tx out pins will work as well. To test the correct operation of these pins also, one can simply connect together Rx out and Tx in pins of the adapter and measure the signal at Tx out of the adapter. The Tx out is not necessary to be connected to the controller. This time the signal should have the Rs-232 levels and should look alike the signal of controller’s Tx.
2. Confirm that the Arduino can read the transmitted data
At this step, we will confirm that the Arduino can read the serial data sent by the Roboteq controller. The data will be sent by the Roboteq through RS-232 port using a script. The controller’s Tx should be connected to adapters Rx in and adapter’s Rx out should be connecter to Arduino Rx in. The data being sent by the controller will be read by Arduino and printed by using the Arduino’s Serial monitor. The Arduinos Tx should not be connected, otherwise the data will be sent back to the Roboteq controller and controller will reply with a minus (-) for each data it will receive, since they will not be a valid command. The adapter should be powered from Arduino’s 3.3 V output, since the Arduino serial voltage level is 3.3 V.
To proceed follow the below steps:
2.1. Configure the Roboteq controller’s serial port baud rate
The baud rate of the two sides must be the same. For this test a baud rate of 9600 is used
2.2. Set the script output to “RS-232”
At this test, we will send some data through RS-232 port by using script. By default, script prints at console tab, but there is also the option to use RS-232 port. The following command needs to be sent to change the script output:
The controller will reply with
2.3. Write a small script that prints some data in a loop
At this time the sent rate will be smaller (10 ms) to avoid overloading the serial port. Send the below script to device and click run. The Roboteq controller will start printing “Hi” on its serial port, every 10 ms.
print("Hi\n")
wait(10)
goto start
2.4. Write on Arduino a sketch that reads and plots the serial data
Upload to device.
Warning! Pause the Roboteq script when uploading a new sketch at Arduino, because the received data will interfere with the upload of the sketch.
String inputString;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop()
{
if(Serial.available() > 0)
{
inputString=Serial.readStringUntil('\n');
Serial.println(inputString);
}
}
2.5. Open the serial monitor.
When the Roboteq script runs, the Arduino’s serial should fill with “Hi”
3. Confirm that the Roboteq controller can receive serial commands from Arduino
This time the Arduino will be used to send serial data to the Roboteq controller and read its reply. The script that used before on Arduino side is not necessary anymore, as the controller will reply automatically to any valid commands. This time both Tx and Rx pins of the devices will be used.
To proceed follow the below steps:
3.1. Pause the script of Roboteq
3.2. Disable the echo function on the Roboteq controller
By default, Roboteq controller will echo back each command it will receive together with its reply. This will create an infinite print loop with the Arduino. The echo function can be disabled by sending the below command:
The new configuration can be saved to controller’s memory by sending:
3.3. Open the serial monitor of Arduino.
The same sketch should be used as before.
3.4. Send a serial query
The terminator character that the Roboteq controller is expecting to receive is a carriage return character (\r) or an underscore (_), so each serial command sent should be followed by these characters. At this test we will query the controller’s firmware ID (?FID_). The controller should reply its firmware version.
If all steps have passed successfully, then the serial communication with Arduino and Roboteq controller can be achieved! The Roboteq controller will be capable of receiving and replying to all commands addressed to him from RS-232 port. The Roboteq controller will process the incoming commands once every 1 ms, so a maximum send rate of 1 ms should be possibly achieved between both sides.