我想知道是否有任何方法通過Windows中的Arduino命令運行python腳本?在Windows中通過Arduino Uno執行python腳本
1
A
回答
1
我不知道這是否回答你的問題,但你可以下載Vpyt漢庫中創建一些很酷的項目,或從Arduino的或反之亦然
所以連接傳感器和獲取數據回蟒蛇例如:
int trigPin=13; //Sensor Trig pin connected to Arduino pin 13
int echoPin=11; //Sensor Echo pin connected to Arduino pin 11
float pingTime; //time for ping to travel from sensor to target and return
float targetDistance; //Distance to Target in inches
float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW); //Set trigger pin low
delayMicroseconds(2000); //Let signal settle
digitalWrite(trigPin, HIGH); //Set trigPin high
delayMicroseconds(15); //Delay in high state
digitalWrite(trigPin, LOW); //ping has now been sent
delayMicroseconds(10); //Delay in low state
pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds
pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
pingTime=pingTime/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour)
targetDistance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles per hour
targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance.
targetDistance= targetDistance*63360; //Convert miles to inches by multipling by 63360 (inches per mile)
Serial.println(targetDistance);
delay(100); //delay tenth of a second to slow things down a little.
}
而在蟒蛇
import serial #Import Serial Library
from visual import * #Import all the vPython library
arduinoSerialData = serial.Serial('com11', 9600) #Create an object for the Serial port. Adjust 'com11' to whatever port your arduino is sending to.
measuringRod = cylinder(radius= .1, length=6, color=color.yellow, pos=(-3,-2,0))
lengthLabel = label(pos=(0,5,0), text='Target Distance is: ', box=false, height=30)
target=box(pos=(0,-.5,0), length=.2, width=3, height=3, color=color.green)
while (1==1): #Create a loop that continues to read and display the data
rate(20)#Tell vpython to run this loop 20 times a second
if (arduinoSerialData.inWaiting()>0): #Check to see if a data point is available on the serial port
myData = arduinoSerialData.readline() #Read the distance measure as a string
print myData #Print the measurement to confirm things are working
distance = float(myData) #convert reading to a floating point number
measuringRod.length=distance #Change the length of your measuring rod to your last measurement
target.pos=(-3+distance,-.5,0)
myLabel= 'Target Distance is: ' + myData #Create label by appending string myData to string
lengthLabel.text = myLabel #display updated myLabel on your graphic
這將用python製作圖形代表你正在超聲波傳感器前面拿着的東西,你可以看到實時移動的物體
我把代碼fr OM這個網站:
這是真的有很好的教程如何連接的Arduino到Python!而且非常簡單
0
我相信不會有任何支持Python的Arduino庫,因爲python被解釋,並且Arduino沒有整個Python的內存,如果你想用Python來編程Arduino,那麼也許只是嘗試c您需要學習編程Arduino的代碼不會差別太大,你會發現在蟒蛇的大部分代碼,你可以在這裏找到代碼: https://www.arduino.cc/en/Reference/HomePage
但這些都是一些相關的Python模塊的在Arduino上運行Python:http://playground.arduino.cc/CommonTopics/PyMite
相關問題
- 1. 通過nodejs執行python腳本
- 2. 如何通過python執行shell腳本
- 3. Salesforce:通過Apex類執行python腳本
- 4. 通過SSH執行遠程python腳本
- 5. DHT11 + Arduino UNO +樹莓pi3 + Windows遠程Arduino
- 6. 通過CGI執行腳本
- 7. 通過PHP執行腳本
- 8. 在python中執行腳本
- 9. 無法通過MySQLdb在Python腳本中執行INSERT語句
- 10. Arduino Uno串行監視器
- 11. 使Python腳本可執行
- 12. 執行python腳本
- 13. Arduino Uno編碼
- 14. Arduino-uno項目
- 15. Arduino Uno R3 + SIM900
- 16. RabbitMQ與Arduino Uno
- 17. Arduino Uno - WebService(AzureML)
- 18. 調試 - 通過API執行PowerShell腳本執行通過API
- 19. 通過鐵python執行python(或鐵蟒)腳本
- 20. 哪個Arduino Uno引腳對應於TCNT0?
- 21. 通過鏈接在web服務器上執行python腳本
- 22. 通過SSH在後臺執行遠程python腳本
- 23. 自己執行python腳本
- 24. 在Windows 10中執行js腳本webView
- 25. 通過cron運行的Python腳本不會偶爾執行
- 26. 通過Windows命令行運行Python腳本
- 27. 從Windows命令行運行Python腳本,參數未通過
- 28. Arduino UNO,CC3000:while(client.connected)
- 29. ESP8266和Arduino的UNO
- 30. Arduino Uno R3錯誤