This Python script visualizes joystick data from an Arduino board using PyFirmata, Matplotlib, and Py-IIR-Filter.
- Python 3.x
- PyFirmata 2.x
- Matplotlib
- NumPy
Install the required Python packages using pip:
pip install -r requirements.txt
or
pip install pyfirmata matplotlib numpy
Note: Start from step 3 if you already have the project files.
-
Clone this repository:
git clone https://github.com/JalalSayed1/IIR-filters.git
-
Navigate to the project folder:
cd IIR-filters
-
Connect your Arduino board to your computer.
-
Connect a joystick to your Arduino board.
- Connect the X-axis to analog pin A0.
- Connect the power and GND pins to the board's 5V and GND pins.
-
Connect two RB LED's to your Arduino board.
- Connect the red pin on one of the LED's to digital pin 5.
- Connect the blue pin of this LED to digital pin 6.
- Connect the other RB LED to the same pins but swap the red and blue pins (to make a switching effect).
- Connect both GND pins to the board's GND.
- No resistors are needed.
-
Run
main.py
script:python main.py
The script will start visualizing the joystick data on a Matplotlib graph in real-time and another small window will appear with a button to toggle between using raw data or filtered data to update the LEDs in real time. The actual sampling rate is displayed in the terminal.