110-Com sans fil Attiny85
Communication sans fil avec l'Attiny85
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).


Programmation de l'Attiny voir chapitre ici.
Charger le programme suivant :
/*
This is an attiny85 example code for the nRF24L01 that can communicate with RF24 library
All the support files and libraries for the attiny85 for nRF24L01 is at repo listed below
* repo : https://github.com/stanleyseow/attiny-nRF24L01
* Author : Stanley Seow
* e-mail : stanleyseow@gmail.com
* date : 11th Apr 2013
Some default values to take note when using this mirf85/spi85 library
- changed the default of CRC8 to CRC16 ( mirf85.h )
- added rf_setup to Nrf24l::config ( mirf85.cpp / mirf85.h )
- added some defines for Dynamic Payload in the header files ( nRF24L0185.h )
- 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>
// ATtiny25/45/85 Pin map
// +-\/-+
// Reset/Ain0 (D 5) PB5 1|o |8 Vcc
// nRF24L01 CE, Pin3 - Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 - nRF24L01 SCK, pin5
// nRF24L01 CSN, Pin4 - Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 - nRF24L01 MOSI, pin7
// GND 4| |5 PB0 (D 0) pwm0 - nRF24L01 MISO, pin6
// Pinout
// CE - Pin 2 / D3 / nRF3
// CSN - Pin 3 / D4 / nRF4
// GND - Pin 4
// MISO - Pin 5 / D0 / nRF7
// MOSI - Pin 6 / D1 / nRF6
// SCK - Pin 7 / D2 / nRF5
// Vcc - Pin 8 ( 3.3V )
char buffer[32] = "test";//message que l'on envois
uint8_t nodeID = 0;
#define CE PB3 //ATTiny
#define CSN PB4 //ATTiny
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[] = {0xe2, 0xf0, 0xf0, 0xf0, 0xf0};
byte TADDR[] = {0xe1, 0xf0, 0xf0, 0xf0, 0xf0}; //Attention l'adresse se lit dans l'autre sens
// Get nodeID from TXADDR and mask the first byte (0xff)
nodeID = *TADDR & 0xff;
Mirf.channel = 0x0; // Same as rpi-hub and sendto_hub canal 0
Mirf.rfsetup = 0x06; // 1Mbps, Max power
//Mirf.setRADDR(RADDR);
Mirf.setTADDR(TADDR);
Mirf.config();
// Enable dynamic payload
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.
Utilisation du bootloader : ATtiny85 @ 8 MHz (internal oscillator; BOD disabled)
Mise à jour 24/01/2014
Créé avec HelpNDoc Personal Edition: Créer des documentations web iPhone