PitNRF24L01 I2C

Comunicazione wireless tra due NRF24L01 tramite BUS I2C.

Comunicazione wireless tra due arduini con NRF24L01 collegati al bus SPI

Riferimenti e istruzioni su github

Cosa serve:

  • 2 Arduini
  • 2 NRF24L01
  • 2 wireless Shields module SPI to IIC I2C TWI Interface
  • cavetti

Codice sorgente trsmettitore (master):


// Wire Master Writer
// by Nicholas Zambetti 

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include 

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
    Serial.begin(9600);  // start serial for output
      Serial.println("hello im the writer");
      delay(4000);

}
unsigned char judge = 0;
char scan;

void loop()
{

if(judge == 0)
{
  Wire.beginTransmission(35); // transmit to device #35
  //Wire.write(7);        // sends five bytes
  Wire.write(scan); 
  Wire.endTransmission();    // stop transmitting
  delay (1000); //ritardo ZappocoS
 judge = 1;
}
 delay(100); 


if(judge == 1)
{
      Wire.requestFrom(35, 1);    // request 1 bytes from slave device #35
      if(Wire.available())
      { 
          unsigned char c = Wire.read(); // receive a byte as character
          if(c !=0x47){
            
            Serial.println(c);
              
           ++scan; 
           if(scan == 8) scan = 0; 
            judge = 0; 
           }      

    
     }  
}
 
  

  


  

}

Codice sorgente ricevitore (slave):




// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device

unsigned char ppt =0;

#include 

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  delay(5000);
  Serial.println("hello im the reader");
}
unsigned char judge = 0,good;

void loop()
{

// Wire Master Reader 
if(judge == 0)
{
      Wire.requestFrom(35, 1);    // request 6 bytes from slave device #2
      if(Wire.available())
      { 
          good = Wire.read(); // receive a byte as character
         
         
          if(good !=0x47){
              //Serial.println(good) ;
              //Serial.println("Recieve code") ;

              
              judge = 1;
              }
    
     }
}


// Wire Master Write
if(judge == 1)
{
 Wire.beginTransmission(35); // transmit to device #35
  //Wire.write(7);        // sends five bytes
  Wire.write(good);              // transfer character 1 then salve will be display "hello ,homepage!"
  
  Wire.endTransmission();    // stop transmitting
  Serial.println(good) ;
  judge = 0;
}



 delay(100);

}

 

 

 

Scarica tutto quello che serve:

 

 

 

ZappocoS, 3 febbraio 2018