The purpose of PyOnArduino is to create a tool that can translate Python-like code to Arduino code. We pursue this target in order to program an educational robot that uses an Arduino microprocessor using Python.
Example of PyOnArduino in action. On this example, the same Python + PyOnArduino code is compiled and uploaded to the robots and the behaviour is the same
- Python 3.6 Download
- Arduino IDE Download
- Arduino Makefile Download and installation
- Check makefiles folders and change the variables if the usb port or directories are different.
- pySerial Documentation
- To execute on mBot you need to add Makeblock libraries to the Arduino IDE following this repo
- If you use MacOS and you want to execute on mBot, you'll probably new ch340 driver Download
To execute the project
python3 translator/Translator.py [input-file] [robot]
python3 translator/Translator.py [input-file] [robot] [architecture-file]
- Complubot (Arduino Robot)
- MBot
- SergioRobot: This is an educational project not a real world development
Sensor/Actuator | Supported functions |
---|---|
DC Engines | setSpeedEnginesControl(left, right), setSpeedEnginesMotor(left, right) |
Ultrasonic sensors | getUS() |
Infrared sensors | getIR[1,2,3,4,5] |
Beep emitter | playBeep(type) |
Sound emitter | playMelody(melody) |
Screen write | setScreenText(text), clearScreen() |
Sensor/Actuator | Supported functions |
---|---|
DC Engines | setSpeedEngines(speed), getLineFollowValue() |
Ultrasonic sensors | getUS() |
LEDs | setLeds(ledNumber, red, green, blue) |
Infrared sensors | getMessage(), sendMessage(message) |
Light sensor | getLightSensor() |
Button | isButtonPressed(), isButtonReleased() |
Buzzer | playBuzzer(tone, length) |
External screen | drawString(name), showClock(hour, min) |
Sensor/Actuator | Supported functions |
---|---|
DC Engines | setSpeedEngine[1,2,3,4] (speed) |
Ultrasonic sensors | getUS() |
Infrared sensors | getIR[1,2] () |
Supported functionality
Feature | Limitations/Comments |
---|---|
Variable declaration | SUPPORTED |
Function definition | With/without return statement |
Operators | + - / * ^ % |
Comparators | < <= >= == != |
Logic operators | and or is not |
Pass | SUPPORTED |
Loops | while, for (future proposal) |
sleep() | SUPPORTED |
If | If/elif/else |
Boolean operations | and or |
Arrays | Future proposal |
Tuples | Future proposal |
Range | Future proposal |
A robot's architecture file can be added when executing PyOnArduino. On this file, added sensors' port can be added, so PyOnArduino can understand where to link them. Example:
ultrasonicSensor = TK2
rgbled = 7
To declare a sensor's port, just add the name + '=' + port name. Example files:
- ultrasonicSensor
- leftMotor
- rightMotor
- ultrasonicSensor
- rgbled
- lightSensor
- ledMtx
- lineFollower
Examples available in examples folder, check them out!
There is a problem with Arduino Robot(Complubot). Sometimes when you upload a project it can make the usb port stop working. If you ever get to this point, the solution is quite simple. Write an empty sketch and upload it. While it's being uploaded press the reset button on the board two times. This should fix the problem! Source
To run the tests, run the following
python3 tests/<test-file>
To run specific tests for a bot, call the function in main and run the above command.