I am trying to use a for loop to execute a series of actions a certain number of times to trigger a raspberry pi 3b+ gpio pin on and off

1 view (last 30 days)
Kevin Graebner
Kevin Graebner on 22 Nov 2019
So. i am currently trying to make the raspberry pi 3b+ control a stepper motor driver. all the driver needs is a step pulse and a direction.
the first image is my simulink
So i have an open and close button. then a clockwise or counter clockwise selection switch and a 90 or 180 degree selection switch. (it is set on 400 steps per revolution so 100 is 90 deg and 200 is 180 deg)
i also have 4 memory store blocks. for done. stepcount. OPENstate and CLOSEDstate (these last two are to prevent people from hitting open if it is already open to avoid damage)
the next image i will post is of the state flow chart. which i think is where my problem is.
it has an initial start phase. where i set the variables to where i think they need to be to start. in the closed state. if this is uncessary let me know (i also set the initial value in the memory data store blocks to the same thing. so it may be reduntant?)
then it goes into standby and waits for the user to press the open button. since it starts closed.
then it is supposed to check the status of the counterclockwise/clockwise switch and adjust the direction to the stepper controller accordingly.
then it is supposed to check the status of the 90 or 180 degree selection switch. and switch between two different for loops with the correct number of steps the motor needs to move. which i used STEPCOUNT as the index and had it count from 0 to 200 or 100 in incriments of 1 (STEPCOUNT = 0:1:100)
in the for loop i have it set to change motor step to 1 and then 0 which is the GPIO PIN going to the stepper controller control.
i did independently test this to make sure the button outputs a signal when i just set it have it make MotorStep = 1 when OPEN >=1 for example. and the motor did work. at one step per button push. which is why i think it is in my coding.
then after the FOR loop is done it is supposed to re-set STEPCOUNT to zero and DONE to 1 which makes it go back to standby and wait for user input.
i really think my issue is somewhere in my if / ifelse / for loop. because i have the circuit hooked to an oscilloscope and i get the button signal in just fine but not the pulses coming out like they are supposed to. at all.
however. when i check my direction signal i am getting a 20mS pulse every 500 or 600 mS and it is outputting this signal regardless of either open or closed button being pressed. ? i am rather confused honestly.
i have also uploaded two oscilloscope pictures and one of them which is sitting in standby is the direction signal (i switched the pins to test a theory and that same pin. gpio 23 is outputting these same pulses even though it has an entirely different purpose asigned to it in simulink now) so in this picture the direction signal is flat and that pulse is what is always coming out of GPIO 23.
then. the with direction switch on is when the direction switch has power going to the pin. and you can see that gpio 23 is still putting out pulses. a little differently than before. and the direction signal. (both of these are what is going to the stepper driver) gets random little blips in it.
any advice would be greatly appreciated!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!