| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <meta http-equiv="X-UA-Compatible" content="IE=9"/>
- <meta name="generator" content="Doxygen 1.8.5"/>
- <title>NRF24: nrf24_audio_tx.pde</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="dynsections.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td style="padding-left: 0.5em;">
- <div id="projectname">NRF24
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.5 -->
- <div id="navrow1" class="tabs">
- <ul class="tablist">
- <li><a href="index.html"><span>Main Page</span></a></li>
- <li><a href="annotated.html"><span>Classes</span></a></li>
- <li><a href="files.html"><span>Files</span></a></li>
- <li><a href="examples.html"><span>Examples</span></a></li>
- </ul>
- </div>
- </div><!-- top -->
- <div class="header">
- <div class="headertitle">
- <div class="title">nrf24_audio_tx.pde</div> </div>
- </div><!--header-->
- <div class="contents">
- <p>Example sketch showing how to create an audio digital transmitter with the <a class="el" href="classNRF24.html" title="Send and receive addressed, reliable, acknowledged datagrams by nRF24L01. ">NRF24</a> class. Connect a 1Vp-p audio sigal to analog input 0, connected through a 1uF capacitor Works with the nrf24_audio_rx sample receiver The audio quality is poor: dont expect hi-fi!</p>
- <p>This code sends about 250 messages per second, each with 32 8 bit samples from analog input 0 It uses the NRF4 in NOACK mode. The receiver never acknowledges or replies Tested on UNO</p>
- <div class="fragment"><div class="line"><span class="comment">// nrf24_audio_tx.pde</span></div>
- <div class="line"><span class="comment">// -*- mode: C++ -*-</span></div>
- <div class="line"><span class="comment">// Example sketch showing how to create an audio digital transmitter </span></div>
- <div class="line"><span class="comment">// with the NRF24 class. </span></div>
- <div class="line"><span class="comment">// Connect a 1Vp-p audio sigal to analog input 0, connected through a 1uF capacitor</span></div>
- <div class="line"><span class="comment">// Works with the nrf24_audio_rx sample receiver</span></div>
- <div class="line"><span class="comment">// The audio quality is poor: dont expect hi-fi!</span></div>
- <div class="line"><span class="comment">//</span></div>
- <div class="line"><span class="comment">// This code sends about 250 messages per second, each with 32 8 bit samples from analog input 0</span></div>
- <div class="line"><span class="comment">// It uses the NRF4 in NOACK mode. The receiver never acknowledges or replies</span></div>
- <div class="line"><span class="comment">// Tested on UNO</span></div>
- <div class="line"></div>
- <div class="line"><span class="preprocessor">#include <NRF24.h></span></div>
- <div class="line"><span class="preprocessor">#include <SPI.h></span></div>
- <div class="line"></div>
- <div class="line"></div>
- <div class="line"><span class="comment">// Singleton instance of the radio</span></div>
- <div class="line"><a name="_a0"></a><a class="code" href="classNRF24.html">NRF24</a> nrf24;</div>
- <div class="line"><span class="comment">// NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf</span></div>
- <div class="line"><span class="comment">// NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin</span></div>
- <div class="line"></div>
- <div class="line"><span class="keywordtype">void</span> setup() </div>
- <div class="line">{</div>
- <div class="line"> Serial.begin(9600);</div>
- <div class="line"> <span class="keywordflow">while</span> (!Serial) </div>
- <div class="line"> ; <span class="comment">// wait for serial port to connect. Needed for Leonardo only</span></div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a1"></a><a class="code" href="classNRF24.html#a6e98cf508939240c1805245170a995f6">init</a>())</div>
- <div class="line"> Serial.println(<span class="stringliteral">"NRF24 init failed"</span>);</div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a2"></a><a class="code" href="classNRF24.html#a3fa90005f98eb2744a533899f9b7e023">setChannel</a>(1))</div>
- <div class="line"> Serial.println(<span class="stringliteral">"setChannel failed"</span>);</div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a3"></a><a class="code" href="classNRF24.html#adb2fbd1d1aadaad1e9b268508149b6c8">setPayloadSize</a>(32))</div>
- <div class="line"> Serial.println(<span class="stringliteral">"setPayloadSize failed"</span>);</div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a4"></a><a class="code" href="classNRF24.html#a3453db8390d5be4aa99d8c7fde3062a4">setRF</a>(<a name="a5"></a><a class="code" href="classNRF24.html#a52d7af9188397d4a6f5dab55d4f04742aca0c89dd1b40bdc57b7026d8da54de9a">NRF24::NRF24DataRate2Mbps</a>, <a name="a6"></a><a class="code" href="classNRF24.html#a8386e81a9a4b824ab26e785879684c7eacef1d6c037e276e6dadaff2b6056ec0c">NRF24::NRF24TransmitPower0dBm</a>))</div>
- <div class="line"> Serial.println(<span class="stringliteral">"setRF failed"</span>); </div>
- <div class="line"> <span class="comment">// Enable the EN_DYN_ACK feature so we can use noack</span></div>
- <div class="line"> nrf24.<a name="a7"></a><a class="code" href="classNRF24.html#a81931bc1679b213b1cb1ae65b8357985">spiWriteRegister</a>(NRF24_REG_1D_FEATURE, NRF24_EN_DYN_ACK);</div>
- <div class="line"> analogReference(INTERNAL); <span class="comment">// So we can read 1Vp-p signals</span></div>
- <div class="line"> Serial.println(<span class="stringliteral">"initialised"</span>);</div>
- <div class="line">}</div>
- <div class="line"> </div>
- <div class="line"><span class="keywordtype">void</span> loop()</div>
- <div class="line">{</div>
- <div class="line"> uint8_t buf[32];</div>
- <div class="line"> uint8_t i;</div>
- <div class="line"> </div>
- <div class="line"> <span class="comment">// Collect 32 audio samples. At 109 microsecs per sample, we can achieve about 250</span></div>
- <div class="line"> <span class="comment">// 32 byte packets transmitted per second: 6.4kHz sample rate</span></div>
- <div class="line"> <span class="keywordflow">for</span> (i = 0; i < 32; i++)</div>
- <div class="line"> buf[i] = analogRead(0); <span class="comment">// 0 - 1023 becomes 0 - 255, top 2 bits clipped. approx 109 microsecs per sample</span></div>
- <div class="line"></div>
- <div class="line"> <span class="comment">// Now send the samples NOACK (EN_DYN_ACK must be enabled first)</span></div>
- <div class="line"> <span class="comment">// With 2Mbps, NOACK and 32 byte payload, can send about 1900 messages per sec</span></div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a8"></a><a class="code" href="classNRF24.html#a7b40c4c481bddf343acdac5179fddc75">setTransmitAddress</a>((uint8_t*)<span class="stringliteral">"aurx1"</span>, 5))</div>
- <div class="line"> Serial.println(<span class="stringliteral">"setTransmitAddress failed"</span>);</div>
- <div class="line"> <span class="comment">// Send the data </span></div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a9"></a><a class="code" href="classNRF24.html#aad280539b80b28e55ab3187714bc7f2f">send</a>(buf, <span class="keyword">sizeof</span>(buf), <span class="keyword">true</span>)) <span class="comment">// NOACK, 110 microsecs</span></div>
- <div class="line"> Serial.println(<span class="stringliteral">"send failed"</span>); </div>
- <div class="line"> <span class="comment">// Transmission takes about 300 microsecs, of which about 130microsecs is transmitter startup time</span></div>
- <div class="line"> <span class="comment">// and 160 microsecs is transmit time for 32 bytes+8 bytes overhead @ 2Mbps</span></div>
- <div class="line"> <span class="keywordflow">if</span> (!nrf24.<a name="a10"></a><a class="code" href="classNRF24.html#a78a011cddedb14b8764ad5ea760c28ae">waitPacketSent</a>())</div>
- <div class="line"> Serial.println(<span class="stringliteral">"waitPacketSent failed"</span>); </div>
- <div class="line"> digitalWrite(3, LOW);</div>
- <div class="line">}</div>
- <div class="line"></div>
- </div><!-- fragment --> </div><!-- contents -->
- <!-- start footer part -->
- <hr class="footer"/><address class="footer"><small>
- Generated by  <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/>
- </a> 1.8.5
- </small></address>
- </body>
- </html>
|