Go Down

Topic: nrf24l01 (Read 889 times) previous topic - next topic

freerpg

Hey kind people. just got a awesome project completed but then ran into an issue. the project was http://arduino-for-beginners.blogspot.com.au/2013/02/setup-nordic-nrf24l01-rf-modules-to.html
the issue was this worked wonderfully on the uno (freetronics eleven) but when I goto mega it doesn't then I found out the pinout for the mega is totally different. so what I am asking for is2 fold, can someone give me the right pinout AND new code?
https://www.dropbox.com/s/k6hh3r32d8ob9c2/Arduino%20nRF24_String_Pingback_RPi.zip is the code for the uno if you want a quicklink

freerpg

Code: [Select]
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

/**
* This example will receive dynamic payload from the Raspberry Pi and send
* back the payload to the Raspberry Pi
* I have added the LCD Module to display the payload and payload length
* on a 20x4 LCD Module
*
* Stanley Seow
* stanleyseow@gmail.com
*/

#include <LiquidCrystal.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

LiquidCrystal lcd(10, 9, 3, 4, 5, 6);
// Make way for the SPI pins
// 10 -> LCD 4
// 9  -> LCD 6
// 3  -> LCD 11
// 4  -> LCD 12
// 5  -> LCD 13
// 6  -> LCD 14

//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 3 & 4

RF24 radio(8,7);
//
// Topology
//

// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };


//
// Payload
//

const int min_payload_size = 4;
const int max_payload_size = 32;
const int payload_size_increments_by = 2;
int next_payload_size = min_payload_size;

char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char

void setup(void)
{
 
  // Setup LCD
  lcd.begin(20,4); // col,row
  lcd.setCursor(0,0);
  lcd.print("nRF24L01 to RPi");
 
  pinMode(2, OUTPUT);
 
  // Print preamble
  //

  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/pingpair_dyn/\n\r");
  //
  // Setup and configure rf radio
  //

  radio.begin();

  // enable dynamic payloads
  radio.enableDynamicPayloads();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(15,15);
  radio.setDataRate(RF24_1MBPS);
  //
  // Open pipes to other nodes for communication
  //

  // This simple sketch opens two pipes for these two nodes to communicate
  // back and forth.
  // Open 'our' pipe for writing
  // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)

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

  radio.startListening();

  //
  // Dump the configuration of the rf unit for debugging
  //

  radio.printDetails();
}

void loop(void)
{

    // if there is data ready
    if ( radio.available() )
    {
      // Dump the payloads until we've gotten everything
      uint8_t len;
      bool done = false;
      while (!done)
      {
        // Fetch the payload, and see if this was the last one.
len = radio.getDynamicPayloadSize();
done = radio.read( receive_payload, len );

// Put a zero at the end for easy printing
receive_payload[len] = 0;

// Spew it
printf("Got payload size=%i value=%s\n\r",len,receive_payload);
             
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(len);
        lcd.setCursor(0,1);
        lcd.print(receive_payload);
       
        digitalWrite(2,HIGH); // Turn on Beep
      }

      // First, stop listening so we can talk
      radio.stopListening();
      delay(50); // Put a small delay before sending response back
     
      // Send the final one back.
      radio.write( receive_payload, len );
      printf("Sent response.\n\r");


      // Now, resume listening so we catch the next packets.
      radio.startListening();
     
      delay(50); // Have a small delay
      digitalWrite(2,LOW); // Turn off beep

    }

}

freerpg

I inserted the code so that people can read through it easier than downloading.
so I need new code for mega and new pin hookup

PeterH

I would have thought that you just need to work out which pins on the Mega correspond to the pins the sketch uses. That is: the SPI bus (SCK, MISO, MOSI) and the Slave Select and Chip Enable pins used by the sketch.
I only provide help via the forum - please do not contact me for private consultancy.

PaulS

Code: [Select]
// Set up nRF24L01 radio on SPI bus plus pins 3 & 4

RF24 radio(8,7);

If you are going to have a comment, why doesn't the code match?

Code: [Select]
LiquidCrystal lcd(10, 9, 3, 4, 5, 6);
// Make way for the SPI pins
// 10 -> LCD 4
// 9  -> LCD 6
// 3  -> LCD 11
// 4  -> LCD 12
// 5  -> LCD 13
// 6  -> LCD 14

More comments that the code doesn't match.

That code isn't doing anything that warrants moving to a Mega. So, why are you?

Nick_Pyner


his worked wonderfully on the uno (freetronics eleven) but when I goto mega it doesn't then I found out the pinout for the mega is totally different.


The pins are not totally different but the ones you are using can be.

Assuming you haven't already bagged them for something else, the CE and CN pins should be OK on the Mega but you might check them as your comment doesn't agree with the assignment command. The SPI is offered on different pins. SS, MOSI, MISO and CLK are on 10,11,12,13  and 53, 51, 50, 52 on the Mega. If you use the 6-pin ICSP cluster, this is common to both Uno and Mega. Some boards use this routinely for SPI. I just plugged my Ethernet shield into the Mega without realising that I should check this. If you assemble the transceivers onto a proto board, headers from the ICSP means you can swap between  UNO to Mega OK. I would be suss about using those boards from Freetronics for this, as the holes may not line up properly.

There is a swag of information about Uno and Mega pins around here.

freerpg


That code isn't doing anything that warrants moving to a Mega. So, why are you?


that code isn't doing anything but my other codes might need it, I want to get the nrf to work on a mega first thenI can do the rest. this is just code I copied to get it to communicate to a raspberry pi. its good but I wantto upgrade to a mega for other things

Go Up