2016年4月15日 星期五

馬達轉速量測V2.0







跑出來的結果如下:

PWM : 1250 spin : 1050
PWM : 1300 spin : 1194
PWM : 1350 spin : 1304
PWM : 1400 spin : 1387
PWM : 1450 spin : 1451
PWM : 1500 spin : 1503
PWM : 1550 spin : 1544
PWM : 1600 spin : 1579
PWM : 1650 spin : 1607
PWM : 1700 spin : 1634
PWM : 1750 spin : 1654
PWM : 1800 spin : 1682
PWM : 1850 spin : 1764
PWM : 1900 spin : 1763
PWM : 1950 spin : 1764



arduino 的code 如下:

我四根馬達接在 pin   6,7,8,9....

然後光電開關接在  A3 (analog pin 3....別懷疑...它也可以當digital pin 使用)

自己選一個馬達測試或是你也可以一次測四個...這樣比較快...但是 arduino 的code要改一下

=================================================================
#include <PinChangeInt.h>
#include <Servo.h>

int Pin = A3;
int val;
#define SERVO_NUM 4
Servo MOTOR[SERVO_NUM];
#define FL_MOTOR_OUT_PIN 6
#define FR_MOTOR_OUT_PIN 7
#define BL_MOTOR_OUT_PIN 8
#define BR_MOTOR_OUT_PIN 9


unsigned int total_cnt=0;
unsigned int older_cnt=0;
void setup()
{
   Serial.begin(9600); //for debugging...
 
   pinMode(Pin, INPUT);
   PCintPort::attachInterrupt(Pin, calc,RISING);
   total_cnt =0;
   older_cnt =0;
 
  MOTOR[0].attach(FL_MOTOR_OUT_PIN);
  MOTOR[1].attach(FR_MOTOR_OUT_PIN);
  MOTOR[2].attach(BL_MOTOR_OUT_PIN);
  MOTOR[3].attach(BR_MOTOR_OUT_PIN);
 
  MOTOR[0].writeMicroseconds(1000);
  MOTOR[1].writeMicroseconds(1000);
  MOTOR[2].writeMicroseconds(1000);
  MOTOR[3].writeMicroseconds(1000);
}


void loop()
{
 int i,j,k,rpm;

 k=3;
 
//  val = digitalRead(Pin);
 
  //Serial.println(val);             // debug value
  for(i=1100;i<2000;i+=50)
  {
     for(j=0;j<4;j++)
     {
        MOTOR[k].writeMicroseconds(i);
        delay(500);
  //   Serial.println(end_time);
        if((total_cnt > older_cnt) & (j==3))
        {
            rpm = total_cnt - older_cnt;
            older_cnt = total_cnt;
            Serial.print("PWM : ");
            Serial.print(i);
            Serial.print(" spin : ");
            Serial.println(rpm);  
        }else
            older_cnt = total_cnt;
     }
   
  }
  MOTOR[k].writeMicroseconds(1000);
  while(1)
  {}
}

void calc()
{

  total_cnt++ ;
 
}

2016年4月13日 星期三

grbl on raspberry



影片連結  https://youtu.be/xCgPsL3ycJQ

Grbl Controller 3.2 on Raspberry Pi
(Thanks to bobt on the Shapeoko forum for providing the basis for these steps)
Assuming you have the Raspberry Pi running in the GUI, open a command window (LXTerminal) and perform the following commands. Bob suggests a 8GB card, but this works on a 4GB fine – I started with about 40% SD card space in-use using the df command and ended up at about 60% use after I got it running. He is running the older 256MB, I am running the newer 512MB pi:
NOTE: All these steps in sequence may take close to two hours to complete due to the slow processor on the Pi.

  1. sudo apt-get update (required for AlaMode)
  2. sudo apt-get install xrdp
  3. sudo apt-get install arduino (required for AlaMode) [For normal Pi, this step is optional, but good to have. NOTE: I got an error that not all items could be downloaded. I tried to repeat command by adding a --fix-missing, i.e. sudo apt-get install --fix-missing arduino but it didn't help. UPDATE: The latest download as of May 2013 doesn't have this problem]
  4. sudo apt-get install libudev-dev
  5. sudo apt-get install qtcreator [This step takes quite awhile to complete. Note: I got an error downloading as in a previous step. If you get an error, repeat command but add a --fix-missing, i.e. sudo apt-get install --fix-missing qtcreator, in this case the --fix-missing worked.]
  6. sudo apt-get install git
  7. mkdir github
  8. cd github
  9. git clone https://github.com/zapmaker/GrblHoming
  10. curl http://www.shapeoko.com/wiki/images/6/6a/Coaster.txt > Coaster.nc
  11. cd GrblHoming
  12. qmake GcodeSenderGUIthreads.pro
  13. make
