Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Programming Questions / Re: nRF24l01 Not receive data on: April 25, 2014, 09:44:45 pm
Ok, a couple of confusing things here. First, I didn't realize it was an array of integers, so that changes everything.

There are 2 bytes in every integer, so your array would actually be  68*2 bytes ( 136 bytes long), which will require 5 payloads just for the data in one array.

Code:
unsigned int Raw[] = {4600,4450,650,1600,650,1600,650,1600,650,500,600,500,650,500,650,500,600,500,650,1600,650,1600,650,1600,650,500,650,450,650,500,650,500,600,500,650,500,600,1650,600,500,650,500,600,500,650,500,600,500,650,500,650,1600,650,500,600,1650,600,1650,600,1650,650,1600,650,1600,650,1600,650};
unsigned int output[16]; // For the payload of nRF24L01 array 30 + 1 for null termination

void setup() {
  Serial.begin(115200);
  //for(int i=0; i< 68; i++){
  //  Raw[i] = i;
  //}
 
}

void loop() {
  
  memcpy(&output[1],&Raw,30);      // Copies 30 bytes or 15 integers
  output[0] = 1;                                         // Sets the first integer (2 bytes) to equal 1
  for(int i=0; i<16; i++){
    Serial.println(output[i]); // Print out the 15 integers + 1 start integer
  }
  memcpy(&output[1],&Raw[15],30);
  output[0] = 2;
  for(int i=0; i<16; i++){
    Serial.println(output[i]);
  }
  memcpy(&output[1],&Raw[30],30);
  output[0] = 3;
  for(int i=0; i<16; i++){
    Serial.println(output[i]);
  }
  memcpy(&output[1],&Raw[45],30);
  output[0] = 4;
  for(int i=0; i<16; i++){
    Serial.println(output[i]);
  }
  memcpy(&output[1],&Raw[60],14);   *Edit: Should be 14 not 16
  output[0] = 5;
  for(int i=0; i<8; i++){
    Serial.println(output[i]);
  }

  Serial.println("********");
  delay(2000);
  
}

The code I posted above shows how to insert the start integer, and ensure that every byte is accounted for. It will actually take 5 transmissions to send all of the data.

When sending, you would still do radio.write(&output,sizeof(output));

Also, your array is 67 integers or 134 bytes long.
17  Using Arduino / Programming Questions / Re: nRF24l01 Not receive data on: April 25, 2014, 03:52:13 pm
Well the pipes vs addressing thing is a bit confusing, so I like to look at it like this:

Code:
 const uint64_t addresses[2] = {   0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1,addresses[1]);

Then, to answer your question, yes. As long as the transmitter and receiver are using opposite addresses, it should work fine. The pipe numbers aren't always that important, mainly the addresses.

Quote
And i thing you have make you're own rf24 library ... write ? i will do a better read  smiley
Yup, I've created a faster/more efficient fork of the RF24/RF24Network libs that support a wider range of hardware and functionality, mainly to improve my audio library and its capabilities.

Quote
if the above it is correct how can i collect the data in Rx side ?

The memcpy looks ok, except the second one should use length 32 instead of 64. In this case you will probably want to use some sort of simple protocol to manage the payloads and re-assembly.

For example, the transmitter could number the payloads by modifying the first or last byte of the payload, so the receiver knows if it has received all of the payloads in the correct sequence. Or you could send a 'start payload' telling the receiver to expect three payloads within a certain timeframe, and indicate that they will need to be re-assembled. I've included an example of the latter method in my library fork: http://tmrh20.github.io/RF24/TransferTimeouts_8ino-example.html  , but the write method needs to be changed to work with any of the other libs. *Edit to add: It might be easiest to also spread out the data being sent so all the payloads are the same size. Otherwise that needs to be accounted for on the receiving end.

Then on the receiving end, its just a matter of confirming successful transfer, then reversing the operation, and writing the payload data into a 68 byte array, which you could do by reversing your memcpy code, or with a for loop.

18  Using Arduino / Programming Questions / Re: nRF24l01 Not receive data on: April 25, 2014, 07:28:36 am

The code looks ok, but I've almost always had problems with the radio modules when trying to only use 1 pipe/address.

The example uses two as well:

Code:
  const uint64_t pipes[2] = {   0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);

 OR for the other radio:

   radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);

That may work better if the modules test ok.
19  Using Arduino / Audio / Re: How can I create a wave file from an ADC INPUT? on: April 25, 2014, 05:57:56 am

It can be a bit of a complicated thing, since the audio needs to be sampled consistently, generally at a fairly high rate, and written to a file at the same time. I am not an expert in any way with programming on the Due, so can't help a whole lot there, but have worked a bit with wav files on smaller arduinos.

If you take a look at https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ , there is a good visual and technical description of the header. You basically need to write a header, then just add the raw audio sample data after that. The Due can also do 12-bit audio sampling, but it might be easier to start with 8-bit samples, since it only requires one byte per sample.

