Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Networking, Protocols, and Devices / Re: Trying to learn basics of NRF24L01+ on: June 25, 2014, 10:54:25 pm
Well, it works ok for me, so we know the the code is fine, here is what I am using:

Transmitter:

Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

RF24 radio(9,10);

const uint64_t pipe = 0xF0F0F0F0E1LL;

void setup(void) {
 
  Serial.begin(57600);
  radio.begin();
  //radio.setRetries(15,15);
  radio.openWritingPipe(pipe);
  
}


void loop () {
  
  unsigned int random_Number = random(0,255);
  Serial.print("Sending: ");
  Serial.println(random_Number);
  
  radio.stopListening();  
    
  boolean ok = radio.write( &random_Number, sizeof(random_Number) );
    
  if (ok) Serial.println("ok...");
  else Serial.println("failed.");
  
  delay(1000);
  
}


Receiver:

Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

RF24 radio(9,10);

const uint64_t pipe = 0xF0F0F0F0E1LL;

void setup(void) {
 
  Serial.begin(57600);  
  radio.begin();
  //radio.setRetries(15,15);
  radio.openReadingPipe(1,pipe);
  radio.openWritingPipe(pipe);
  radio.startListening();
  Serial.println("Ready!");
  
}


void loop () {
  
  if ( radio.available() ) {
    Serial.println("radio is available");
    unsigned int data;
    boolean done=false;
      radio.read( &data, sizeof(data) );
      Serial.print("Received: ");
      Serial.println(data);
  }
  
}


So, if you are using that code and it doesn't work, it usually indicates another problem.

To get debugging info, you need to do a few things:
1. Add the printf.h file from one of the examples to your sketch folder
2. Add the line   #include "printf.h" in your sketch
3. Do printf_begin();  right after Serial.begin(57600);
4. Finally, at the end of your setup() function, do a radio.printDetails();

It should look exactly like the attached picture on the receiver with the debug details printed.

Since you say it works fine with the getting started sketch, we know the wiring is ok, and the code works fine for me, so the code is fine, then something odd is usually to blame, but difficult to figure out from my end. Also, power cycle the Arduino, since some settings cannot be undone otherwise, and may interfere if you have been running other example sketches. Not sure what library fork you are using, but of course I am using my fork found here: https://github.com/TMRh20/RF24/archive/master.zip
2  Using Arduino / Networking, Protocols, and Devices / Re: Trying to learn basics of NRF24L01+ on: June 23, 2014, 01:07:35 pm

1. Use the same pipe for both:  const uint64_t pipe = 0xF0F0F0F0D1LL;
2. Open a writing pipe on the receiver:

Code:
radio.openWritingPipe(pipe);

Info: The transmitter must transmit to the receiving address of the receiver for the payload to be delivered. In order for the receiver to acknowledge (ACK) transmission, it needs a writing pipe opened to send back the ACK packet.
3  Using Arduino / Networking, Protocols, and Devices / Re: RF24 library with nrf24l01+. Can you receive messages while transmitting? on: May 02, 2014, 02:32:15 pm

Well technically, that is the expected behaviour. The radio modules switch between two primary modes, being primary transmitter and primary receiver.

The radio will not receive any normal payloads while in TX mode, and will not send any normal payloads while in RX mode, however, the radios do support something called ACK payloads.

When a payload is successfully transmitted, the receiving radio responds back with an ACKnowledgement payload. Making use of the ack payload feature allows you to respond back with an ACK payload without havign to manually switch out of receiver mode, and the transmitter can be set to send until an appropriate response is received.

This makes for a much faster call-response scenario, and I believe would suit what you are doing much better than manually switching from TX to RX modes.

Take a look at this example: http://tmrh20.github.io/RF24/GettingStarted_CallResponse_8ino-example.html   It may not work very well with the original library though.

4  Using Arduino / Project Guidance / Re: Arduino & Video? on: April 30, 2014, 08:26:03 pm

I was looking at some of these for video overlay, but have never tried them:
http://www.robotshop.com/ca/en/video-experimenter-arduino-compatible-shield.html
http://www.seeedstudio.com/depot/Video-Overlay-Shield-p-1232.html

It might be possible to do some overlay directly using just an Arduino, but something like the above would probably be the way to go.
5  Using Arduino / Programming Questions / Re: Need help programming servo movement to audio file from sd card on: April 29, 2014, 07:05:04 pm
I believe that the main problem with your code is that the servo library and the audio library both are trying to use TIMER1 at the same time, so you end up with a few options:

1. Do a  myservo.detach(); before playing audio and do a myservo.attach(servo1_pin); before trying to use the servo
2. Use the timer2 servo library (google it) or a custom servo solution
3. Attempt to use the timer2 option of the TMRpcm library (untested with servo lib) - see the wiki on github to enable
4. Use an audio shield to offload the audio processing from Arduino

See https://github.com/TMRh20/TMRpcm/issues/3


6  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.
7  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.

8  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.
9  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.

10  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.
11  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
12  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...
13  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.
14  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() {


}

15  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.
Pages: [1] 2 3 ... 6