Make sure that you have your Grbl/Arduino plugged into the pi prior to running the last command:
./GrblController
Pick /dev/tty/USB0 as your port and click Open. The status window should report the Grbl version.
If you wish, you can connect to your Raspberry Pi via RDP from a Windows PC (or Mac):
  1. Determine the pi’s IP, open a terminal window and type ifconfig
  2. In the Windows PC, open Remote Desktop Connection and enter the IP that is associated with eth0 (or the wifi interface, if using that).
  3. You should see a login screen that originates from the pi. Enter pi as the user and raspberry as the password.
  4. This is not like VNC, which means you have separate sessions for each RDP connection in. If you are not running headless, you first need to close any GrblControllers that are running, such as on the monitor connected to the pi, then in the RDP window, open LXTerminal, go to the GrblHoming folder and type ./GrblController as noted above
To update your code with the latest version, open a terminal window to the existing GrblHoming folder and perform these commands:
  1. git pull
  2. qmake GcodeSenderGUIthreads.pro
  3. (optionally perform a make clean)
  4. make
then run as usual.
How to tell if you need to make clean? Usually sub-minor build number increments (i.e. 3.3.2->3.3.3) do not require make clean. But minor revs probably will. If in doubt, make clean. Compiler errors definitely mean do a make clean.

Possible Hookup Configuration

I’m using a Belkin F5U234 hub which is rated by elinux to support powering the Raspberry Pi and also provide USB hub capability. This is evident in the picture below where the hub is connected to the pi in two places. Check out this site:

51 THOUGHTS ON “1. RUNNING GRBL CONTROLLER ON RASPBERRY PI”


ref : http://zapmaker.org/raspberry-pi/running-grbl-controller-on-raspberry-pi/

2016年4月12日 星期二

光電轉速計和arduino 的結合


之前在掏寶買的光電轉速計....剛好最近有量馬達的需求...就把他裝起來...

掏寶連結如下:   https://world.taobao.com/item/20059648052.htm?fromSite=main&spm=a312a.7700846.0.0.OPM0NM&_u=d2bnm38caed7


架設起來的照片如下:


那個綠色的電路板就是光電轉速計.....

他其實就是三個訊號....VCC,GND,SIG

SIG會輸出類似方波的訊號.....當碼盤來到有洞的地方....會輸出 0.....來到沒有洞的地方... 會輸

出1....利用這個特性...我們就可以測試轉速.....

目前我是用arduino 來接收訊號....程式碼如下:

利用中斷的作法...當 sig 產生一個正緣的訊號...就把  total_cnt ++;

然後每隔一秒printf 出來total_cnt......

量測出來的結果如下

Back Rear motor:
 PWM  -> rpm 
1200 -> 1790
1250 -> 2266
1300 -> 2550
1350 -> 2800
1400 -> 2970
1500 -> 3228
1550 -> 3305
1600 -> 3388
1650 -> 3442
1700 -> 3480
1800 -> 3560
1900 -> 3760


Front Rear motor :
 PWM  -> rpm 
1200 -> 1720
1250 -> 2099
1300 -> 2400
1350 -> 2623
1400 -> 2823
1450 -> 3000
1500 -> 3080
1550 -> 3169
1600 -> 3255
1650 -> 3308
1700 -> 3350
1750 -> 3400
1800 -> 3442
1850 -> 3574
1900 -> 3636

=====================================================================
#include <PinChangeInt.h>

int Pin = 2;
int val;


unsigned int total_cnt=0;
unsigned int older_cnt=0;
void setup()
{
   Serial.begin(9600); //for debugging...
   
   pinMode(Pin, INPUT);
   
   PCintPort::attachInterrupt(Pin, calc,RISING);
   total_cnt =0;
   older_cnt =0;
}


void loop()
{

  
//  val = digitalRead(Pin);
  
  //Serial.println(val);             // debug value 
  
  delay(1000);
  //   Serial.println(end_time);  
  if(total_cnt > older_cnt)
  {
      Serial.println(total_cnt - older_cnt);    
  }
  older_cnt = total_cnt;
}

