问题描述
我为连接到arduino的A4998驱动器编写了一个步进电机代码:
// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
const int cycle = 200*8;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
char val = Serial.read();
if (val == '1') {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int i=0; i<=cycle/10; i++){
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
// delay(2000);
}
if (val == '0') {
digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int i=0; i<=cycle/10; i++){
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
// delay(2000);
}
}
}
当我在arduino程序中使用“串行监视器”时,这很好用, 但是当我尝试从我的python代码启动电机时:
import serial
ser = serial.Serial('COM8',baudrate=9600,timeout=1)
ser.write(b'1')
ser.close()
它不起作用,什么也没发生。
我想念什么?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)