PyduinoPyduino is a new programming language that allows you to write code for the Arduino Microcontroller in a Python-like syntax. It is designed to be easy to learn and use, and is a great way to get started with programming. The core features of Pyduino are:
The language works by transpiling the Pyduino code to C++ and the compiling it to run on the Arduino and on the PC. To exchange data or call functions between the PC and the Arduino, the serial port is used. The PC uses a separate listener thread to listen for data from the Arduino. The Arduino doesn't support multithreading, so it checks after every command if there is data to be read from the serial port. If there is, it reads it and executes the command. Getting StartedTo get started, you need to install VS Code. You can download it from here. You also need a Python interpreter. You can download it from here (at the bottom of the page). Make sure to add Python to your PATH by checking the box in the installer. Currently, 7zip is required to extract the C++ Compiler. You can download it from here. To install the Pyduino extension, open VS Code and press Ctrl+Shift+X to open the extensions menu. Search for Pyduino and install it. Then open a .pino file and the Extension will provide Syntax Highlighting and Error Checking. To run the code, press the run Button in the bottom left corner. The code will be transpiled to C++ and compiled. If there are no errors, the code will be executed. FeaturesVariablesVariables are declared with the datatype and name, and can be assigned a value. There is no semicolon at the end of a line.
Arrays are declared with the datatype, name and an intializer list.
LoopsThere are two types of loops: for loops and while loops. They work the same as in Python.
You can also use the Input and OutputThe print function prints to the PC's console. If it is called on the Arduino and the Arduino is connected to the PC, it will print to the PC's console as well.
The analogRead reads the value of the analog pin on the Arduino and returns it as an int from 0 to 1023. The digitalRead reads the value of the digital pin and returns it as a boolean.
The analogWrite writes an analog value to the pin. The value must be an int from 0 to 255. The digitalWrite writes a digital value to the pin.
These functions can also be called on the PC if the Arduino is connected to the PC. The PC will then write to the Arduino's serial port and the Arduino will read the value and write it to the pin, but this process is a lot slower than calling the functions directly on the Arduino. Functions are defined before the #main or #board part and can be called on both Platforms after that.
If you want a function to run on a specific platform, no matter from where it is called, you can use the
|