Jump to content

Raspberry pi c++ stepper motor

BaconStorm

Hi I am trying to use the wiring pi library to use a stepper motor with c++ for a project in my engineering class. I am not very experienced in programing so I tried to basically convert the code from a video that used python into c++, I am using different pins however but that's the only way i could get it to feel like it was trying to move. I can feel the motor trying to move but it's not actually moving any visible amount.

 

video: 

 

 

 

my code:

 

#include <wiringPi.h>
#include <iostream>

using namespace std;

void Sleep()
{
    for (int i = 0; i < 1000; i++)
    {

    }
}

int main(void)
{

    wiringPiSetup();

    int uPin[4] = { 5, 6, 10, 11 };

    for (int i = 0; i < 4; i++)
    {
        pinMode (uPin, OUTPUT);
        digitalWrite (uPin, 0);
    }

    int seq[8][4] = { {1,0,0,0}, {1,1,0,0}, {0,1,0,0}, {0,1,1,0}, {0,0,1,0}, {0,0,1,1}, {0,0,0,1}, {1,0,0,1} };

    for (int i = 0; i <= 512; i++)
    {
        for (int step = 0; step <= 8; step++)
        {
            for (int pin = 0; pin <= 4; pin++)
            {
                digitalWrite(uPin[pin], seq[step][pin]);
                Sleep();
                cout << "slept \n";
            }
        }
    }


    return 0;
}

Link to comment
Share on other sites

Link to post
Share on other sites

sorry I somehow accidentally posed this 2 times. please respond on the other one:

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×