In this project I am going to teach any beginner Arduino / Python programmer how to use pyserial to control your serial ports with Python code. You can't run code directly from the Python editor to your Arduino, but through the pyserial library you can send and receive messages from your device.
Step 1: Installing the Editor
Mu editor is a great editor, perfect for beginners because of its easy to use design. It also comes with a built in pyserial library, so no additional downloads are necessary. To download Mu, click here and select the correct installer for your operating system. Install and then open it.
If you need the Arduino IDE, click here.
Step 2: The Arduino Part
Now just open the Arduino IDE and paste the Arduino code shown in the code section below into it and upload it to your board.
Step 3: The Python Part
Back to Mu. The first time you open it, Mu shows a "mode" window. For now select "Python 3". Later you can change this by clicking the "Mode" button in the top left corner of the screen. Paste the Python code (shown below in the code section) into Mu. Now you must find the port your board is connected to. It shows this in the bottom right corner of the Arduino IDE. Type this in place of COM12. (Line 4 in the Python code.) Now run the code. Enter 1 to turn the on board LED on and 0 to turn it off.
Questions? Problems? Ideas? See comment section below. Have a great day and don't forget to respect this project!
Comments
Please log in or sign up to comment.