Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 7668|回復: 10
打印 上一主題 下一主題

可用無線電遙控Arduino驅動伺服馬達嗎?

[複製鏈接]
跳轉到指定樓層
1#
發表於 2011-4-16 16:20:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
各位大大好  
請問可以用315MHz的無線電遙控arduino嗎?
打算用無線電上兩個按鈕指令 Start 跟 Stop 當Start按下去晶片就會令伺服馬達作一系列正反轉
Stop按下去就停止  也許會需要操縱多顆伺服馬達
單晶片的型號是Arduino UNO的 無線電是TG-11 馬達是S03T
因為我還是個單晶片的新手 問了蠢問題還請見諒
2#
發表於 2011-4-16 20:54:29 | 只看該作者
可以用315MHz的無線電遙控arduino
這個也是315Mhz RF link kit
http://www.seeedstudio.com/depot/315mhz-rf-link-kit-p-76.html
然後這樣接:

---------------------------------------------
3#
 樓主| 發表於 2011-4-16 23:07:17 | 只看該作者
原來是這麼接 謝謝V大
不過我還可以再問一個問題嗎?
就是如果我這樣接上去之後 我是不是還要在arduino裡頭寫一串無線電程式碼才能夠讓arduino接收到指令
如果要的話那請問我一開始的#include該寫什麼呢
我有去找過他的官網有找到一個

#include <SoftwareServo.h>

SoftwareServo servo1;
SoftwareServo servo2;

void setup()
{
  pinMode(13,OUTPUT);
  servo1.attach(2);
  servo1.setMaximumPulse(2200);
  servo2.attach(4);
  servo2.setMaximumPulse(2200);
  Serial.begin(9600);
  Serial.print("Ready");
}

void loop()
{
  static int value = 0;
  static char CurrentServo = 0;

  if ( Serial.available()) {
    char ch = Serial.read();
    switch(ch) {
      case 'A':
        servo1.attach(2);
        CurrentServo='A';
        digitalWrite(13,LOW);
        break;
      case 'B':
        servo2.attach(4);
        CurrentServo='B';
        digitalWrite(13,HIGH);
        break;
      case '0' ... '9':
        value=(ch-'0')*20;
        if (CurrentServo=='A')
        {
          servo1.write(value);
        }
        else if (CurrentServo=='B')
        {
          servo2.write(value);
        }
        break;
    }
  }
  SoftwareServo::refresh();
}


但似乎一開始的 SoftwareServo servo1  就宣告失敗了
4#
發表於 2011-4-17 12:02:38 | 只看該作者
我有去找過他的官網有找到一個
Suzaku 發表於 2011-4-16 23:07


你硬碟有 SoftwareServo.h file嗎?
應該是少這行:
int val;
....
....
val = map(val, 0, 2200, 0, 179);
=========================
An Example
The following code lets you control Servo on pin2 by potentiometer on analog 0
#include <SoftwareServo.h>
SoftwareServo myservo;  // create servo object to control a servo
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
void setup()
{
  myservo.attach(2);  // attaches the servo on pin 2 to the servo object
}
void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
  SoftwareServo::refresh();
}
5#
發表於 2011-4-17 12:08:28 | 只看該作者
本帖最後由 vegewell 於 2011-4-17 12:09 編輯
我是不是還要在arduino裡頭寫一串無線電程式碼才能夠讓arduino接收到指令
Suzaku 發表於 2011-4-16 23:07