void calc()
{

  total_cnt++ ;
  
}





2016年3月24日 星期四

arduino pwm frequency table



he 8-bit PWM value that you set when you call the analogWrite function:

analogWrite(myPWMpin, value); Outputs a square wave




// For Arduino Uno, Nano, Micro Magician, Mini Driver, Lilly Pad and any other board using ATmega 8, 168 or 328**
 
//---------------------------------------------- Set PWM frequency for D5 & D6 -------------------------------
 
//TCCR0B = TCCR0B & B11111000 | B00000001;    // set timer 0 divisor to     1 for PWM frequency of 62500.00 Hz
//TCCR0B = TCCR0B & B11111000 | B00000010;    // set timer 0 divisor to     8 for PWM frequency of  7812.50 Hz
  TCCR0B = TCCR0B & B11111000 | B00000011;    // set timer 0 divisor to    64 for PWM frequency of   976.56 Hz (The DEFAULT)
//TCCR0B = TCCR0B & B11111000 | B00000100;    // set timer 0 divisor to   256 for PWM frequency of   244.14 Hz
//TCCR0B = TCCR0B & B11111000 | B00000101;    // set timer 0 divisor to  1024 for PWM frequency of    61.04 Hz
 
 
//---------------------------------------------- Set PWM frequency for D9 & D10 ------------------------------
 
//TCCR1B = TCCR1B & B11111000 | B00000001;    // set timer 1 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR1B = TCCR1B & B11111000 | B00000010;    // set timer 1 divisor to     8 for PWM frequency of  3921.16 Hz
  TCCR1B = TCCR1B & B11111000 | B00000011;    // set timer 1 divisor to    64 for PWM frequency of   490.20 Hz (The DEFAULT)
//TCCR1B = TCCR1B & B11111000 | B00000100;    // set timer 1 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR1B = TCCR1B & B11111000 | B00000101;    // set timer 1 divisor to  1024 for PWM frequency of    30.64 Hz
 
//---------------------------------------------- Set PWM frequency for D3 & D11 ------------------------------
 
//TCCR2B = TCCR2B & B11111000 | B00000001;    // set timer 2 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR2B = TCCR2B & B11111000 | B00000010;    // set timer 2 divisor to     8 for PWM frequency of  3921.16 Hz
//TCCR2B = TCCR2B & B11111000 | B00000011;    // set timer 2 divisor to    32 for PWM frequency of   980.39 Hz
  TCCR2B = TCCR2B & B11111000 | B00000100;    // set timer 2 divisor to    64 for PWM frequency of   490.20 Hz (The DEFAULT)
//TCCR2B = TCCR2B & B11111000 | B00000101;    // set timer 2 divisor to   128 for PWM frequency of   245.10 Hz
//TCCR2B = TCCR2B & B11111000 | B00000110;    // set timer 2 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR2B = TCCR2B & B11111000 | B00000111;    // set timer 2 divisor to  1024 for PWM frequency of    30.64 Hz
 
 
 
//For Arduino Mega1280, Mega2560, MegaADK, Spider or any other board using ATmega1280 or ATmega2560**
 
//---------------------------------------------- Set PWM frequency for D4 & D13 ------------------------------
 
//TCCR0B = TCCR0B & B11111000 | B00000001;    // set timer 0 divisor to     1 for PWM frequency of 62500.00 Hz
//TCCR0B = TCCR0B & B11111000 | B00000010;    // set timer 0 divisor to     8 for PWM frequency of  7812.50 Hz
  TCCR0B = TCCR0B & B11111000 | B00000011;    <// set timer 0 divisor to    64 for PWM frequency of   976.56 Hz (Default)
//TCCR0B = TCCR0B & B11111000 | B00000100;    // set timer 0 divisor to   256 for PWM frequency of   244.14 Hz
//TCCR0B = TCCR0B & B11111000 | B00000101;    // set timer 0 divisor to  1024 for PWM frequency of    61.04 Hz
 
 
//---------------------------------------------- Set PWM frequency for D11 & D12 -----------------------------
 
