├── .gitmodules ├── Projects ├── 3 канальное управление │ ├── README.MD │ ├── RX │ │ └── RX.ino │ ├── TX │ │ └── TX.ino │ ├── мосфет.jpg │ ├── передатчик.jpg │ └── приёмник.jpg ├── Дистанционное управление с обратной связью │ ├── RX_response │ │ └── RX_response.ino │ └── TX_response │ │ └── TX_response.ino └── простой приём передача │ ├── RX │ └── RX.ino │ └── TX │ └── TX.ino ├── README.md ├── RF24-master ├── .gitignore ├── Doxyfile ├── FAQ ├── README.md ├── RF24.cpp ├── RF24.h ├── RF24_config.h ├── doxygen-custom.css ├── examples │ ├── GettingStarted │ │ ├── GettingStarted.pde │ │ ├── Jamfile │ │ └── printf.h │ ├── led_remote │ │ ├── Jamfile │ │ ├── led_remote.pde │ │ └── printf.h │ ├── nordic_fob │ │ ├── Jamfile │ │ ├── nordic_fob.pde │ │ └── printf.h │ ├── pingpair │ │ ├── Jamfile │ │ ├── pingpair.pde │ │ └── printf.h │ ├── pingpair_dyn │ │ ├── Jamfile │ │ ├── pingpair_dyn.pde │ │ └── printf.h │ ├── pingpair_irq │ │ ├── Jamfile │ │ ├── pingpair_irq.pde │ │ └── printf.h │ ├── pingpair_maple │ │ ├── Jamfile │ │ ├── main.cpp │ │ └── pingpair_maple.pde │ ├── pingpair_pl │ │ ├── Jamfile │ │ ├── pingpair_pl.pde │ │ └── printf.h │ ├── pingpair_sleepy │ │ ├── Jamfile │ │ ├── pingpair_sleepy.pde │ │ └── printf.h │ ├── scanner │ │ ├── Jamfile │ │ ├── output │ │ │ ├── core.a │ │ │ ├── scanner.cpp │ │ │ ├── scanner.elf │ │ │ └── scanner.hex │ │ ├── printf.h │ │ └── scanner.pde │ └── starping │ │ ├── Jamfile │ │ ├── printf.h │ │ └── starping.pde ├── keywords.txt ├── nRF24L01.h ├── tests │ ├── README │ ├── native │ │ ├── Jamfile │ │ ├── pingpair_irq.pde │ │ └── printf.h │ ├── pingpair_blocking │ │ ├── Jamfile │ │ ├── pingpair_blocking.pde │ │ ├── printf.h │ │ ├── runtest.py │ │ ├── runtests.sh │ │ └── test.ex │ └── pingpair_test │ │ ├── Jamfile │ │ ├── pingpair_test.pde │ │ ├── printf.h │ │ ├── runtest.py │ │ ├── runtests.sh │ │ └── test.ex └── wikidoc.xslt ├── connect.jpg ├── connect_adapter.png ├── nRF24L01 tests ├── GettingStarted_CallResponse │ └── GettingStarted_CallResponse.ino ├── nrf_listen_air │ └── nrf_listen_air.ino ├── время передачи │ ├── RX_time │ │ └── RX_time.ino │ └── TX_time │ │ └── TX_time.ino └── тест расстояния │ ├── RX_time_disp │ └── RX_time_disp.ino │ └── TX_time_disp │ └── TX_time_disp.ino ├── power.txt ├── прерывание.txt └── сбережение.txt /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "RF24"] 2 | path = RF24 3 | url = git@github.com:maniacbug/RF24.git 4 | -------------------------------------------------------------------------------- /Projects/3 канальное управление/README.MD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/Projects/3 канальное управление/README.MD -------------------------------------------------------------------------------- /Projects/3 канальное управление/RX/RX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include 9 | #include "nRF24L01.h" 10 | #include "RF24.h" 11 | #include 12 | 13 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 14 | //RF24 radio(9,53); // для Меги 15 | 16 | byte recieved_data[3]; // массив принятых данных 17 | byte relay = 2; // реле на 2 цифровом 18 | byte servo = 3; // сервопривод на 3 цифровом 19 | byte mosfet = 5; // мосфет на 5 цифровом (ТУТ ЕСТЬ ШИМ!!!) 20 | 21 | Servo myservo; 22 | 23 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 24 | 25 | void setup() { 26 | Serial.begin(9600); // открываем порт для связи с ПК 27 | 28 | pinMode(relay, OUTPUT); // настроить пин реле как выход 29 | pinMode(mosfet, OUTPUT); // настроить пин мосфета как выход 30 | 31 | myservo.attach(servo); 32 | 33 | radio.begin(); //активировать модуль 34 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 35 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 36 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 37 | radio.setPayloadSize(32); // размер пакета, в байтах 38 | 39 | radio.openReadingPipe(1, address[0]); // хотим слушать трубу 0 40 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 41 | 42 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 43 | radio.setDataRate (RF24_250KBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 44 | //должна быть одинакова на приёмнике и передатчике! 45 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 46 | 47 | radio.powerUp(); // начать работу 48 | radio.startListening(); // начинаем слушать эфир, мы приёмный модуль 49 | } 50 | 51 | void loop() { 52 | byte pipeNo; 53 | while ( radio.available(&pipeNo)) { // есть входящие данные 54 | // чиатем входящий сигнал 55 | radio.read(&recieved_data, sizeof(recieved_data)); 56 | 57 | // подать на реле сигнал с 0 места массива 58 | digitalWrite(relay, recieved_data[0]); 59 | 60 | // повернуть серво на угол 0..180 61 | // значение получено с 1 элемента массива 62 | myservo.write(recieved_data[1]); 63 | 64 | // подать на мосфет ШИМ сигнал 65 | // в соответствии с принятыми данными со 2 места массива, диапазон 0...255 66 | analogWrite(mosfet, recieved_data[2]); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Projects/3 канальное управление/TX/TX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include 9 | #include "nRF24L01.h" 10 | #include "RF24.h" 11 | 12 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 13 | //RF24 radio(9,53); // для Меги 14 | 15 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 16 | 17 | byte button = 3; // кнопка на 3 цифровом 18 | byte potent = 0; // потенциометр на 0 аналоговом 19 | byte slider = 1; // движковый потенциометр на 1 аналоговом пине 20 | 21 | byte transmit_data[3]; // массив, хранящий передаваемые данные 22 | byte latest_data[3]; // массив, хранящий последние переданные данные 23 | boolean flag; // флажок отправки данных 24 | 25 | void setup() { 26 | Serial.begin(9600); //открываем порт для связи с ПК 27 | 28 | pinMode(button, INPUT_PULLUP); // настроить пин кнопки 29 | 30 | radio.begin(); // активировать модуль 31 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 32 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 33 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 34 | radio.setPayloadSize(32); // размер пакета, в байтах 35 | 36 | radio.openWritingPipe(address[0]); // мы - труба 0, открываем канал для передачи данных 37 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 38 | 39 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 40 | radio.setDataRate (RF24_250KBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 41 | //должна быть одинакова на приёмнике и передатчике! 42 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 43 | 44 | radio.powerUp(); //начать работу 45 | radio.stopListening(); //не слушаем радиоэфир, мы передатчик 46 | } 47 | 48 | void loop() { 49 | // инвертированный (!) сигнал с кнопки 50 | transmit_data[0] = !digitalRead(button); 51 | 52 | transmit_data[1] = map(analogRead(potent), 0, 1023, 0, 180); // получить значение 53 | // в диапазоне 0..1023, перевести в 0..180, и записать на 1 место в массиве 54 | transmit_data[2] = map(analogRead(slider), 0, 1023, 0, 255); 55 | 56 | for (int i = 0; i < 3; i++) { // в цикле от 0 до числа каналов 57 | if (transmit_data[i] != latest_data[i]) { // если есть изменения в transmit_data 58 | flag = 1; // поднять флаг отправки по радио 59 | latest_data[i] = transmit_data[i]; // запомнить последнее изменение 60 | } 61 | } 62 | 63 | if (flag == 1) { 64 | radio.powerUp(); // включить передатчик 65 | radio.write(&transmit_data, sizeof(transmit_data)); // отправить по радио 66 | flag = 0; //опустить флаг 67 | radio.powerDown(); // выключить передатчик 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Projects/3 канальное управление/мосфет.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/Projects/3 канальное управление/мосфет.jpg -------------------------------------------------------------------------------- /Projects/3 канальное управление/передатчик.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/Projects/3 канальное управление/передатчик.jpg -------------------------------------------------------------------------------- /Projects/3 канальное управление/приёмник.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/Projects/3 канальное управление/приёмник.jpg -------------------------------------------------------------------------------- /Projects/Дистанционное управление с обратной связью/RX_response/RX_response.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Пример скетча "управление с телеметрией", то есть модуль ПЕРЕДАТЧИК 3 | шлёт на ПРИЁМНИК команды управления, ПРИЁМНИК при получении пакета данных 4 | отправляет ПЕРЕДАТЧИКУ пакет телеметрии (какие-то свои данные). ПЕРЕДАТЧИК 5 | эти данные принимает. Вот такие пироги. Также в этом примере реализован 6 | расчёт RSSI (процент ошибок связи), на основании которого можно судить о 7 | качестве связи между модулями. 8 | */ 9 | 10 | // ЭТО СКЕТЧ ПРИЁМНИКА!!! 11 | 12 | //--------------------- НАСТРОЙКИ ---------------------- 13 | #define CH_NUM 0x60 // номер канала (должен совпадать с передатчиком) 14 | //--------------------- НАСТРОЙКИ ---------------------- 15 | 16 | //--------------------- ДЛЯ РАЗРАБОТЧИКОВ ----------------------- 17 | // УРОВЕНЬ МОЩНОСТИ ПЕРЕДАТЧИКА 18 | // На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 19 | #define SIG_POWER RF24_PA_MIN 20 | 21 | // СКОРОСТЬ ОБМЕНА 22 | // На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 23 | // должна быть одинакова на приёмнике и передатчике! 24 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 25 | // ВНИМАНИЕ!!! enableAckPayload НЕ РАБОТАЕТ НА СКОРОСТИ 250 kbps! 26 | #define SIG_SPEED RF24_1MBPS 27 | //--------------------- ДЛЯ РАЗРАБОТЧИКОВ ----------------------- 28 | 29 | //--------------------- БИБЛИОТЕКИ ---------------------- 30 | #include 31 | #include "nRF24L01.h" 32 | #include "RF24.h" 33 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 для НАНО/УНО 34 | //RF24 radio(9, 53); // для МЕГИ 35 | //--------------------- БИБЛИОТЕКИ ---------------------- 36 | 37 | //--------------------- ПЕРЕМЕННЫЕ ---------------------- 38 | byte pipeNo; 39 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; // возможные номера труб 40 | 41 | int recieved_data[2]; // массив принятых данных 42 | int telemetry[2]; // массив данных телеметрии (то что шлём на передатчик) 43 | //--------------------- ПЕРЕМЕННЫЕ ---------------------- 44 | 45 | void setup() { 46 | Serial.begin(9600); 47 | radioSetup(); 48 | } 49 | 50 | void loop() { 51 | while (radio.available(&pipeNo)) { // слушаем эфир 52 | radio.read(&recieved_data, sizeof(recieved_data)); // чиатем входящий сигнал 53 | 54 | // формируем пакет данных телеметрии (напряжение АКБ, скорость, температура...) 55 | telemetry[0] = 20; 56 | telemetry[1] = 20; 57 | 58 | // отправляем пакет телеметрии 59 | radio.writeAckPayload(pipeNo, &telemetry, sizeof(telemetry)); 60 | } 61 | } 62 | 63 | void radioSetup() { // настройка радио 64 | radio.begin(); // активировать модуль 65 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 66 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 67 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 68 | radio.setPayloadSize(32); // размер пакета, байт 69 | radio.openReadingPipe(1, address[0]); // хотим слушать трубу 0 70 | radio.setChannel(CH_NUM); // выбираем канал (в котором нет шумов!) 71 | radio.setPALevel(SIG_POWER); // уровень мощности передатчика 72 | radio.setDataRate(SIG_SPEED); // скорость обмена 73 | // должна быть одинакова на приёмнике и передатчике! 74 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 75 | 76 | radio.powerUp(); // начать работу 77 | radio.startListening(); // начинаем слушать эфир, мы приёмный модуль 78 | } 79 | -------------------------------------------------------------------------------- /Projects/Дистанционное управление с обратной связью/TX_response/TX_response.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Пример скетча "управление с телеметрией", то есть модуль ПЕРЕДАТЧИК 3 | шлёт на ПРИЁМНИК команды управления, ПРИЁМНИК при получении пакета данных 4 | отправляет ПЕРЕДАТЧИКУ пакет телеметрии (какие-то свои данные). ПЕРЕДАТЧИК 5 | эти данные принимает. Вот такие пироги. Также в этом примере реализован 6 | расчёт RSSI (процент ошибок связи), на основании которого можно судить о 7 | качестве связи между модулями. 8 | */ 9 | 10 | // ЭТО СКЕТЧ ПЕРЕДАТЧИКА!!! 11 | 12 | //--------------------- НАСТРОЙКИ ---------------------- 13 | #define CH_NUM 0x60 // номер канала (должен совпадать с приёмником) 14 | //--------------------- НАСТРОЙКИ ---------------------- 15 | 16 | //--------------------- ДЛЯ РАЗРАБОТЧИКОВ ----------------------- 17 | // УРОВЕНЬ МОЩНОСТИ ПЕРЕДАТЧИКА 18 | // На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 19 | #define SIG_POWER RF24_PA_LOW 20 | 21 | // СКОРОСТЬ ОБМЕНА 22 | // На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 23 | // должна быть одинакова на приёмнике и передатчике! 24 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 25 | // ВНИМАНИЕ!!! enableAckPayload НЕ РАБОТАЕТ НА СКОРОСТИ 250 kbps! 26 | #define SIG_SPEED RF24_1MBPS 27 | //--------------------- ДЛЯ РАЗРАБОТЧИКОВ ----------------------- 28 | 29 | //--------------------- БИБЛИОТЕКИ ---------------------- 30 | #include 31 | #include "nRF24L01.h" 32 | #include "RF24.h" 33 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 34 | //RF24 radio(9, 53); // для Меги 35 | //--------------------- БИБЛИОТЕКИ ---------------------- 36 | 37 | //--------------------- ПЕРЕМЕННЫЕ ---------------------- 38 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; // возможные номера труб 39 | 40 | int transmit_data[2]; // массив пересылаемых данных 41 | int telemetry[2]; // массив принятых от приёмника данных телеметрии 42 | byte rssi; 43 | int trnsmtd_pack = 1, failed_pack; 44 | unsigned long RSSI_timer; 45 | //--------------------- ПЕРЕМЕННЫЕ ---------------------- 46 | 47 | void setup() { 48 | Serial.begin(9600); // открываем порт для связи с ПК 49 | radioSetup(); 50 | } 51 | 52 | void loop() { 53 | // забиваем transmit_data данными, для примера 54 | transmit_data[0] = 10; 55 | transmit_data[0] = 20; 56 | 57 | // отправка пакета transmit_data 58 | if (radio.write(&transmit_data, sizeof(transmit_data))) { 59 | trnsmtd_pack++; 60 | if (!radio.available()) { // если получаем пустой ответ 61 | } else { 62 | while (radio.available() ) { // если в ответе что-то есть 63 | radio.read(&telemetry, sizeof(telemetry)); // читаем 64 | // получили забитый данными массив telemetry ответа от приёмника 65 | } 66 | } 67 | } else { 68 | failed_pack++; 69 | } 70 | 71 | if (millis() - RSSI_timer > 1000) { // таймер RSSI 72 | // расчёт качества связи (0 - 100%) на основе числа ошибок и числа успешных передач 73 | rssi = (1 - ((float)failed_pack / trnsmtd_pack)) * 100; 74 | 75 | // сбросить значения 76 | failed_pack = 0; 77 | trnsmtd_pack = 0; 78 | RSSI_timer = millis(); 79 | } 80 | } 81 | 82 | void radioSetup() { 83 | radio.begin(); // активировать модуль 84 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 85 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 86 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 87 | radio.setPayloadSize(32); // размер пакета, в байтах 88 | radio.openWritingPipe(address[0]); // мы - труба 0, открываем канал для передачи данных 89 | radio.setChannel(CH_NUM); // выбираем канал (в котором нет шумов!) 90 | radio.setPALevel(SIG_POWER); // уровень мощности передатчика 91 | radio.setDataRate(SIG_SPEED); // скорость обмена 92 | // должна быть одинакова на приёмнике и передатчике! 93 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 94 | 95 | radio.powerUp(); // начать работу 96 | radio.stopListening(); // не слушаем радиоэфир, мы передатчик 97 | } 98 | -------------------------------------------------------------------------------- /Projects/простой приём передача/RX/RX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include 9 | #include "nRF24L01.h" 10 | #include "RF24.h" 11 | 12 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 13 | //RF24 radio(9,53); // для Меги 14 | 15 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 16 | 17 | void setup() { 18 | Serial.begin(9600); // открываем порт для связи с ПК 19 | radio.begin(); // активировать модуль 20 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 21 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 22 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 23 | radio.setPayloadSize(32); // размер пакета, в байтах 24 | 25 | radio.openReadingPipe(1, address[0]); // хотим слушать трубу 0 26 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 27 | 28 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 29 | radio.setDataRate (RF24_250KBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 30 | //должна быть одинакова на приёмнике и передатчике! 31 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 32 | 33 | radio.powerUp(); // начать работу 34 | radio.startListening(); // начинаем слушать эфир, мы приёмный модуль 35 | } 36 | 37 | void loop() { 38 | byte pipeNo, gotByte; 39 | while (radio.available(&pipeNo)) { // слушаем эфир со всех труб 40 | radio.read(&gotByte, sizeof(gotByte)); // чиатем входящий сигнал 41 | Serial.print("Recieved: "); 42 | Serial.println(gotByte); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Projects/простой приём передача/TX/TX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include // библиотека для работы с шиной SPI 9 | #include "nRF24L01.h" // библиотека радиомодуля 10 | #include "RF24.h" // ещё библиотека радиомодуля 11 | 12 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 13 | //RF24 radio(9,53); // для Меги 14 | 15 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 16 | 17 | byte counter; 18 | 19 | void setup() { 20 | Serial.begin(9600); // открываем порт для связи с ПК 21 | 22 | radio.begin(); // активировать модуль 23 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 24 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 25 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 26 | radio.setPayloadSize(32); // размер пакета, в байтах 27 | 28 | radio.openWritingPipe(address[0]); // мы - труба 0, открываем канал для передачи данных 29 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 30 | 31 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 32 | radio.setDataRate (RF24_250KBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 33 | //должна быть одинакова на приёмнике и передатчике! 34 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 35 | 36 | radio.powerUp(); // начать работу 37 | radio.stopListening(); // не слушаем радиоэфир, мы передатчик 38 | } 39 | 40 | void loop() { 41 | Serial.print("Sent: "); 42 | Serial.println(counter); 43 | radio.write(&counter, sizeof(counter)); 44 | counter++; 45 | delay(10); 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nRF24L01 2 | Модули беспроводной связи nRF24L01, настройка и примеры 3 | 4 | ## Купить на AliExpress 5 | NRF24L01 обычные, мини, с усилителем, а также модуль питания: 6 | - https://ali.ski/BlCLzU 7 | - https://ali.ski/Tatilw 8 | 9 | ## Папки 10 | 11 | **RF24-master** - библиотека для модуля связи, установить в C:\Program Files\Arduino\libraries 12 | 13 | **nRF24 tests** - тесты модулей 14 | 15 | - **GettingStarted_CallResponse** - тест качества связи между двумя модулями 16 | - **nrf_listen_air** - тест одного модуля, прослушивание всех каналов 17 | - **время передачи** - скетч, измеряющий время передачи с модуля на модуль (сильно упрощённый GettingStarted_CallResponse) 18 | - **тест расстояния** - скетч из видео, к Ардуино подключен дисплей, отображающий число принятых пакетов за единицу времени 19 | 20 | **Projects** - папка со схемами и скетчами 21 | 22 | - **3 канальное управление** - трёхканальное управлением реле, LED лентой и сервомашинкой 23 | - **простой приём передача** - базовая пара скетчей со всеми настрйоками модулей, а также примером передачи данных 24 | 25 | 26 | ## Схема подключения 27 | ![подключение](https://github.com/AlexGyver/nRF24L01/blob/master/connect.jpg) 28 | ![подключение](https://github.com/AlexGyver/nRF24L01/blob/master/connect_adapter.png) 29 | 30 | -------------------------------------------------------------------------------- /RF24-master/.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.o 3 | .*.swp 4 | *.orig 5 | .swp 6 | docs/ 7 | output/ 8 | ojam/ 9 | out/ 10 | 16000000/ 11 | 8000000/ 12 | out_native/ 13 | version.h 14 | Session.vim 15 | -------------------------------------------------------------------------------- /RF24-master/FAQ: -------------------------------------------------------------------------------- 1 | /** 2 | * @page FAQ Frequently Asked Questions 3 | * 4 | * @ref starting 5 | * 6 | * @ref hardware 7 | * 8 | * @ref range 9 | * 10 | * @ref issues 11 | * 12 | * @ref ram 13 | * 14 | * @ref tests 15 | * 16 | * @section starting Where do I start? 17 | * 18 | * See my blog post: 19 | * Getting Started with nRF24L01+ on Arduino 20 | * 21 | * @section hardware Where can I buy some hardware? 22 | * 23 | * @li iTeadStudio sells the basic 2.4G Wireless nRF24L01+ Module for $4. Such a deal! 24 | * @li MDfly.com sells the same unit, 2.4Ghz Wireless nRF24L01+ Transceiver Module for $6.95, but it ships from the US so it gets there a lot faster. Great place to get a few units and get started quickly. 25 | * @li MDfly.com also has the nRF24L01 2.4GHz Transceiver Module w/ Power Amplifier for $13.95, which increases range dramatically and uses a chip antenna 26 | * @li MDfly.com also has the 2.4GHz Transceiver Module w/ Power Amplifier with an external antenna for $19.95 27 | * 28 | * @section range What is the range of these units? 29 | * 30 | * Here are some results from measurements I have taken, using the basic $4 iTeadStudio units. 31 | * I recommend that everyone take their own measurements in their particular circumstances. 32 | * 33 | * @li non-plus unit, 2MBps (worst case), 41+ ft line of sight indoors, immediate dropoff with any deviation from LOS. (41 ft is as far as I can go in my house without turning a corner) 34 | * @li Plus unit, 250kbps (best case), 46 ft around two corners indoors, 49 ft around one corner. More importantly, at 250k, packet loss is almost negligible through almost all of that range. 35 | * @li Both units at 1MBps, plus unit gets about 10% range improvement over non-plus in almost all situations. 36 | * 37 | * @section issues What should I do if I find a problem? 38 | * 39 | * Please open an issue on github if you find any problems using it with any version of Arduino or Maple. 40 | * 41 | * @section ram What is the RAM footprint of this library? 42 | * 43 | * 16 bytes. A single radio object consumes 16 bytes of RAM, and the library 44 | * does not use any other RAM statically. 45 | * 46 | * @section tests Why are the examples in the 'tests' directory failing? 47 | * 48 | * The sketches in the 'tests' directory are not for general use. 49 | * Please use the examples in the 'examples' directory instead. 50 | * 51 | * The 'tests' directory is only for people making changes to the library 52 | * to ensure that their changes do not break anything. 53 | */ 54 | -------------------------------------------------------------------------------- /RF24-master/README.md: -------------------------------------------------------------------------------- 1 | # Arduino driver for nRF24L01 2.4GHz Wireless Transceiver 2 | 3 | Design Goals: This library is designed to be... 4 | 5 | * Maximally compliant with the intended operation of the chip 6 | * Easy for beginners to use 7 | * Consumed with a public interface that's similiar to other Arduino standard libraries 8 | * Built against the standard SPI library. 9 | 10 | Please refer to: 11 | 12 | * [Documentation Main Page](http://maniacbug.github.com/RF24) 13 | * [RF24 Class Documentation](http://maniacbug.github.com/RF24/classRF24.html) 14 | * [Source Code](https://github.com/maniacbug/RF24) 15 | * [Downloads](https://github.com/maniacbug/RF24/archives/master) 16 | * [Chip Datasheet](http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf) 17 | 18 | This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or 19 | the SPI hardware will go into 'slave' mode. 20 | 21 | -------------------------------------------------------------------------------- /RF24-master/RF24_config.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright (C) 2011 J. Coliz 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | version 2 as published by the Free Software Foundation. 8 | */ 9 | 10 | #ifndef __RF24_CONFIG_H__ 11 | #define __RF24_CONFIG_H__ 12 | 13 | #if ARDUINO < 100 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #include 20 | 21 | // Stuff that is normally provided by Arduino 22 | #ifdef ARDUINO 23 | #include 24 | #else 25 | #include 26 | #include 27 | #include 28 | extern HardwareSPI SPI; 29 | #define _BV(x) (1<<(x)) 30 | #endif 31 | 32 | #undef SERIAL_DEBUG 33 | #ifdef SERIAL_DEBUG 34 | #define IF_SERIAL_DEBUG(x) ({x;}) 35 | #else 36 | #define IF_SERIAL_DEBUG(x) 37 | #endif 38 | 39 | // Avoid spurious warnings 40 | #if 1 41 | #if ! defined( NATIVE ) && defined( ARDUINO ) 42 | #undef PROGMEM 43 | #define PROGMEM __attribute__(( section(".progmem.data") )) 44 | #undef PSTR 45 | #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) 46 | #endif 47 | #endif 48 | 49 | // Progmem is Arduino-specific 50 | #ifdef ARDUINO 51 | #include 52 | #define PRIPSTR "%S" 53 | #else 54 | typedef char const char; 55 | typedef uint16_t prog_uint16_t; 56 | #define PSTR(x) (x) 57 | #define printf_P printf 58 | #define strlen_P strlen 59 | #define PROGMEM 60 | #define pgm_read_word(p) (*(p)) 61 | #define PRIPSTR "%s" 62 | #endif 63 | 64 | #endif // __RF24_CONFIG_H__ 65 | // vim:ai:cin:sts=2 sw=2 ft=cpp 66 | -------------------------------------------------------------------------------- /RF24-master/examples/GettingStarted/GettingStarted.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example for Getting Started with nRF24L01+ radios. 11 | * 12 | * This is an example of how to use the RF24 class. Write this sketch to two 13 | * different nodes. Put one of the nodes into 'transmit' mode by connecting 14 | * with the serial monitor and sending a 'T'. The ping node sends the current 15 | * time to the pong node, which responds by sending the value back. The ping 16 | * node can then see how long the whole cycle took. 17 | */ 18 | 19 | #include 20 | #include "nRF24L01.h" 21 | #include "RF24.h" 22 | #include "printf.h" 23 | 24 | // 25 | // Hardware configuration 26 | // 27 | 28 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 29 | 30 | RF24 radio(9,10); 31 | 32 | // 33 | // Topology 34 | // 35 | 36 | // Radio pipe addresses for the 2 nodes to communicate. 37 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 38 | 39 | // 40 | // Role management 41 | // 42 | // Set up role. This sketch uses the same software for all the nodes 43 | // in this system. Doing so greatly simplifies testing. 44 | // 45 | 46 | // The various roles supported by this sketch 47 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 48 | 49 | // The debug-friendly names of those roles 50 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 51 | 52 | // The role of the current running sketch 53 | role_e role = role_pong_back; 54 | 55 | void setup(void) 56 | { 57 | // 58 | // Print preamble 59 | // 60 | 61 | Serial.begin(57600); 62 | printf_begin(); 63 | printf("\n\rRF24/examples/GettingStarted/\n\r"); 64 | printf("ROLE: %s\n\r",role_friendly_name[role]); 65 | printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); 66 | 67 | // 68 | // Setup and configure rf radio 69 | // 70 | 71 | radio.begin(); 72 | 73 | // optionally, increase the delay between retries & # of retries 74 | radio.setRetries(15,15); 75 | 76 | // optionally, reduce the payload size. seems to 77 | // improve reliability 78 | //radio.setPayloadSize(8); 79 | 80 | // 81 | // Open pipes to other nodes for communication 82 | // 83 | 84 | // This simple sketch opens two pipes for these two nodes to communicate 85 | // back and forth. 86 | // Open 'our' pipe for writing 87 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 88 | 89 | //if ( role == role_ping_out ) 90 | { 91 | //radio.openWritingPipe(pipes[0]); 92 | radio.openReadingPipe(1,pipes[1]); 93 | } 94 | //else 95 | { 96 | //radio.openWritingPipe(pipes[1]); 97 | //radio.openReadingPipe(1,pipes[0]); 98 | } 99 | 100 | // 101 | // Start listening 102 | // 103 | 104 | radio.startListening(); 105 | 106 | // 107 | // Dump the configuration of the rf unit for debugging 108 | // 109 | 110 | radio.printDetails(); 111 | } 112 | 113 | void loop(void) 114 | { 115 | // 116 | // Ping out role. Repeatedly send the current time 117 | // 118 | 119 | if (role == role_ping_out) 120 | { 121 | // First, stop listening so we can talk. 122 | radio.stopListening(); 123 | 124 | // Take the time, and send it. This will block until complete 125 | unsigned long time = millis(); 126 | printf("Now sending %lu...",time); 127 | bool ok = radio.write( &time, sizeof(unsigned long) ); 128 | 129 | if (ok) 130 | printf("ok..."); 131 | else 132 | printf("failed.\n\r"); 133 | 134 | // Now, continue listening 135 | radio.startListening(); 136 | 137 | // Wait here until we get a response, or timeout (250ms) 138 | unsigned long started_waiting_at = millis(); 139 | bool timeout = false; 140 | while ( ! radio.available() && ! timeout ) 141 | if (millis() - started_waiting_at > 200 ) 142 | timeout = true; 143 | 144 | // Describe the results 145 | if ( timeout ) 146 | { 147 | printf("Failed, response timed out.\n\r"); 148 | } 149 | else 150 | { 151 | // Grab the response, compare, and send to debugging spew 152 | unsigned long got_time; 153 | radio.read( &got_time, sizeof(unsigned long) ); 154 | 155 | // Spew it 156 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 157 | } 158 | 159 | // Try again 1s later 160 | delay(1000); 161 | } 162 | 163 | // 164 | // Pong back role. Receive each packet, dump it out, and send it back 165 | // 166 | 167 | if ( role == role_pong_back ) 168 | { 169 | // if there is data ready 170 | if ( radio.available() ) 171 | { 172 | // Dump the payloads until we've gotten everything 173 | unsigned long got_time; 174 | bool done = false; 175 | while (!done) 176 | { 177 | // Fetch the payload, and see if this was the last one. 178 | done = radio.read( &got_time, sizeof(unsigned long) ); 179 | 180 | // Spew it 181 | printf("Got payload %lu...",got_time); 182 | 183 | // Delay just a little bit to let the other unit 184 | // make the transition to receiver 185 | delay(20); 186 | } 187 | 188 | // First, stop listening so we can talk 189 | radio.stopListening(); 190 | 191 | // Send the final one back. 192 | radio.write( &got_time, sizeof(unsigned long) ); 193 | printf("Sent response.\n\r"); 194 | 195 | // Now, resume listening so we catch the next packets. 196 | radio.startListening(); 197 | } 198 | } 199 | 200 | // 201 | // Change roles 202 | // 203 | 204 | if ( Serial.available() ) 205 | { 206 | char c = toupper(Serial.read()); 207 | if ( c == 'T' && role == role_pong_back ) 208 | { 209 | printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); 210 | 211 | // Become the primary transmitter (ping out) 212 | role = role_ping_out; 213 | radio.openWritingPipe(pipes[0]); 214 | radio.openReadingPipe(1,pipes[1]); 215 | } 216 | else if ( c == 'R' && role == role_ping_out ) 217 | { 218 | printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); 219 | 220 | // Become the primary receiver (pong back) 221 | role = role_pong_back; 222 | radio.openWritingPipe(pipes[1]); 223 | radio.openReadingPipe(1,pipes[0]); 224 | } 225 | } 226 | } 227 | // vim:cin:ai:sts=2 sw=2 ft=cpp 228 | -------------------------------------------------------------------------------- /RF24-master/examples/GettingStarted/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | # (2) Board Information 6 | 7 | UPLOAD_PROTOCOL ?= arduino ; 8 | UPLOAD_SPEED ?= 57600 ; 9 | MCU ?= atmega328p ; 10 | F_CPU ?= 16000000 ; 11 | CORE ?= arduino ; 12 | VARIANT ?= standard ; 13 | ARDUINO_VERSION ?= 100 ; 14 | 15 | # (3) USB Ports 16 | 17 | PORTS = p4 p6 p9 u0 u1 u2 ; 18 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 19 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 20 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 21 | PORT_u0 = /dev/ttyUSB0 ; 22 | PORT_u1 = /dev/ttyUSB1 ; 23 | PORT_u2 = /dev/ttyUSB2 ; 24 | 25 | # (4) Location of AVR tools 26 | # 27 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 28 | # distribution. 29 | 30 | if $(OS) = MACOSX 31 | { 32 | AVR_BIN = /usr/local/avrtools/bin ; 33 | AVR_ETC = /usr/local/avrtools/etc ; 34 | AVR_INCLUDE = /usr/local/avrtools/include ; 35 | } 36 | else 37 | { 38 | AVR_BIN ?= /usr/bin ; 39 | AVR_INCLUDE ?= /usr/lib/avr/include ; 40 | AVR_ETC = /etc ; 41 | } 42 | 43 | # (5) Directories where Arduino core and libraries are located 44 | 45 | ARDUINO_DIR ?= /opt/Arduino ; 46 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 47 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 48 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 49 | 50 | # 51 | # -------------------------------------------------- 52 | # Below this line usually never needs to be modified 53 | # 54 | 55 | # Tool locations 56 | 57 | CC = $(AVR_BIN)/avr-gcc ; 58 | C++ = $(AVR_BIN)/avr-g++ ; 59 | LINK = $(AVR_BIN)/avr-gcc ; 60 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 61 | AVRDUDE = $(AVR_BIN)/avrdude ; 62 | 63 | # Flags 64 | 65 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 66 | OPTIM = -Os ; 67 | CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 68 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 69 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 70 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 71 | 72 | # Search everywhere for headers 73 | 74 | HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 75 | 76 | # Output locations 77 | 78 | LOCATE_TARGET = $(F_CPU) ; 79 | LOCATE_SOURCE = $(F_CPU) ; 80 | 81 | # 82 | # Custom rules 83 | # 84 | 85 | rule GitVersion 86 | { 87 | Always $(<) ; 88 | Depends all : $(<) ; 89 | } 90 | 91 | actions GitVersion 92 | { 93 | echo "const char program_version[] = \"\\" > $(<) 94 | git log -1 --pretty=format:%h >> $(<) 95 | echo "\";" >> $(<) 96 | } 97 | 98 | GitVersion version.h ; 99 | 100 | rule Pde 101 | { 102 | Depends $(<) : $(>) ; 103 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 104 | Clean clean : $(<) ; 105 | } 106 | 107 | if ( $(ARDUINO_VERSION) < 100 ) 108 | { 109 | ARDUINO_H = WProgram.h ; 110 | } 111 | else 112 | { 113 | ARDUINO_H = Arduino.h ; 114 | } 115 | 116 | actions Pde 117 | { 118 | echo "#include <$(ARDUINO_H)>" > $(<) 119 | echo "#line 1 \"$(>)\"" >> $(<) 120 | cat $(>) >> $(<) 121 | } 122 | 123 | rule C++Pde 124 | { 125 | local _CPP = $(>:B).cpp ; 126 | Pde $(_CPP) : $(>) ; 127 | C++ $(<) : $(_CPP) ; 128 | } 129 | 130 | rule UserObject 131 | { 132 | switch $(>:S) 133 | { 134 | case .ino : C++Pde $(<) : $(>) ; 135 | case .pde : C++Pde $(<) : $(>) ; 136 | } 137 | } 138 | 139 | rule Objects 140 | { 141 | local _i ; 142 | 143 | for _i in [ FGristFiles $(<) ] 144 | { 145 | local _b = $(_i:B)$(SUFOBJ) ; 146 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 147 | Object $(_o) : $(_i) ; 148 | Depends obj : $(_o) ; 149 | } 150 | } 151 | 152 | rule Main 153 | { 154 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 155 | Objects $(>) ; 156 | } 157 | 158 | rule Hex 159 | { 160 | Depends $(<) : $(>) ; 161 | MakeLocate $(<) : $(LOCATE_TARGET) ; 162 | Depends hex : $(<) ; 163 | Clean clean : $(<) ; 164 | } 165 | 166 | actions Hex 167 | { 168 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 169 | } 170 | 171 | rule Upload 172 | { 173 | Depends $(1) : $(2) ; 174 | Depends $(2) : $(3) ; 175 | NotFile $(1) ; 176 | Always $(1) ; 177 | Always $(2) ; 178 | UploadAction $(2) : $(3) ; 179 | } 180 | 181 | actions UploadAction 182 | { 183 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 184 | } 185 | 186 | # 187 | # Targets 188 | # 189 | 190 | # Grab everything from the core directory 191 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 192 | 193 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 194 | # can specify specific modules to pick up in PROJECT_MODULES 195 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 196 | 197 | # Grab everything from the current dir 198 | PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ; 199 | 200 | # Main output executable 201 | MAIN = $(PWD:B).elf ; 202 | 203 | Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 204 | Hex $(MAIN:B).hex : $(MAIN) ; 205 | 206 | # Upload targets 207 | for _p in $(PORTS) 208 | { 209 | Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ; 210 | } 211 | -------------------------------------------------------------------------------- /RF24-master/examples/GettingStarted/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/led_remote/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /RF24-master/examples/led_remote/led_remote.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example LED Remote 11 | * 12 | * This is an example of how to use the RF24 class to control a remote 13 | * bank of LED's using buttons on a remote control. 14 | * 15 | * On the 'remote', connect any number of buttons or switches from 16 | * an arduino pin to ground. Update 'button_pins' to reflect the 17 | * pins used. 18 | * 19 | * On the 'led' board, connect the same number of LED's from an 20 | * arduino pin to a resistor to ground. Update 'led_pins' to reflect 21 | * the pins used. Also connect a separate pin to ground and change 22 | * the 'role_pin'. This tells the sketch it's running on the LED board. 23 | * 24 | * Every time the buttons change on the remote, the entire state of 25 | * buttons is send to the led board, which displays the state. 26 | */ 27 | 28 | #include 29 | #include "nRF24L01.h" 30 | #include "RF24.h" 31 | #include "printf.h" 32 | 33 | // 34 | // Hardware configuration 35 | // 36 | 37 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 38 | 39 | RF24 radio(9,10); 40 | 41 | // sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver 42 | // Leave open to be the 'remote' transmitter 43 | const int role_pin = A4; 44 | 45 | // Pins on the remote for buttons 46 | const uint8_t button_pins[] = { 2,3,4,5,6,7 }; 47 | const uint8_t num_button_pins = sizeof(button_pins); 48 | 49 | // Pins on the LED board for LED's 50 | const uint8_t led_pins[] = { 2,3,4,5,6,7 }; 51 | const uint8_t num_led_pins = sizeof(led_pins); 52 | 53 | // 54 | // Topology 55 | // 56 | 57 | // Single radio pipe address for the 2 nodes to communicate. 58 | const uint64_t pipe = 0xE8E8F0F0E1LL; 59 | 60 | // 61 | // Role management 62 | // 63 | // Set up role. This sketch uses the same software for all the nodes in this 64 | // system. Doing so greatly simplifies testing. The hardware itself specifies 65 | // which node it is. 66 | // 67 | // This is done through the role_pin 68 | // 69 | 70 | // The various roles supported by this sketch 71 | typedef enum { role_remote = 1, role_led } role_e; 72 | 73 | // The debug-friendly names of those roles 74 | const char* role_friendly_name[] = { "invalid", "Remote", "LED Board"}; 75 | 76 | // The role of the current running sketch 77 | role_e role; 78 | 79 | // 80 | // Payload 81 | // 82 | 83 | uint8_t button_states[num_button_pins]; 84 | uint8_t led_states[num_led_pins]; 85 | 86 | // 87 | // Setup 88 | // 89 | 90 | void setup(void) 91 | { 92 | // 93 | // Role 94 | // 95 | 96 | // set up the role pin 97 | pinMode(role_pin, INPUT); 98 | digitalWrite(role_pin,HIGH); 99 | delay(20); // Just to get a solid reading on the role pin 100 | 101 | // read the address pin, establish our role 102 | if ( digitalRead(role_pin) ) 103 | role = role_remote; 104 | else 105 | role = role_led; 106 | 107 | // 108 | // Print preamble 109 | // 110 | 111 | Serial.begin(57600); 112 | printf_begin(); 113 | printf("\n\rRF24/examples/led_remote/\n\r"); 114 | printf("ROLE: %s\n\r",role_friendly_name[role]); 115 | 116 | // 117 | // Setup and configure rf radio 118 | // 119 | 120 | radio.begin(); 121 | 122 | // 123 | // Open pipes to other nodes for communication 124 | // 125 | 126 | // This simple sketch opens a single pipes for these two nodes to communicate 127 | // back and forth. One listens on it, the other talks to it. 128 | 129 | if ( role == role_remote ) 130 | { 131 | radio.openWritingPipe(pipe); 132 | } 133 | else 134 | { 135 | radio.openReadingPipe(1,pipe); 136 | } 137 | 138 | // 139 | // Start listening 140 | // 141 | 142 | if ( role == role_led ) 143 | radio.startListening(); 144 | 145 | // 146 | // Dump the configuration of the rf unit for debugging 147 | // 148 | 149 | radio.printDetails(); 150 | 151 | // 152 | // Set up buttons / LED's 153 | // 154 | 155 | // Set pull-up resistors for all buttons 156 | if ( role == role_remote ) 157 | { 158 | int i = num_button_pins; 159 | while(i--) 160 | { 161 | pinMode(button_pins[i],INPUT); 162 | digitalWrite(button_pins[i],HIGH); 163 | } 164 | } 165 | 166 | // Turn LED's ON until we start getting keys 167 | if ( role == role_led ) 168 | { 169 | int i = num_led_pins; 170 | while(i--) 171 | { 172 | pinMode(led_pins[i],OUTPUT); 173 | led_states[i] = HIGH; 174 | digitalWrite(led_pins[i],led_states[i]); 175 | } 176 | } 177 | 178 | } 179 | 180 | // 181 | // Loop 182 | // 183 | 184 | void loop(void) 185 | { 186 | // 187 | // Remote role. If the state of any button has changed, send the whole state of 188 | // all buttons. 189 | // 190 | 191 | if ( role == role_remote ) 192 | { 193 | // Get the current state of buttons, and 194 | // Test if the current state is different from the last state we sent 195 | int i = num_button_pins; 196 | bool different = false; 197 | while(i--) 198 | { 199 | uint8_t state = ! digitalRead(button_pins[i]); 200 | if ( state != button_states[i] ) 201 | { 202 | different = true; 203 | button_states[i] = state; 204 | } 205 | } 206 | 207 | // Send the state of the buttons to the LED board 208 | if ( different ) 209 | { 210 | printf("Now sending..."); 211 | bool ok = radio.write( button_states, num_button_pins ); 212 | if (ok) 213 | printf("ok\n\r"); 214 | else 215 | printf("failed\n\r"); 216 | } 217 | 218 | // Try again in a short while 219 | delay(20); 220 | } 221 | 222 | // 223 | // LED role. Receive the state of all buttons, and reflect that in the LEDs 224 | // 225 | 226 | if ( role == role_led ) 227 | { 228 | // if there is data ready 229 | if ( radio.available() ) 230 | { 231 | // Dump the payloads until we've gotten everything 232 | bool done = false; 233 | while (!done) 234 | { 235 | // Fetch the payload, and see if this was the last one. 236 | done = radio.read( button_states, num_button_pins ); 237 | 238 | // Spew it 239 | printf("Got buttons\n\r"); 240 | 241 | // For each button, if the button now on, then toggle the LED 242 | int i = num_led_pins; 243 | while(i--) 244 | { 245 | if ( button_states[i] ) 246 | { 247 | led_states[i] ^= HIGH; 248 | digitalWrite(led_pins[i],led_states[i]); 249 | } 250 | } 251 | } 252 | } 253 | } 254 | } 255 | // vim:ai:cin:sts=2 sw=2 ft=cpp 256 | -------------------------------------------------------------------------------- /RF24-master/examples/led_remote/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/nordic_fob/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = RF24 SPI ; 4 | PROJECT_DIRS = $(PWD) ; 5 | 6 | # (2) Board Information 7 | 8 | UPLOAD_PROTOCOL ?= stk500v1 ; 9 | UPLOAD_SPEED ?= 115200 ; 10 | MCU ?= atmega328p ; 11 | F_CPU ?= 16000000 ; 12 | CORE ?= arduino ; 13 | VARIANT ?= standard ; 14 | ARDUINO_VERSION ?= 100 ; 15 | 16 | # (3) USB Ports 17 | 18 | PORTS = p4 p6 p9 u0 u1 u2 ; 19 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 20 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 21 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 22 | PORT_u0 = /dev/ttyUSB0 ; 23 | PORT_u1 = /dev/ttyUSB1 ; 24 | PORT_u2 = /dev/ttyUSB2 ; 25 | 26 | # (4) Location of AVR tools 27 | # 28 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 29 | # distribution. 30 | 31 | if $(OS) = MACOSX 32 | { 33 | AVR_BIN = /usr/local/avrtools/bin ; 34 | AVR_ETC = /usr/local/avrtools/etc ; 35 | AVR_INCLUDE = /usr/local/avrtools/include ; 36 | } 37 | else 38 | { 39 | AVR_BIN = /usr/bin ; 40 | AVR_INCLUDE = /usr/lib/avr/include ; 41 | AVR_ETC = /etc ; 42 | } 43 | 44 | # (5) Directories where Arduino core and libraries are located 45 | 46 | ARDUINO_DIR ?= /opt/Arduino ; 47 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 48 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 49 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 50 | 51 | # 52 | # -------------------------------------------------- 53 | # Below this line usually never needs to be modified 54 | # 55 | 56 | # Tool locations 57 | 58 | CC = $(AVR_BIN)/avr-gcc ; 59 | C++ = $(AVR_BIN)/avr-g++ ; 60 | LINK = $(AVR_BIN)/avr-gcc ; 61 | AR = $(AVR_BIN)/avr-ar rcs ; 62 | RANLIB = ; 63 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 64 | AVRDUDE = $(AVR_BIN)/avrdude ; 65 | 66 | # Flags 67 | 68 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 69 | OPTIM = -Os ; 70 | CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 71 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 72 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 73 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 74 | 75 | # Search everywhere for headers 76 | 77 | HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 78 | 79 | # Output locations 80 | 81 | LOCATE_TARGET = $(F_CPU) ; 82 | LOCATE_SOURCE = $(F_CPU) ; 83 | 84 | # 85 | # Custom rules 86 | # 87 | 88 | rule GitVersion 89 | { 90 | Always $(<) ; 91 | Depends all : $(<) ; 92 | } 93 | 94 | actions GitVersion 95 | { 96 | echo "const char program_version[] = \"\\" > $(<) 97 | git log -1 --pretty=format:%h >> $(<) 98 | echo "\";" >> $(<) 99 | } 100 | 101 | GitVersion version.h ; 102 | 103 | rule Pde 104 | { 105 | Depends $(<) : $(>) ; 106 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 107 | Clean clean : $(<) ; 108 | } 109 | 110 | if ( $(ARDUINO_VERSION) < 100 ) 111 | { 112 | ARDUINO_H = WProgram.h ; 113 | } 114 | else 115 | { 116 | ARDUINO_H = Arduino.h ; 117 | } 118 | 119 | actions Pde 120 | { 121 | echo "#include <$(ARDUINO_H)>" > $(<) 122 | echo "#line 1 \"$(>)\"" >> $(<) 123 | cat $(>) >> $(<) 124 | } 125 | 126 | rule C++Pde 127 | { 128 | local _CPP = $(>:B).cpp ; 129 | Pde $(_CPP) : $(>) ; 130 | C++ $(<) : $(_CPP) ; 131 | } 132 | 133 | rule UserObject 134 | { 135 | switch $(>:S) 136 | { 137 | case .ino : C++Pde $(<) : $(>) ; 138 | case .pde : C++Pde $(<) : $(>) ; 139 | } 140 | } 141 | 142 | rule Objects 143 | { 144 | local _i ; 145 | 146 | for _i in [ FGristFiles $(<) ] 147 | { 148 | local _b = $(_i:B)$(SUFOBJ) ; 149 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 150 | Object $(_o) : $(_i) ; 151 | Depends obj : $(_o) ; 152 | } 153 | } 154 | 155 | rule Library 156 | { 157 | LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; 158 | Objects $(>) ; 159 | } 160 | 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | rule Hex 168 | { 169 | Depends $(<) : $(>) ; 170 | MakeLocate $(<) : $(LOCATE_TARGET) ; 171 | Depends hex : $(<) ; 172 | Clean clean : $(<) ; 173 | } 174 | 175 | actions Hex 176 | { 177 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 178 | } 179 | 180 | rule Upload 181 | { 182 | Depends $(1) : $(2) ; 183 | Depends $(2) : $(3) ; 184 | NotFile $(1) ; 185 | Always $(1) ; 186 | Always $(2) ; 187 | UploadAction $(2) : $(3) ; 188 | } 189 | 190 | actions UploadAction 191 | { 192 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 193 | } 194 | 195 | rule Arduino 196 | { 197 | LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; 198 | Main $(<) : $(>) ; 199 | LinkLibraries $(<) : libs core ; 200 | Hex $(<:B).hex : $(<) ; 201 | for _p in $(PORTS) 202 | { 203 | Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; 204 | } 205 | } 206 | 207 | # 208 | # Targets 209 | # 210 | 211 | # Grab everything from the core directory 212 | Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 213 | 214 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 215 | # can specify specific modules to pick up in PROJECT_MODULES 216 | Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 217 | 218 | # Main output executable 219 | Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; 220 | -------------------------------------------------------------------------------- /RF24-master/examples/nordic_fob/nordic_fob.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example Nordic FOB Receiver 11 | * 12 | * This is an example of how to use the RF24 class to receive signals from the 13 | * Sparkfun Nordic FOB. Thanks to Kirk Mower for providing test hardware. 14 | * 15 | * See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/ 16 | */ 17 | 18 | #include 19 | #include 20 | #include "nRF24L01.h" 21 | #include "printf.h" 22 | 23 | // 24 | // Hardware configuration 25 | // 26 | 27 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 28 | 29 | RF24 radio(9,10); 30 | 31 | // 32 | // Payload 33 | // 34 | 35 | struct payload_t 36 | { 37 | uint8_t buttons; 38 | uint16_t id; 39 | uint8_t empty; 40 | }; 41 | 42 | const char* button_names[] = { "Up", "Down", "Left", "Right", "Center" }; 43 | const int num_buttons = 5; 44 | 45 | // 46 | // Forward declarations 47 | // 48 | 49 | uint16_t flip_endian(uint16_t in); 50 | 51 | // 52 | // Setup 53 | // 54 | 55 | void setup(void) 56 | { 57 | // 58 | // Print preamble 59 | // 60 | 61 | Serial.begin(57600); 62 | printf_begin(); 63 | printf("\r\nRF24/examples/nordic_fob/\r\n"); 64 | 65 | // 66 | // Setup and configure rf radio according to the built-in parameters 67 | // of the FOB. 68 | // 69 | 70 | radio.begin(); 71 | radio.setChannel(2); 72 | radio.setPayloadSize(4); 73 | radio.setAutoAck(false); 74 | radio.setCRCLength(RF24_CRC_8); 75 | radio.openReadingPipe(1,0xE7E7E7E7E7LL); 76 | 77 | // 78 | // Start listening 79 | // 80 | 81 | radio.startListening(); 82 | 83 | // 84 | // Dump the configuration of the rf unit for debugging 85 | // 86 | 87 | radio.printDetails(); 88 | } 89 | 90 | // 91 | // Loop 92 | // 93 | 94 | void loop(void) 95 | { 96 | // 97 | // Receive each packet, dump it out 98 | // 99 | 100 | // if there is data ready 101 | if ( radio.available() ) 102 | { 103 | // Get the packet from the radio 104 | payload_t payload; 105 | radio.read( &payload, sizeof(payload) ); 106 | 107 | // Print the ID of this message. Note that the message 108 | // is sent 'big-endian', so we have to flip it. 109 | printf("#%05u Buttons ",flip_endian(payload.id)); 110 | 111 | // Print the name of each button 112 | int i = num_buttons; 113 | while (i--) 114 | { 115 | if ( ! ( payload.buttons & _BV(i) ) ) 116 | { 117 | printf("%s ",button_names[i]); 118 | } 119 | } 120 | 121 | // If no buttons, print None 122 | if ( payload.buttons == _BV(num_buttons) - 1 ) 123 | printf("None"); 124 | 125 | printf("\r\n"); 126 | } 127 | } 128 | 129 | // 130 | // Helper functions 131 | // 132 | 133 | // Change a big-endian word into a little-endian 134 | uint16_t flip_endian(uint16_t in) 135 | { 136 | uint16_t low = in >> 8; 137 | uint16_t high = in << 8; 138 | 139 | return high | low; 140 | } 141 | 142 | // vim:cin:ai:sts=2 sw=2 ft=cpp 143 | -------------------------------------------------------------------------------- /RF24-master/examples/nordic_fob/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | PROJECT_DIRS = $(PWD) ; 5 | 6 | # (2) Board Information 7 | 8 | UPLOAD_PROTOCOL ?= arduino ; 9 | UPLOAD_SPEED ?= 115200 ; 10 | MCU ?= atmega328p ; 11 | F_CPU ?= 16000000 ; 12 | CORE ?= arduino ; 13 | VARIANT ?= standard ; 14 | ARDUINO_VERSION ?= 100 ; 15 | 16 | # (3) USB Ports 17 | 18 | PORTS = p4 p6 p9 u0 u1 u2 ; 19 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 20 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 21 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 22 | PORT_u0 = /dev/ttyUSB0 ; 23 | PORT_u1 = /dev/ttyUSB1 ; 24 | PORT_u2 = /dev/ttyUSB2 ; 25 | 26 | # (4) Location of AVR tools 27 | # 28 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 29 | # distribution. 30 | 31 | if $(OS) = MACOSX 32 | { 33 | AVR_BIN ?= /usr/local/avrtools/bin ; 34 | AVR_ETC = /usr/local/avrtools/etc ; 35 | AVR_INCLUDE = /usr/local/avrtools/include ; 36 | } 37 | else 38 | { 39 | AVR_BIN ?= /usr/bin ; 40 | AVR_INCLUDE = /usr/lib/avr/include ; 41 | AVR_ETC = /etc ; 42 | } 43 | 44 | # (5) Directories where Arduino core and libraries are located 45 | 46 | ARDUINO_DIR ?= /opt/Arduino ; 47 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 48 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 49 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 50 | 51 | # 52 | # -------------------------------------------------- 53 | # Below this line usually never needs to be modified 54 | # 55 | 56 | # Tool locations 57 | 58 | CC = $(AVR_BIN)/avr-gcc ; 59 | C++ = $(AVR_BIN)/avr-g++ ; 60 | LINK = $(AVR_BIN)/avr-gcc ; 61 | AR = $(AVR_BIN)/avr-ar rcs ; 62 | RANLIB = ; 63 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 64 | AVRDUDE ?= $(AVR_BIN)/avrdude ; 65 | 66 | # Flags 67 | 68 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 69 | OPTIM = -Os ; 70 | CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 71 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 72 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 73 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 74 | 75 | # Search everywhere for headers 76 | 77 | HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 78 | 79 | # Output locations 80 | 81 | LOCATE_TARGET = $(F_CPU) ; 82 | LOCATE_SOURCE = $(F_CPU) ; 83 | 84 | # 85 | # Custom rules 86 | # 87 | 88 | rule GitVersion 89 | { 90 | Always $(<) ; 91 | Depends all : $(<) ; 92 | } 93 | 94 | actions GitVersion 95 | { 96 | echo "const char program_version[] = \"\\" > $(<) 97 | git log -1 --pretty=format:%h >> $(<) 98 | echo "\";" >> $(<) 99 | } 100 | 101 | GitVersion version.h ; 102 | 103 | rule Pde 104 | { 105 | Depends $(<) : $(>) ; 106 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 107 | Clean clean : $(<) ; 108 | } 109 | 110 | if ( $(ARDUINO_VERSION) < 100 ) 111 | { 112 | ARDUINO_H = WProgram.h ; 113 | } 114 | else 115 | { 116 | ARDUINO_H = Arduino.h ; 117 | } 118 | 119 | actions Pde 120 | { 121 | echo "#include <$(ARDUINO_H)>" > $(<) 122 | echo "#line 1 \"$(>)\"" >> $(<) 123 | cat $(>) >> $(<) 124 | } 125 | 126 | rule C++Pde 127 | { 128 | local _CPP = $(>:B).cpp ; 129 | Pde $(_CPP) : $(>) ; 130 | C++ $(<) : $(_CPP) ; 131 | } 132 | 133 | rule UserObject 134 | { 135 | switch $(>:S) 136 | { 137 | case .ino : C++Pde $(<) : $(>) ; 138 | case .pde : C++Pde $(<) : $(>) ; 139 | } 140 | } 141 | 142 | rule Objects 143 | { 144 | local _i ; 145 | 146 | for _i in [ FGristFiles $(<) ] 147 | { 148 | local _b = $(_i:B)$(SUFOBJ) ; 149 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 150 | Object $(_o) : $(_i) ; 151 | Depends obj : $(_o) ; 152 | } 153 | } 154 | 155 | rule Library 156 | { 157 | LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; 158 | Objects $(>) ; 159 | } 160 | 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | rule Hex 168 | { 169 | Depends $(<) : $(>) ; 170 | MakeLocate $(<) : $(LOCATE_TARGET) ; 171 | Depends hex : $(<) ; 172 | Clean clean : $(<) ; 173 | } 174 | 175 | actions Hex 176 | { 177 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 178 | } 179 | 180 | rule Upload 181 | { 182 | Depends $(1) : $(2) ; 183 | Depends $(2) : $(3) ; 184 | NotFile $(1) ; 185 | Always $(1) ; 186 | Always $(2) ; 187 | UploadAction $(2) : $(3) ; 188 | } 189 | 190 | actions UploadAction 191 | { 192 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 193 | } 194 | 195 | rule Arduino 196 | { 197 | LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; 198 | Main $(<) : $(>) ; 199 | LinkLibraries $(<) : core libs ; 200 | Hex $(<:B).hex : $(<) ; 201 | for _p in $(PORTS) 202 | { 203 | Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; 204 | } 205 | } 206 | 207 | # 208 | # Targets 209 | # 210 | 211 | # Grab everything from the core directory 212 | Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 213 | 214 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 215 | # can specify specific modules to pick up in PROJECT_MODULES 216 | Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 217 | 218 | # Main output executable 219 | Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; 220 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair/pingpair.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example RF Radio Ping Pair 11 | * 12 | * This is an example of how to use the RF24 class. Write this sketch to two different nodes, 13 | * connect the role_pin to ground on one. The ping node sends the current time to the pong node, 14 | * which responds by sending the value back. The ping node can then see how long the whole cycle 15 | * took. 16 | */ 17 | 18 | #include 19 | #include "nRF24L01.h" 20 | #include "RF24.h" 21 | #include "printf.h" 22 | 23 | // 24 | // Hardware configuration 25 | // 26 | 27 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 28 | 29 | RF24 radio(9,10); 30 | 31 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 32 | // Leave open to be the 'ping' transmitter 33 | const int role_pin = 7; 34 | 35 | // 36 | // Topology 37 | // 38 | 39 | // Radio pipe addresses for the 2 nodes to communicate. 40 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 41 | 42 | // 43 | // Role management 44 | // 45 | // Set up role. This sketch uses the same software for all the nodes 46 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 47 | // which node it is. 48 | // 49 | // This is done through the role_pin 50 | // 51 | 52 | // The various roles supported by this sketch 53 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 54 | 55 | // The debug-friendly names of those roles 56 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 57 | 58 | // The role of the current running sketch 59 | role_e role; 60 | 61 | void setup(void) 62 | { 63 | // 64 | // Role 65 | // 66 | 67 | // set up the role pin 68 | pinMode(role_pin, INPUT); 69 | digitalWrite(role_pin,HIGH); 70 | delay(20); // Just to get a solid reading on the role pin 71 | 72 | // read the address pin, establish our role 73 | if ( ! digitalRead(role_pin) ) 74 | role = role_ping_out; 75 | else 76 | role = role_pong_back; 77 | 78 | // 79 | // Print preamble 80 | // 81 | 82 | Serial.begin(57600); 83 | printf_begin(); 84 | printf("\n\rRF24/examples/pingpair/\n\r"); 85 | printf("ROLE: %s\n\r",role_friendly_name[role]); 86 | 87 | // 88 | // Setup and configure rf radio 89 | // 90 | 91 | radio.begin(); 92 | 93 | // optionally, increase the delay between retries & # of retries 94 | radio.setRetries(15,15); 95 | 96 | // optionally, reduce the payload size. seems to 97 | // improve reliability 98 | radio.setPayloadSize(8); 99 | 100 | // 101 | // Open pipes to other nodes for communication 102 | // 103 | 104 | // This simple sketch opens two pipes for these two nodes to communicate 105 | // back and forth. 106 | // Open 'our' pipe for writing 107 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 108 | 109 | if ( role == role_ping_out ) 110 | { 111 | radio.openWritingPipe(pipes[0]); 112 | radio.openReadingPipe(1,pipes[1]); 113 | } 114 | else 115 | { 116 | radio.openWritingPipe(pipes[1]); 117 | radio.openReadingPipe(1,pipes[0]); 118 | } 119 | 120 | // 121 | // Start listening 122 | // 123 | 124 | radio.startListening(); 125 | 126 | // 127 | // Dump the configuration of the rf unit for debugging 128 | // 129 | 130 | radio.printDetails(); 131 | } 132 | 133 | void loop(void) 134 | { 135 | // 136 | // Ping out role. Repeatedly send the current time 137 | // 138 | 139 | if (role == role_ping_out) 140 | { 141 | // First, stop listening so we can talk. 142 | radio.stopListening(); 143 | 144 | // Take the time, and send it. This will block until complete 145 | unsigned long time = millis(); 146 | printf("Now sending %lu...",time); 147 | bool ok = radio.write( &time, sizeof(unsigned long) ); 148 | 149 | if (ok) 150 | printf("ok..."); 151 | else 152 | printf("failed.\n\r"); 153 | 154 | // Now, continue listening 155 | radio.startListening(); 156 | 157 | // Wait here until we get a response, or timeout (250ms) 158 | unsigned long started_waiting_at = millis(); 159 | bool timeout = false; 160 | while ( ! radio.available() && ! timeout ) 161 | if (millis() - started_waiting_at > 200 ) 162 | timeout = true; 163 | 164 | // Describe the results 165 | if ( timeout ) 166 | { 167 | printf("Failed, response timed out.\n\r"); 168 | } 169 | else 170 | { 171 | // Grab the response, compare, and send to debugging spew 172 | unsigned long got_time; 173 | radio.read( &got_time, sizeof(unsigned long) ); 174 | 175 | // Spew it 176 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 177 | } 178 | 179 | // Try again 1s later 180 | delay(1000); 181 | } 182 | 183 | // 184 | // Pong back role. Receive each packet, dump it out, and send it back 185 | // 186 | 187 | if ( role == role_pong_back ) 188 | { 189 | // if there is data ready 190 | if ( radio.available() ) 191 | { 192 | // Dump the payloads until we've gotten everything 193 | unsigned long got_time; 194 | bool done = false; 195 | while (!done) 196 | { 197 | // Fetch the payload, and see if this was the last one. 198 | done = radio.read( &got_time, sizeof(unsigned long) ); 199 | 200 | // Spew it 201 | printf("Got payload %lu...",got_time); 202 | 203 | // Delay just a little bit to let the other unit 204 | // make the transition to receiver 205 | delay(20); 206 | } 207 | 208 | // First, stop listening so we can talk 209 | radio.stopListening(); 210 | 211 | // Send the final one back. 212 | radio.write( &got_time, sizeof(unsigned long) ); 213 | printf("Sent response.\n\r"); 214 | 215 | // Now, resume listening so we catch the next packets. 216 | radio.startListening(); 217 | } 218 | } 219 | } 220 | // vim:cin:ai:sts=2 sw=2 ft=cpp 221 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_dyn/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_dyn/pingpair_dyn.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example using Dynamic Payloads 11 | * 12 | * This is an example of how to use payloads of a varying (dynamic) size. 13 | */ 14 | 15 | #include 16 | #include "nRF24L01.h" 17 | #include "RF24.h" 18 | #include "printf.h" 19 | 20 | // 21 | // Hardware configuration 22 | // 23 | 24 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 25 | 26 | RF24 radio(9,10); 27 | 28 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 29 | // Leave open to be the 'ping' transmitter 30 | const int role_pin = 7; 31 | 32 | // 33 | // Topology 34 | // 35 | 36 | // Radio pipe addresses for the 2 nodes to communicate. 37 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 38 | 39 | // 40 | // Role management 41 | // 42 | // Set up role. This sketch uses the same software for all the nodes 43 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 44 | // which node it is. 45 | // 46 | // This is done through the role_pin 47 | // 48 | 49 | // The various roles supported by this sketch 50 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 51 | 52 | // The debug-friendly names of those roles 53 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 54 | 55 | // The role of the current running sketch 56 | role_e role; 57 | 58 | // 59 | // Payload 60 | // 61 | 62 | const int min_payload_size = 4; 63 | const int max_payload_size = 32; 64 | const int payload_size_increments_by = 2; 65 | int next_payload_size = min_payload_size; 66 | 67 | char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char 68 | 69 | void setup(void) 70 | { 71 | // 72 | // Role 73 | // 74 | 75 | // set up the role pin 76 | pinMode(role_pin, INPUT); 77 | digitalWrite(role_pin,HIGH); 78 | delay(20); // Just to get a solid reading on the role pin 79 | 80 | // read the address pin, establish our role 81 | if ( digitalRead(role_pin) ) 82 | role = role_ping_out; 83 | else 84 | role = role_pong_back; 85 | 86 | // 87 | // Print preamble 88 | // 89 | 90 | Serial.begin(57600); 91 | printf_begin(); 92 | printf("\n\rRF24/examples/pingpair_dyn/\n\r"); 93 | printf("ROLE: %s\n\r",role_friendly_name[role]); 94 | 95 | // 96 | // Setup and configure rf radio 97 | // 98 | 99 | radio.begin(); 100 | 101 | // enable dynamic payloads 102 | radio.enableDynamicPayloads(); 103 | 104 | // optionally, increase the delay between retries & # of retries 105 | radio.setRetries(15,15); 106 | 107 | // 108 | // Open pipes to other nodes for communication 109 | // 110 | 111 | // This simple sketch opens two pipes for these two nodes to communicate 112 | // back and forth. 113 | // Open 'our' pipe for writing 114 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 115 | 116 | if ( role == role_ping_out ) 117 | { 118 | radio.openWritingPipe(pipes[0]); 119 | radio.openReadingPipe(1,pipes[1]); 120 | } 121 | else 122 | { 123 | radio.openWritingPipe(pipes[1]); 124 | radio.openReadingPipe(1,pipes[0]); 125 | } 126 | 127 | // 128 | // Start listening 129 | // 130 | 131 | radio.startListening(); 132 | 133 | // 134 | // Dump the configuration of the rf unit for debugging 135 | // 136 | 137 | radio.printDetails(); 138 | } 139 | 140 | void loop(void) 141 | { 142 | // 143 | // Ping out role. Repeatedly send the current time 144 | // 145 | 146 | if (role == role_ping_out) 147 | { 148 | // The payload will always be the same, what will change is how much of it we send. 149 | static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012"; 150 | 151 | // First, stop listening so we can talk. 152 | radio.stopListening(); 153 | 154 | // Take the time, and send it. This will block until complete 155 | printf("Now sending length %i...",next_payload_size); 156 | radio.write( send_payload, next_payload_size ); 157 | 158 | // Now, continue listening 159 | radio.startListening(); 160 | 161 | // Wait here until we get a response, or timeout 162 | unsigned long started_waiting_at = millis(); 163 | bool timeout = false; 164 | while ( ! radio.available() && ! timeout ) 165 | if (millis() - started_waiting_at > 500 ) 166 | timeout = true; 167 | 168 | // Describe the results 169 | if ( timeout ) 170 | { 171 | printf("Failed, response timed out.\n\r"); 172 | } 173 | else 174 | { 175 | // Grab the response, compare, and send to debugging spew 176 | uint8_t len = radio.getDynamicPayloadSize(); 177 | radio.read( receive_payload, len ); 178 | 179 | // Put a zero at the end for easy printing 180 | receive_payload[len] = 0; 181 | 182 | // Spew it 183 | printf("Got response size=%i value=%s\n\r",len,receive_payload); 184 | } 185 | 186 | // Update size for next time. 187 | next_payload_size += payload_size_increments_by; 188 | if ( next_payload_size > max_payload_size ) 189 | next_payload_size = min_payload_size; 190 | 191 | // Try again 1s later 192 | delay(1000); 193 | } 194 | 195 | // 196 | // Pong back role. Receive each packet, dump it out, and send it back 197 | // 198 | 199 | if ( role == role_pong_back ) 200 | { 201 | // if there is data ready 202 | if ( radio.available() ) 203 | { 204 | // Dump the payloads until we've gotten everything 205 | uint8_t len; 206 | bool done = false; 207 | while (!done) 208 | { 209 | // Fetch the payload, and see if this was the last one. 210 | len = radio.getDynamicPayloadSize(); 211 | done = radio.read( receive_payload, len ); 212 | 213 | // Put a zero at the end for easy printing 214 | receive_payload[len] = 0; 215 | 216 | // Spew it 217 | printf("Got payload size=%i value=%s\n\r",len,receive_payload); 218 | } 219 | 220 | // First, stop listening so we can talk 221 | radio.stopListening(); 222 | 223 | // Send the final one back. 224 | radio.write( receive_payload, len ); 225 | printf("Sent response.\n\r"); 226 | 227 | // Now, resume listening so we catch the next packets. 228 | radio.startListening(); 229 | } 230 | } 231 | } 232 | // vim:cin:ai:sts=2 sw=2 ft=cpp 233 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_dyn/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_irq/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | PROJECT_DIRS = $(PWD) ; 5 | 6 | # (2) Board Information 7 | 8 | UPLOAD_PROTOCOL ?= arduino ; 9 | UPLOAD_SPEED ?= 115200 ; 10 | MCU ?= atmega328p ; 11 | F_CPU ?= 16000000 ; 12 | CORE ?= arduino ; 13 | VARIANT ?= standard ; 14 | ARDUINO_VERSION ?= 100 ; 15 | 16 | # (3) USB Ports 17 | 18 | PORTS = p4 p6 p9 u0 u1 u2 ; 19 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 20 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 21 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 22 | PORT_u0 = /dev/ttyUSB0 ; 23 | PORT_u1 = /dev/ttyUSB1 ; 24 | PORT_u2 = /dev/ttyUSB2 ; 25 | 26 | # (4) Location of AVR tools 27 | # 28 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 29 | # distribution. 30 | 31 | if $(OS) = MACOSX 32 | { 33 | AVR_BIN ?= /usr/local/avrtools/bin ; 34 | AVR_ETC = /usr/local/avrtools/etc ; 35 | AVR_INCLUDE = /usr/local/avrtools/include ; 36 | } 37 | else 38 | { 39 | AVR_BIN ?= /usr/bin ; 40 | AVR_INCLUDE ?= /usr/lib/avr/include ; 41 | AVR_ETC = /etc ; 42 | } 43 | 44 | # (5) Directories where Arduino core and libraries are located 45 | 46 | ARDUINO_DIR ?= /opt/Arduino ; 47 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 48 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 49 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 50 | 51 | # 52 | # -------------------------------------------------- 53 | # Below this line usually never needs to be modified 54 | # 55 | 56 | # Tool locations 57 | 58 | CC = $(AVR_BIN)/avr-gcc ; 59 | C++ = $(AVR_BIN)/avr-g++ ; 60 | LINK = $(AVR_BIN)/avr-gcc ; 61 | AR = $(AVR_BIN)/avr-ar rcs ; 62 | RANLIB = ; 63 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 64 | AVRDUDE ?= $(AVR_BIN)/avrdude ; 65 | 66 | # Flags 67 | 68 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 69 | OPTIM = -Os ; 70 | CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 71 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 72 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 73 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 74 | 75 | # Search everywhere for headers 76 | 77 | HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 78 | 79 | # Output locations 80 | 81 | LOCATE_TARGET = $(F_CPU) ; 82 | LOCATE_SOURCE = $(F_CPU) ; 83 | 84 | # 85 | # Custom rules 86 | # 87 | 88 | rule GitVersion 89 | { 90 | Always $(<) ; 91 | Depends all : $(<) ; 92 | } 93 | 94 | actions GitVersion 95 | { 96 | echo "const char program_version[] = \"\\" > $(<) 97 | git log -1 --pretty=format:%h >> $(<) 98 | echo "\";" >> $(<) 99 | } 100 | 101 | GitVersion version.h ; 102 | 103 | rule Pde 104 | { 105 | Depends $(<) : $(>) ; 106 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 107 | Clean clean : $(<) ; 108 | } 109 | 110 | if ( $(ARDUINO_VERSION) < 100 ) 111 | { 112 | ARDUINO_H = WProgram.h ; 113 | } 114 | else 115 | { 116 | ARDUINO_H = Arduino.h ; 117 | } 118 | 119 | actions Pde 120 | { 121 | echo "#include <$(ARDUINO_H)>" > $(<) 122 | echo "#line 1 \"$(>)\"" >> $(<) 123 | cat $(>) >> $(<) 124 | } 125 | 126 | rule C++Pde 127 | { 128 | local _CPP = $(>:B).cpp ; 129 | Pde $(_CPP) : $(>) ; 130 | C++ $(<) : $(_CPP) ; 131 | } 132 | 133 | rule UserObject 134 | { 135 | switch $(>:S) 136 | { 137 | case .ino : C++Pde $(<) : $(>) ; 138 | case .pde : C++Pde $(<) : $(>) ; 139 | } 140 | } 141 | 142 | rule Objects 143 | { 144 | local _i ; 145 | 146 | for _i in [ FGristFiles $(<) ] 147 | { 148 | local _b = $(_i:B)$(SUFOBJ) ; 149 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 150 | Object $(_o) : $(_i) ; 151 | Depends obj : $(_o) ; 152 | } 153 | } 154 | 155 | rule Library 156 | { 157 | LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; 158 | Objects $(>) ; 159 | } 160 | 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | rule Hex 168 | { 169 | Depends $(<) : $(>) ; 170 | MakeLocate $(<) : $(LOCATE_TARGET) ; 171 | Depends hex : $(<) ; 172 | Clean clean : $(<) ; 173 | } 174 | 175 | actions Hex 176 | { 177 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 178 | } 179 | 180 | rule Upload 181 | { 182 | Depends $(1) : $(2) ; 183 | Depends $(2) : $(3) ; 184 | NotFile $(1) ; 185 | Always $(1) ; 186 | Always $(2) ; 187 | UploadAction $(2) : $(3) ; 188 | } 189 | 190 | actions UploadAction 191 | { 192 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 193 | } 194 | 195 | rule Arduino 196 | { 197 | LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; 198 | Main $(<) : $(>) ; 199 | LinkLibraries $(<) : core libs ; 200 | Hex $(<:B).hex : $(<) ; 201 | for _p in $(PORTS) 202 | { 203 | Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; 204 | } 205 | } 206 | 207 | # 208 | # Targets 209 | # 210 | 211 | # Grab everything from the core directory 212 | Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 213 | 214 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 215 | # can specify specific modules to pick up in PROJECT_MODULES 216 | Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 217 | 218 | # Main output executable 219 | Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; 220 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_irq/pingpair_irq.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example of using interrupts 11 | * 12 | * This is an example of how to user interrupts to interact with the radio. 13 | * It builds on the pingpair_pl example, and uses ack payloads. 14 | */ 15 | 16 | #include 17 | #include "nRF24L01.h" 18 | #include "RF24.h" 19 | #include "printf.h" 20 | 21 | // 22 | // Hardware configuration 23 | // 24 | 25 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 26 | 27 | RF24 radio(8,9); 28 | 29 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 30 | // Leave open to be the 'ping' transmitter 31 | const short role_pin = 7; 32 | 33 | // 34 | // Topology 35 | // 36 | 37 | // Single radio pipe address for the 2 nodes to communicate. 38 | const uint64_t pipe = 0xE8E8F0F0E1LL; 39 | 40 | // 41 | // Role management 42 | // 43 | // Set up role. This sketch uses the same software for all the nodes in this 44 | // system. Doing so greatly simplifies testing. The hardware itself specifies 45 | // which node it is. 46 | // 47 | // This is done through the role_pin 48 | // 49 | 50 | // The various roles supported by this sketch 51 | typedef enum { role_sender = 1, role_receiver } role_e; 52 | 53 | // The debug-friendly names of those roles 54 | const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; 55 | 56 | // The role of the current running sketch 57 | role_e role; 58 | 59 | // Interrupt handler, check the radio because we got an IRQ 60 | void check_radio(void); 61 | 62 | void setup(void) 63 | { 64 | // 65 | // Role 66 | // 67 | 68 | // set up the role pin 69 | pinMode(role_pin, INPUT); 70 | digitalWrite(role_pin,HIGH); 71 | delay(20); // Just to get a solid reading on the role pin 72 | 73 | // read the address pin, establish our role 74 | if ( digitalRead(role_pin) ) 75 | role = role_sender; 76 | else 77 | role = role_receiver; 78 | 79 | // 80 | // Print preamble 81 | // 82 | 83 | Serial.begin(57600); 84 | printf_begin(); 85 | printf("\n\rRF24/examples/pingpair_irq/\n\r"); 86 | printf("ROLE: %s\n\r",role_friendly_name[role]); 87 | 88 | // 89 | // Setup and configure rf radio 90 | // 91 | 92 | radio.begin(); 93 | 94 | // We will be using the Ack Payload feature, so please enable it 95 | radio.enableAckPayload(); 96 | 97 | // 98 | // Open pipes to other nodes for communication 99 | // 100 | 101 | // This simple sketch opens a single pipe for these two nodes to communicate 102 | // back and forth. One listens on it, the other talks to it. 103 | 104 | if ( role == role_sender ) 105 | { 106 | radio.openWritingPipe(pipe); 107 | } 108 | else 109 | { 110 | radio.openReadingPipe(1,pipe); 111 | } 112 | 113 | // 114 | // Start listening 115 | // 116 | 117 | if ( role == role_receiver ) 118 | radio.startListening(); 119 | 120 | // 121 | // Dump the configuration of the rf unit for debugging 122 | // 123 | 124 | radio.printDetails(); 125 | 126 | // 127 | // Attach interrupt handler to interrupt #0 (using pin 2) 128 | // on BOTH the sender and receiver 129 | // 130 | 131 | attachInterrupt(0, check_radio, FALLING); 132 | } 133 | 134 | static uint32_t message_count = 0; 135 | 136 | void loop(void) 137 | { 138 | // 139 | // Sender role. Repeatedly send the current time 140 | // 141 | 142 | if (role == role_sender) 143 | { 144 | // Take the time, and send it. 145 | unsigned long time = millis(); 146 | printf("Now sending %lu\n\r",time); 147 | radio.startWrite( &time, sizeof(unsigned long) ); 148 | 149 | // Try again soon 150 | delay(2000); 151 | } 152 | 153 | // 154 | // Receiver role: Does nothing! All the work is in IRQ 155 | // 156 | 157 | } 158 | 159 | void check_radio(void) 160 | { 161 | // What happened? 162 | bool tx,fail,rx; 163 | radio.whatHappened(tx,fail,rx); 164 | 165 | // Have we successfully transmitted? 166 | if ( tx ) 167 | { 168 | if ( role == role_sender ) 169 | printf("Send:OK\n\r"); 170 | 171 | if ( role == role_receiver ) 172 | printf("Ack Payload:Sent\n\r"); 173 | } 174 | 175 | // Have we failed to transmit? 176 | if ( fail ) 177 | { 178 | if ( role == role_sender ) 179 | printf("Send:Failed\n\r"); 180 | 181 | if ( role == role_receiver ) 182 | printf("Ack Payload:Failed\n\r"); 183 | } 184 | 185 | // Transmitter can power down for now, because 186 | // the transmission is done. 187 | if ( ( tx || fail ) && ( role == role_sender ) ) 188 | radio.powerDown(); 189 | 190 | // Did we receive a message? 191 | if ( rx ) 192 | { 193 | // If we're the sender, we've received an ack payload 194 | if ( role == role_sender ) 195 | { 196 | radio.read(&message_count,sizeof(message_count)); 197 | printf("Ack:%lu\n\r",message_count); 198 | } 199 | 200 | // If we're the receiver, we've received a time message 201 | if ( role == role_receiver ) 202 | { 203 | // Get this payload and dump it 204 | static unsigned long got_time; 205 | radio.read( &got_time, sizeof(got_time) ); 206 | printf("Got payload %lu\n\r",got_time); 207 | 208 | // Add an ack packet for the next time around. This is a simple 209 | // packet counter 210 | radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); 211 | ++message_count; 212 | } 213 | } 214 | } 215 | 216 | // vim:ai:cin:sts=2 sw=2 ft=cpp 217 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_irq/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_maple/Jamfile: -------------------------------------------------------------------------------- 1 | MCU = cortex-m3 ; 2 | CHIP = STM32F103ZE ; 3 | BOARD = maple_native ; 4 | 5 | #CHIP = at91sam3u4 ; 6 | #BOARD = sam3u-ek ; 7 | 8 | if ! $(TOOLSET) 9 | { 10 | TOOLSET = devkit ; 11 | Echo "Assuming TOOLSET=devkit" ; 12 | } 13 | 14 | if $(TOOLSET) = yagarto 15 | { 16 | TOOLS_PATH = ~/Source/yagarto-4.6.2/bin ; 17 | TOOLS_ARCH = arm-none-eabi- ; 18 | } 19 | if $(TOOLSET) = yagarto-install 20 | { 21 | TOOLS_PATH = ~/Source/yagarto/install/bin ; 22 | TOOLS_ARCH = arm-none-eabi- ; 23 | } 24 | else if $(TOOLSET) = devkit 25 | { 26 | TOOLS_PATH = /opt/devkitARM/bin ; 27 | TOOLS_ARCH = arm-eabi- ; 28 | } 29 | else if $(TOOLSET) = maple 30 | { 31 | TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ; 32 | TOOLS_ARCH = arm-none-eabi- ; 33 | } 34 | else if $(TOOLSET) = ports 35 | { 36 | TOOLS_PATH = /opt/local/bin ; 37 | TOOLS_ARCH = arm-none-eabi- ; 38 | } 39 | 40 | CC = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc ; 41 | C++ = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ; 42 | AS = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc -c ; 43 | LINK = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ; 44 | OBJCOPY = $(TOOLS_PATH)/$(TOOLS_ARCH)objcopy ; 45 | DFU = dfu-util ; 46 | 47 | DEFINES += VECT_TAB_FLASH BOARD_$(BOARD) MCU_$(CHIP) ERROR_LED_PORT=GPIOC ERROR_LED_PIN=15 STM32_HIGH_DENSITY MAPLE_IDE ; 48 | OPTIM = -Os ; 49 | MFLAGS = cpu=$(MCU) thumb arch=armv7-m ; 50 | CCFLAGS = -Wall -m$(MFLAGS) -g -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections ; 51 | C++FLAGS = $(CCFLAGS) -fno-rtti -fno-exceptions ; 52 | LINKFLAGS += -m$(MFLAGS) -Xlinker --gc-sections ; 53 | DFUFLAGS = -a1 -d 0x1eaf:0x0003 -R ; 54 | 55 | MAPLE_DIR = $(HOME)/Source/SAM3U/libmaple ; 56 | MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ; 57 | MAPLE_SUBDIRS = wirish wirish/comm wirish/boards libmaple libmaple/usb libmaple/usb/usb_lib ; 58 | 59 | SKETCH_DIR = $(HOME)/Source/Arduino ; 60 | SKETCH_LIBS = RF24 ; 61 | 62 | MODULE_DIRS = . $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) $(SKETCH_DIR)/libraries/$(SKETCH_LIBS) ; 63 | HDRS = $(MODULE_DIRS) ; 64 | LOCATE_TARGET = out/$(TOOLSET) ; 65 | LOCATE_SOURCE = $(LOCATE_TARGET) ; 66 | 67 | rule Pde 68 | { 69 | Depends $(<) : $(>) ; 70 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 71 | Clean clean : $(<) ; 72 | } 73 | 74 | if ( $(ARDUINO_VERSION) < 100 ) 75 | { 76 | ARDUINO_H = WProgram.h ; 77 | } 78 | else 79 | { 80 | ARDUINO_H = Arduino.h ; 81 | } 82 | 83 | actions Pde 84 | { 85 | echo "#include <$(ARDUINO_H)>" > $(<) 86 | echo "#line 1 \"$(>)\"" >> $(<) 87 | cat $(>) >> $(<) 88 | } 89 | 90 | rule C++Pde 91 | { 92 | local _CPP = $(>:B).cpp ; 93 | Pde $(_CPP) : $(>) ; 94 | C++ $(<) : $(_CPP) ; 95 | } 96 | 97 | rule Hex 98 | { 99 | Depends $(<) : $(>) ; 100 | MakeLocate $(<) : $(LOCATE_TARGET) ; 101 | Depends hex : $(<) ; 102 | Clean clean : $(<) ; 103 | } 104 | 105 | actions Hex 106 | { 107 | $(OBJCOPY) -O ihex $(>) $(<) 108 | } 109 | 110 | rule Binary 111 | { 112 | Depends $(<) : $(>) ; 113 | MakeLocate $(<) : $(LOCATE_TARGET) ; 114 | Depends binary : $(<) ; 115 | Clean clean : $(<) ; 116 | } 117 | 118 | actions Binary 119 | { 120 | $(OBJCOPY) -O binary $(>) $(<) 121 | } 122 | 123 | rule UserObject 124 | { 125 | switch $(>:S) 126 | { 127 | case .S : As $(<) : $(>) ; 128 | case .ino : C++Pde $(<) : $(>) ; 129 | case .pde : C++Pde $(<) : $(>) ; 130 | } 131 | } 132 | 133 | rule Upload 134 | { 135 | Depends up : $(<) ; 136 | NotFile up ; 137 | Always $(<) ; 138 | Always up ; 139 | } 140 | 141 | actions Upload 142 | { 143 | $(DFU) $(DFUFLAGS) -D $(<) 144 | } 145 | 146 | # Override base objects rule, so all output can go in the output dir 147 | rule Objects 148 | { 149 | local _i ; 150 | 151 | for _i in [ FGristFiles $(<) ] 152 | { 153 | local _b = $(_i:B)$(SUFOBJ) ; 154 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 155 | Object $(_o) : $(_i) ; 156 | Depends obj : $(_o) ; 157 | } 158 | } 159 | 160 | # Override base main rule, so all output can go in the output dir 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | # Modules 168 | MODULES = [ GLOB $(MODULE_DIRS) : *.pde *.c *.cpp *.S ] ; 169 | 170 | # Main output executable 171 | MAIN = $(PWD:B).elf ; 172 | 173 | # Linker script 174 | LINK_DIR = $(MAPLE_DIR)/support/ld ; 175 | LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ; 176 | 177 | # Bring in the map and link script 178 | LINKFLAGS += -Wl,-Map=$(LOCATE_TARGET)/$(MAIN:B).map -T$(LINKSCRIPT) -L$(LINK_DIR) ; 179 | 180 | Main $(MAIN) : $(MODULES) ; 181 | Binary $(MAIN:B).bin : $(MAIN) ; 182 | Upload $(MAIN:B).bin ; 183 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_maple/main.cpp: -------------------------------------------------------------------------------- 1 | #ifdef MAPLE_IDE 2 | 3 | #include 4 | #include "wirish.h" 5 | 6 | extern void setup(void); 7 | extern void loop(void); 8 | 9 | void board_start(const char* program_name) 10 | { 11 | // Set up the LED to steady on 12 | pinMode(BOARD_LED_PIN, OUTPUT); 13 | digitalWrite(BOARD_LED_PIN, HIGH); 14 | 15 | // Setup the button as input 16 | pinMode(BOARD_BUTTON_PIN, INPUT); 17 | digitalWrite(BOARD_BUTTON_PIN, HIGH); 18 | 19 | SerialUSB.begin(); 20 | SerialUSB.println("Press BUT"); 21 | 22 | // Wait for button press 23 | while ( !isButtonPressed() ) 24 | { 25 | } 26 | 27 | SerialUSB.println("Welcome!"); 28 | SerialUSB.println(program_name); 29 | 30 | int i = 11; 31 | while (i--) 32 | { 33 | toggleLED(); 34 | delay(50); 35 | } 36 | } 37 | 38 | /** 39 | * Custom version of _write, which will print to the USB. 40 | * In order to use it you MUST ADD __attribute__((weak)) 41 | * to _write in libmaple/syscalls.c 42 | */ 43 | extern "C" int _write (int file, char * ptr, int len) 44 | { 45 | if ( (file != 1) && (file != 2) ) 46 | return 0; 47 | else 48 | SerialUSB.write(ptr,len); 49 | return len; 50 | } 51 | 52 | /** 53 | * Re-entrant version of _write. Yagarto and Devkit now use 54 | * the re-entrant newlib, so these get called instead of the 55 | * non_r versions. 56 | */ 57 | extern "C" int _write_r (void*, int file, char * ptr, int len) 58 | { 59 | return _write( file, ptr, len); 60 | } 61 | 62 | __attribute__((constructor)) __attribute__ ((weak)) void premain() 63 | { 64 | init(); 65 | } 66 | 67 | __attribute__((weak)) void setup(void) 68 | { 69 | board_start("No program defined"); 70 | } 71 | 72 | __attribute__((weak)) void loop(void) 73 | { 74 | } 75 | 76 | __attribute__((weak)) int main(void) 77 | { 78 | setup(); 79 | 80 | while (true) 81 | { 82 | loop(); 83 | } 84 | return 0; 85 | } 86 | #endif // ifdef MAPLE_IDE 87 | // vim:cin:ai:sts=2 sw=2 ft=cpp 88 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_maple/pingpair_maple.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example RF Radio Ping Pair ... for Maple 11 | * 12 | * This is an example of how to use the RF24 class. Write this sketch to two different nodes, 13 | * connect the role_pin to ground on one. The ping node sends the current time to the pong node, 14 | * which responds by sending the value back. The ping node can then see how long the whole cycle 15 | * took. 16 | */ 17 | 18 | #include "WProgram.h" 19 | #include 20 | #include "nRF24L01.h" 21 | #include "RF24.h" 22 | 23 | // 24 | // Maple specific setup. Other than this section, the sketch is the same on Maple as on 25 | // Arduino 26 | // 27 | 28 | #ifdef MAPLE_IDE 29 | 30 | // External startup function 31 | extern void board_start(const char* program_name); 32 | 33 | // Use SPI #2. 34 | HardwareSPI SPI(2); 35 | 36 | #else 37 | #define board_startup printf 38 | #define toggleLED(x) (x) 39 | #endif 40 | 41 | // 42 | // Hardware configuration 43 | // 44 | 45 | // Set up nRF24L01 radio on SPI bus plus pins 7 & 6 46 | // (This works for the Getting Started board plugged into the 47 | // Maple Native backwards.) 48 | 49 | RF24 radio(7,6); 50 | 51 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 52 | // Leave open to be the 'ping' transmitter 53 | const int role_pin = 10; 54 | 55 | // 56 | // Topology 57 | // 58 | 59 | // Radio pipe addresses for the 2 nodes to communicate. 60 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 61 | 62 | // 63 | // Role management 64 | // 65 | // Set up role. This sketch uses the same software for all the nodes 66 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 67 | // which node it is. 68 | // 69 | // This is done through the role_pin 70 | // 71 | 72 | // The various roles supported by this sketch 73 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 74 | 75 | // The debug-friendly names of those roles 76 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 77 | 78 | // The role of the current running sketch 79 | role_e role; 80 | 81 | void setup(void) 82 | { 83 | // 84 | // Role 85 | // 86 | 87 | // set up the role pin 88 | pinMode(role_pin, INPUT); 89 | digitalWrite(role_pin,HIGH); 90 | delay(20); // Just to get a solid reading on the role pin 91 | 92 | // read the address pin, establish our role 93 | if ( digitalRead(role_pin) ) 94 | role = role_ping_out; 95 | else 96 | role = role_pong_back; 97 | 98 | // 99 | // Print preamble 100 | // 101 | 102 | board_start("\n\rRF24/examples/pingpair/\n\r"); 103 | printf("ROLE: %s\n\r",role_friendly_name[role]); 104 | 105 | // 106 | // Setup and configure rf radio 107 | // 108 | 109 | radio.begin(); 110 | 111 | // optionally, increase the delay between retries & # of retries 112 | radio.setRetries(15,15); 113 | 114 | // optionally, reduce the payload size. seems to 115 | // improve reliability 116 | radio.setPayloadSize(8); 117 | 118 | // 119 | // Open pipes to other nodes for communication 120 | // 121 | 122 | // This simple sketch opens two pipes for these two nodes to communicate 123 | // back and forth. 124 | // Open 'our' pipe for writing 125 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 126 | 127 | if ( role == role_ping_out ) 128 | { 129 | radio.openWritingPipe(pipes[0]); 130 | radio.openReadingPipe(1,pipes[1]); 131 | } 132 | else 133 | { 134 | radio.openWritingPipe(pipes[1]); 135 | radio.openReadingPipe(1,pipes[0]); 136 | } 137 | 138 | // 139 | // Start listening 140 | // 141 | 142 | radio.startListening(); 143 | 144 | // 145 | // Dump the configuration of the rf unit for debugging 146 | // 147 | 148 | radio.printDetails(); 149 | } 150 | 151 | void loop(void) 152 | { 153 | // 154 | // Ping out role. Repeatedly send the current time 155 | // 156 | 157 | if (role == role_ping_out) 158 | { 159 | toggleLED(); 160 | 161 | // First, stop listening so we can talk. 162 | radio.stopListening(); 163 | 164 | // Take the time, and send it. This will block until complete 165 | unsigned long time = millis(); 166 | printf("Now sending %lu...",time); 167 | bool ok = radio.write( &time, sizeof(unsigned long) ); 168 | 169 | if (ok) 170 | printf("ok...\r\n"); 171 | else 172 | printf("failed.\r\n"); 173 | 174 | // Now, continue listening 175 | radio.startListening(); 176 | 177 | // Wait here until we get a response, or timeout (250ms) 178 | unsigned long started_waiting_at = millis(); 179 | bool timeout = false; 180 | while ( ! radio.available() && ! timeout ) 181 | if (millis() - started_waiting_at > 200 ) 182 | timeout = true; 183 | 184 | // Describe the results 185 | if ( timeout ) 186 | { 187 | printf("Failed, response timed out.\r\n"); 188 | } 189 | else 190 | { 191 | // Grab the response, compare, and send to debugging spew 192 | unsigned long got_time; 193 | radio.read( &got_time, sizeof(unsigned long) ); 194 | 195 | // Spew it 196 | printf("Got response %lu, round-trip delay: %lu\r\n",got_time,millis()-got_time); 197 | } 198 | 199 | toggleLED(); 200 | 201 | // Try again 1s later 202 | delay(1000); 203 | } 204 | 205 | // 206 | // Pong back role. Receive each packet, dump it out, and send it back 207 | // 208 | 209 | if ( role == role_pong_back ) 210 | { 211 | // if there is data ready 212 | if ( radio.available() ) 213 | { 214 | // Dump the payloads until we've gotten everything 215 | unsigned long got_time; 216 | bool done = false; 217 | while (!done) 218 | { 219 | // Fetch the payload, and see if this was the last one. 220 | done = radio.read( &got_time, sizeof(unsigned long) ); 221 | 222 | // Spew it 223 | printf("Got payload %lu...",got_time); 224 | 225 | // Delay just a little bit to let the other unit 226 | // make the transition to receiver 227 | delay(20); 228 | } 229 | 230 | // First, stop listening so we can talk 231 | radio.stopListening(); 232 | 233 | // Send the final one back. 234 | radio.write( &got_time, sizeof(unsigned long) ); 235 | printf("Sent response.\r\n"); 236 | 237 | // Now, resume listening so we catch the next packets. 238 | radio.startListening(); 239 | } 240 | } 241 | } 242 | // vim:cin:ai:sts=2 sw=2 ft=cpp 243 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_pl/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_pl/pingpair_pl.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example of using Ack Payloads 11 | * 12 | * This is an example of how to do two-way communication without changing 13 | * transmit/receive modes. Here, a payload is set to the transmitter within 14 | * the Ack packet of each transmission. Note that the payload is set BEFORE 15 | * the sender's message arrives. 16 | */ 17 | 18 | #include 19 | #include "nRF24L01.h" 20 | #include "RF24.h" 21 | #include "printf.h" 22 | 23 | // 24 | // Hardware configuration 25 | // 26 | 27 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 28 | 29 | RF24 radio(9,10); 30 | 31 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 32 | // Leave open to be the 'ping' transmitter 33 | const short role_pin = 7; 34 | 35 | // 36 | // Topology 37 | // 38 | 39 | // Single radio pipe address for the 2 nodes to communicate. 40 | const uint64_t pipe = 0xE8E8F0F0E1LL; 41 | 42 | // 43 | // Role management 44 | // 45 | // Set up role. This sketch uses the same software for all the nodes in this 46 | // system. Doing so greatly simplifies testing. The hardware itself specifies 47 | // which node it is. 48 | // 49 | // This is done through the role_pin 50 | // 51 | 52 | // The various roles supported by this sketch 53 | typedef enum { role_sender = 1, role_receiver } role_e; 54 | 55 | // The debug-friendly names of those roles 56 | const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; 57 | 58 | // The role of the current running sketch 59 | role_e role; 60 | 61 | void setup(void) 62 | { 63 | // 64 | // Role 65 | // 66 | 67 | // set up the role pin 68 | pinMode(role_pin, INPUT); 69 | digitalWrite(role_pin,HIGH); 70 | delay(20); // Just to get a solid reading on the role pin 71 | 72 | // read the address pin, establish our role 73 | if ( digitalRead(role_pin) ) 74 | role = role_sender; 75 | else 76 | role = role_receiver; 77 | 78 | // 79 | // Print preamble 80 | // 81 | 82 | Serial.begin(57600); 83 | printf_begin(); 84 | printf("\n\rRF24/examples/pingpair_pl/\n\r"); 85 | printf("ROLE: %s\n\r",role_friendly_name[role]); 86 | 87 | // 88 | // Setup and configure rf radio 89 | // 90 | 91 | radio.begin(); 92 | 93 | // We will be using the Ack Payload feature, so please enable it 94 | radio.enableAckPayload(); 95 | 96 | // 97 | // Open pipes to other nodes for communication 98 | // 99 | 100 | // This simple sketch opens a single pipes for these two nodes to communicate 101 | // back and forth. One listens on it, the other talks to it. 102 | 103 | if ( role == role_sender ) 104 | { 105 | radio.openWritingPipe(pipe); 106 | } 107 | else 108 | { 109 | radio.openReadingPipe(1,pipe); 110 | } 111 | 112 | // 113 | // Start listening 114 | // 115 | 116 | if ( role == role_receiver ) 117 | radio.startListening(); 118 | 119 | // 120 | // Dump the configuration of the rf unit for debugging 121 | // 122 | 123 | radio.printDetails(); 124 | } 125 | 126 | void loop(void) 127 | { 128 | static uint32_t message_count = 0; 129 | 130 | // 131 | // Sender role. Repeatedly send the current time 132 | // 133 | 134 | if (role == role_sender) 135 | { 136 | // Take the time, and send it. This will block until complete 137 | unsigned long time = millis(); 138 | printf("Now sending %lu...",time); 139 | radio.write( &time, sizeof(unsigned long) ); 140 | 141 | if ( radio.isAckPayloadAvailable() ) 142 | { 143 | radio.read(&message_count,sizeof(message_count)); 144 | printf("Ack: [%lu] ",message_count); 145 | } 146 | printf("OK\n\r"); 147 | 148 | // Try again soon 149 | delay(2000); 150 | } 151 | 152 | // 153 | // Receiver role. Receive each packet, dump it out, add ack payload for next time 154 | // 155 | 156 | if ( role == role_receiver ) 157 | { 158 | // if there is data ready 159 | if ( radio.available() ) 160 | { 161 | // Dump the payloads until we've gotten everything 162 | static unsigned long got_time; 163 | bool done = false; 164 | while (!done) 165 | { 166 | // Fetch the payload, and see if this was the last one. 167 | done = radio.read( &got_time, sizeof(unsigned long) ); 168 | 169 | // Spew it 170 | printf("Got payload %lu\n",got_time); 171 | } 172 | 173 | // Add an ack packet for the next time around. This is a simple 174 | // packet counter 175 | radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); 176 | ++message_count; 177 | } 178 | } 179 | } 180 | // vim:ai:cin:sts=2 sw=2 ft=cpp 181 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_pl/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_sleepy/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_sleepy/pingpair_sleepy.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example RF Radio Ping Pair which Sleeps between Sends 11 | * 12 | * This is an example of how to use the RF24 class to create a battery- 13 | * efficient system. It is just like the pingpair.pde example, but the 14 | * ping node powers down the radio and sleeps the MCU after every 15 | * ping/pong cycle. 16 | * 17 | * As with the pingpair.pde example, write this sketch to two different nodes, 18 | * connect the role_pin to ground on one. The ping node sends the current 19 | * time to the pong node, which responds by sending the value back. The ping 20 | * node can then see how long the whole cycle took. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "nRF24L01.h" 27 | #include "RF24.h" 28 | #include "printf.h" 29 | 30 | // 31 | // Hardware configuration 32 | // 33 | 34 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 35 | 36 | RF24 radio(9,10); 37 | 38 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 39 | // Leave open to be the 'ping' transmitter 40 | const int role_pin = 7; 41 | 42 | // 43 | // Topology 44 | // 45 | 46 | // Radio pipe addresses for the 2 nodes to communicate. 47 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 48 | 49 | // 50 | // Role management 51 | // 52 | // Set up role. This sketch uses the same software for all the nodes 53 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 54 | // which node it is. 55 | // 56 | // This is done through the role_pin 57 | // 58 | 59 | // The various roles supported by this sketch 60 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 61 | 62 | // The debug-friendly names of those roles 63 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 64 | 65 | // The role of the current running sketch 66 | role_e role; 67 | 68 | // 69 | // Sleep declarations 70 | // 71 | 72 | typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s } wdt_prescalar_e; 73 | 74 | void setup_watchdog(uint8_t prescalar); 75 | void do_sleep(void); 76 | 77 | const short sleep_cycles_per_transmission = 4; 78 | volatile short sleep_cycles_remaining = sleep_cycles_per_transmission; 79 | 80 | // 81 | // Normal operation 82 | // 83 | 84 | void setup(void) 85 | { 86 | // 87 | // Role 88 | // 89 | 90 | // set up the role pin 91 | pinMode(role_pin, INPUT); 92 | digitalWrite(role_pin,HIGH); 93 | delay(20); // Just to get a solid reading on the role pin 94 | 95 | // read the address pin, establish our role 96 | if ( digitalRead(role_pin) ) 97 | role = role_ping_out; 98 | else 99 | role = role_pong_back; 100 | 101 | // 102 | // Print preamble 103 | // 104 | 105 | Serial.begin(57600); 106 | printf_begin(); 107 | printf("\n\rRF24/examples/pingpair_sleepy/\n\r"); 108 | printf("ROLE: %s\n\r",role_friendly_name[role]); 109 | 110 | // 111 | // Prepare sleep parameters 112 | // 113 | 114 | // Only the ping out role sleeps. Wake up every 4s to send a ping 115 | if ( role == role_ping_out ) 116 | setup_watchdog(wdt_1s); 117 | 118 | // 119 | // Setup and configure rf radio 120 | // 121 | 122 | radio.begin(); 123 | 124 | // 125 | // Open pipes to other nodes for communication 126 | // 127 | 128 | // This simple sketch opens two pipes for these two nodes to communicate 129 | // back and forth. 130 | // Open 'our' pipe for writing 131 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 132 | 133 | if ( role == role_ping_out ) 134 | { 135 | radio.openWritingPipe(pipes[0]); 136 | radio.openReadingPipe(1,pipes[1]); 137 | } 138 | else 139 | { 140 | radio.openWritingPipe(pipes[1]); 141 | radio.openReadingPipe(1,pipes[0]); 142 | } 143 | 144 | // 145 | // Start listening 146 | // 147 | 148 | radio.startListening(); 149 | 150 | // 151 | // Dump the configuration of the rf unit for debugging 152 | // 153 | 154 | radio.printDetails(); 155 | } 156 | 157 | void loop(void) 158 | { 159 | // 160 | // Ping out role. Repeatedly send the current time 161 | // 162 | 163 | if (role == role_ping_out) 164 | { 165 | // First, stop listening so we can talk. 166 | radio.stopListening(); 167 | 168 | // Take the time, and send it. This will block until complete 169 | unsigned long time = millis(); 170 | printf("Now sending %lu...",time); 171 | radio.write( &time, sizeof(unsigned long) ); 172 | 173 | // Now, continue listening 174 | radio.startListening(); 175 | 176 | // Wait here until we get a response, or timeout (250ms) 177 | unsigned long started_waiting_at = millis(); 178 | bool timeout = false; 179 | while ( ! radio.available() && ! timeout ) 180 | if (millis() - started_waiting_at > 250 ) 181 | timeout = true; 182 | 183 | // Describe the results 184 | if ( timeout ) 185 | { 186 | printf("Failed, response timed out.\n\r"); 187 | } 188 | else 189 | { 190 | // Grab the response, compare, and send to debugging spew 191 | unsigned long got_time; 192 | radio.read( &got_time, sizeof(unsigned long) ); 193 | 194 | // Spew it 195 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 196 | } 197 | 198 | // 199 | // Shut down the system 200 | // 201 | 202 | // Experiment with some delay here to see if it has an effect 203 | delay(500); 204 | 205 | // Power down the radio. Note that the radio will get powered back up 206 | // on the next write() call. 207 | radio.powerDown(); 208 | 209 | // Sleep the MCU. The watchdog timer will awaken in a short while, and 210 | // continue execution here. 211 | while( sleep_cycles_remaining ) 212 | do_sleep(); 213 | 214 | sleep_cycles_remaining = sleep_cycles_per_transmission; 215 | } 216 | 217 | // 218 | // Pong back role. Receive each packet, dump it out, and send it back 219 | // 220 | // This is untouched from the pingpair example. 221 | // 222 | 223 | if ( role == role_pong_back ) 224 | { 225 | // if there is data ready 226 | if ( radio.available() ) 227 | { 228 | // Dump the payloads until we've gotten everything 229 | unsigned long got_time; 230 | bool done = false; 231 | while (!done) 232 | { 233 | // Fetch the payload, and see if this was the last one. 234 | done = radio.read( &got_time, sizeof(unsigned long) ); 235 | 236 | // Spew it. Include our time, because the ping_out millis counter is unreliable 237 | // due to it sleeping 238 | printf("Got payload %lu @ %lu...",got_time,millis()); 239 | } 240 | 241 | // First, stop listening so we can talk 242 | radio.stopListening(); 243 | 244 | // Send the final one back. 245 | radio.write( &got_time, sizeof(unsigned long) ); 246 | printf("Sent response.\n\r"); 247 | 248 | // Now, resume listening so we catch the next packets. 249 | radio.startListening(); 250 | } 251 | } 252 | } 253 | 254 | // 255 | // Sleep helpers 256 | // 257 | 258 | // 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms 259 | // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec 260 | 261 | void setup_watchdog(uint8_t prescalar) 262 | { 263 | prescalar = min(9,prescalar); 264 | uint8_t wdtcsr = prescalar & 7; 265 | if ( prescalar & 8 ) 266 | wdtcsr |= _BV(WDP3); 267 | 268 | MCUSR &= ~_BV(WDRF); 269 | WDTCSR = _BV(WDCE) | _BV(WDE); 270 | WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); 271 | } 272 | 273 | ISR(WDT_vect) 274 | { 275 | --sleep_cycles_remaining; 276 | } 277 | 278 | void do_sleep(void) 279 | { 280 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here 281 | sleep_enable(); 282 | 283 | sleep_mode(); // System sleeps here 284 | 285 | sleep_disable(); // System continues execution here when watchdog timed out 286 | } 287 | 288 | // vim:ai:cin:sts=2 sw=2 ft=cpp 289 | -------------------------------------------------------------------------------- /RF24-master/examples/pingpair_sleepy/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/examples/scanner/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | # (2) Board Information 6 | 7 | UPLOAD_PROTOCOL ?= stk500v1 ; 8 | UPLOAD_SPEED ?= 57600 ; 9 | MCU ?= atmega328p ; 10 | F_CPU ?= 16000000 ; 11 | CORE ?= arduino ; 12 | VARIANT ?= standard ; 13 | ARDUINO_VERSION ?= 100 ; 14 | 15 | # (3) USB Ports 16 | 17 | PORTS = p4 p6 p9 u0 u1 u2 ; 18 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 19 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 20 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 21 | PORT_u0 = /dev/ttyUSB0 ; 22 | PORT_u1 = /dev/ttyUSB1 ; 23 | PORT_u2 = /dev/ttyUSB2 ; 24 | 25 | # (4) Location of AVR tools 26 | # 27 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 28 | # distribution. 29 | 30 | if $(OS) = MACOSX 31 | { 32 | AVR_BIN = /usr/local/avrtools/bin ; 33 | AVR_ETC = /usr/local/avrtools/etc ; 34 | AVR_INCLUDE = /usr/local/avrtools/include ; 35 | } 36 | else 37 | { 38 | AVR_BIN = /usr/bin ; 39 | AVR_INCLUDE = /usr/lib/avr/include ; 40 | AVR_ETC = /etc ; 41 | } 42 | 43 | # (5) Directories where Arduino core and libraries are located 44 | 45 | ARDUINO_DIR ?= /opt/Arduino ; 46 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 47 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 48 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 49 | 50 | # 51 | # -------------------------------------------------- 52 | # Below this line usually never needs to be modified 53 | # 54 | 55 | # Tool locations 56 | 57 | CC = $(AVR_BIN)/avr-gcc ; 58 | C++ = $(AVR_BIN)/avr-g++ ; 59 | LINK = $(AVR_BIN)/avr-gcc ; 60 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 61 | AVRDUDE = $(AVR_BIN)/avrdude ; 62 | 63 | # Flags 64 | 65 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 66 | OPTIM = -Os ; 67 | CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 68 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 69 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 70 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 71 | 72 | # Search everywhere for headers 73 | 74 | HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 75 | 76 | # Output locations 77 | 78 | LOCATE_TARGET = $(F_CPU) ; 79 | LOCATE_SOURCE = $(F_CPU) ; 80 | 81 | # 82 | # Custom rules 83 | # 84 | 85 | rule GitVersion 86 | { 87 | Always $(<) ; 88 | Depends all : $(<) ; 89 | } 90 | 91 | actions GitVersion 92 | { 93 | echo "const char program_version[] = \"\\" > $(<) 94 | git log -1 --pretty=format:%h >> $(<) 95 | echo "\";" >> $(<) 96 | } 97 | 98 | GitVersion version.h ; 99 | 100 | rule Pde 101 | { 102 | Depends $(<) : $(>) ; 103 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 104 | Clean clean : $(<) ; 105 | } 106 | 107 | if ( $(ARDUINO_VERSION) < 100 ) 108 | { 109 | ARDUINO_H = WProgram.h ; 110 | } 111 | else 112 | { 113 | ARDUINO_H = Arduino.h ; 114 | } 115 | 116 | actions Pde 117 | { 118 | echo "#include <$(ARDUINO_H)>" > $(<) 119 | echo "#line 1 \"$(>)\"" >> $(<) 120 | cat $(>) >> $(<) 121 | } 122 | 123 | rule C++Pde 124 | { 125 | local _CPP = $(>:B).cpp ; 126 | Pde $(_CPP) : $(>) ; 127 | C++ $(<) : $(_CPP) ; 128 | } 129 | 130 | rule UserObject 131 | { 132 | switch $(>:S) 133 | { 134 | case .ino : C++Pde $(<) : $(>) ; 135 | case .pde : C++Pde $(<) : $(>) ; 136 | } 137 | } 138 | 139 | rule Objects 140 | { 141 | local _i ; 142 | 143 | for _i in [ FGristFiles $(<) ] 144 | { 145 | local _b = $(_i:B)$(SUFOBJ) ; 146 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 147 | Object $(_o) : $(_i) ; 148 | Depends obj : $(_o) ; 149 | } 150 | } 151 | 152 | rule Main 153 | { 154 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 155 | Objects $(>) ; 156 | } 157 | 158 | rule Hex 159 | { 160 | Depends $(<) : $(>) ; 161 | MakeLocate $(<) : $(LOCATE_TARGET) ; 162 | Depends hex : $(<) ; 163 | Clean clean : $(<) ; 164 | } 165 | 166 | actions Hex 167 | { 168 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 169 | } 170 | 171 | rule Upload 172 | { 173 | Depends $(1) : $(2) ; 174 | Depends $(2) : $(3) ; 175 | NotFile $(1) ; 176 | Always $(1) ; 177 | Always $(2) ; 178 | UploadAction $(2) : $(3) ; 179 | } 180 | 181 | actions UploadAction 182 | { 183 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 184 | } 185 | 186 | # 187 | # Targets 188 | # 189 | 190 | # Grab everything from the core directory 191 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 192 | 193 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 194 | # can specify specific modules to pick up in PROJECT_MODULES 195 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 196 | 197 | # Grab everything from the current dir 198 | PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ; 199 | 200 | # Main output executable 201 | MAIN = $(PWD:B).elf ; 202 | 203 | Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 204 | Hex $(MAIN:B).hex : $(MAIN) ; 205 | 206 | # Upload targets 207 | for _p in $(PORTS) 208 | { 209 | Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ; 210 | } 211 | -------------------------------------------------------------------------------- /RF24-master/examples/scanner/output/core.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/RF24-master/examples/scanner/output/core.a -------------------------------------------------------------------------------- /RF24-master/examples/scanner/output/scanner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #line 1 "scanner.pde" 3 | 4 | /* 5 | Copyright (C) 2011 James Coliz, Jr. 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | version 2 as published by the Free Software Foundation. 10 | */ 11 | 12 | /** 13 | * Channel scanner 14 | * 15 | * Example to detect interference on the various channels available. 16 | * This is a good diagnostic tool to check whether you're picking a 17 | * good channel for your application. 18 | * 19 | * Inspired by cpixip. 20 | * See http://arduino.cc/forum/index.php/topic,54795.0.html 21 | */ 22 | 23 | #include 24 | #include "nRF24L01.h" 25 | #include "RF24.h" 26 | #include "printf.h" 27 | 28 | // 29 | // Hardware configuration 30 | // 31 | 32 | // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 33 | 34 | RF24 radio(8,9); 35 | 36 | // 37 | // Channel info 38 | // 39 | 40 | const short num_channels = 128; 41 | short values[num_channels]; 42 | 43 | // 44 | // Setup 45 | // 46 | 47 | void setup(void) 48 | { 49 | // 50 | // Print preamble 51 | // 52 | 53 | Serial.begin(57600); 54 | printf_begin(); 55 | printf("\n\rRF24/examples/scanner/\n\r"); 56 | 57 | // 58 | // Setup and configure rf radio 59 | // 60 | 61 | radio.begin(); 62 | radio.setAutoAck(false); 63 | 64 | // Get into standby mode 65 | radio.startListening(); 66 | radio.stopListening(); 67 | 68 | // Print out header, high then low digit 69 | int i = 0; 70 | while ( i < num_channels ) 71 | { 72 | printf("%x",i>>4); 73 | ++i; 74 | } 75 | printf("\n\r"); 76 | i = 0; 77 | while ( i < num_channels ) 78 | { 79 | printf("%x",i&0xf); 80 | ++i; 81 | } 82 | printf("\n\r"); 83 | } 84 | 85 | // 86 | // Loop 87 | // 88 | 89 | const short num_reps = 100; 90 | 91 | void loop(void) 92 | { 93 | // Clear measurement values 94 | memset(values,0,num_channels); 95 | 96 | // Scan all channels num_reps times 97 | int rep_counter = num_reps; 98 | while (rep_counter--) 99 | { 100 | int i = num_channels; 101 | while (i--) 102 | { 103 | // Select this channel 104 | radio.setChannel(i); 105 | 106 | // Listen for a little 107 | radio.startListening(); 108 | delayMicroseconds(128); 109 | radio.stopListening(); 110 | 111 | // Did we get a carrier? 112 | if ( radio.testCarrier() ) 113 | ++values[i]; 114 | } 115 | } 116 | 117 | // Print out channel measurements, clamped to a single hex digit 118 | int i = 0; 119 | while ( i < num_channels ) 120 | { 121 | printf("%x",min(0xf,values[i]&0xf)); 122 | ++i; 123 | } 124 | printf("\n\r"); 125 | } 126 | 127 | 128 | // vim:ai:cin:sts=2 sw=2 ft=cpp 129 | -------------------------------------------------------------------------------- /RF24-master/examples/scanner/output/scanner.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/RF24-master/examples/scanner/output/scanner.elf -------------------------------------------------------------------------------- /RF24-master/examples/scanner/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | int serial_putc( char c, FILE * ) 20 | { 21 | Serial.write( c ); 22 | 23 | return c; 24 | } 25 | 26 | void printf_begin(void) 27 | { 28 | fdevopen( &serial_putc, 0 ); 29 | } 30 | 31 | #endif // __PRINTF_H__ 32 | -------------------------------------------------------------------------------- /RF24-master/examples/scanner/scanner.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Channel scanner 11 | * 12 | * Example to detect interference on the various channels available. 13 | * This is a good diagnostic tool to check whether you're picking a 14 | * good channel for your application. 15 | * 16 | * Inspired by cpixip. 17 | * See http://arduino.cc/forum/index.php/topic,54795.0.html 18 | */ 19 | 20 | #include 21 | #include "nRF24L01.h" 22 | #include "RF24.h" 23 | #include "printf.h" 24 | 25 | // 26 | // Hardware configuration 27 | // 28 | 29 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 30 | 31 | RF24 radio(9,10); 32 | 33 | // 34 | // Channel info 35 | // 36 | 37 | const uint8_t num_channels = 128; 38 | uint8_t values[num_channels]; 39 | 40 | // 41 | // Setup 42 | // 43 | 44 | void setup(void) 45 | { 46 | // 47 | // Print preamble 48 | // 49 | 50 | Serial.begin(57600); 51 | printf_begin(); 52 | printf("\n\rRF24/examples/scanner/\n\r"); 53 | 54 | // 55 | // Setup and configure rf radio 56 | // 57 | 58 | radio.begin(); 59 | radio.setAutoAck(false); 60 | 61 | // Get into standby mode 62 | radio.startListening(); 63 | radio.stopListening(); 64 | 65 | // Print out header, high then low digit 66 | int i = 0; 67 | while ( i < num_channels ) 68 | { 69 | printf("%x",i>>4); 70 | ++i; 71 | } 72 | printf("\n\r"); 73 | i = 0; 74 | while ( i < num_channels ) 75 | { 76 | printf("%x",i&0xf); 77 | ++i; 78 | } 79 | printf("\n\r"); 80 | } 81 | 82 | // 83 | // Loop 84 | // 85 | 86 | const int num_reps = 100; 87 | 88 | void loop(void) 89 | { 90 | // Clear measurement values 91 | memset(values,0,sizeof(values)); 92 | 93 | // Scan all channels num_reps times 94 | int rep_counter = num_reps; 95 | while (rep_counter--) 96 | { 97 | int i = num_channels; 98 | while (i--) 99 | { 100 | // Select this channel 101 | radio.setChannel(i); 102 | 103 | // Listen for a little 104 | radio.startListening(); 105 | delayMicroseconds(128); 106 | radio.stopListening(); 107 | 108 | // Did we get a carrier? 109 | if ( radio.testCarrier() ) 110 | ++values[i]; 111 | } 112 | } 113 | 114 | // Print out channel measurements, clamped to a single hex digit 115 | int i = 0; 116 | while ( i < num_channels ) 117 | { 118 | printf("%x",min(0xf,values[i]&0xf)); 119 | ++i; 120 | } 121 | printf("\n\r"); 122 | } 123 | 124 | // vim:ai:cin:sts=2 sw=2 ft=cpp 125 | -------------------------------------------------------------------------------- /RF24-master/examples/starping/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = EEPROM SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /RF24-master/examples/starping/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/keywords.txt: -------------------------------------------------------------------------------- 1 | RF24 KEYWORD1 2 | begin KEYWORD2 3 | setChannel KEYWORD2 4 | setPayloadSize KEYWORD2 5 | getPayloadSize KEYWORD2 6 | print_details KEYWORD2 7 | startListening KEYWORD2 8 | stopListening KEYWORD2 9 | write KEYWORD2 10 | available KEYWORD2 11 | read KEYWORD2 12 | openWritingPipe KEYWORD2 13 | openReadingPipe KEYWORD2 -------------------------------------------------------------------------------- /RF24-master/nRF24L01.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007 Stefan Engelke 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, copy, 8 | modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /* Memory Map */ 26 | #define CONFIG 0x00 27 | #define EN_AA 0x01 28 | #define EN_RXADDR 0x02 29 | #define SETUP_AW 0x03 30 | #define SETUP_RETR 0x04 31 | #define RF_CH 0x05 32 | #define RF_SETUP 0x06 33 | #define STATUS 0x07 34 | #define OBSERVE_TX 0x08 35 | #define CD 0x09 36 | #define RX_ADDR_P0 0x0A 37 | #define RX_ADDR_P1 0x0B 38 | #define RX_ADDR_P2 0x0C 39 | #define RX_ADDR_P3 0x0D 40 | #define RX_ADDR_P4 0x0E 41 | #define RX_ADDR_P5 0x0F 42 | #define TX_ADDR 0x10 43 | #define RX_PW_P0 0x11 44 | #define RX_PW_P1 0x12 45 | #define RX_PW_P2 0x13 46 | #define RX_PW_P3 0x14 47 | #define RX_PW_P4 0x15 48 | #define RX_PW_P5 0x16 49 | #define FIFO_STATUS 0x17 50 | #define DYNPD 0x1C 51 | #define FEATURE 0x1D 52 | 53 | /* Bit Mnemonics */ 54 | #define MASK_RX_DR 6 55 | #define MASK_TX_DS 5 56 | #define MASK_MAX_RT 4 57 | #define EN_CRC 3 58 | #define CRCO 2 59 | #define PWR_UP 1 60 | #define PRIM_RX 0 61 | #define ENAA_P5 5 62 | #define ENAA_P4 4 63 | #define ENAA_P3 3 64 | #define ENAA_P2 2 65 | #define ENAA_P1 1 66 | #define ENAA_P0 0 67 | #define ERX_P5 5 68 | #define ERX_P4 4 69 | #define ERX_P3 3 70 | #define ERX_P2 2 71 | #define ERX_P1 1 72 | #define ERX_P0 0 73 | #define AW 0 74 | #define ARD 4 75 | #define ARC 0 76 | #define PLL_LOCK 4 77 | #define RF_DR 3 78 | #define RF_PWR 6 79 | #define RX_DR 6 80 | #define TX_DS 5 81 | #define MAX_RT 4 82 | #define RX_P_NO 1 83 | #define TX_FULL 0 84 | #define PLOS_CNT 4 85 | #define ARC_CNT 0 86 | #define TX_REUSE 6 87 | #define FIFO_FULL 5 88 | #define TX_EMPTY 4 89 | #define RX_FULL 1 90 | #define RX_EMPTY 0 91 | #define DPL_P5 5 92 | #define DPL_P4 4 93 | #define DPL_P3 3 94 | #define DPL_P2 2 95 | #define DPL_P1 1 96 | #define DPL_P0 0 97 | #define EN_DPL 2 98 | #define EN_ACK_PAY 1 99 | #define EN_DYN_ACK 0 100 | 101 | /* Instruction Mnemonics */ 102 | #define R_REGISTER 0x00 103 | #define W_REGISTER 0x20 104 | #define REGISTER_MASK 0x1F 105 | #define ACTIVATE 0x50 106 | #define R_RX_PL_WID 0x60 107 | #define R_RX_PAYLOAD 0x61 108 | #define W_TX_PAYLOAD 0xA0 109 | #define W_ACK_PAYLOAD 0xA8 110 | #define FLUSH_TX 0xE1 111 | #define FLUSH_RX 0xE2 112 | #define REUSE_TX_PL 0xE3 113 | #define NOP 0xFF 114 | 115 | /* Non-P omissions */ 116 | #define LNA_HCURR 0 117 | 118 | /* P model memory Map */ 119 | #define RPD 0x09 120 | 121 | /* P model bit Mnemonics */ 122 | #define RF_DR_LOW 5 123 | #define RF_DR_HIGH 3 124 | #define RF_PWR_LOW 1 125 | #define RF_PWR_HIGH 2 126 | -------------------------------------------------------------------------------- /RF24-master/tests/README: -------------------------------------------------------------------------------- 1 | The sketches in this directory are intended to be checkin tests. 2 | No code should be pushed to github without these tests passing. 3 | 4 | See "runtests.sh" script inside each sketch dir. This script is fully compatible with 5 | git bisest. 6 | 7 | Note that this requires python and py-serial 8 | -------------------------------------------------------------------------------- /RF24-master/tests/native/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | SKETCH_DIR = $(HOME)/Source/Arduino ; 28 | AVR_TOOLS_PATH ?= /usr/bin ; 29 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 30 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 31 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 32 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 33 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 34 | SKETCH_LIB = $(SKETCH_DIR)/libraries ; 35 | AVR_AS = $(AVR_TOOLS_PATH)/avr-as ; 36 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 38 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 39 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 40 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 41 | 42 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H HAL=1 ; 43 | CTUNING = -ffunction-sections -fdata-sections ; 44 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 45 | ASFLAGS = -mmcu=$(MCU) ; 46 | CFLAGS = -Os -Wall -Wextra $(ASFLAGS) $(CTUNING) ; 47 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 48 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 49 | 50 | # Search everywhere for headers 51 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 52 | HDRS += [ GLOB $(HDRS) : utility ] ; 53 | 54 | # Grab everything from the core directory 55 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 56 | 57 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 58 | # can specify specific modules to pick up in PROJECT_MODULES 59 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 60 | 61 | # In addition to explicitly-specified program modules, pick up anything from the current 62 | # dir. 63 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 64 | 65 | # Shortcut for the out files 66 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 67 | 68 | # AvrDude setup 69 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 70 | 71 | rule GitVersion 72 | { 73 | Always $(<) ; 74 | Depends all : $(<) ; 75 | } 76 | 77 | actions GitVersion 78 | { 79 | echo "const char program_version[] = \"\\" > $(<) 80 | git log -1 --pretty=format:%h >> $(<) 81 | echo "\";" >> $(<) 82 | } 83 | 84 | # GitVersion version.h ; 85 | 86 | rule AvrAsm 87 | { 88 | Depends $(<) : $(>) ; 89 | Depends $(<) : $(<:D) ; 90 | Clean clean : $(<) ; 91 | 92 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 93 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 94 | } 95 | 96 | actions AvrAsm 97 | { 98 | $(AVR_AS) $(ASFLAGS) -o $(<) $(>) 99 | } 100 | 101 | rule AvrCc 102 | { 103 | Depends $(<) : $(>) ; 104 | Depends $(<) : $(<:D) ; 105 | Clean clean : $(<) ; 106 | 107 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 108 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 109 | } 110 | 111 | actions AvrCc 112 | { 113 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 114 | } 115 | 116 | rule AvrC++ 117 | { 118 | Depends $(<) : $(>) ; 119 | Depends $(<) : $(<:D) ; 120 | Clean clean : $(<) ; 121 | 122 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 123 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 124 | } 125 | 126 | actions AvrC++ 127 | { 128 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 129 | } 130 | 131 | rule AvrAsmFromC++ 132 | { 133 | Depends $(<) : $(>) ; 134 | Depends $(<) : $(<:D) ; 135 | Clean clean : $(<) ; 136 | 137 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 138 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 139 | } 140 | 141 | actions AvrAsmFromC++ 142 | { 143 | $(AVR_CXX) -S -fverbose-asm -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 144 | } 145 | 146 | rule Pde 147 | { 148 | Depends $(<) : $(>) ; 149 | Depends $(<) : $(<:D) ; 150 | Clean clean : $(<) ; 151 | } 152 | 153 | actions Pde 154 | { 155 | echo "#include " > $(<) 156 | echo "#line 1 \"$(>)\"" >> $(<) 157 | cat $(>) >> $(<) 158 | } 159 | 160 | rule AvrPde 161 | { 162 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 163 | Pde $(_CPP) : $(>) ; 164 | AvrC++ $(<) : $(_CPP) ; 165 | } 166 | 167 | rule AvrObject 168 | { 169 | switch $(>:S) 170 | { 171 | case .S : AvrAsm $(<) : $(>) ; 172 | case .c : AvrCc $(<) : $(>) ; 173 | case .cpp : AvrC++ $(<) : $(>) ; 174 | case .pde : AvrPde $(<) : $(>) ; 175 | } 176 | } 177 | 178 | rule AvrObjects 179 | { 180 | for _I in $(<) 181 | { 182 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 183 | } 184 | } 185 | 186 | rule AvrMainFromObjects 187 | { 188 | Depends $(<) : $(>) ; 189 | Depends $(<) : $(<:D) ; 190 | MkDir $(<:D) ; 191 | Depends all : $(<) ; 192 | Clean clean : $(<) ; 193 | } 194 | 195 | actions AvrMainFromObjects 196 | { 197 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 198 | } 199 | 200 | rule AvrMain 201 | { 202 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 203 | AvrObjects $(>) ; 204 | } 205 | 206 | rule AvrHex 207 | { 208 | Depends $(<) : $(>) ; 209 | Depends $(<) : $(<:D) ; 210 | Depends hex : $(<) ; 211 | Clean clean : $(<) ; 212 | } 213 | 214 | actions AvrHex 215 | { 216 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 217 | } 218 | 219 | rule AvrUpload 220 | { 221 | Depends $(1) : $(2) ; 222 | Depends $(2) : $(3) ; 223 | NotFile $(1) ; 224 | Always $(1) ; 225 | Always $(2) ; 226 | AvrUploadAction $(2) : $(3) ; 227 | } 228 | 229 | actions AvrUploadAction 230 | { 231 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 232 | } 233 | 234 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) 235 | AvrHex $(OUT).hex : $(OUT).elf ; 236 | 237 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 238 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 239 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 240 | 241 | # 242 | # Native 243 | # 244 | 245 | OUT_DIR_NATIVE = out_native ; 246 | OUT_NATIVE = $(OUT_DIR_NATIVE)/$(PROJECT_NAME) ; 247 | NATIVE_CORE = $(SKETCH_DIR)/hardware/native ; 248 | HDRS = $(NATIVE_CORE) $(HDRS) ; 249 | NATIVE_CORE_MODULES = [ GLOB $(NATIVE_CORE) : *.c *.cpp ] ; 250 | NATIVE_MODULES = ; 251 | DEFINES += NATIVE ; 252 | 253 | rule NativePde 254 | { 255 | local _CPP = $(OUT_DIR_NATIVE)/$(_I:B).cpp ; 256 | Pde $(_CPP) : $(>) ; 257 | C++ $(<) : $(_CPP) ; 258 | } 259 | 260 | rule UserObject 261 | { 262 | switch $(>) 263 | { 264 | case *.pde : NativePde $(<) : $(>) ; 265 | } 266 | } 267 | 268 | rule Objects 269 | { 270 | for _I in $(<) 271 | { 272 | local _O = $(OUT_DIR_NATIVE)/$(_I:B).o ; 273 | Object $(_O) : $(_I) ; 274 | } 275 | } 276 | 277 | rule Main 278 | { 279 | MainFromObjects $(<) : $(OUT_DIR_NATIVE)/$(>:B).o ; 280 | Objects $(>) ; 281 | } 282 | 283 | actions C++ 284 | { 285 | c++ -c -o $(<) $(CCHDRS) $(CCDEFS) $(>) 286 | } 287 | 288 | actions Link 289 | { 290 | c++ -o $(<) $(>) 291 | } 292 | 293 | 294 | 295 | MkDir $(OUT_DIR_NATIVE) ; 296 | Depends $(OUT_NATIVE) : $(OUT_DIR_NATIVE) ; 297 | Main $(OUT_NATIVE) : $(NATIVE_CORE_MODULES) $(NATIVE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 298 | 299 | Depends native : $(OUT_NATIVE) ; 300 | 301 | -------------------------------------------------------------------------------- /RF24-master/tests/native/pingpair_irq.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Interrupt-driven test for native target 11 | * 12 | * This example is the friendliest for the native target because it doesn't do 13 | * any polling. Made a slight change to call done() at the end of setup. 14 | */ 15 | 16 | #include 17 | #include "nRF24L01.h" 18 | #include "RF24.h" 19 | #include "printf.h" 20 | 21 | // 22 | // Hardware configuration 23 | // 24 | 25 | // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 26 | 27 | RF24 radio(8,9); 28 | 29 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 30 | // Leave open to be the 'ping' transmitter 31 | const short role_pin = 7; 32 | 33 | // 34 | // Topology 35 | // 36 | 37 | // Single radio pipe address for the 2 nodes to communicate. 38 | const uint64_t pipe = 0xE8E8F0F0E1LL; 39 | 40 | // 41 | // Role management 42 | // 43 | // Set up role. This sketch uses the same software for all the nodes in this 44 | // system. Doing so greatly simplifies testing. The hardware itself specifies 45 | // which node it is. 46 | // 47 | // This is done through the role_pin 48 | // 49 | 50 | // The various roles supported by this sketch 51 | typedef enum { role_sender = 1, role_receiver } role_e; 52 | 53 | // The debug-friendly names of those roles 54 | const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; 55 | 56 | // The role of the current running sketch 57 | role_e role; 58 | 59 | // Interrupt handler, check the radio because we got an IRQ 60 | void check_radio(void); 61 | 62 | void setup(void) 63 | { 64 | // 65 | // Role 66 | // 67 | 68 | // set up the role pin 69 | pinMode(role_pin, INPUT); 70 | digitalWrite(role_pin,HIGH); 71 | delay(20); // Just to get a solid reading on the role pin 72 | 73 | // read the address pin, establish our role 74 | if ( digitalRead(role_pin) ) 75 | role = role_sender; 76 | else 77 | role = role_receiver; 78 | 79 | // 80 | // Print preamble 81 | // 82 | 83 | Serial.begin(57600); 84 | printf_begin(); 85 | printf("\n\rRF24/examples/pingpair_irq/\n\r"); 86 | printf("ROLE: %s\n\r",role_friendly_name[role]); 87 | 88 | // 89 | // Setup and configure rf radio 90 | // 91 | 92 | radio.begin(); 93 | 94 | // We will be using the Ack Payload feature, so please enable it 95 | radio.enableAckPayload(); 96 | 97 | // 98 | // Open pipes to other nodes for communication 99 | // 100 | 101 | // This simple sketch opens a single pipe for these two nodes to communicate 102 | // back and forth. One listens on it, the other talks to it. 103 | 104 | if ( role == role_sender ) 105 | { 106 | radio.openWritingPipe(pipe); 107 | } 108 | else 109 | { 110 | radio.openReadingPipe(1,pipe); 111 | } 112 | 113 | // 114 | // Start listening 115 | // 116 | 117 | if ( role == role_receiver ) 118 | radio.startListening(); 119 | 120 | // 121 | // Dump the configuration of the rf unit for debugging 122 | // 123 | 124 | radio.printDetails(); 125 | 126 | // 127 | // Attach interrupt handler to interrupt #0 (using pin 2) 128 | // on BOTH the sender and receiver 129 | // 130 | 131 | attachInterrupt(0, check_radio, FALLING); 132 | 133 | // 134 | // On the native target, this is as far as we get 135 | // 136 | #if NATIVE 137 | done(); 138 | #endif 139 | } 140 | 141 | static uint32_t message_count = 0; 142 | 143 | void loop(void) 144 | { 145 | // 146 | // Sender role. Repeatedly send the current time 147 | // 148 | 149 | if (role == role_sender) 150 | { 151 | // Take the time, and send it. 152 | unsigned long time = millis(); 153 | printf("Now sending %lu\n\r",time); 154 | radio.startWrite( &time, sizeof(unsigned long) ); 155 | 156 | // Try again soon 157 | delay(2000); 158 | } 159 | 160 | // 161 | // Receiver role: Does nothing! All the work is in IRQ 162 | // 163 | 164 | } 165 | 166 | void check_radio(void) 167 | { 168 | // What happened? 169 | bool tx,fail,rx; 170 | radio.whatHappened(tx,fail,rx); 171 | 172 | // Have we successfully transmitted? 173 | if ( tx ) 174 | { 175 | if ( role == role_sender ) 176 | printf("Send:OK\n\r"); 177 | 178 | if ( role == role_receiver ) 179 | printf("Ack Payload:Sent\n\r"); 180 | } 181 | 182 | // Have we failed to transmit? 183 | if ( fail ) 184 | { 185 | if ( role == role_sender ) 186 | printf("Send:Failed\n\r"); 187 | 188 | if ( role == role_receiver ) 189 | printf("Ack Payload:Failed\n\r"); 190 | } 191 | 192 | // Transmitter can power down for now, because 193 | // the transmission is done. 194 | if ( ( tx || fail ) && ( role == role_sender ) ) 195 | radio.powerDown(); 196 | 197 | // Did we receive a message? 198 | if ( rx ) 199 | { 200 | // If we're the sender, we've received an ack payload 201 | if ( role == role_sender ) 202 | { 203 | radio.read(&message_count,sizeof(message_count)); 204 | printf("Ack:%lu\n\r",(unsigned long)message_count); 205 | } 206 | 207 | // If we're the receiver, we've received a time message 208 | if ( role == role_receiver ) 209 | { 210 | // Get this payload and dump it 211 | static unsigned long got_time; 212 | radio.read( &got_time, sizeof(got_time) ); 213 | printf("Got payload %lu\n\r",got_time); 214 | 215 | // Add an ack packet for the next time around. This is a simple 216 | // packet counter 217 | radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); 218 | ++message_count; 219 | } 220 | } 221 | } 222 | 223 | // vim:ai:cin:sts=2 sw=2 ft=cpp 224 | -------------------------------------------------------------------------------- /RF24-master/tests/native/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #include "WProgram.h" 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #endif // __PRINTF_H__ 34 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_blocking/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | PROJECT_DIRS = $(PWD) ; 5 | 6 | # (2) Board Information 7 | 8 | UPLOAD_PROTOCOL ?= arduino ; 9 | UPLOAD_SPEED ?= 115200 ; 10 | MCU ?= atmega328p ; 11 | F_CPU ?= 16000000 ; 12 | CORE ?= arduino ; 13 | VARIANT ?= standard ; 14 | ARDUINO_VERSION ?= 100 ; 15 | 16 | # (3) USB Ports 17 | 18 | PORTS = p4 p6 p9 u0 u1 u2 ; 19 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 20 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 21 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 22 | PORT_u0 = /dev/ttyUSB0 ; 23 | PORT_u1 = /dev/ttyUSB1 ; 24 | PORT_u2 = /dev/ttyUSB2 ; 25 | 26 | # (4) Location of AVR tools 27 | # 28 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 29 | # distribution. 30 | 31 | if $(OS) = MACOSX 32 | { 33 | AVR_BIN ?= /usr/local/avrtools/bin ; 34 | AVR_ETC = /usr/local/avrtools/etc ; 35 | AVR_INCLUDE = /usr/local/avrtools/include ; 36 | } 37 | else 38 | { 39 | AVR_BIN ?= /usr/bin ; 40 | AVR_INCLUDE = /usr/lib/avr/include ; 41 | AVR_ETC = /etc ; 42 | } 43 | 44 | # (5) Directories where Arduino core and libraries are located 45 | 46 | ARDUINO_DIR ?= /opt/Arduino ; 47 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 48 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 49 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 50 | 51 | # 52 | # -------------------------------------------------- 53 | # Below this line usually never needs to be modified 54 | # 55 | 56 | # Tool locations 57 | 58 | CC = $(AVR_BIN)/avr-gcc ; 59 | C++ = $(AVR_BIN)/avr-g++ ; 60 | LINK = $(AVR_BIN)/avr-gcc ; 61 | AR = $(AVR_BIN)/avr-ar rcs ; 62 | RANLIB = ; 63 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 64 | AVRDUDE ?= $(AVR_BIN)/avrdude ; 65 | 66 | # Flags 67 | 68 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 69 | OPTIM = -Os ; 70 | CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 71 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 72 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 73 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 74 | 75 | # Search everywhere for headers 76 | 77 | HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 78 | 79 | # Output locations 80 | 81 | LOCATE_TARGET = $(F_CPU) ; 82 | LOCATE_SOURCE = $(F_CPU) ; 83 | 84 | # 85 | # Custom rules 86 | # 87 | 88 | rule GitVersion 89 | { 90 | Always $(<) ; 91 | Depends all : $(<) ; 92 | } 93 | 94 | actions GitVersion 95 | { 96 | echo "const char program_version[] = \"\\" > $(<) 97 | git log -1 --pretty=format:%h >> $(<) 98 | echo "\";" >> $(<) 99 | } 100 | 101 | GitVersion version.h ; 102 | 103 | rule Pde 104 | { 105 | Depends $(<) : $(>) ; 106 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 107 | Clean clean : $(<) ; 108 | } 109 | 110 | if ( $(ARDUINO_VERSION) < 100 ) 111 | { 112 | ARDUINO_H = WProgram.h ; 113 | } 114 | else 115 | { 116 | ARDUINO_H = Arduino.h ; 117 | } 118 | 119 | actions Pde 120 | { 121 | echo "#include <$(ARDUINO_H)>" > $(<) 122 | echo "#line 1 \"$(>)\"" >> $(<) 123 | cat $(>) >> $(<) 124 | } 125 | 126 | rule C++Pde 127 | { 128 | local _CPP = $(>:B).cpp ; 129 | Pde $(_CPP) : $(>) ; 130 | C++ $(<) : $(_CPP) ; 131 | } 132 | 133 | rule UserObject 134 | { 135 | switch $(>:S) 136 | { 137 | case .ino : C++Pde $(<) : $(>) ; 138 | case .pde : C++Pde $(<) : $(>) ; 139 | } 140 | } 141 | 142 | rule Objects 143 | { 144 | local _i ; 145 | 146 | for _i in [ FGristFiles $(<) ] 147 | { 148 | local _b = $(_i:B)$(SUFOBJ) ; 149 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 150 | Object $(_o) : $(_i) ; 151 | Depends obj : $(_o) ; 152 | } 153 | } 154 | 155 | rule Library 156 | { 157 | LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; 158 | Objects $(>) ; 159 | } 160 | 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | rule Hex 168 | { 169 | Depends $(<) : $(>) ; 170 | MakeLocate $(<) : $(LOCATE_TARGET) ; 171 | Depends hex : $(<) ; 172 | Clean clean : $(<) ; 173 | } 174 | 175 | actions Hex 176 | { 177 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 178 | } 179 | 180 | rule Upload 181 | { 182 | Depends $(1) : $(2) ; 183 | Depends $(2) : $(3) ; 184 | NotFile $(1) ; 185 | Always $(1) ; 186 | Always $(2) ; 187 | UploadAction $(2) : $(3) ; 188 | } 189 | 190 | actions UploadAction 191 | { 192 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 193 | } 194 | 195 | rule Arduino 196 | { 197 | LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; 198 | Main $(<) : $(>) ; 199 | LinkLibraries $(<) : core libs ; 200 | Hex $(<:B).hex : $(<) ; 201 | for _p in $(PORTS) 202 | { 203 | Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; 204 | } 205 | } 206 | 207 | # 208 | # Targets 209 | # 210 | 211 | # Grab everything from the core directory 212 | Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 213 | 214 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 215 | # can specify specific modules to pick up in PROJECT_MODULES 216 | Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 217 | 218 | # Main output executable 219 | Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; 220 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_blocking/pingpair_blocking.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #include 10 | #include "nRF24L01.h" 11 | #include "RF24.h" 12 | #include "printf.h" 13 | 14 | // 15 | // Test version of RF24, exposes some protected interface 16 | // 17 | 18 | class RF24Test: public RF24 19 | { 20 | public: RF24Test(int a, int b): RF24(a,b) {} 21 | }; 22 | 23 | 24 | // 25 | // Hardware configuration 26 | // 27 | 28 | // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 29 | 30 | RF24Test radio(8,9); 31 | 32 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 33 | // Leave open to be the 'ping' transmitter 34 | const int role_pin = 7; 35 | 36 | // 37 | // Topology 38 | // 39 | 40 | // Radio pipe addresses for the 2 nodes to communicate. 41 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 42 | 43 | // 44 | // Role management 45 | // 46 | // Set up role. This sketch uses the same software for all the nodes 47 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 48 | // which node it is. 49 | // 50 | // This is done through the role_pin 51 | // 52 | 53 | // The various roles supported by this sketch 54 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 55 | 56 | // The debug-friendly names of those roles 57 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 58 | 59 | // The role of the current running sketch 60 | role_e role; 61 | 62 | // 63 | // Test state 64 | // 65 | 66 | bool done; //*< Are we done with the test? */ 67 | bool passed; //*< Have we passed the test? */ 68 | bool notified; //*< Have we notified the user we're done? */ 69 | const int num_needed = 10; //*< How many success/failures until we're done? */ 70 | int receives_remaining = num_needed; //*< How many ack packets until we declare victory? */ 71 | int failures_remaining = num_needed; //*< How many more failed sends until we declare failure? */ 72 | const int interval = 100; //*< ms to wait between sends */ 73 | 74 | char configuration = '1'; //*< Configuration key, one char sent in by the test framework to tell us how to configure, this is the default */ 75 | 76 | void one_ok(void) 77 | { 78 | // Have we received enough yet? 79 | if ( ! --receives_remaining ) 80 | { 81 | done = true; 82 | passed = true; 83 | } 84 | } 85 | 86 | void one_failed(void) 87 | { 88 | // Have we failed enough yet? 89 | if ( ! --failures_remaining ) 90 | { 91 | done = true; 92 | passed = false; 93 | } 94 | } 95 | 96 | void setup(void) 97 | { 98 | // 99 | // Role 100 | // 101 | 102 | // set up the role pin 103 | pinMode(role_pin, INPUT); 104 | digitalWrite(role_pin,HIGH); 105 | delay(20); // Just to get a solid reading on the role pin 106 | 107 | // read the address pin, establish our role 108 | if ( digitalRead(role_pin) ) 109 | role = role_ping_out; 110 | else 111 | role = role_pong_back; 112 | 113 | // 114 | // Print preamble 115 | // 116 | 117 | Serial.begin(57600); 118 | printf_begin(); 119 | printf("\n\rRF24/tests/pingpair_blocking/\n\r"); 120 | printf("ROLE: %s\n\r",role_friendly_name[role]); 121 | 122 | // 123 | // get test config 124 | // 125 | 126 | printf("+READY press any key to start\n\r\n\r"); 127 | 128 | while (! Serial.available() ) {} 129 | configuration = Serial.read(); 130 | printf("Configuration\t = %c\n\r",configuration); 131 | 132 | // 133 | // Setup and configure rf radio 134 | // 135 | 136 | radio.begin(); 137 | 138 | // 139 | // Open pipes to other nodes for communication 140 | // 141 | 142 | // This simple sketch opens two pipes for these two nodes to communicate 143 | // back and forth. 144 | // Open 'our' pipe for writing 145 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 146 | 147 | if ( role == role_ping_out ) 148 | { 149 | radio.openWritingPipe(pipes[0]); 150 | radio.openReadingPipe(1,pipes[1]); 151 | } 152 | else 153 | { 154 | radio.openWritingPipe(pipes[1]); 155 | radio.openReadingPipe(1,pipes[0]); 156 | } 157 | 158 | // 159 | // Start listening 160 | // 161 | 162 | radio.startListening(); 163 | 164 | // 165 | // Dump the configuration of the rf unit for debugging 166 | // 167 | 168 | radio.printDetails(); 169 | 170 | if ( role == role_pong_back ) 171 | printf("\n\r+OK "); 172 | } 173 | 174 | void loop(void) 175 | { 176 | // 177 | // Ping out role. Repeatedly send the current time 178 | // 179 | 180 | if (role == role_ping_out) 181 | { 182 | // First, stop listening so we can talk. 183 | radio.stopListening(); 184 | 185 | // Take the time, and send it. This will block until complete 186 | unsigned long time = millis(); 187 | printf("Now sending %lu...",time); 188 | radio.write( &time, sizeof(unsigned long) ); 189 | 190 | // Now, continue listening 191 | radio.startListening(); 192 | 193 | // Wait here until we get a response, or timeout (250ms) 194 | unsigned long started_waiting_at = millis(); 195 | bool timeout = false; 196 | while ( ! radio.available() && ! timeout ) 197 | if (millis() - started_waiting_at > 200 ) 198 | timeout = true; 199 | 200 | // Describe the results 201 | if ( timeout ) 202 | { 203 | printf("Failed, response timed out.\n\r"); 204 | one_failed(); 205 | } 206 | else 207 | { 208 | // Grab the response, compare, and send to debugging spew 209 | unsigned long got_time; 210 | radio.read( &got_time, sizeof(unsigned long) ); 211 | 212 | // Spew it 213 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 214 | one_ok(); 215 | } 216 | 217 | // Try again later 218 | delay(250); 219 | } 220 | 221 | // 222 | // Pong back role. Receive each packet, dump it out, and send it back 223 | // 224 | 225 | if ( role == role_pong_back ) 226 | { 227 | // if there is data ready 228 | if ( radio.available() ) 229 | { 230 | // Dump the payloads until we've gotten everything 231 | unsigned long got_time; 232 | bool done = false; 233 | while (!done) 234 | { 235 | // Fetch the payload, and see if this was the last one. 236 | done = radio.read( &got_time, sizeof(unsigned long) ); 237 | 238 | // Spew it 239 | printf("Got payload %lu...",got_time); 240 | 241 | // Delay just a little bit to let the other unit 242 | // make the transition to receiver 243 | delay(20); 244 | } 245 | 246 | // First, stop listening so we can talk 247 | radio.stopListening(); 248 | 249 | // Send the final one back. 250 | radio.write( &got_time, sizeof(unsigned long) ); 251 | printf("Sent response.\n\r"); 252 | 253 | // Now, resume listening so we catch the next packets. 254 | radio.startListening(); 255 | 256 | } 257 | } 258 | 259 | // 260 | // Stop the test if we're done and report results 261 | // 262 | if ( done && ! notified ) 263 | { 264 | notified = true; 265 | 266 | printf("\n\r+OK "); 267 | if ( passed ) 268 | printf("PASS\n\r\n\r"); 269 | else 270 | printf("FAIL\n\r\n\r"); 271 | } 272 | } 273 | // vim:cin:ai:sts=2 sw=2 ft=cpp 274 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_blocking/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_blocking/runtest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys,serial 4 | 5 | def read_until(token): 6 | while 1: 7 | line = ser.readline(None) 8 | sys.stdout.write(line) 9 | 10 | if (line.startswith(token)): 11 | break 12 | return line 13 | 14 | 15 | ser = serial.Serial(sys.argv[1], 57600, timeout=5, dsrdtr=False, rtscts=False) 16 | 17 | read_until("+READY") 18 | ser.write(sys.argv[2]) 19 | 20 | line = read_until("+OK") 21 | ser.close() 22 | if (line.find("PASS") != -1): 23 | sys.exit(0) 24 | else: 25 | sys.exit(1) 26 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_blocking/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Connect u0 to receiver, u1 to sender 4 | 5 | jam u0 u1 && expect test.ex 6 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_blocking/test.ex: -------------------------------------------------------------------------------- 1 | #/usr/bin/expect 2 | 3 | set timeout 100 4 | spawn picocom -b 57600 /dev/ttyUSB0 5 | expect "+READY" 6 | send "1" 7 | expect "+OK" 8 | spawn picocom -b 57600 /dev/ttyUSB1 9 | expect "+READY" 10 | send "1" 11 | expect "+OK" 12 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_test/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | PROJECT_DIRS = $(PWD) ; 5 | 6 | # (2) Board Information 7 | 8 | UPLOAD_PROTOCOL ?= arduino ; 9 | UPLOAD_SPEED ?= 115200 ; 10 | MCU ?= atmega328p ; 11 | F_CPU ?= 16000000 ; 12 | CORE ?= arduino ; 13 | VARIANT ?= standard ; 14 | ARDUINO_VERSION ?= 100 ; 15 | 16 | # (3) USB Ports 17 | 18 | PORTS = p4 p6 p9 u0 u1 u2 ; 19 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 20 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 21 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 22 | PORT_u0 = /dev/ttyUSB0 ; 23 | PORT_u1 = /dev/ttyUSB1 ; 24 | PORT_u2 = /dev/ttyUSB2 ; 25 | 26 | # (4) Location of AVR tools 27 | # 28 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 29 | # distribution. 30 | 31 | if $(OS) = MACOSX 32 | { 33 | AVR_BIN ?= /usr/local/avrtools/bin ; 34 | AVR_ETC = /usr/local/avrtools/etc ; 35 | AVR_INCLUDE = /usr/local/avrtools/include ; 36 | } 37 | else 38 | { 39 | AVR_BIN ?= /usr/bin ; 40 | AVR_INCLUDE = /usr/lib/avr/include ; 41 | AVR_ETC = /etc ; 42 | } 43 | 44 | # (5) Directories where Arduino core and libraries are located 45 | 46 | ARDUINO_DIR ?= /opt/Arduino ; 47 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 48 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 49 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 50 | 51 | # 52 | # -------------------------------------------------- 53 | # Below this line usually never needs to be modified 54 | # 55 | 56 | # Tool locations 57 | 58 | CC = $(AVR_BIN)/avr-gcc ; 59 | C++ = $(AVR_BIN)/avr-g++ ; 60 | LINK = $(AVR_BIN)/avr-gcc ; 61 | AR = $(AVR_BIN)/avr-ar rcs ; 62 | RANLIB = ; 63 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 64 | AVRDUDE ?= $(AVR_BIN)/avrdude ; 65 | 66 | # Flags 67 | 68 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 69 | OPTIM = -Os ; 70 | CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 71 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 72 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 73 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 74 | 75 | # Search everywhere for headers 76 | 77 | HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 78 | 79 | # Output locations 80 | 81 | LOCATE_TARGET = $(F_CPU) ; 82 | LOCATE_SOURCE = $(F_CPU) ; 83 | 84 | # 85 | # Custom rules 86 | # 87 | 88 | rule GitVersion 89 | { 90 | Always $(<) ; 91 | Depends all : $(<) ; 92 | } 93 | 94 | actions GitVersion 95 | { 96 | echo "const char program_version[] = \"\\" > $(<) 97 | git log -1 --pretty=format:%h >> $(<) 98 | echo "\";" >> $(<) 99 | } 100 | 101 | GitVersion version.h ; 102 | 103 | rule Pde 104 | { 105 | Depends $(<) : $(>) ; 106 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 107 | Clean clean : $(<) ; 108 | } 109 | 110 | if ( $(ARDUINO_VERSION) < 100 ) 111 | { 112 | ARDUINO_H = WProgram.h ; 113 | } 114 | else 115 | { 116 | ARDUINO_H = Arduino.h ; 117 | } 118 | 119 | actions Pde 120 | { 121 | echo "#include <$(ARDUINO_H)>" > $(<) 122 | echo "#line 1 \"$(>)\"" >> $(<) 123 | cat $(>) >> $(<) 124 | } 125 | 126 | rule C++Pde 127 | { 128 | local _CPP = $(>:B).cpp ; 129 | Pde $(_CPP) : $(>) ; 130 | C++ $(<) : $(_CPP) ; 131 | } 132 | 133 | rule UserObject 134 | { 135 | switch $(>:S) 136 | { 137 | case .ino : C++Pde $(<) : $(>) ; 138 | case .pde : C++Pde $(<) : $(>) ; 139 | } 140 | } 141 | 142 | rule Objects 143 | { 144 | local _i ; 145 | 146 | for _i in [ FGristFiles $(<) ] 147 | { 148 | local _b = $(_i:B)$(SUFOBJ) ; 149 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 150 | Object $(_o) : $(_i) ; 151 | Depends obj : $(_o) ; 152 | } 153 | } 154 | 155 | rule Library 156 | { 157 | LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; 158 | Objects $(>) ; 159 | } 160 | 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | rule Hex 168 | { 169 | Depends $(<) : $(>) ; 170 | MakeLocate $(<) : $(LOCATE_TARGET) ; 171 | Depends hex : $(<) ; 172 | Clean clean : $(<) ; 173 | } 174 | 175 | actions Hex 176 | { 177 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 178 | } 179 | 180 | rule Upload 181 | { 182 | Depends $(1) : $(2) ; 183 | Depends $(2) : $(3) ; 184 | NotFile $(1) ; 185 | Always $(1) ; 186 | Always $(2) ; 187 | UploadAction $(2) : $(3) ; 188 | } 189 | 190 | actions UploadAction 191 | { 192 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 193 | } 194 | 195 | rule Arduino 196 | { 197 | LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; 198 | Main $(<) : $(>) ; 199 | LinkLibraries $(<) : core libs ; 200 | Hex $(<:B).hex : $(<) ; 201 | for _p in $(PORTS) 202 | { 203 | Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; 204 | } 205 | } 206 | 207 | # 208 | # Targets 209 | # 210 | 211 | # Grab everything from the core directory 212 | Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 213 | 214 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 215 | # can specify specific modules to pick up in PROJECT_MODULES 216 | Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 217 | 218 | # Main output executable 219 | Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; 220 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_test/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_test/runtest.py: -------------------------------------------------------------------------------- 1 | #!/opt/local/bin/python 2 | 3 | import sys,serial 4 | 5 | def read_until(token): 6 | while 1: 7 | line = ser.readline(None,"\r") 8 | sys.stdout.write(line) 9 | 10 | if (line.startswith(token)): 11 | break 12 | return line 13 | 14 | 15 | ser = serial.Serial(sys.argv[1], 57600, timeout=5, dsrdtr=False, rtscts=False) 16 | 17 | read_until("+READY") 18 | ser.write(sys.argv[2]) 19 | 20 | line = read_until("+OK") 21 | ser.close() 22 | if (line.find("PASS") != -1): 23 | sys.exit(0) 24 | else: 25 | sys.exit(1) 26 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_test/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Connect u0 to receiver, u0 to sender 4 | # WARNING: Test config 2 only works with PLUS units. 5 | 6 | jam u0 u1 && expect test.ex 1 7 | sleep 1 8 | stty 57600 raw ignbrk hup < /dev/ttyUSB0 9 | sleep 1 10 | stty 57600 raw ignbrk hup < /dev/ttyUSB1 11 | expect test.ex 2 12 | sleep 1 13 | stty 57600 raw ignbrk hup < /dev/ttyUSB0 14 | sleep 1 15 | stty 57600 raw ignbrk hup < /dev/ttyUSB1 16 | expect test.ex 3 17 | sleep 1 18 | stty 57600 raw ignbrk hup < /dev/ttyUSB0 19 | sleep 1 20 | stty 57600 raw ignbrk hup < /dev/ttyUSB1 21 | expect test.ex 4 22 | -------------------------------------------------------------------------------- /RF24-master/tests/pingpair_test/test.ex: -------------------------------------------------------------------------------- 1 | #/usr/bin/expect 2 | 3 | set timeout 100 4 | spawn picocom -b 57600 /dev/ttyUSB0 5 | expect "+READY" 6 | send [lindex $argv 0] 7 | expect "+OK" 8 | spawn picocom -b 57600 /dev/ttyUSB1 9 | expect "+READY" 10 | send [lindex $argv 0] 11 | expect "+OK" 12 | -------------------------------------------------------------------------------- /RF24-master/wikidoc.xslt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | === === 9 | 10 | 11 | 12 | 13 | '''' 14 | 15 | Parameters: 16 | 17 | 18 | 19 | * '''': 20 | 21 | 22 | 23 | 24 | 25 | Returns: 26 | 27 | * 28 | 29 | 30 | Warning: 31 | 32 | 33 | 34 | <pre> </pre> 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /connect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/connect.jpg -------------------------------------------------------------------------------- /connect_adapter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/connect_adapter.png -------------------------------------------------------------------------------- /nRF24L01 tests/GettingStarted_CallResponse/GettingStarted_CallResponse.ino: -------------------------------------------------------------------------------- 1 | /* 2 | March 2014 - TMRh20 - Updated along with High Speed RF24 Library fork 3 | Parts derived from examples by J. Coliz 4 | */ 5 | /** 6 | Example for efficient call-response using ack-payloads 7 | 8 | This example continues to make use of all the normal functionality of the radios including 9 | the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well. 10 | This allows very fast call-response communication, with the responding radio never having to 11 | switch out of Primary Receiver mode to send back a payload, but having the option to switch to 12 | primary transmitter if wanting to initiate communication instead of respond to a commmunication. 13 | */ 14 | 15 | #include 16 | #include "nRF24L01.h" 17 | #include "RF24.h" 18 | #include "printf.h" 19 | 20 | // Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10 21 | RF24 radio(9, 10); 22 | // Topology 23 | byte addresses[][6] = {"1Node", "2Node"}; // Radio pipe addresses for the 2 nodes to communicate. 24 | 25 | // Role management: Set up role. This sketch uses the same software for all the nodes 26 | // in this system. Doing so greatly simplifies testing. 27 | typedef enum { role_ping_out = 1, role_pong_back } role_e; // The various roles supported by this sketch 28 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; // The debug-friendly names of those roles 29 | role_e role = role_pong_back; // The role of the current running sketch 30 | 31 | byte counter = 1; // A single byte to keep track of the data being sent back and forth 32 | 33 | 34 | void setup() { 35 | 36 | Serial.begin(9600); 37 | printf_begin(); 38 | printf("\n\rRF24/examples/GettingStarted/\n\r"); 39 | printf("ROLE: %s\n\r", role_friendly_name[role]); 40 | printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); 41 | 42 | // Setup and configure radio 43 | 44 | radio.begin(); 45 | radio.setAutoAck(1); // Ensure autoACK is enabled 46 | radio.enableAckPayload(); // Allow optional ack payloads 47 | radio.setRetries(0, 15); // Smallest time between retries, max no. of retries 48 | radio.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed 49 | radio.openWritingPipe(addresses[1]); // Both radios listen on the same pipes by default, and switch when writing 50 | radio.openReadingPipe(1, addresses[0]); // Open a reading pipe on address 0, pipe 1 51 | radio.startListening(); // Start listening 52 | radio.powerUp(); 53 | radio.printDetails(); // Dump the configuration of the rf unit for debugging 54 | } 55 | 56 | void loop(void) { 57 | 58 | /****************** Ping Out Role ***************************/ 59 | 60 | if (role == role_ping_out) { // Radio is in ping mode 61 | 62 | byte gotByte; // Initialize a variable for the incoming response 63 | 64 | radio.stopListening(); // First, stop listening so we can talk. 65 | printf("Now sending %d as payload. ", counter); // Use a simple byte counter as payload 66 | unsigned long time = micros(); // Record the current microsecond count 67 | 68 | if ( radio.write(&counter, 1) ) { // Send the counter variable to the other radio 69 | if (!radio.available()) { // If nothing in the buffer, we got an ack but it is blank 70 | printf("Got blank response. round-trip delay: %lu microseconds\n\r", micros() - time); 71 | } else { 72 | while (radio.available() ) { // If an ack with payload was received 73 | radio.read( &gotByte, 1 ); // Read it, and display the response time 74 | printf("Got response %d, round-trip delay: %lu microseconds\n\r", gotByte, micros() - time); 75 | counter++; // Increment the counter variable 76 | } 77 | } 78 | 79 | } else { 80 | printf("Sending failed.\n\r"); // If no ack response, sending failed 81 | } 82 | 83 | delay(1000); // Try again later 84 | } 85 | 86 | /****************** Pong Back Role ***************************/ 87 | 88 | if ( role == role_pong_back ) { 89 | byte pipeNo, gotByte; // Declare variables for the pipe and the byte received 90 | while ( radio.available(&pipeNo)) { // Read all available payloads 91 | radio.read( &gotByte, 1 ); 92 | // Since this is a call-response. Respond directly with an ack payload. 93 | // Ack payloads are much more efficient than switching to transmit mode to respond to a call 94 | radio.writeAckPayload(pipeNo, &gotByte, 1 ); // This can be commented out to send empty payloads. 95 | printf("Sent response %d \n\r", gotByte); 96 | } 97 | } 98 | 99 | /****************** Change Roles via Serial Commands ***************************/ 100 | 101 | if ( Serial.available() ) 102 | { 103 | char c = toupper(Serial.read()); 104 | if ( c == 'T' && role == role_pong_back ) 105 | { 106 | printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); 107 | 108 | role = role_ping_out; // Change roles (ping out) 109 | radio.openWritingPipe(addresses[0]); // Open different pipes when writing. Write on pipe 0, address 0 110 | radio.openReadingPipe(1, addresses[1]); // Read on pipe 1, as address 1 111 | } 112 | else if ( c == 'R' && role == role_ping_out ) 113 | { 114 | printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); 115 | 116 | role = role_pong_back; // Become the primary receiver (pong back) 117 | radio.openWritingPipe(addresses[1]); // Since only two radios involved, both listen on the same addresses and pipe numbers in RX mode 118 | radio.openReadingPipe(1, addresses[0]); // then switch pipes & addresses to transmit. 119 | radio.startListening(); // Need to start listening after opening new reading pipes 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /nRF24L01 tests/nrf_listen_air/nrf_listen_air.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nRF24L01.h" 3 | #include "RF24.h" 4 | 5 | RF24 radio(9, 10); // инициализировать модуль на пинах 9 и 10 Для Уно 6 | //RF24 radio(9,53); // Для Меги 7 | 8 | const uint8_t num_channels = 128; 9 | uint8_t values[num_channels]; 10 | void setup() { 11 | Serial.begin(9600); 12 | printf_begin(); 13 | radio.begin(); 14 | radio.setAutoAck(false); 15 | radio.startListening(); 16 | 17 | radio.printDetails(); // Вот эта строка напечатает нам что-то, если все правильно соединили. 18 | delay(5000); // И посмотрим на это пять секунд. 19 | 20 | radio.stopListening(); 21 | int i = 0; // А это напечатает нам заголовки всех 127 каналов 22 | while ( i < num_channels ) { 23 | printf("%x", i >> 4); 24 | ++i; 25 | } 26 | printf("\n\r"); 27 | i = 0; 28 | while ( i < num_channels ) { 29 | printf("%x", i & 0xf); 30 | ++i; 31 | } 32 | printf("\n\r"); 33 | } 34 | const int num_reps = 100; 35 | 36 | void loop(void) 37 | { 38 | memset(values, 0, sizeof(values)); 39 | int rep_counter = num_reps; 40 | while (rep_counter--) { 41 | int i = num_channels; 42 | while (i--) { 43 | radio.setChannel(i); 44 | radio.startListening(); 45 | delayMicroseconds(128); 46 | radio.stopListening(); 47 | if ( radio.testCarrier() ) 48 | ++values[i]; 49 | } 50 | } 51 | int i = 0; 52 | while ( i < num_channels ) { 53 | printf("%x", min(0xf, values[i] & 0xf)); 54 | ++i; 55 | } 56 | printf("\n\r"); 57 | } 58 | int serial_putc( char c, FILE * ) { 59 | Serial.write( c ); 60 | return c; 61 | } 62 | 63 | void printf_begin(void) { 64 | fdevopen( &serial_putc, 0 ); 65 | } 66 | -------------------------------------------------------------------------------- /nRF24L01 tests/время передачи/RX_time/RX_time.ino: -------------------------------------------------------------------------------- 1 | /* В данном скетче с передающей части (ТХ) отправляется значение переменной counter, 2 | переменная эта с каждым шагом увеличивается на единицу. Приёмник (RX) принимает 3 | сигнал, и отправляет обратно то, что получил, используя функцию radio.writeAckPayload 4 | То есть наш приёмник на одно мгновение становится передатчиком! Если наш передатчик (TX) 5 | принимает ответный сигнал, он выдаёт то, что принял, и пишет посчитанное вермя между 6 | отправкой и приёмом сигнала в микросекундах. Данный скетч можно использовать для теста 7 | модулей на качество связи, а также для понимания работы функции radio.writeAckPayload 8 | by AlexGyver 2016 9 | */ 10 | 11 | #include 12 | #include "nRF24L01.h" 13 | #include "RF24.h" 14 | 15 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 16 | //RF24 radio(9,53); // для Меги 17 | 18 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; // возможные номера труб 19 | 20 | void setup() { 21 | Serial.begin(9600); // открываем порт для связи с ПК 22 | radio.begin(); // активировать модуль 23 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 24 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 25 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 26 | radio.setPayloadSize(32); // размер пакета, в байтах 27 | 28 | radio.openReadingPipe(1, address[0]); // хотим слушать трубу 0 29 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 30 | 31 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 32 | radio.setDataRate (RF24_1MBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 33 | // должна быть одинакова на приёмнике и передатчике! 34 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 35 | // ВНИМАНИЕ!!! enableAckPayload НЕ РАБОТАЕТ НА СКОРОСТИ 250 kbps! 36 | 37 | radio.powerUp(); // начать работу 38 | radio.startListening(); // начинаем слушать эфир, мы приёмный модуль 39 | } 40 | 41 | void loop(void) { 42 | byte pipeNo, gotByte; 43 | while ( radio.available(&pipeNo)) { // слушаем эфир со всех труб 44 | radio.read( &gotByte, 1 ); // чиатем входящий сигнал 45 | // отправляем обратно то что приняли 46 | radio.writeAckPayload(pipeNo, &gotByte, 1 ); 47 | Serial.print("Recieved: "); 48 | Serial.println(gotByte); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /nRF24L01 tests/время передачи/TX_time/TX_time.ino: -------------------------------------------------------------------------------- 1 | /* В данном скетче с передающей части (ТХ) отправляется значение переменной counter, 2 | переменная эта с каждым шагом увеличивается на единицу. Приёмник (RX) принимает 3 | сигнал, и отправляет обратно то, что получил, используя функцию radio.writeAckPayload 4 | То есть наш приёмник на одно мгновение становится передатчиком! Если наш передатчик (TX) 5 | принимает ответный сигнал, он выдаёт то, что принял, и пишет посчитанное вермя между 6 | отправкой и приёмом сигнала в микросекундах. Данный скетч можно использовать для теста 7 | модулей на качество связи, а также для понимания работы функции radio.writeAckPayload 8 | by AlexGyver 2016 9 | */ 10 | 11 | #include 12 | #include "nRF24L01.h" 13 | #include "RF24.h" 14 | 15 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 16 | //RF24 radio(9,53); // для Меги 17 | 18 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 19 | 20 | byte counter; 21 | 22 | void setup() { 23 | Serial.begin(9600); // открываем порт для связи с ПК 24 | 25 | radio.begin(); // активировать модуль 26 | radio.setAutoAck(1); // режим подтверждения приёма, 1 вкл 0 выкл 27 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 28 | radio.enableAckPayload(); // разрешить отсылку данных в ответ на входящий сигнал 29 | radio.setPayloadSize(32); // размер пакета, в байтах 30 | 31 | radio.openWritingPipe(address[0]); // мы - труба 0, открываем канал для передачи данных 32 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 33 | 34 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 35 | radio.setDataRate (RF24_1MBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 36 | // должна быть одинакова на приёмнике и передатчике! 37 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 38 | // ВНИМАНИЕ!!! enableAckPayload НЕ РАБОТАЕТ НА СКОРОСТИ 250 kbps! 39 | 40 | radio.powerUp(); // начать работу 41 | radio.stopListening(); // не слушаем радиоэфир, мы передатчик 42 | } 43 | 44 | void loop(void) { 45 | byte gotByte; 46 | Serial.print("Sending... "); 47 | Serial.println(counter); 48 | 49 | // запоминаем время отправки 50 | uint32_t last_time = micros(); 51 | 52 | if (radio.write(&counter, 1) ) { // отправляем значение counter 53 | if (!radio.available()) { // если получаем пустой ответ 54 | Serial.print("Empty, "); 55 | Serial.print(" Time: "); 56 | Serial.print(micros() - last_time); 57 | Serial.println(" microseconds"); 58 | Serial.println(); 59 | } else { 60 | while (radio.available() ) { // если в ответе что-то есть 61 | radio.read( &gotByte, 1 ); // читаем 62 | Serial.print("Anser: "); 63 | Serial.print(gotByte); 64 | Serial.print(" Time: "); 65 | Serial.print(micros() - last_time); 66 | Serial.println(" microseconds"); 67 | Serial.println(); 68 | counter++; 69 | } 70 | } 71 | } else { 72 | Serial.println("Fail"); 73 | } 74 | delay(1000); 75 | } 76 | -------------------------------------------------------------------------------- /nRF24L01 tests/тест расстояния/RX_time_disp/RX_time_disp.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nRF24L01.h" 3 | #include "RF24.h" 4 | 5 | //-----------дисплей----------- 6 | #include "TM1637.h" //библиотека дисплея 7 | #define CLK 2 //пин дисплея 8 | #define DIO 3 //пин дисплея 9 | TM1637 disp(CLK, DIO); //обозвать дисплей disp 10 | //--------дисплей------- 11 | 12 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 13 | //RF24 radio(9,53); // для Меги 14 | 15 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 16 | byte pipeNo, gotByte; 17 | 18 | void setup() { 19 | Serial.begin(9600); 20 | pinMode(4, OUTPUT); 21 | digitalWrite(4, 0); 22 | disp.init(); // инициализация дисплея 23 | disp.set(6); // яркость (0-7) 24 | 25 | radio.begin(); // активировать модуль 26 | radio.setAutoAck(0); // режим подтверждения приёма, 1 вкл 0 выкл 27 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 28 | 29 | radio.setPayloadSize(32); // размер пакета, в байтах 30 | 31 | radio.openReadingPipe(1, address[0]); // хотим слушать трубу 0 32 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 33 | 34 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 35 | radio.setDataRate (RF24_250KBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 36 | // должна быть одинакова на приёмнике и передатчике! 37 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 38 | 39 | radio.powerUp(); // начать работу 40 | radio.startListening(); // начинаем слушать эфир, мы приёмный модуль 41 | } 42 | 43 | void black_print(String x) { 44 | disp.point(POINT_OFF); 45 | // тут измеряется длина строки и соотвествено выводится всё на дисплей 46 | switch (x.length()) { 47 | case 1: 48 | disp.display(0, 18); 49 | disp.display(1, 18); 50 | disp.display(2, 18); 51 | disp.display(3, x[0] - '0'); 52 | break; 53 | case 2: 54 | disp.display(0, 18); 55 | disp.display(1, 18); 56 | disp.display(2, x[0] - '0'); 57 | disp.display(3, x[1] - '0'); 58 | break; 59 | case 3: 60 | disp.display(0, 18); 61 | disp.display(1, x[0] - '0'); 62 | disp.display(2, x[1] - '0'); 63 | disp.display(3, x[2] - '0'); 64 | break; 65 | } 66 | } 67 | 68 | void loop() { 69 | int count = 0; 70 | volatile long timer = millis(); 71 | while (millis() - timer < 2000) { 72 | while ( radio.available(&pipeNo)) { // слушаем эфир со всех труб 73 | radio.read( &gotByte, 1 ); // чиатем входящий сигнал 74 | count++; 75 | } 76 | } 77 | Serial.println(count); 78 | String nums = String(round(count)); 79 | black_print(nums); 80 | } 81 | -------------------------------------------------------------------------------- /nRF24L01 tests/тест расстояния/TX_time_disp/TX_time_disp.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nRF24L01.h" 3 | #include "RF24.h" 4 | 5 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 6 | //RF24 radio(9,53); // для Меги 7 | 8 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 9 | 10 | byte counter = 1; 11 | 12 | void setup() { 13 | //Serial.begin(9600); // открываем порт для связи с ПК 14 | 15 | radio.begin(); // активировать модуль 16 | radio.setAutoAck(0); // режим подтверждения приёма, 1 вкл 0 выкл 17 | radio.setRetries(0, 15); // (время между попыткой достучаться, число попыток) 18 | 19 | radio.setPayloadSize(32); //размер пакета, в байтах 20 | 21 | radio.openWritingPipe(address[0]); // мы - труба 0, открываем канал для передачи данных 22 | radio.setChannel(0x60); // выбираем канал (в котором нет шумов!) 23 | 24 | radio.setPALevel (RF24_PA_MAX); // уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 25 | radio.setDataRate (RF24_250KBPS); // скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 26 | // должна быть одинакова на приёмнике и передатчике! 27 | // при самой низкой скорости имеем самую высокую чувствительность и дальность!! 28 | 29 | radio.powerUp(); // начать работу 30 | radio.stopListening(); // не слушаем радиоэфир, мы передатчик 31 | } 32 | 33 | void loop(void) { 34 | radio.write(&counter, 1); 35 | delay(5); 36 | } 37 | -------------------------------------------------------------------------------- /power.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/nRF24L01/6b0293330b9796be315ddb6c143fe0568f22e6d2/power.txt -------------------------------------------------------------------------------- /прерывание.txt: -------------------------------------------------------------------------------- 1 | radio.maskIRQ(1, 1, 0); -------------------------------------------------------------------------------- /сбережение.txt: -------------------------------------------------------------------------------- 1 | Enter low-power mode 2 | To return to normal power mode, either write() some data or startListening, or powerUp(). 3 | @note Optimization: The radio will never enter power down unless instructed by the MCU via this command. 4 | 5 | void powerDown(void); 6 | 7 | * @note Optimization: New Command * 8 | * This will not block until the 3 FIFO buffers are filled with data. 9 | * Once the FIFOs are full, writeFast will simply wait for success or timeout, and return 1 or 0 respectively. From a user perspective, just keep trying to send the same data. The library will keep auto retrying the current payload using the built in functionality. 10 | * @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO to clear by issuing txStandBy() or ensure appropriate time between transmissions. 11 | * ONLY max retry interrupt flags will be cleared when writeFast is called 12 | 13 | * Example (Partial blocking): 14 | 15 | radio.writeFast(&buf,32); // Writes 1 payload to the buffers 16 | 17 | txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail. 18 | 19 | radio.writeFast(&buf,32); // Writes 1 payload to the buffers 20 | 21 | txStandBy(1000); // Using extended timeouts, returns 1 if success. Retries failed payloads for 1 seconds before returning 0 22 | 23 | 24 | --------------------------------------------------------------------------------