Maker Pro
Maker Pro

nRF24L01 2.4GHz tranceiver - ATMega328p

sheffladreece

Jan 24, 2014
22
Joined
Jan 24, 2014
Messages
22
I am currently attempting to communicate between two- nRF24L01 2.4GHz tranceivers using a ATMega328p with use of the USBtinyISP in C/C++ ... Is there any chance that anyone would have any coding regarding the setup/ communcation process or be able to offer any advice at all regarding this setup or coding of... I have limited experience, having only started coding and building electronics projects over the last 2 days so please bare with me if I do not understand elements of your replys. Thanks.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Whilst I will keep my clothes on, I am happy to share some code.

It will have to wait for quite a few hours though.

First things:

1 are you powering the device from 3.3v?

2 are you using the small modules with 8 or10 pins? (beware that these have very different pinouts)

3 are you using the arduino compiler?

4 have you downloaded one of the available libraries and tried the demos they come with?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
My strong recommendation is to get the appropriate libraries (RF24, and maybe RF24Network) and go through the examples.

Here is the simplest bit of code I have. It has the advantage of operating stand-alone, that is, it only requires a single NRF24L01. It is a fancy signal strength meter.

Code:
/*
  Combines RF24's scanner with the LCD output to make a standalone scanner
   
 - - - - - - - - - - - - - - - - - -
 
  The circuit:
 * LCD pin 1 (gnd) to gnd
 * LCD pin 2 (Vcc) to +5v
 * LCD pin 3 (VO) to wiper of 20k pot between Vcc and gnd (contrast adj)
 * LCD pin 4 (RS) to digital pin 7
 * LCD pin 5 (R/W) to gnd
 * LCD pin 6 (clock/enable) to digital pin 6
 * LCD pin 7 (D0) UNUSED
 * LCD pin 8 (D1) UNUSED
 * LCD pin 9 (D2) UNUSED
 * LCD pin 10 (D3) UNUSED
 * LCD pin 11 (D4) to digital pin 5
 * LCD pin 12 (D5) to digital pin 4
 * LCD pin 13 (D6) to digital pin 3
 * LCD pin 14 (D7) to digital pin 2
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 - - - - - - - - - - - - - - - - - -
 Example to detect interference on the various channels available.
 This is a good diagnostic tool to check whether you're picking a
 good channel for your application.
 Inspired by cpixip.
 See http://arduino.cc/forum/index.php/topic,54795.0.html

 The circuit:
 * nRF24L01 pin 1 gnd to gnd
 * nRF24L01 pin 2 Vcc tp 3v3
 * nRF24L01 pin 3 CE to 9
 * nRF24L01 pin 4 CSN to 10
 * nRF24L01 pin 5 SCK to 13
 * nRF24L01 pin 6 MOSI to 11
 * nRF24L01 pin 7 MISO to 12
 * nRF24L01 pin 8 IRQ UNUSED
 */

// include the library code:
#include <LiquidCrystal.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

const
  uint8_t num_rows = 2;
  uint8_t num_cols = 16;
  uint8_t scan_wide = (num_rows - 1) * num_cols;


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10

RF24 radio(2,3);

//
// Channel info
//

const
  uint8_t num_channels = 128;
  uint8_t grp_size = num_channels / scan_wide;
  uint8_t values[num_channels];

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(num_cols, num_rows);
  // Print a message to the LCD.
  lcd.print("nRF24L01 Scanner");
 
  radio.begin();
  radio.setAutoAck(false);

  // Get into standby mode
  radio.startListening();
  radio.stopListening();

}

const int num_reps = 100;

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);

  // Clear measurement values
  memset(values,0,sizeof(values));

  // Scan all channels num_reps times
  int rep_counter = num_reps;
  while (rep_counter--)
  {
  int i = num_channels;
  while (i--)
  {
  // Select this channel
  radio.setChannel(i);

  // Listen for a little
  radio.startListening();
  delayMicroseconds(128);
  radio.stopListening();

  // Did we get a carrier?
  if ( radio.testCarrier() )
  ++values[i];
  }
  }

  // Print out channel measurements, clamped to a single hex digit
  int i = 0;
  while ( i < num_channels )
  {
  int group = 0;
   
  for ( int j=0; j < grp_size; j++)
  {
  group += values[i];
  ++i;
  }
   
  lcd.print(min(0xf,group), HEX);
  }
}
 
Top