Solution for Teensy 3.6 (could be used for Teensy 3.2 too)
Hi,
My friends and I are trying to do a similar project. Were you successful? Do you know any other websites or tutorials that can give us more information about the hardware connection and software details? Do you think teensy 3.6 will be a better option than teensy 3.2?
Thank you.
Hi
I'm new here, but I think I have probably a solution for you.
Look at my code and have fun.
//******************************************************************************************************
// Transmitter program to transmit 16 bit audio data (audio streaming) from LINEIN of Teensy Audio board
// to nrf24l01+ module with a Teensy 3.6 (selected CPU speed = 180 MHz)
//******************************************************************************************************
// used Hardware components:
// Teensy 3.6 board, Teensy Audio board, nrf24l01+ RF module
// wiring connections:
//
// From Teensy 3.6 to Teensy Audio board only a few pins are connected, (only 9 pins are wired)
// the others from Audio board are not connected:
// Teensy 3.6 pin GND (left pin of pin 0) wired to pin GND of Audio board (1:1)
// Teensy 3.6 pin 9 wired to pin BCLK of Audio board (1:1)
// Teensy 3.6 pin 11 wired to pin MCLK of Audio board (1:1)
// Teensy 3.6 pin 13 wired to pin RX of Audio board (1:1)
// Teensy 3.6 pin 18 wired to pin SDA of Audio board (1:1)
// Teensy 3.6 pin 19 wired to pin SCL of Audio board (1:1)
// Teensy 3.6 pin 22 wired to pin TX of Audio board (1:1)
// Teensy 3.6 pin 23 wired to pin LRCLK of Audio board (1:1)
// Teensy 3.6 pin 3.3V (left pin of pin 23) wired to pin +3.3V of Audio board (1:1)
//
// From Teensy 3.6 to nrf24l01+ module the following pins are connected:
// Teensy 3.6 pin 7 wired to pin MOSI of nrf24l01+
// Teensy 3.6 pin 8 wired to pin MISO of nrf24l01+
// Teensy 3.6 pin 3.3V (right pin of pin 12) wired to pin 3.3V of nrf24l01+
// Teensy 3.6 pin GND (right pin of pin 13) wired to pin GND of nrf24l01+
// Teensy 3.6 pin 14 wired to pin SCK of nrf24l01+
// Teensy 3.6 pin 15 wired to pin CSN of nrf24l01+
// Teensy 3.6 pin 21 wired to pin CE of nrf24l01+
// pin IRQ of nrf24l01+ is not connected
//
// 3.5mm or 6.3mm audio jack wired to LINEIN of Teensy Audio board for analog audio source
//******************************************************************************************************
#include <Audio.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define audiobuffersize 128 // one block in audio library has 128 values of 2 byte
RF24 radio(21, 15); // Teensy 3.6 pin 21=CE, Teensy 3.6 pin 15=CSN
const uint64_t pipeaddress = 0xFA51AA55AFLL; //nrf24 pipe address must be the same for transmitter and receiver
// GUItool: begin automatically generated code
// defs for audio library
AudioInputI2S i2s1;
AudioRecordQueue queue1;
AudioConnection patchCord1(i2s1, 0, queue1, 0);
AudioConnection patchCord2(i2s1, 1, queue1, 1);
AudioControlSGTL5000 sgtl5000_1;
// GUItool: end automatically generated code
uint8_t bufr[audiobuffersize * 2]; //buffer to hold 256 byte of audio data
uint8_t errorcount; //error counter for nrf24 transfer errors
void setup()
{
//Serial.begin(9600);
//Serial.println("Start Transmitter");
errorcount = 0;
AudioMemory(64); //give the Audio Library some memory to work with
// use alternate SPI pins for nrf24
SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(14);
SPI.begin();
// Setup the SGTL5000 AIC
//sgtl5000_1.enable(); //activate AIC
sgtl5000_1.enable(); //Enable the SGTL5000
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN); //which input to use LINEIN
sgtl5000_1.lineInLevel(3);
sgtl5000_1.adcHighPassFilterDisable();
radio.begin();
radio.setPayloadSize(32); //this is the maximum payload size for a packet transfer of nrf24
radio.setAutoAck(false); // no Ack
radio.disableCRC(); // no CRC
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
delay(50);
radio.openWritingPipe(pipeaddress);
radio.stopListening(); // switch to transmit mode
delay(50);
queue1.begin();
}
void loop()
{
if (queue1.available())
{
memcpy(bufr, queue1.readBuffer(), audiobuffersize * 2); // copy 256 byte audio data from audio library buffer to bufr
queue1.freeBuffer();
// send audio data in 8 packages a 32 byte to the FIFO buffers
for (int i=0; i<8; i++)
{
if (!radio.writeFast(&bufr[i * 32],32)) errorcount++;
}
if (errorcount > 0)
{
//Serial.print("Errors: ");
//Serial.println(errorcount);
errorcount = 0;
}
}
}
//***************************************************************************************************
// Receiver program to get 16 bit audio data (audio streaming) from nrf24l01+ module to the headphone
// and LINEOUT of Teensy Audio board with a Teensy 3.6 (selected CPU speed = 180 MHz)
//***************************************************************************************************
// used Hardware components:
// Teensy 3.6 board, Teensy Audio board, nrf24l01+ RF module
// wiring connections:
//
// From Teensy 3.6 to Teensy Audio board only a few pins are connected, (only 9 pins are wired)
// the others from Audio board are not connected:
// Teensy 3.6 pin GND (left pin of pin 0) wired to pin GND of Audio board (1:1)
// Teensy 3.6 pin 9 wired to pin BCLK of Audio board (1:1)
// Teensy 3.6 pin 11 wired to pin MCLK of Audio board (1:1)
// Teensy 3.6 pin 13 wired to pin RX of Audio board (1:1)
// Teensy 3.6 pin 18 wired to pin SDA of Audio board (1:1)
// Teensy 3.6 pin 19 wired to pin SCL of Audio board (1:1)
// Teensy 3.6 pin 22 wired to pin TX of Audio board (1:1)
// Teensy 3.6 pin 23 wired to pin LRCLK of Audio board (1:1)
// Teensy 3.6 pin 3.3V (left pin of pin 23) wired to pin +3.3V of Audio board (1:1)
//
// From Teensy 3.6 to nrf24l01+ module the following pins are connected:
// Teensy 3.6 pin 7 wired to pin MOSI of nrf24l01+
// Teensy 3.6 pin 8 wired to pin MISO of nrf24l01+
// Teensy 3.6 pin 3.3V (right pin of pin 12) wired to pin 3.3V of nrf24l01+
// Teensy 3.6 pin GND (right pin of pin 13) wired to pin GND of nrf24l01+
// Teensy 3.6 pin 14 wired to pin SCK of nrf24l01+
// Teensy 3.6 pin 15 wired to pin CSN of nrf24l01+
// Teensy 3.6 pin 21 wired to pin CE of nrf24l01+
// pin IRQ of nrf24l01+ is not connected
//
// 3.5mm or 6.3mm audio jack wired to LINEOUT of Teensy Audio board or headphone connected to
// headphone jack on Teensy Audio board
//***************************************************************************************************
#include <Audio.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define audiobuffersize 128 // one block in audio library has 128 values of 2 byte
RF24 radio(21, 15); // Teensy 3.6 pin 21=CE, Teensy 3.6 pin 15=CSN
const uint64_t pipeaddress = 0xFA51AA55AFLL; //nrf24 pipe address must be the same for transmitter and receiver
// GUItool: begin automatically generated code
// defs for audio library
AudioPlayQueue queue1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(queue1, 0, i2s1, 0);
AudioConnection patchCord2(queue1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
// GUItool: end automatically generated code
uint8_t bufr[audiobuffersize * 2]; //buffer to hold 256 byte of audio data
uint8_t bufcount; //received nrf24l01+ packet counter
void setup()
{
//Serial.begin(9600);
bufcount = 0;
AudioMemory(64); //give the Audio Library some memory to work with
// use alternate SPI pins for nrf24
SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(14);
SPI.begin();
// Setup the SGTL5000 AIC
sgtl5000_1.enable(); //Enable the SGTL5000
sgtl5000_1.volume(0.4); //set the headphone volume
sgtl5000_1.lineOutLevel(5, 5);
radio.begin();
radio.setPayloadSize(32); //this is the maximum payload size for a packet transfer of nrf24
radio.setAutoAck(false); //no Ack
radio.disableCRC(); //no CRC
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
delay(100);
radio.openReadingPipe(0, pipeaddress);
delay(50);
radio.startListening();
}
void loop()
{
if (radio.available())
{
// get 8 packets a 32 byte audio data
if ((bufcount >= 0) && (bufcount < 8))
{
// get 32 byte audio packet data
radio.read(&bufr[bufcount * 32], 32);
// test if all 8 packets received
if (bufcount == 7)
{
bufcount = 0;
int16_t *p = queue1.getBuffer();
memcpy(p, &bufr[0], (audiobuffersize * 2));
queue1.playBuffer();
} else bufcount++;
}
}
}