Robofun 機器人論壇
標題:
RF電路 兩片板子不接同一台PC 傳輸距離變得很短
[打印本頁]
作者:
kaiwen789
時間:
2013-6-8 13:45
標題:
RF電路 兩片板子不接同一台PC 傳輸距離變得很短
前情提要:
我想要設計微波電路,讓兩片Arduino板子可以溝通 (我是用Uno)
目前買了這個東西
http://tinyurl.com/k54ehem
(益眾科技 - 27MHz ASK RF 數據傳輸模組 型號A06-0001)
然後利用
http://www.glacialwanderer.com/hobbyrobotics/?p=291
的程式及電路
我把兩片Arduino板子用USB連接線,接在同一台PC上,工作狀況良好
有超過1.5公尺的傳輸距離 ((因為我USB線長度有限,不知道更大可以多少
目前問題:
但是,如果我把其中一片Arduino板子的供電改為 "另一台電腦" 或是 "電池"
他的傳輸距離就會突然變得超級短,大概只有10公分以內
我另外再接了一條50歐姆、一公尺的傳輸線之後,才大概有一公尺半的傳輸距離
想請問有沒有人知道這是怎麼樣的狀況呢?
先謝謝大家指教!!!!!
隨文附上使用的 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(300); // 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
複製代碼
Error_Catching
// Maurice Ribble
// 8-30-2009
// http://www.glacialwanderer.com/hobbyrobotics
// Used Arduino 0017
// This does does some error checking to try to make sure the receiver on this one way RF
// serial link doesn't repond to garbage
#define NETWORK_SIG_SIZE 3
#define VAL_SIZE 2
#define CHECKSUM_SIZE 1
#define PACKET_SIZE (NETWORK_SIG_SIZE + VAL_SIZE + CHECKSUM_SIZE)
// The network address byte and can be change if you want to run different devices in proximity to each other without interfearance
#define NET_ADDR 5
const byte g_network_sig[NETWORK_SIG_SIZE] = {0x8F, 0xAA, NET_ADDR}; // Few bytes used to initiate a transfer
// Sends an unsigned int over the RF network
void writeUInt(unsigned int val)
{
byte checksum = (val/256) ^ (val&0xFF);
Serial.write(0xF0); // This gets reciever in sync with transmitter
Serial.write(g_network_sig, NETWORK_SIG_SIZE);
Serial.write((byte*)&val, VAL_SIZE);
Serial.write(checksum); //CHECKSUM_SIZE
}
// Receives an unsigned int over the RF network
unsigned int readUInt(bool wait)
{
int pos = 0; // Position in the network signature
unsigned int val; // Value of the unsigned int
byte c = 0; // Current byte
if((Serial.available() < PACKET_SIZE) && (wait == false))
{
return 0xFFFF;
}
while(pos < NETWORK_SIG_SIZE)
{
while(Serial.available() == 0); // Wait until something is avalible
c = Serial.read();
if (c == g_network_sig[pos])
{
if (pos == NETWORK_SIG_SIZE-1)
{
byte checksum;
while(Serial.available() < VAL_SIZE + CHECKSUM_SIZE); // Wait until something is avalible
val = Serial.read();
val += ((unsigned int)Serial.read())*256;
checksum = Serial.read();
if (checksum != ((val/256) ^ (val&0xFF)))
{
// Checksum failed
pos = -1;
}
}
++pos;
}
else if (c == g_network_sig[0])
{
pos = 1;
}
else
{
pos = 0;
if (!wait)
{
return 0xFFFF;
}
}
}
return val;
}
複製代碼
作者:
vegewell
時間:
2013-6-12 03:44
回復
1#
kaiwen789
>>想請問有沒有人知道這是怎麼樣的狀況呢?
會不會是電力不足?
另外地線有沒有連接也要考慮
作者:
kaiwen789
時間:
2013-6-13 09:22
呼我自己解決了XD
我想應該是Phase Lock Loop的問題
我原本以為是微波的Phase Lock
但後來想想微波應該是在接收器上面就有做Phase Lock
所以應該是電路Clock的Phase Lock
總之解法就是改用下方這個網站的函式庫就解決了XD
http://www.airspayce.com/mikem/arduino/
也謝謝vegewell網友的回覆=P
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2