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++ ;
  
}