Summary
Keywords
Full Transcript
#python #arduino #ROS2 #robotics #mechatronics #mechanicalengineering #electricalengineering It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way: - Buy me a Coffee: https://www.buymeacoffee.com/AleksandarHaber - PayPal: https://www.paypal.me/AleksandarHaber - Patreon: https://www.patreon.com/user?u=32080176&fan_landing=true - You Can also press the Thanks YouTube Dollar button In this tutorial, we explain how to establish a serial communication link between a computer running a Python script and Arduino. We explain how to perform this task in Linux Ubuntu. Our goal is to send an integer from a computer running a Python script to Arduino. Then, Arduino should receive this integer and perform mathematical operations on the integer, and send back the result to the computer. First, we define an integer in Python. Then, we convert the integer to string, and then string to bytes. Then, we use the pySerial Python library to send the bytes data structure. On the other side, the Arduino accepts the message and converts the message first to a string, and then from a string to an integer. Arduino adds number 100 to the received string and converts the result to a string. Then, the string is sent back through the communication channel to the computer running the Python script. The Python script and the pySerial library accept the message, convert the message to string, and string to integer. Finally, the string is displayed on the computer screen.
