samirmartins / pydaq

Data Acquisition and Experimental Analysis with Python and Graphical User Interface
https://pydaq.org
BSD 3-Clause "New" or "Revised" License
19 stars 7 forks source link

Programming Arduino Directly from PYDAQ #15

Open samirmartins opened 2 months ago

samirmartins commented 2 months ago

As is known, in the current version of PYDAQ, to use the Arduino it is necessary to load a code onto it prior to executing PYDAQ. With this improvement, it is expected that the code loading will be done directly via Python/PYDAQ

Nikhildave4478 commented 2 days ago

Currently, to use an Arduino with PYDAQ, you need to upload a code (sketch) onto the Arduino beforehand. This can be cumbersome, especially if you frequently change the sketch. The goal here is to automate the process of uploading the Arduino code directly from Python, making it more efficient and user-friendly.

Steps to Achieve This

  1. Install Arduino CLI:
  2. Set Up Your Environment:
  3. Write a Python Function (Ensure you have Python installed and also install the subprocess module)
import subprocess

def upload_sketch(sketch_path, board_fqbn, port):

        compile_command = f"arduino-cli compile --fqbn {board_fqbn} {sketch_path}"
        print("compiling sketch")
        subprocess.run(compile_command, shell=True, check=True)

        upload_command = f"arduino-cli upload -p {port} --fqbn {board_fqbn} {sketch_path}"
        print("uploading sketch")
        subprocess.run(upload_command, shell=True, check=True)

        print("upload successful!")

if __name__ == "__main__":
    sketch_path = "path/to/your_sketch.ino"
    board_fqbn = "arduino:avr:uno"  # Change as per your board
    port = "/dev/ttyUSB0"  # Change according to your connection

    upload_sketch(sketch_path, board_fqbn, port)
samirmartins commented 11 hours ago

Dear @Nikhildave4478 ,

thanks for your comment and suggestion for improvement into PYDAQ.

At this moment I'm working on solving a different issue. In this sense, you are more than invited to implement the suggestion into PYDAQ, make tests and submit a PR.

Tell me if you want to proceed with this contribution. If so, we could be in contact by Telegram/Discord to discuss the implementation of it.

Best regards,