Modifying the Simple-Stepper program to remove getchar

C, C++, and Visual C++
Posts: 5
Joined: Thu Feb 09, 2017 1:10 pm

Modifying the Simple-Stepper program to remove getchar

Postby bluwavguy » Sat Feb 18, 2017 1:00 pm


I'm running the simple-stepper.c program and have modifed it to set the current, accel, veloc and can control the motor...using the 1067 controller and a raspberryPi3.

Now. I am missing some understanding of the useage of the getchar() function as when I start modifying the code to go one direction for a set amount of steps and then to reverse the same amount of steps I can only perform this operation as shown below. If I am correct in my recall, as I've been messing with this code for hours...if I remove any of the 3 getchar() functions the routine does not function as desired. I'm working towards runnnig the stepper without user input. Tried creating while loops, delays, and not sure what i need to code as I don't understand the intimacies of C vs needed delay times between the function calls...or??

Any help will be greatly appreciated. Thank you, Brian

This is just part of code where steps1-4 were located to where the stepper is disengaged.

//keep displaying stepper event data until user input is read

printf("Press any key to continue as we are about to start\n");

CPhidgetStepper_setCurrentPosition(stepper, 0, 0);
printf("Current Position within If loop: %lld\n", curr_pos);
CPhidgetStepper_setEngaged(stepper, 0, 1);
CPhidgetStepper_setTargetPosition(stepper, 0,34000);


printf("Current Position within If loop: %lld\n", curr_pos);
CPhidgetStepper_setCurrentPosition(stepper, 0, 0);
CPhidgetStepper_setTargetPosition(stepper, 0, -34000);


// printf("Press any key to end the stepper function\n");
// getchar();
CPhidgetStepper_setEngaged(stepper, 0, 0);
CPhidgetStepper_setCurrentPosition(stepper, 0, 0);

Posts: 19
Joined: Fri Oct 07, 2016 4:47 pm

Re: Modifying the Simple-Stepper program to remove getchar

Postby LucasP » Tue Feb 21, 2017 5:06 pm

This function is what you are looking for:

Code: Select all


Note: this function only lets you know if commands are being sent to the motor. The 1067 has no way of knowing if the shaft is actually moving or not.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 4 guests