Hi!
I have 2 Teensy 3.5’s, each connected to a Teensy audio adaptor and a nRF24. I have a mic attached to one that is set to transmit, and a speaker attached to the one set to receive. Currently, they are communicating, but the audio quality is so bad that its barely recognisable. I know the audio adaptors are capable of 16bit 44kHz audio and have tested them using example libraries. I’m fairly certain the problem is in my code, as I’m a complete newbie to programming. Can anyone help?
Here is my transmitter code:
// Transmitter
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(28, 39); // CE, CSN
const byte address[6] = “00001”;
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=206,128
AudioRecordQueue queue1; //xy=437,134
AudioConnection patchCord1(i2s1, 0, queue1, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=394,305
// GUItool: end automatically generated code
uint8_t bufr[256];
void setup() {
Serial.begin(9600);
AudioMemory(64);
// Enable the audio shield, select input, and enable output
SPI.setMOSI(7);
SPI.setSCK(14);
sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
sgtl5000_1.volume(0.6);
sgtl5000_1.micGain(1);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.stopListening();
queue1.begin();
}
void loop() {
if (queue1.available() >= 2) {
memcpy(bufr, queue1.readBuffer(), 32);
queue1.freeBuffer();
radio.write(&bufr[0], 32);
And here is my receiver code:
//Receiver
#include <Audio.h>
#include <Wire.h>
#include <SerialFlash.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(28, 39); // CE, CSN
const byte address[6] = “00001”;
// GUItool: begin automatically generated code
AudioPlayQueue queue1; //xy=299,187
AudioOutputI2S i2s1; //xy=587,179
AudioConnection patchCord1(queue1, 0, i2s1, 0);
AudioConnection patchCord2(queue1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=393,311
// GUItool: end automatically generated code
void setup() {
AudioMemory(64);
SPI.setMOSI(7);
SPI.setSCK(14);
sgtl5000_1.enable();
sgtl5000_1.volume(0.6);
radio.begin();
Serial.begin(9600);
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.startListening();
}
void loop() {
if (radio.available()) {
uint8_t text[32];
radio.read(&text, sizeof(text));
Serial.println(text[0]);
Serial.println(text[15]);
Serial.println(text[31]);
int16_t *p=queue1.getBuffer();
memcpy(p, text, 32);
for (int i=32; i < 256; i++) {
*((char *)p + i) =0; // fill rest of buffer with zero
}
queue1.playBuffer();
}
}
Any assistance would be super appreciated!!!