Configure VS Code for rosserial_arduino
Configure VS Code for rosserial_arduino
The package rosserial_arduino contains Arduino-specific extensions required to run rosserial_client on an Arduino boards. Roswiki has detailed tutorials and examples to configure the Arduino IDE to use rosserial_arduino. Here we disuss the steps to configure VS Code for rosserial_arduino project.
Install rosserial_arduino (if not already installed)
sudo apt-get install ros-noetic-rosserial-arduino
sudo apt-get install ros-noetic-rosserial
- Install platformio extension from VS code extensions
In case of the Platformio installation error PlatformIO IDE can’t find Python interpreter on Linux install python3-venv
sudo apt install python3-venv
- Once the platformio extension is installed, create a new project in platformio vscode
- give a project name
- select the board // search for uno
- select a project location
- Platformio automatically detects the USB port to which Arduino board is connect to the PC. In case, it does not, follow these steps
a) Run the commandls /dev/tty*
in a terminal
b) USB port would be listed as /dev/ttyUSB*
c) Edit the platformio.ini file within the project folder- Add the line
monitor_port = /dev/ttyUSB0
if the step b lists the port as/dev/ttyUSB0
- Add the line
monitor_port = /dev/ttyUSB0
- Build ros_lib library in the project folder
- Right click on the
lib
folder in the project folder within the VS code explorer pane.
- Select the option “Open in Integrated Terminal”. _This will open the directory in a terminal within VS code
- In the terminal window you just opened, run the following command:
- Right click on the
rosrun rosserial_arduino make_libraries.py .
Note the “.” at the end; this would create ros_lib library in the lib folder. \
This will build the ros_lib library in your project. Once this is finished we can move on to using our test script for out microcontroller.
-
Write the script to be downloaded to Arduino in the project name/src/main.cpp
-
Build the project and upload it to the Arduino board
Video tutorial
Other Errors
- In case of the following error avrdude stk500_recv() programmer is not responding comes up while uploading the code to the Arduino board, follow the solutions in the links given below.
99-platformio-udev.rules
platformio-arduino-error message
- avrdude stk500_recv() programmer is not responding may also arise if ROS Serial is running while code is being dumped to Arduino board.
The solution is simple : Stop the rosserial_arduino running in the terminal and then again try to dump code to Arduino.