본문 바로가기

코딩 놀이

xyDrawing 부르투스 제어[ 14 ]

2개의 스탭핑모터를 부르투스와 inventer app으로 전후좌우로 제어합니다. 

apk 파일 :

Bluetooth.apk
3.64MB

소스파일:

Bluetooth.aia
0.00MB

 

인벤터 엡 코딩

디자인입니다.

콘포넌트 입니다.

전후 좌우 이동 할 때  초기값입니다.

x,y 이동 현재 값입니다.

 

여기서 까지는 부루투스 설정입니다.

아래

x 단계별 값으로  모터가 1회전하는데는 3200, 180도 1600, 90도 800입니다. 모터축에 벨트를 연결하기 위한 풀리의 기어  산 수는 16개이며, 산과 산사이 골 길이는 1mm 입니다. 1회전에 32mm, 180도 16mm가 됩니다. 

 

모터가 최초 욺직이기 시작한 출발 위치입니다.

부루투스 목록에서 선택

연결이되면 "연결됨"이 나타납니다.

#include <AccelStepper.h>  
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // 12-->TXD, 13-->RXD

const int step_pinX = 2;  
const int dir_pinX  = 5; 
const int step_pinY = 3;  
const int dir_pinY  = 6;
long motorPositionX = 0;
long motorPositionY = 0;
AccelStepper stepperX(AccelStepper::DRIVER, step_pinX, dir_pinX);   
AccelStepper stepperY(AccelStepper::DRIVER, step_pinY, dir_pinY);   


void setup()   {   
  Serial.begin(9600); 
 mySerial.begin(9600);
 
  stepperX_init();    
  stepperX.setCurrentPosition(0); 
   stepperY_init();    
  stepperY.setCurrentPosition(0);   
}   
  
void loop()   {   
   //if(Serial.available()){  
 if (mySerial.available()) {
String getDATA = mySerial.readStringUntil('\n');
     int yy=getDATA.indexOf('y');
     String xs=getDATA.substring(0,yy);
     String ys=getDATA.substring(yy);
     char x0=xs.charAt(0);
     String xn=xs.substring(1);
     char y0=ys.charAt(0);
     String yn=ys.substring(1);

            if(x0=='x'){
              int Xn=xn.toInt();
              stepperX.moveTo(Xn);  
              stepperX.runToPosition();  
              motorPositionX = stepperX.currentPosition();    
               stepperX.stop();
            }
            if(y0=='y'){
              int Yn=yn.toInt();
              stepperY.moveTo(Yn);  
              stepperY.runToPosition();  
              motorPositionY = stepperY.currentPosition();    
              stepperY.stop();
            }                   
}

void stepperX_init(){   
  stepperX.setMaxSpeed(2000);   
  stepperX.setAcceleration(1500);   
}  
void stepperY_init(){   
  stepperY.setMaxSpeed(2000);   
  stepperY.setAcceleration(1500);   
}  


     

여기서 부터 시작했습니다.