Skip to content

Reading and using the input from Arduino

Kristiyan Petrov edited this page Apr 20, 2021 · 5 revisions

Input, what input?

Well the base of the hardware part sits on potentiometers. We are using an Arduino Mega 2560. We use it because it has 54 digital input/output pins that we'll use to connect potentiometers to the controller. So basically you connect the potentiometer and take the output it gives (analogRead in Arduino), which is a lot of numbers and then convert it from 0 - 1023 to 0 - 100 as in percents (using map in Arduino). So now you can use it easily for example the volume control

What potentiometers you might ask?

We are using these two:

How do I use that output?

Now you have a potentiometer that outputs numbers between 0 and 100 what to do with it? Simple you use it in a function as we previously said can be used in a volume controller. But that volume controller is in Python so you need to send that data from the Arduino to the Python code with Serial Communication

How to program that output in Python?

After you've established the communication you will need to get that information from the Serial and you do that with:

board.readline().decode('ISO-8859-1').strip()

This is a command that reads the output of the Arduino and decodes it to a readable format, which I found ISO to be working for me and strip it of symbols. That command should convert the output of the potentiometer to a string and with that string you can do whatever you want. For example you can use it in an terminal command which the code sends and control your Linux master volume.

Making a Linux volume controller: