Can I just tell the python to open a particular Arduino file and run it?
I have a python program, when it run to a certain steps, If true, I want it turns to run a Arduino program. I try pyserial library, I tried pyfirmata2, I tried RPI.GPIO, all have problems,
So at the end of the day, can I just ask python, to open a given arduino file name and please run it.
What exactly do you mean by "run it"? Do you mean run the code on a PC, or download the code to an Arduino and run it?
You could use python to compile and upload a particular sketch to an Arduino using the arduino-cli tool.
'import cv2
'import numpy as np
'from pyzbar.pyzbar import decode
'import pyfirmata
'from pyfirmata import Arduino, SERVO
'import time
'cap = cv2.VideoCapture('http://192.168.86.1:81/stream')
'cap.set(3,640)
'cap.set(4,480)
'with open('order.txt')as f:
' myDataList = f.read().splitlines()
'while True:
' success, img = cap.read()
' for barcode in decode(img):
' myData = barcode.data.decode('utf-8')
' print(myData)
' if myData in myDataList:
' print('Authorized')
' digitalWrite(2,50)
' else:
' print('Un-Authorized')
' pts = np.array([barcode.polygon],np.int32)
' pts = pts.reshape((-1,1,2))
' cv2.polylines(img,[pts],True,(255,0,255),5)
' pts2 = barcode.rect
' 'cv2.putText(img,myData,'(pts2[0],pts2[1]),cv2.FONT_HERSHEY_SCRIPT_SI''MPLEX,0.9,(255,0,255),2)
'Use code tags to format code for the forum cv2.imshow('Result',img)
``Use code tags to format code for the forum` cv2.waitKey(1)
At row 14, if return a authorized text, then a want to run a servo motor. But I dont know how to ask python to run servo motor. Can I ask python to run my Arduino program for the servo motor. I just tell the python what is the arduino file name or location. Please open it
Let me study what is arduino-cli, sounds like helpful, Thank You
@greenfood1234 you can have a servo program that is running on an Arduino and you can send commands from Python to Arduino that moves the servo, is that what you wanted?
Yes, please, How can I do that?
you need your python code to talk to the Arduino board, possibly using the Serial line.
I've written a small tutorial on interfacing with Python. See Two ways communication between Python3 and Arduino
Hi @greenfood1234.
Arduino CLI is definitely the way to accomplish what you asked for:
However, this is an "XY problem". Using Arduino CLI ("X") is an absolutely terrible way to accomplish your true goal ("Y"):
Let me study first, Thank You
I follow your think way, Arduino CLI ("X") manage arduino files. I need Y to X.
I am buying new linear actuator can be programmed by python. Then no more XY interaction.
Do you know which company own python? I should go there to ask how to use Y to connect X
Did you get the XY reference right?
Python is owned by the Python Software Foundation, as google would tell you. They have a forum here https://discuss.python.org/
I'm not sure that they will be able to help much with Python/Arduino integration, but give it a try.