|
||||||
|
||||||
|
상품번호 : 259 | |
(2) | (0) |
---|
원거리 통신이 가능한 저렴한 모듈입니다. 2.4GHz 의 높은 주파수라 수신감도가 좋고 양방향 통신이 가능한 장점도 있습니다.
SPI 방식이라 제어도 복잡하지 않습니다.
번호 | 핀명 | 기능 |
---|---|---|
1 | GND | GROUND |
2 | VCC | 3.3V 입력 |
3 | CE | Chip Enable Activates RX or TX mode |
4 | CSN | SPI Chip Select |
5 | SCK | SPI Clock |
6 | MOSI | SPI Slave Data Input |
7 | MISO | SPI Slave Data Output, with tri-state option |
8 | IRQ | Maskable interrupt pin. Active low |
UNO R3 에서 제공하는 3.3V는 전류가 매우 낮아서 별도의 3.3V 모듈(WAT-DC533)을 사용하였습니다.
번호 | 2.4GHz 모듈 | Arduino UNO R3 | WAT-DC533 | COLOR |
---|---|---|---|---|
1 | GND | GND | GND | BLACK |
2 | VCC | 3.3V를 2.4GHz 모듈에 연결 | RED | |
3 | CE | 9 | VIOLET | |
4 | CSN | 10 | BROWN | |
5 | SCK | 13 | BLUE | |
6 | MOSI | 11 | GRAY | |
7 | MISO | 12 | BLUE | |
8 | IRQ | x |
최신 소스코드는 [파일]=>[예제]=> [WhiteAT UNO]=>[RF24_simple] 에 있으며
라이브러리는 아두이노 개발환경 (http://docs.whiteat.com/?page_id=319)을 참조하세요
한개는 radioNumber 를 0 으로 다른 한개는 radioNumber 1로 합니다.
/*
UNO 와2.4GHz 모듈통신예제입니다.
개별부품
.UNO R3 : /goods/view?no=71
.2.4GHz 모듈: /goods/view?no=259
출처: http://whiteat.com/Arduino
*/
#include
#include "RF24.h"
// 장치고유번호설정: 한개는0, 다른한개는1
bool radioNumber = 0;
// CE: pin 9
// CSN: pin 10
RF24 radio(9, 10);
/**********************************************************/
// 장치의주소(이름) 지정
byte addresses[][6] = { "WAT1", "WAT2" };
void setup()
{
Serial.begin(115200);
Serial.println(F("RF24/examples/GettingStarted"));
Serial.println("Arduino Examples - RF24 Simple Test");
Serial.println(" http://docs.whiteat.com/?p=3754");
radio.begin();
// 가까운거리에서사용할때는RF24_PA_LOW
// 먼거리에서사용할때는RF24_PA_MAX 으로설정해야한다.
radio.setPALevel(RF24_PA_LOW);
// Open a writing and reading pipe on each radio, with opposite addresses
if (0==radioNumber)
{
Serial.println(F("This is PING part ")); // 요청
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1, addresses[0]);
}
else
{
Serial.println(F("This is PONG part ")); // 응답
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
}
// 수신상태로전환
radio.startListening();
}
void loop()
{
/****************** Ping Out Role ***************************/
if (radioNumber == 0)
{
// 수신대기상태를정지
radio.stopListening();
Serial.println(F("Now sending"));
// 현재시간을보내고
// 다보내질때까지기다린다.
unsigned long start_time = micros();
if (!radio.write(&start_time, sizeof(unsigned long)))
{
Serial.println(F("failed"));
}
// 수신상태로전환
radio.startListening();
// 응답을기다림
// 200ms 동안응답이없으면timeout 처리
unsigned long started_waiting_at = micros();
boolean timeout = false;
while (!radio.available()) // 받은게없다면
{
if (micros() - started_waiting_at > 200000)// 200mS 동안받은게없다면
{
timeout = true;
break;
}
}
if (timeout) // timeout이라면
{
Serial.println(F("Failed, response timed out."));
}
else
{
// 응답시간을표시
unsigned long got_time;
radio.read(&got_time, sizeof(unsigned long));
unsigned long end_time = micros();
Serial.print(F("Sent "));
Serial.print(start_time);
Serial.print(F(", Got response "));
Serial.print(got_time);
Serial.print(F(", Round-trip delay "));
Serial.print(end_time - start_time);
Serial.println(F(" microseconds"));
}
// 1초대기
delay(1000);
}
/****************** Pong Back Role ***************************/
if (radioNumber != 0)
{
unsigned long got_time;
// 수신데이터가있으면
if (radio.available())
{
while (radio.available())
{
radio.read(&got_time, sizeof(unsigned long)); // 데이터읽기
}
radio.stopListening(); // 수신대기상태를정지
radio.write(&got_time, sizeof(unsigned long)); // 응답시간을보냄
radio.startListening(); // 수신상태로전환
Serial.print(F("Sent response "));
Serial.println(got_time);
}
}
} // Loop
|
(2) | (0) |
---|
<<<<<<<<<<<<< 전체 상품 후기 보기 (클릭) >>>>>>>>>>>>>> |
(2) | (0) |
---|
(2) | (0) |
---|
|
|||||||||||
회사명 : 화이트앳
| 사업자등록번호 : 106-11-55283 [사업자정보확인]
| 주소 : 서울특별시 구로구 고척동 253-64 지층 101호 통신판매업 신고 : 2022-서울구로-1047 | 연락처 : 070-4412-5754 | FAX : 02-0000-0000 | 개인정보관리 책임자 : 한정욱 | 대표자 : 박원호 contact : help@kit128.com for more information |
|||||||||||