How to use Arduino to fetch values output by Python script?

Question:

I have a GUI that was created using the PySimpleGUI package in Python. Based on user selection from a dropdown menu, the script writes 4 integers to a csv file.

(For example, the user selects option A, and the script writes (20, 30, 40, 50) to the csv.)

Note that the Python file is being run on my local PC

I have an arduino file that runs simultaneously, but on an Arduino R3 microcontroller. The main loop of this arduino file needs to use the integers that are being output by the python script. The intention is to assign these values to global integer variable in the Arduino code.

How do I grab the values from the python script use in the arduino file?

Note: I have seen solutions for sending data from arduino to python. But I would like to go in the opposite direction (send from python to arduino)

I tried writing the data from the python script to a csv file, then grabbing the data in the arduino code using fp = fopen("filename.csv", "r")
Note that I did add the directive #include <stdio.h>

However, this doesn’t seem to work since I get an error saying that there is an undefined reference to fopen.

Asked By: Adam Cassie

||

Answers:

Using csv seems like a very roundabout way of doing this. Maybe consider PySerial, a python module that lets you send data both ways via Arduino’s serial port.

Answered By: Ray
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.