//TCCR1B = TCCR1B & B11111000 | B00000001;    // set timer 1 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR1B = TCCR1B & B11111000 | B00000010;    // set timer 1 divisor to     8 for PWM frequency of  3921.16 Hz
  TCCR1B = TCCR1B & B11111000 | B00000011;    // set timer 1 divisor to    64 for PWM frequency of   490.20 Hz
//TCCR1B = TCCR1B & B11111000 | B00000100;    // set timer 1 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR1B = TCCR1B & B11111000 | B00000101;    // set timer 1 divisor to  1024 for PWM frequency of    30.64 Hz
 
//---------------------------------------------- Set PWM frequency for D9 & D10 ------------------------------
 
//TCCR2B = TCCR2B & B11111000 | B00000001;    // set timer 2 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR2B = TCCR2B & B11111000 | B00000010;    // set timer 2 divisor to     8 for PWM frequency of  3921.16 Hz
//TCCR2B = TCCR2B & B11111000 | B00000011;    // set timer 2 divisor to    32 for PWM frequency of   980.39 Hz
  TCCR2B = TCCR2B & B11111000 | B00000100;    // set timer 2 divisor to    64 for PWM frequency of   490.20 Hz
//TCCR2B = TCCR2B & B11111000 | B00000101;    // set timer 2 divisor to   128 for PWM frequency of   245.10 Hz
//TCCR2B = TCCR2B & B11111000 | B00000110;    // set timer 2 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR2B = TCCR2B & B11111000 | B00000111;    // set timer 2 divisor to  1024 for PWM frequency of    30.64 Hz
 
 
//---------------------------------------------- Set PWM frequency for D2, D3 & D5 ---------------------------
 
//TCCR3B = TCCR3B & B11111000 | B00000001;    // set timer 3 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR3B = TCCR3B & B11111000 | B00000010;    // set timer 3 divisor to     8 for PWM frequency of  3921.16 Hz
  TCCR3B = TCCR3B & B11111000 | B00000011;    // set timer 3 divisor to    64 for PWM frequency of   490.20 Hz
//TCCR3B = TCCR3B & B11111000 | B00000100;    // set timer 3 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR3B = TCCR3B & B11111000 | B00000101;    // set timer 3 divisor to  1024 for PWM frequency of    30.64 Hz
 
 
//---------------------------------------------- Set PWM frequency for D6, D7 & D8 ---------------------------
 
//TCCR4B = TCCR4B & B11111000 | B00000001;    // set timer 4 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR4B = TCCR4B & B11111000 | B00000010;    // set timer 4 divisor to     8 for PWM frequency of  3921.16 Hz
  TCCR4B = TCCR4B & B11111000 | B00000011;    // set timer 4 divisor to    64 for PWM frequency of   490.20 Hz
//TCCR4B = TCCR4B & B11111000 | B00000100;    // set timer 4 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR4B = TCCR4B & B11111000 | B00000101;    // set timer 4 divisor to  1024 for PWM frequency of    30.64 Hz
 
 
//---------------------------------------------- Set PWM frequency for D44, D45 & D46 ------------------------
 
//TCCR5B = TCCR5B & B11111000 | B00000001;    // set timer 5 divisor to     1 for PWM frequency of 31372.55 Hz
//TCCR5B = TCCR5B & B11111000 | B00000010;    // set timer 5 divisor to     8 for PWM frequency of  3921.16 Hz
  TCCR5B = TCCR5B & B11111000 | B00000011;    // set timer 5 divisor to    64 for PWM frequency of   490.20 Hz
//TCCR5B = TCCR5B & B11111000 | B00000100;    // set timer 5 divisor to   256 for PWM frequency of   122.55 Hz
//TCCR5B = TCCR5B & B11111000 | B00000101;    // set timer 5 divisor to  1024 for PWM frequency of    30.64 Hz
 

Reference : https://arduino-info.wikispaces.com/Arduino-PWM-Frequency

2016年3月18日 星期五

SG-90 馬達 和 57BYGH82



一般伺服馬達有三條線,電源(紅色)、接地(黑或棕色)、訊號線(白、黃、橘、藍,甚至是黑色)。透過訊號線傳送PWM脈波來控制軸柄的停止位置旋轉角度,這個訊號脈波必須每秒重複50次(也就是50Hz),而脈衝持續時間長短便代表了馬達該將軸柄轉到什麼位置,範圍從1.0ms到2.0ms(millisecond,毫秒,千分之一秒),若想置中則是1.5ms;也可將1.0ms當做角度0度,那麼1.5ms會是90度,2.0ms則是轉到底180度。注意,也有可能反過來。


