Communication sans fil avec l'Attiny84



Voir chapitre sur le LaunchPad ici pour les information sur le nrf24l01.


Installation des bibliothèques:

Télécharger la bibliothèque suivante https://github.com/stanleyseow/attiny-nRF24L01/archive/master.zip ou ici


Décompresser l'archive.

Copier les répertoires mirf85 et SPI85 dans libraries (exemple :C:\Users\Christophe\Documents\Arduino\libraries).





Pour la bonne attribution des broches il faut utiliser la bibliothèque: https://code.google.com/p/arduino-tiny/downloads/list ou ici . Ne pas utiliser l'autre bibliothèque pour cette application.



Programmation de l'Attiny voir chapitre ici.


Charger le programme suivant :


/*


This is an attiny84 example code for the nRF24L01 that can communicate with RF24 library


All the support files and libraries for the attiny for nRF24L01 is at repo listed  below


*  repo   : https://github.com/stanleyseow/arduino-nrf24l01/

*  Author : Stanley Seow

*  e-mail : stanleyseow@gmail.com

*  date   : 8 Aug 2013

Some default values to take note when using this mirf/spi85 library

Uses Mirf forked library from https://github.com/xdarklight/arduino-nrf24l01

- node addressing is similar to RF24 libs but the bytes are flipped

  byte TADDR[] = {0xe3, 0xf0, 0xf0, 0xf0, 0xf0}; will matches receiver node of RF24 below

  const uint64_t pipes[2] = { 0x7365727631LL, 0xF0F0F0F0E3LL };

The repo for the RF24 lib is at https://github.com/stanleyseow/RF24/


Added TinyDebugSerial to the codes for TX only serial debugging

https://code.google.com/p/arduino-tiny/


*/

//Modifier par Christophe CARON

//www.caron.ws


#include <avr/io.h>

#include <inttypes.h>

#include <avr/interrupt.h>

#include <util/delay.h>

#include <SPI85.h>

#include <Mirf85.h>

#include <nRF24L0185.h>

#include <MirfHardwareSpiDriver85.h>



// This USI was defined in SPI85.cpp

// Not to be confused with SPI (MOSI/MISO) used by ICSP pins

// Refer to page 61 of attiny84 datahseet

//

//#define USI-DO  5

//#define USI-DI  4

//#define USCK   6


#define CE    8    

#define CSN   7


// ATMEL ATTINY84 / ARDUINO

//

//                           +-\/-+

//                     VCC  1|    |14  GND

//  SerialTx   (D  0)  PB0  2|    |13  AREF (D 10)

//             (D  1)  PB1  3|    |12  PA1  (D  9)

//  RESET              PB3  4|    |11  PA2  (D  8)

//  PWM  INT0  (D  2)  PB2  5|    |10  PA3  (D  7)  CE

//  SS/CSN     (D  3)  PA7  6|    |9   PA4  (D  6)  USCK

//  USI-DI     (D  4)  PA6  7|    |8   PA5  (D  5)  USI-DO

//                           +----+


char buffer[32] = "azer"; //texte à envoyer

uint8_t nodeID = 0;


void setup(){

 Mirf.cePin = CE;

 Mirf.csnPin = CSN;

 Mirf.spi = &MirfHardwareSpi;

 Mirf.init();


 // This address is compatible with my example of rpi-hub or nRF24_Arduino_as_hub

 // at repo https://github.com/stanleyseow/RF24/examples/

 

 //byte RADDR[] = {0xe7, 0xde, 0xde, 0xde, 0xde};

 byte TADDR[] = {0xe1, 0xf0, 0xf0, 0xf0, 0xf0}; // Ardresse du raspberry . Lecture en sens inverse

 // Get nodeID from TXADDR

 nodeID = *TADDR & 0xff;

 

 

 Mirf.channel = 0x0; // Same as rpi-hub and sendto_hub ( channel 0 )

 Mirf.rfsetup = 0x06; // 1Mbps, Max power

 //Mirf.setRADDR(RADDR);  

 Mirf.setTADDR(TADDR);

 Mirf.config();

 

 // Enable dynamic payload on the other side

 Mirf.configRegister( FEATURE, 1<<EN_DPL );

 Mirf.configRegister( DYNPD, 1<<DPL_P0 | 1<<DPL_P1 | 1<<DPL_P2 | 1<<DPL_P3 | 1<<DPL_P4 | 1<<DPL_P5 );

 

 delay(100);

}


void loop(){

 

 uint8_t sent = false;

   

 Mirf.send((byte *) buffer);

 

 while( Mirf.isSending() )

 {

   delay(1);

   sent = true; // Sent success

 }

 

   

   delay(1000);

} // End loop()



Téléchargement du programme ici


Raccordement:

Le module nRF24L01+ doit être alimenté avec une tension inférieure à 3,6V.







Maintenant votre Attiny envois les messages. Pour les voir sur le Raspberry aller dans le chapitre ici


Pour des raisons pratique je mets les deux montages en //. C'est à dire celui de la programmation et du raccordement du module sans fil.


Mise à jour 25/12/2013


Créé avec HelpNDoc Personal Edition: Générateur de documentation Qt Help gratuit