我只能提供類似的code做參考 畢竟範本RF不是    TG-11,
code
;
// Maurice Ribble
// 8-30-2009
// http://www.glacialwanderer.com/hobbyrobotics
// Used Arduino 0017
// This is a simple test app for some cheap RF transmitter and receiver hardware.
// RF Transmitter: http://www.sparkfun.com/commerce/product_info.php?products_id=8945
// RF Receiver: http://www.sparkfun.com/commerce/product_info.php?products_id=8948
// This says whether you are building the transmistor or reciever.
// Only one of these should be defined.
//#define TRANSMITTER
#define RECEIVER
// Arduino digital pins
#define BUTTON_PIN  2
#define LED_PIN     13
// Button hardware is setup so the button goes LOW when pressed
#define BUTTON_PRESSED LOW
#define BUTTON_NOT_PRESSED HIGH
void setup()
{
  pinMode(BUTTON_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  Serial.begin(1200);  // Hardware supports up to 2400, but 1200 gives longer range
}
#ifdef TRANSMITTER
void loop()
{
  static int prev_button = BUTTON_NOT_PRESSED;  // Previous button press value
  int        cur_button;                        // Current button press value
  cur_button = digitalRead(BUTTON_PIN);
  if ((prev_button == BUTTON_NOT_PRESSED) && (cur_button == BUTTON_PRESSED))
  {
    writeUInt(271); // Put any number you want to send here (71 is just a test)
  }

  delay(50); // Debounce button
  prev_button = cur_button;
}
#endif //TRANSMITTER
#ifdef RECEIVER
void loop()
{
  boolean light_led = false;
  if (readUInt(true) == 271) // Check to see if we got the 71 test number
  {
    light_led = true;
  }
  
  if (light_led)
  {
    digitalWrite(LED_PIN, HIGH);
    delay(1000);
    digitalWrite(LED_PIN, LOW);
  }
}
#endif //RECEIVER

===========================================
你要自己去結合兩個code達到控制servo目的.
6#
 樓主| 發表於 2011-4-17 15:12:38 | 只看該作者
我好像沒有SoftwareServo.h file 這個是要去額外載來安裝的嗎?
如果能的話可以給我個載點嗎
我Google爬了好幾天只找到一個國外網站他說沒安裝成功似乎就沒有SoftwareServo.h 這個檔案 但我找很久也找不到arduino-0022要怎麼安裝

不是TG-11的也沒關係總是要靠自己摸索一下 能給我個大概的方向就很感激了
不然我自己摸老半天還找錯目標 謝謝V大囉
7#
發表於 2011-4-18 09:13:10 | 只看該作者
我好像沒有SoftwareServo.h file 這個是要去額外載來安裝的嗎?
如果能的話可以給我個載點嗎
我Google爬 ...
Suzaku 發表於 2011-4-17 15:12


SoftwareServo 好像是舊的 Library,參考底下網址的說明,它建議使用 Arduino Servo Library (Arduino 0017 之後的版本都有內附):http://www.arduino.cc/playground/ComponentLib/Servo
8#
 樓主| 發表於 2011-4-18 20:55:44 | 只看該作者
了了  謝謝cooper囉
V大 可以問一下這串  if (readUInt(true) == 271) // Check to see if we got the 71 test number
中的readUInt是指讀取前面的writeUInt的值如果為真就執行LED燈亮吧
可是readUInt他似乎說未宣告不能編譯 是哪裡少打了嗎?
9#
 樓主| 發表於 2011-4-23 22:15:11 | 只看該作者
本帖最後由 Suzaku 於 2011-4-25 00:13 編輯

弄成功了 似乎我要的功能不需用到傳送位元組
下面是程式碼供後人參考
#include <Servo.h>

const int  BUTTON_PIN = 2;  // 令BUTTON_PIN 為2
int buttonState = 0;  // 初始狀態為0

Servo servo_motor1;
Servo servo_motor2;

void setup(){
  servo_motor1.attach(9);    //伺服馬達接在9號位置
  servo_motor1.writeMicroseconds(1380);  //令伺服馬達轉到中央約90度位置
  servo_motor2.attach(3);
  servo_motor2.writeMicroseconds(1380);

  delay(5000);   //延遲5秒
  pinMode(BUTTON_PIN, INPUT);  //BUTTON_PIN 為輸入
  }


void loop()      
{
   buttonState = digitalRead(BUTTON_PIN);   //讀取BUTTON_PIN的狀態

if (buttonState == HIGH)   //按鈕按下狀態為HIGH

{
  servo_motor1.writeMicroseconds(2340);
  servo_motor2.writeMicroseconds(860);


delay(5000);}

else{
  
servo_motor1.writeMicroseconds(860);
servo_motor2.writeMicroseconds(2340);


delay(5000);}
}



若有錯請不吝賜教
10#
發表於 2011-4-23 22:40:08 | 只看該作者
所以不用無線電遙控了?

如果程式碼可以簡單註解一下,後來的人會比較容易懂。
11#
 樓主| 發表於 2011-4-25 00:06:06 | 只看該作者
有  還是用無線電遙控只是沒那麼複雜
只單純按下按鈕給一個digital腳位HIGH 令晶片接收到HIGH之後去啟動馬達轉到0度位置
沒按的話就是LOW  馬達自動回復到180度位置
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-5-19 20:20 , Processed in 0.239198 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表