티스토리 뷰

OS/micro:bit

micro:bit : 스탭모터(28BYJ48 ​+ ULN2003) 제어

파란크리스마스 2019. 8. 17. 22:49
728x90

출처

micro:bit : 스탭모터(28BYJ48 ​+ ULN2003) 제어

스탭모터(28BYJ48)와 스텝 모터 드라이버(ULN2003)는 저렴하고 많이 사용하고 있어서 많은 예제가 있습니다. 스탭의 반복하면서 반복 하는 시간차와 회수를 계산해서 원하는 각도로 회전하거나, 스탭의 방향에 따라서 정방향, 역방향으로 회전 시킬 수 있습니다.

  • IN1 = micro:bit 디지탈 0번핀
  • IN2 = micro:bit 디지탈 1번핀
  • IN3 = micro:bit 디지탈 2번핀
  • IN4 = micro:bit 디지탈 3번핀​​

소스

/*
############################################
##           sMotor v0.1 Test Program     ##
##          created by Samuel Matildes    ##
############################################
        ---- sam.naeec@gmail.com -----
This library was made for 4-Phase Stepper Motors
I don't take any resposability for the damage caused to your equipment.
 
*/
 
#include "MicroBit.h"
#include "sMotor.h"
 
//MicroBit uBit;
MicroBitSerial gSerial(USBTX, USBRX);
sMotor motor(P0_0, P0_1, P0_2, P0_3); // creates new stepper motor: IN1, IN2, IN3, IN4
//BusOut motor_out(P0_0, P0_1, P0_2, P0_3);  // blue - pink - yellow - orange
 
int step_speed = 1200; // 1200 ; // set default motor speed
int numstep = 512 ; // defines full turn of 360 degree
//you might want to calibrate this value according to your motor
 
int step = 0; 
int dir = 1; // direction
 
int main() {
	
	 //uBit.init();
	 //uBit.display.disable();
 
    //Credits
    printf("4 Phase Stepper Motor v0.1 - Test Program\r\n");
    printf("developed by Samuel Matildes\r\n");
    printf("\n\r");
 
    // Screen Menu
    printf("Default Speed: %d\n\r",step_speed);
    printf("1- 360 degree clockwise step\n\r");
    printf("2- 360 degree anticlockwise step\n\r");
    printf("3- 180 degree clockwise step\n\r");
    printf("4- 180 degree anticlockwise step\n\r");
    printf("5- Change Speed\n\r");
    
    while (1) {
 
        if (gSerial.readable()) { // checks for serial
 
            if (gSerial.getc()=='1') 
                motor.step(numstep,0,step_speed); // number of steps, direction, speed
 
            if (gSerial.getc()=='2')
                motor.step(numstep,1,step_speed);
 
            if (gSerial.getc()=='3')
                motor.step(numstep/2,0,step_speed);
 
            if (gSerial.getc()=='4')
                motor.step(numstep/2,1,step_speed);
 
            if (gSerial.getc()=='5') {
                printf("Current Speed: %d\n\r", step_speed);
                printf("New speed: \n\r");
                //gSerial.scanf("%d",&step_speed); // sets new speed
            }
        }
    }
    
    /*
		while(1)
    { 
        switch(step)
        { 
            case 0: motor_out = 0x1; break;  // 0001
            case 1: motor_out = 0x3; break;  // 0011
            case 2: motor_out = 0x2; break;  // 0010   
            case 3: motor_out = 0x6; break;  // 0110
            case 4: motor_out = 0x4; break;  // 0100
            case 5: motor_out = 0xC; break;  // 1100
            case 6: motor_out = 0x8; break;  // 1000
            case 7: motor_out = 0x9; break;  // 1001
            
            default: motor_out = 0x0; break; // 0000
        }
  
        if(dir) step++; else step--; 
        if(step>7)step=0; 
        if(step<0)step=7; 
        //wait(0.015);  // speed
        wait_us(step_speed);
    }
    */
}

실행 영상

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함