“SKU:RB-02S043 光電測(cè)速碼盤套件”的版本間的差異

來自ALSROBOT WiKi
跳轉(zhuǎn)至: 導(dǎo)航搜索
?使用方法
?產(chǎn)品相關(guān)推薦
第118行: 第118行:
 
通過串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速
 
通過串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速
  
?
==產(chǎn)品相關(guān)推薦==
+
==資料下載==
 
[[文件:erweima.png|230px|無框|右]]
 
[[文件:erweima.png|230px|無框|右]]
?
===購買地址===
+
* 產(chǎn)品資料
?
[http://www.alsrobot.cn/goods-185.html 光電測(cè)速碼盤]
+
下載鏈接:https://pan.baidu.com/s/1XWomNov02Z87UlrCiaTHRg
?
===周邊產(chǎn)品推薦===
+
提取碼:6mpi  <br/>
?
[http://lifestyle201.com/goods-407.html Arduino 4WD鋁合金移動(dòng)平臺(tái)車燈套件]<br/>
+
* 產(chǎn)品購買鏈接:http://lifestyle201.com/goods-185.html
?
[http://lifestyle201.com/goods-185.html Arduino 光電碼盤 光電測(cè)速傳感器]<br/>
+
?
===相關(guān)問題解答===
+
?
===相關(guān)學(xué)習(xí)資料===
+
?
[http://www.makerspace.cn/portal.php 奧松機(jī)器人技術(shù)論壇]
+

2018年9月29日 (六) 14:21的版本

Gdcsmp.jpg

目錄

產(chǎn)品概述

Arduino 光電碼盤是哈爾濱奧松機(jī)器人科技有限公司2012年最新推出的光電測(cè)試傳感器,該產(chǎn)品是一款短響應(yīng)速度、開關(guān)量輸出的測(cè)速模組,配合白色碼盤可以測(cè)量電機(jī)轉(zhuǎn)速,該款測(cè)試碼盤可以直接固定到雙輸出軸直流減速電機(jī)上方便安裝,簡(jiǎn)單易用。

規(guī)格參數(shù)

  1. 工作電壓:5v DC
  2. 工作電流:小于 20mA
  3. 工作溫度:10℃ - 30℃
  4. 與傳感器擴(kuò)展板I/O兼容
  5. 傳感器類型:模擬輸出
  6. 平面尺寸:15×35×16mm
  7. 重量大小:24g

接口定義

  • S:信號(hào)控制端(Signal)
  • +:電源(VCC)
  • -:地(GND)

使用方法

接線方法1

將光電測(cè)速碼盤的 S 端口接到控制器的數(shù)字 I/O 口 5,+ 和-分別接到電源的 +5V 和 GND。

例子程序1

#include "MsTimer2.h"
#define ENCODER_READ 5
unsigned int encoderPos,a;
void setup()
{  
    Serial.begin(9600);
    MsTimer2::set(1000, flash); // 500ms period
    MsTimer2::start();
    counterStart();
}

void loop()
{
}
void counterStart()
{
  TCCR1A=0;                       
  TCCR1B=0;                
  TCNT1=0;                     
  TCCR1B = TCCR1B | 7; 
}
unsigned int getCount()
{
  unsigned int count;
  count = TCNT1;  
  TCNT1=0;  
  TCCR1B = TCCR1B & ~7;                      
  TCCR1B = TCCR1B | 7;                  
  return count;                             
}
void flash() {
encoderPos = getCount();
a=encoderPos*6;
Serial.print("rotate speed = ");
Serial.print(a);
Serial.println(" RPM");
}

程序效果1

在串口打印出"rotate speed ="及 "RPM"相關(guān)數(shù)據(jù)

接線方法2

將光電測(cè)速碼盤1的 S 端口接到控制器的數(shù)字 I/O 口 2,+ 和-分別接到電源的 +5V 和 GND
將光電測(cè)速碼盤2的 S 端口接到控制器的數(shù)字 I/O 口 3,+ 和-分別接到電源的 +5V 和 GND

例子程序2

#include "TimerOne.h"

const byte MOTOR1 = 2;  // Motor 1 使用外部中斷 0
const byte MOTOR2 = 3;  // Motor 2 使用外部中斷 1

unsigned int counter1 = 0;
unsigned int counter2 = 0;

float diskslots = 10;  //碼盤數(shù)

void ISR_count1()  
{
  counter1++;  //Motor1
} 

void ISR_count2()  
{
  counter2++;  //Motor 2
} 

// TimerOne 中斷
void ISR_timerone()
{
  Timer1.detachInterrupt();  // Stop the timer
  Serial.print("Motor Speed 1: "); 
  float rotation1 = (counter1 / diskslots) * 60.00;  // Motor 1
  Serial.print(rotation1);  
  Serial.print(" RPM  "); 
  counter1 = 0;  
  Serial.print("Motor Speed 2: "); 
  float rotation2 = (counter2 / diskslots) * 60.00;  // Motor 2
  Serial.print(rotation2);  
  Serial.println(" RPM"); 
  counter2 = 0;  
  Timer1.attachInterrupt( ISR_timerone );  
}

void setup() 
{
  Serial.begin(9600);
  
  Timer1.initialize(1000000); // 設(shè)定時(shí)間為 1s
  attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING);  // 當(dāng)檢測(cè)到上升沿時(shí),計(jì)數(shù)
  attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING);  
  Timer1.attachInterrupt( ISR_timerone ); // 開啟Timer中斷
} 

void loop()
{

}

程序效果2

通過串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速

資料下載

Erweima.png
  • 產(chǎn)品資料

下載鏈接:https://pan.baidu.com/s/1XWomNov02Z87UlrCiaTHRg 提取碼:6mpi