不過每個廠牌型號的伺服馬達可允許旋轉的角度各不相同,也就是說可接受的訊號脈衝範圍也不相同,必須查閱產品資料規格書,若超出範圍可能會損害伺服馬達。底下是Tower Pro SG90的規格:
  • 重量:9g
  • 尺寸:23*12.2*29mm
  • 工作電壓:4.8V
  • 轉矩:1.8kg-cm,當工作電壓為4.8V時
  • 運轉速度:0.1秒 ∕ 60度 ,當工作電壓為4.8V時
  • 脈衝寬度範圍:500~2400µs 
  • 死頻帶寬度(dead band width):10µs
從中我們可知,可允許的脈衝範圍是500~2400µs,也就是0.5~2.4ms,比剛剛說的一般範圍還要寬,也就代表這個伺服馬達能旋轉的角度更大。另外有項值得一提的數據是死頻帶寬度,意思是說,因為訊號可能不穩上下起伏,當這一次脈衝寬度與上一次相差不超過死頻帶寬度時,伺服馬達便不會動作。

硬體線路很簡單,因為只有一個伺服馬達,我直接由Arduino的5V腳位供電。若想使用超過兩個,則應以另外的電源供電,而且要記得共同接地。

電路圖如下,除了電源5V與接地外,訊號線接往Arduino的數位腳位9。
 

照片如下,Tower Pro SG90的三條線顏色分別是黃、紅、棕,對應訊號、電源、接地。


接下來是軟體的部份,先讓伺服馬達來回旋轉吧。

#include <Servo.h>

Servo myservo; // 建立Servo物件,控制伺服馬達

void setup() 
{ 
  myservo.attach(9, 500, 2400); // 修正脈衝寬度範圍
} 

void loop() 
{
  for(int i = 500; i <= 2400; i+=100){
    myservo.writeMicroseconds(i); // 直接以脈衝寬度控制

    delay(300);
  }
  for(int i = 2400; i >= 500; i-=100){
    myservo.writeMicroseconds(i);

    delay(300);
  }
}




  A :  BLK
  A- :  GRN
  B :   RED
  B- : BLU


Reference : http://yehnan.blogspot.tw/2013/09/arduinotower-pro-sg90.html

2016年3月15日 星期二

TB6560 研究筆記





   http://goods.ruten.com.tw/item/show?21529132593035

57步進馬達 套裝 57BYGH51 兩相4線 含驅動器 TB6560










arduino + TB6560  :


Step 1: connection

Connection to arduino
pin 9 (Step pin) to CLK+,
pin 8 (Dir pin) to CW+,
CLK- and CW- connect to GND arduino.
Do not connect EN+ and EN- to any ARDUINO PIN.
Stepper motor connection, you need to know which color is A+, A-, B+ and B-, according to the stepper motor spec. sheet.
It only works for 1/8 step ( S3 on and S4 on) and 1/16 step (S4 only on, S3 off), half and full bridge does not work (for my case).
Amp setting can be change according to the table on the DRIVER.

Step 2: THE CODE

int Distance = 0; // Record the number of steps we've taken 
void setup() {
pinMode(8, OUTPUT);  //   direction
pinMode(9, OUTPUT); //  step 
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, HIGH);
delayMicroseconds(100);
digitalWrite(9, LOW);
delayMicroseconds(100);
Distance = Distance + 1; // record this step // Check to see if we are at the end of our move
// two rotation for 1/8 bridge and 1 rotation for 1/6 bridge (for this code)
if (Distance == 3200) { // We are! Reverse direction (invert DIR signal)
if (digitalRead(8) == LOW) {
digitalWrite(8, HIGH); }
else {
digitalWrite(8, LOW);
} // Reset our distance back to zero since we're // starting a new move
Distance = 0; // Now pause for half a second delay(500);
}
}



Reference : http://www.electrodragon.com/w/TB6560_3A_Stepper_Motor_Driver_Board_Single-Axis

Reference : http://world.taobao.com/item/43795521964.htm?fromSite=main&spm=a1z3o.7695460.0.0.RDMGep

Reference : http://www.instructables.com/id/ARDUINO-UNO-TB6560-Stepper-motor-driver/

arduino + HC06 blue-tooth




Reference : http://swf.com.tw/?p=712