From my experience, the biggest challenges are getting quality samples at the correct sample rates, and writing to SD card etc with enough speed and/or a big enough data buffer, but this should be much easier on the Due since it has more memory and a faster processor.

20  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 22, 2014, 02:02:55 pm
Well the answer is yes and no because again, it depends on what exactly you are doing.

I use two separate ISRs along with 'nested interrupts' to due to timing issues.

The TX_0 sketch found here https://github.com/TMRh20/Sketches may be easier to look at than the library code, and shows how this is done. This is the sketch I used to develop the libary initially.

All my library documentation can be found here: http://tmrh20.github.io/
My blog is here: http://TMRh20.blogspot.com
The datasheet is here: http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf
Arduino Reference: http://arduino.cc/en/Reference/HomePage

All the information you need is there. Not trying to be rude, but you really need to understand what is going on if you ever hope to write this type of code yourself, and the only way to do that is to put in the effort, and read the documentation and examples provided.
21  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 21, 2014, 09:56:12 pm

Which is the one last question?

 smiley-twist
22  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 21, 2014, 12:55:03 pm
- Where did you say to the arduino to work with port 9 an 10, besides defining them as output, where are you using them?
Code:
TCCR1A = _BV(COM1A1)  | _BV(COM1B0) | _BV(COM1B1);  //Enable the timer port/pins as output
OCR1A = OCR1B = ADCL | ADCH << 8;  // Read the ADC values directly into the timer compare register.

Quote
Why 2 ports instead of just 1 and GND?

To enable complimentary (push/pull) speaker output instead of push/null.

Quote
I just wanted the ADC values somewhere so i could work with them because i don't know where to get them, what should i do?

Either use analogRead() to get the ADC values, or learn how to work with the registers.

I would recommend checking out http://arduino.cc/en/Reference/HomePage  and looking at the bitwise &, | and <<     >> (bitshift)  operators if you are not already familiar with them. That will help to understand how to work with binary data.

From there, read the datasheet if you really do want to learn. If you can understand the concepts of working with bits and bytes via the above operators, then its just a matter of writing/reading the correct values to/from the registers to work with or control any aspect of the MCU.

I can lead you to water, but I cannot force you to drink...
23  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 21, 2014, 12:25:56 am

You either read the ADC registers, or the TIMER1 compare registers. As I said, you're going to have to read the data sheet if you need more help with that code.

Its not as simple as just printing the values in the loop function, since timing is generally important. If I had some idea of what you were trying to do, I could provide an example, but I'm not going to write your code for you.
24  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 19, 2014, 10:45:52 pm
Oh, in that case, yup. The library has the feature of redirecting directly to pwm output while transmitting, and this is that same code simplified in sketch form:
I kind of hate to say it, but if you need assistance with this code, read the datasheet. That is about the only way to learn.

Code:


#define SAMPLE_RATE 32000
volatile unsigned int sampleData;



void setup() {
 
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
 
  /******* Set up timer1 ********/
  ICR1 = 10 * (1600000/SAMPLE_RATE);                 // For PWM generation. Timer TOP value.
  TCCR1A = _BV(COM1A1) | _BV(COM1B0) | _BV(COM1B1);  //Enable the timer port/pin as output
  TCCR1A |= _BV(WGM11);                              //WGM11,12,13 all set to 1 = fast PWM/w ICR TOP
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);      //CS10 = no prescaling
 
  /******** Set up the ADC ******/
  ADMUX = _BV(REFS0);                                // Set analog reference to 5v
  ADCSRB |= _BV(ADTS1) | _BV(ADTS2);                 // Attach ADC to TIMER1 Overflow interrupt
   
  byte prescaleByte = 0;                             // Adjusts the ADC prescaler depending on sample rate for best quality audio

  if(      SAMPLE_RATE < 8900){  prescaleByte = B00000111;} //128
  else if( SAMPLE_RATE < 18000){ prescaleByte = B00000110;} //ADC division factor 64 (16MHz / 64 / 13clock cycles = 19230 Hz Max Sample Rate )
  else if( SAMPLE_RATE < 27000){ prescaleByte = B00000101;} //32  (38461Hz Max)
  else if( SAMPLE_RATE < 65000){ prescaleByte = B00000100;} //16  (76923Hz Max)
  else   {                       prescaleByte = B00000011;} //8  (fast as hell)

  ADCSRA = prescaleByte;                        // Set the prescaler
  ADCSRA |= _BV(ADEN) | _BV(ADATE);             // ADC Enable, Auto-trigger enable


  TIMSK1 = _BV(TOIE1);          //Enable the TIMER1 interrupt to begin everything
}




ISR(TIMER1_OVF_vect){
 
  OCR1A = OCR1B = ADCL | ADCH << 8;  // Read the ADC values directly into the timer compare register.
 
}



void loop() {


}

25  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 19, 2014, 07:08:53 pm
... tell me please the source to convert from the analog port to PWM port (analog to digital) cuz i already tried it and i just got noise coming out smiley-sad

