Skip to content

Connecting Arduino with Python

Kristiyan Petrov edited this page Apr 20, 2021 · 1 revision

Arduino with Python, what is that?

In order for you to be able to create programs that the C++ that Arduino uses doesn't support you'll have to use another language. After several hours of research we found out that Python is the most capable of doing what we need. Why you might ask? As we all know Python is an easy to write language, that is very popular amongst programmers, so that means that there is a lot of information about it in the Web. Out of the most common languages such as Java, C, C++ we found out that Python is the best to write an simple audio player. Anyways, we got a bit of topic.

How do we write on the Arduino with Python, isn't it easy?

Well yes and no, first of all we can't directly write on the Arduino with Python as it supports C++ so that idea falls out. I had an idea of making some sort of a communication between a separate python program and the Arduino, good news that's the way to do it, bad news not that easy to do.

How do we establish communication between a Python program and the controller?

I didn't find a lot of methods but I came down to two:

But which one is better you might ask?

Well after a lot of research I found out that PyFrimata is not that good overall since it doesn't support a lot of functions and in order to run it you need to use a library directly on the Arduino (which fills up the Arduino and doesn't let you program it), so I guess it won't be this.

Serial Communication

Wow we are finally getting to the real deal, well basically one of the basic things you learn with Arduino is the fact that it use a Serial communication to display your code in the IDE. This communication can not only be used in the IDE but outside of it, by importing a simple serial and time library in Python you can establish communication with the Arduino. Basically whatever you serial print with the Arduino can be gathered by Python.