Hello,
I have a problem for driving a stepper motor out of python(blender). The stepper should make the same rotation as cube in Blender3D. I´m using Blender 2.63, Pyserial 2.6, Arduino Mega2560, a big easy driver and a 1A stepper motor with 200 steps.
Python code:
import bpy
import math
from math import degrees
import serial
ser = serial.Serial('COM5',115200,timeout=1)
def my_handler(scene):
data = ''
eulx = bpy.data.objects['Cube'].rotation_euler
x = degrees(eulx.y)
a = (x/360)*200
data = bytes([int(a)])
ser.write(data)
bpy.app.handlers.frame_change_post.append(my_handler)
Arduino code:
#include <AccelStepper.h>
int motorSpeed = 115200;
int motorAccel = 8000;
int motorDirPin = 9;
int motorStepPin = 8;
AccelStepper stepper(1, motorStepPin, motorDirPin);
void setup(){
Serial.begin(115200);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
stepper.setMaxSpeed(motorSpeed);
stepper.setSpeed(motorSpeed);
stepper.setAcceleration(motorAccel);
}
int num;
void loop()
{
if (stepper.distanceToGo() == 0)
num = Serial.read();
stepper.moveTo(num);
stepper.run();
}
When I try this, the shaft moves and immediately moves back to its origin position. When I replace the "num" in the arduino code for testing, everything works fine (the shaft moves half of a full rotation).
Has anybody an idea why this could happen?
Thank you very much!