Merhaba arkadaşlar güzel bir proje olan arduino ile yapılmış walkie-talkie telsiz projesinden bahsedeceğim.
Ses iletimi Nordic firmasınca geliştirilen NRF24L01 kablosuz modül ile yapılmıştır, 2.4GHz frekansında kablosuz haberleşme yapmanıza imkan sağlayan bu modül düşük güç tüketimine de sahiptir. 2.4GHz bandında yayın yapabilir. 250KBps, 1MBps ve 2MBps gibi hızlarda haberleşme hızı seçilebilir. Kullandığım modülün açık alanda haberleşmesi 250m dir. Mesafeyi uzatmak için antenli modeli seçilip mesafe 1-4km ye çıkarılabilir.
Ses verisini aktarabilmemiz için RF24Audio kütüphanesini kullanmamız gerekmektedir. Bu kütüphane NRF24L01 radyo modülleri üzerinden analog girişlerden veri / ses akışına izin verir. Kütüphaneyi buradan indirebilirsiniz. https://github.com/xl2pfu/RF24Audio-1.git
Gerekli Malzemeler.
2x arduino nano, nrf24l01, push button, hoparlör, elektret mikrofonu, 0.1uf kutupsuz kapasitör, 10k res, 100k res, 2N3904 transistör.
Mikrofondan aldığımız sesi mikrodenetleyiciye gönderebilmek için basit bir mikrofondevresine ihtiyacımız vardır. Aşağıdaki şemada inceleyebilirsiniz.
Sesi sürekli iletmeyeceğiz. Bas konuş olduğu için bunu algılayacak bir devreye ihtiyacımız var. Bunun için arduino da button okuyarak interrup ile ses dalgalarını alıp Nrf24l01e ileteceğiz oda alıcıya gönderecek. Devre hem alıcı hem verici özelliğe sahip olmalıdır. Aşağıda buton devresini inceleyebilirsiniz.
Hoparlör bağlantısı
Nrf24l01 ile mikrodenetleyici bağlansıtısı SPI protokolü ile yapılmaktadır.
Bitmiş devre şeması
Kodlar
/* DESCRIPTION Simple example for creating a walkie talkie by sending audio using the nRF24L01 RF transceiver module. DISCLAIMER This code is in the public domain. Please feel free to modify, use, etc however you see fit. But, please give reference to original authors as a courtesy to Open Source developers. Modified example from RF24 Audio Library by TMRh20. Comments from TMRh20 below. */ /* RF24 Audio Library TMRh20 2014 This sketch is intended to demonstrate the basic functionality of the audio library. Requirements: 2 Arduinos (Uno,Nano,Mega, etc supported) 2 NRF24LO1 Radio Modules 1 or more input devices (microphone, ipod, etc) 1 or more output devices (speaker, amplifier, etc) Setup: 1. Change the CE,CS pins below to match your chosen pins (I use 7,8 on 328 boards, and 48,49 on Mega boards) 2. Upload this sketch to two or more devices 3. Default Pin Selections: Speaker: pins 9,10 on UNO, Nano, pins 11,12 on Mega 2560 Input/Microphone: Analog pin A0 on all boards */ #include <RF24.h> #include <SPI.h> #include <RF24Audio.h> #include "printf.h" // General includes for radio and audio lib RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS) RF24Audio rfAudio(radio,0); // Set up the audio using the radio, and set to radio number 0 int talkButton = 3; void setup() { Serial.begin(115200); printf_begin(); radio.begin(); radio.printDetails(); rfAudio.begin(); pinMode(talkButton, INPUT); //sets interrupt to check for button talk abutton press attachInterrupt(digitalPinToInterrupt(talkButton), talk, CHANGE); //sets the default state for each module to recevie rfAudio.receive(); } //void talk() //Called in response to interrupt. Checks the state of the button. //If the button is pressed (and held) enters transmit mode to send //audio. If button is release, enters receive mode to listen. void talk() { if (digitalRead(talkButton)){ rfAudio.transmit(); } else {rfAudio.receive(); } } void loop() { }
User Config ayarları kütüphanenin içindedir.
/*********************************************** //******* MANDATORY User Variables **************/ // Maximum Range: Sample rate 16000, RF_SPEED RF24_250KBPS // Maximum Quality: Sample rate 44000, RF_SPEED RF24_2MBPS #define SAMPLE_RATE 24000 // The sample rate to use for transferring audio samples Note: 44khz+ sample rate requires 8-bits per sample 24000 dü #define RF_SPEED RF24_2MBPS // RF24_250KBPS will do 13-20khz+ sample rate, RF24_1MBPS up to 24-44khz+, RF24_2MBPS for higher. These are not limits, just a guide. 1Mb di #define ANALOG_PIN A0 // The pin that analog readings will be taken from (microphone pin) /************ OverRides *************************/ //10-bit audio requires more bandwidth. A 20khz sample rate will need 25KB/S transfer rate, which is about max for 250kbps data rate. //With a 32khz sample rate, the volume can be set to -1 to shift the sample down to 9-bit, which is the highest the timers can handle at 32khz //#define tenBit // Enable 10-bit samples Note: 44khz+ sample rate requires 8-bits per sample //#define speakerPin 9 // If using a non-standard board, override the timer1 pins //#define speakerPin 10 #define ENABLE_LED // Indicator pin. Using pin 6 on Uno enables audio visualization. Pin 13 on Mega 2560 (TIMER0 COMPA) The pin# cannot be changed. /***************** Optional/Advanced User Variables ******/ //#define MANUAL_BUTTON_HANDLING // Disables button handling via timer0. Allow users to customize button handling #define TX_PIN A1 // Button pin to trigger recording & transmission #define VOL_UP_PIN A2 // Pin for external volume control #define VOL_DN_PIN A3 // Pin for external volume control #define REMOTE_TX_PIN A4 // Pin for externally triggering remote recording #define REMOTE_RX_PIN 4 // Pin for externally stopping remote recording (needs timeout enabled) #define buffSize 32 // The size of the memory buffer to use. Not really configurable. //#define speakerTX // Whether to output to speaker while transmitting //#define oversampling // Oversampling is recommended for low sample rates only. This only affects playback. //#define RX_ONLY //#define TX_ONLY // Not functional yet /********* Automated pin selections, override by defining above ************/ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || (__AVR_ATmega32U4__) || (__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || (__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) #define rampMega #if !defined (speakerPin) //Speaker pin selection for mega etc #define speakerPin 11 //The pins to output audio on. (11,12 on Mega 2560) #endif #if !defined (speakerPin2) #define speakerPin2 12 #endif #if defined (ENABLE_LED) #define ledPin 13 #endif #else //Speaker selection for Uno,Nano, etc #if !defined (speakerPin) #define speakerPin 9 //The pins to output audio on. (9,10 on UNO,Nano) #endif #if !defined (speakerPin2) #define speakerPin2 10 #endif #if defined (ENABLE_LED) #define ledPin 6 #endif #endif //********Radio Defines **************************** // Radio pipe addresses for the 2 nodes to communicate. const uint64_t pipes[14] = { 0xABCDABCD71LL, 0x544d52687CLL, 0x544d526832LL, 0x544d52683CLL,0x544d526846LL, 0x544d526850LL,0x544d52685ALL, 0x544d526820LL, 0x544d52686ELL, 0x544d52684BLL, 0x544d526841LL, 0x544d526855LL,0x544d52685FLL,0x544d526869LL};
/*********************************************** //******* MANDATORY User Variables **************/ // Maximum Range: Sample rate 16000, RF_SPEED RF24_250KBPS // Maximum Quality: Sample rate 44000, RF_SPEED RF24_2MBPS #define SAMPLE_RATE 24000 // The sample rate to use for transferring audio samples Note: 44khz+ sample rate requires 8-bits per sample 24000 dü #define RF_SPEED RF24_2MBPS // RF24_250KBPS will do 13-20khz+ sample rate, RF24_1MBPS up to 24-44khz+, RF24_2MBPS for higher. These are not limits, just a guide. 1Mb di #define ANALOG_PIN A0 // The pin that analog readings will be taken from (microphone pin) /************ OverRides *************************/ //10-bit audio requires more bandwidth. A 20khz sample rate will need 25KB/S transfer rate, which is about max for 250kbps data rate. //With a 32khz sample rate, the volume can be set to -1 to shift the sample down to 9-bit, which is the highest the timers can handle at 32khz //#define tenBit // Enable 10-bit samples Note: 44khz+ sample rate requires 8-bits per sample //#define speakerPin 9 // If using a non-standard board, override the timer1 pins //#define speakerPin 10 #define ENABLE_LED // Indicator pin. Using pin 6 on Uno enables audio visualization. Pin 13 on Mega 2560 (TIMER0 COMPA) The pin# cannot be changed. /***************** Optional/Advanced User Variables ******/ //#define MANUAL_BUTTON_HANDLING // Disables button handling via timer0. Allow users to customize button handling #define TX_PIN A1 // Button pin to trigger recording & transmission #define VOL_UP_PIN A2 // Pin for external volume control #define VOL_DN_PIN A3 // Pin for external volume control #define REMOTE_TX_PIN A4 // Pin for externally triggering remote recording #define REMOTE_RX_PIN 4 // Pin for externally stopping remote recording (needs timeout enabled) #define buffSize 32 // The size of the memory buffer to use. Not really configurable. //#define speakerTX // Whether to output to speaker while transmitting //#define oversampling // Oversampling is recommended for low sample rates only. This only affects playback. //#define RX_ONLY //#define TX_ONLY // Not functional yet /********* Automated pin selections, override by defining above ************/ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || (__AVR_ATmega32U4__) || (__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || (__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) #define rampMega #if !defined (speakerPin) //Speaker pin selection for mega etc #define speakerPin 11 //The pins to output audio on. (11,12 on Mega 2560) #endif #if !defined (speakerPin2) #define speakerPin2 12 #endif #if defined (ENABLE_LED) #define ledPin 13 #endif #else //Speaker selection for Uno,Nano, etc #if !defined (speakerPin) #define speakerPin 9 //The pins to output audio on. (9,10 on UNO,Nano) #endif #if !defined (speakerPin2) #define speakerPin2 10 #endif #if defined (ENABLE_LED) #define ledPin 6 #endif #endif //********Radio Defines **************************** // Radio pipe addresses for the 2 nodes to communicate. const uint64_t pipes[14] = { 0xABCDABCD71LL, 0x544d52687CLL, 0x544d526832LL, 0x544d52683CLL,0x544d526846LL, 0x544d526850LL,0x544d52685ALL, 0x544d526820LL, 0x544d52686ELL, 0x544d52684BLL, 0x544d526841LL, 0x544d526855LL,0x544d52685FLL,0x544d526869LL};
İlk Yorumu Siz Yapın