Not sure what you are asking here?  In my video, I used an iPod connected to the preamp circuit. If using a microphone breakout, they usually have an opamp or something to manage the pre-amp function, and the gain would need to be adjusted. It uses the onboard ADC reading pin A0 to convert from analog to digital, then uses timer1 pwm functions to reproduce the PCM audio.  The default volume might be a bit high, so adding rfAudio.setVolume(4); may resolve the issue also.
26  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 19, 2014, 06:13:23 pm
Heh, that would be me.
I've posted some initial board/wiring info here: http://tmrh20.github.io/RF24Audio/Setup.html and attached a few pictures here, including schematic type diagrams, which will likely get added to the main documentation page eventually. I couldn't seem to find a good fritzing part for NRF24L01 modules, so that is probably not the best example. The buttons aren't needed if using serial commands for testing etc.

The SD module in the video is only really there because it was just easier to not disconnect it, since I was also experimenting with improvements when streaming audio from SD card at the time. You can probably tell that video production is not one of my strong points.

Please keep in mind the current schematics are designed to be about as simple as possible, while producing OK results, and have just been put together (Hopefully no errors). During development, I generally just grab the closest parts that will work, and stick them together. I'm sure that adding some low-pass filters etc would increase sound quality a fair bit, and that there are at least a few folks on these forums who could provide much better advice on that type of thing than I. 
27  Using Arduino / Audio / Re: New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 19, 2014, 03:38:06 pm
Thanks robtillaart!

tsunamy_boy: Yeah, pretty much any board with an ATmel 328 chip like the Uno should work fine. I've specifically tested with Arduino Duemilanove, Nano, Pro-mini (5v 16mhz), and Mega2560 boards. Arduino Due is not supported currently.
28  Using Arduino / Audio / New Library: RF24Audio - Realtime Audio Streaming, Multicasting and More on: April 17, 2014, 03:54:17 am
I mentioned a little while back in a couple posts that I was developing a wireless audio library for Arduino, and it has finally come to fruition. Many people are familiar with my WAV Audio library for playing audio from SD cards using Arduino, and I've developed another related library for wireless audio streaming.

The new library relies on my optimized RF24 library fork which enhances the speed and reliability of NRF24L01 radio modules, and is required for proper use of the RF24Audio library. The integration with the core radio library allows additional features like streaming wireless audio directly to a PC for analysis and/or recording of the audio.

Beginner Arduino users can create simple radios or intercom devices at very low cost, simply by connecting a microphone, speaker and radio module, and running one of the example sketches. The audio can be broadcast in realtime to one or more groups of radios running the RF24Audio library.

The library also integrates directly with the TMRpcm audio library, so users can also broadcast audio from SD card wirelessly in the case of such things like halloween displays etc, where everything can be timed and broadcast wirelessly from a single Arduino.

Documentation/Downloads can be found here: http://tmrh20.github.io/RF24Audio/

Optimized RF24 Radio Library: https://github.com/TMRh20/RF24
TMRpcm SD Audio Library:  https://github.com/TMRh20/TMRpcm

*Edit to add youtube demonstration : https://www.youtube.com/watch?v=eTFsQIXMXA0
29  Using Arduino / Networking, Protocols, and Devices / Re: rf24 library question (nrf24l01) on: April 11, 2014, 04:19:57 am
Using ACK Payloads, you can send back data without switching out of RX mode, and it makes a much more efficient call-response scenario, since the transmitter does not need to be interrupted.

See http://tmrh20.github.io/RF24/GettingStarted_CallResponse_8ino-example.html for an example.

30  Using Arduino / Networking, Protocols, and Devices / Re: Serial Communication at 1Mb on: April 06, 2014, 12:08:18 pm
Well technically, the UART is capable of up to 8Mhz in Synhronous Master Mode.

I've had the UART set to run at 8Mhz and outputting video data smoothly in Master SPI mode. I believe the max rate in UART Synchronous master mode is 8Mhz as well. It is double buffered, so actually seems to perform better in some ways than the actual SPI hardware. This would put the maximum transfer rate at 8mHz/8bytes = 1MB/s minus overhead (start, stop bytes etc)  So 1MB/s or 8Mbps would be the max rate minus overhead. In non-synchronous modes, the limit is 2mbps according to the datasheet (250KB/s minus overhead).

An example sketch for outputting NTSC video at 8mhz is a bit messy but is here: https://github.com/TMRh20/Sketches

I did a bit of a writeup on ensuring the output is timed correctly and smooth, which can be found at my blog:
http://tmrh20.blogspot.com/2013/12/arduino-high-speed-8mhz-signaling-ntsc.html

It may not work that well at 8mhz for actual communication, I haven't tested that specifically. It might require a kind of custom solution as well, as the Arduinos would not be able to stream at 8MHZ continuously without a large memory buffer.

*Edit to add: Just remembered, that I have used it at 8mhz in SPI mode for controlling a radio module and it worked well for that communication, so there is no reason it wouldn't work otherwise.
Pages: 1 [2] 3 4 ... 6