arduino mega + nrf24L01+ problem with digital pins ?

Hi,

I've been prototyping several musical devices, reading sensors on analog inputs and digital inputs and sending Midi CC via the serial Tx.

Everything worked fine, until I switched to wireless (2.4Ghz) communication, with an arduino Mega reading my sensors and sending data (via a NRF24L01+ chip with an antenna, that thing: http://hackspark.fr/fr/nrf24l01-with-pa-and-lna-2-4ghz-rf-module-long-distance-antenna.html) to an arduino Uno which acts as a receptor and translates my data in Midi.
The RF communication works quite fine, EXCEPT that I couldn't read the digital pins of my arduino mega.

Is there a trick with the Digital Pin numbers of the mega ?

Is it the MIRF library (which I use to operate the RF communication) or the SPI library messing up the use of digital pins ?

My code is attached.

I found a workaround by connecting my switches to the available analog inputs, but I'd like to use the digital ones instead.

Weird thing is that everything was working ok before switching to RF communication...

any tip is welcome !

Machine_coudre_2_RF_transmit_FINAL.ino (4.5 KB)

I understand this is an old thread.
I have the same problem on 2 megas, after attempting to use nrf24 's (nrf24 library) none of the digital pins function.

Did anyone find a solution to this?

I found by using and older version of the IDE ( 1.0 ) all is back to normal.
My later version of the ide has a custom boards txt so that could be the cause.

Yeah for the fix was to put some caps (can't find the boards now as they are in a box, it's been a long time !) across the + and the Gnd of the NRF24L01+

The problem seemed to come from a bad 3.3V given by the arduino mega, as my "receptors", based on a arduino uno, were working quite fine.

Anyway, even with that cap fix, I still had random problems from time to time.

I found the last code I used, maybe it can be helpful:

//reads 16 analog inputs of an arduino mega & convert it to midi

// just for memory, the MIDI status byte is 176 to define we send a MIDI CC on Channel 1.


//define the MIDI channel here


#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

int midiChannel = 2; // Midi Channel

// Variables

// define variables for the controller data

int AnalogValue[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 

// define variables for the digital inputs

int DigitalValue[10]= {0,0,0,0,0,0,0,0,0,0};

// define the "lastValue" variables for analog inputs

int lastAnalogValue[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 

// define the last Digital value variable

int lastDigitalValue[10] = {0,0,0,0,0,0,0,0,0,0};

//select the midi controller number for each digital input

int digmidiCCselect[10] = {110,111,36,37,38,39,40,41,42,43};
  
// select the midi Controller Number for each analogue input

int midiCCselect[16] = {20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35};

// select threshold for each analog input

int thresh[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};   // was 1 on the original program

// select number of desired analog inputs and digital inputs (max 16 on arduino mega)

int an_input_no = 16;
int dig_input_no= 10; //will scan digital inputs 2 to 9 (0 & 1 are used for serial communication)


void setup() {
 //  set the states of the I/O pins:
 // pinMode(switchPin, INPUT);
 pinMode(2, INPUT);
 pinMode(3, INPUT);
 pinMode(4, INPUT);
 pinMode(5, INPUT);
 pinMode(6, INPUT);
 pinMode(7, INPUT);
 pinMode(8, INPUT);
 pinMode(9, INPUT);
 
 //  Set MIDI baud rate:
 // NOT NECESSARY IN THE TRANSMITTER SKETCH !
 // Serial.begin(31250); 
 
 
 //Notes: :)
 /* Pins:
 * Hardware SPI:
 * MISO -> 12 // 50 //on arduino mega
 * MOSI -> 11 // 51 //on mega
 * SCK -> 13 // 52 //on mega
 *
 * Configurable:
 * CE -> 8
 * CSN -> 7
 */
 
  Mirf.cePin = 49; // CE sur Digital pin dispo de l'arduino Mega
  Mirf.csnPin = 53; // CSN sur Digital pin dispo de l'arduino Mega
  Mirf.spi = &MirfHardwareSpi; 
  Mirf.init();
 


  Mirf.channel = 0; 
  Mirf.payload = 3*sizeof(byte); 
  Mirf.config(); 

  Mirf.setTADDR((byte *)"singer01t"); //a checker ds sketch recepteur
  Mirf.setRADDR((byte *)"singer01r"); //a checker
  
  //a essayer: 0x06 = 1Mbs data rate - 0x26 = 250 Kbs data rate (longest range)
  Mirf.configRegister(RF_SETUP,0x06); 


}

// main program loop

void loop() {
  
  //scan the digital inputs 2 to "dig_input_no" and send CC

for(int i=2;i<dig_input_no;i++) {
  
  DigitalValue[i] = (digitalRead(i))*127; //scale 0-1 digital inputs to have a midi value 0-127
    
  if ( DigitalValue[i] != lastDigitalValue [i] ) {
    
    //send control change on cc#i on midiChannel
           
           midiCC((175+midiChannel), digmidiCCselect[i], DigitalValue[i]); 
           // update lastAnalogValue variable
           lastDigitalValue[i] = DigitalValue[i];
    
    //end if 
 }
  
  //end for
 
} 
 
//scan the analog inputs and send CC

for(int i=0;i<an_input_no;i++){

         AnalogValue[i] = (analogRead(i))/8;    // read the value from the analog input and divide by 8 for range 0-127
     // check if value is greater than defined threshold (good for resistive touchpads etc)
     if ( AnalogValue [i]>thresh[i] ) {
           // check if analog input has changed
           if ( AnalogValue[i] != lastAnalogValue[i] ) {

           //send control change on cc#i on midiChannel
           
           midiCC((175+midiChannel), midiCCselect[i], AnalogValue[i]); 
           // update lastAnalogValue variable
           //lastAnalogValue[i] = AnalogValue[i];

           //End if
           }   
       //End if
     }
     
     
   //A ESSAYER POUR STABILISER LES VALEURS
   
     else if (AnalogValue [i]<=thresh[i] ) {
       
       
       
      // AnalogValue[i]=0;
     // midiCC((175+midiChannel), midiCCselect[i], AnalogValue[i]); 
    // midiCC((175+midiChannel), midiCCselect[i], 0); 
       
      // lastAnalogValue[i] = AnalogValue[i];
       //delay(1);
       
       //endif
        
      }   
   
  
//End for 
}


//End Loop
}

// This function sends a Midi CC. 
//void midiCC(char CC_data, char c_num, char c_val){
 //Serial.print(CC_data, BYTE);
 //Serial.print(c_num, BYTE);
 //Serial.print(c_val, BYTE);

// }

// This function sends a Midi CC over the NRF20L01+ transceiver

void midiCC(char CC_data, char c_num, char c_val){

byte data[Mirf.payload];
data[0] = CC_data;
data[1] = c_num;
data[2] = c_val;

Mirf.send((byte*)&data);

while(Mirf.isSending()); 

}