Line 1... |
Line 1... |
1 |
/* |
1 |
/* |
2 |
connections arduino RF01 and RF02 |
2 |
RF02 TX sample for Arduino |
3 |
|
3 |
|
4 |
in arduino version 018 |
4 |
in arduino version 022 |
5 |
(not yet tested in more recent arduino versions) |
- |
|
6 |
|
5 |
|
7 |
tested with ATmega 328 |
6 |
tested with MLAB modules with ATmega 328 at 16MHz |
8 |
on frequency 433 |
- |
|
9 |
|
- |
|
10 |
no range test done yet, just in one room |
7 |
see RF02 library for a Band and Frequency |
11 |
*/ |
8 |
*/ |
12 |
|
9 |
|
13 |
//connections RF02: (sending) |
10 |
//connections RF02: (TX) |
14 |
#define SDI 0 // SDI, -> RF02 Atmega PB0 Arduino 8 cannot be changed |
11 |
// SDI, -> RF02 Atmega PB0 Arduino 8 cannot be changed |
15 |
#define SCK 1 // SCK, -> RF02 Atmega PB1 Arduino 9 cannot be changed |
12 |
// SCK, -> RF02 Atmega PB1 Arduino 9 cannot be changed |
16 |
#define CS 2 // nSEL, -> RF02 Atmega PB2 Arduino 10 cannot be changed |
13 |
// nSEL, -> RF02 Atmega PB2 Arduino 10 cannot be changed |
17 |
#define IRQ 4 // nIRQ, <- RF02 Atmega PB4 Arduino 12 cannot be changed |
14 |
// nIRQ, <- RF02 Atmega PB4 Arduino 12 cannot be changed |
18 |
//------------------// FSK: Pullupto VCC |
15 |
// FSK: Pullupto VCC |
19 |
|
- |
|
20 |
|
- |
|
21 |
// RF02 sending words |
- |
|
22 |
// tested with lib, november 2010 |
- |
|
23 |
|
16 |
|
24 |
#include <RF02.h> |
17 |
#include <RF02.h> |
25 |
#include <stdint.h> |
- |
|
26 |
|
18 |
|
27 |
int wissel = 0;//wissel means change in dutch |
- |
|
28 |
|
- |
|
29 |
void setup() { |
19 |
void setup() |
30 |
|
20 |
{ |
31 |
Serial.begin(9600); |
21 |
Serial.begin(9600); |
32 |
Serial.print("hello" ); |
- |
|
33 |
Serial.println("init" ); |
22 |
Serial.println("\nSTM02 init" ); |
34 |
|
23 |
|
35 |
|
- |
|
36 |
rf02_prepAll(); |
24 |
rf02_prepAll(); |
37 |
Serial.println("done" ); |
- |
|
38 |
|
- |
|
39 |
pinMode(4, OUTPUT); //testing leds |
- |
|
40 |
pinMode(5, OUTPUT); |
- |
|
41 |
ledBlink(4); |
- |
|
42 |
ledBlink(5); |
- |
|
43 |
} |
- |
|
44 |
|
- |
|
45 |
void ledBlink(int num){ |
- |
|
46 |
digitalWrite(num, HIGH); |
- |
|
47 |
delay(100); |
- |
|
48 |
digitalWrite(num, LOW); |
- |
|
49 |
delay(100); |
- |
|
50 |
} |
- |
|
51 |
|
25 |
|
52 |
unsigned int ble='a'; |
26 |
Serial.println("done" ); |
- |
|
27 |
} |
53 |
|
28 |
|
54 |
void loop() |
29 |
void loop() |
55 |
{ |
30 |
{ |
- |
|
31 |
unsigned char _tx_buffer[]="0123456789"; |
56 |
|
32 |
|
57 |
// ledBlink(4); |
33 |
delay(1000); |
58 |
|
34 |
|
59 |
delay(1000); |
- |
|
60 |
|
- |
|
61 |
// unsigned char buf[] = { "01234567890123456789012345678901\n" }; // Motor, Rudder |
- |
|
62 |
unsigned char buf[] = { "0123456789012345678$0123456789" }; |
- |
|
63 |
|
- |
|
64 |
unsigned char sum=0; |
- |
|
65 |
//buf[19]=ble; |
- |
|
66 |
for(unsigned int a=0;a<20;a++) |
- |
|
67 |
{ |
- |
|
68 |
sum+=buf[a]; |
- |
|
69 |
}; |
- |
|
70 |
if(ble>'z') {ble='a';} else {ble++;} |
- |
|
71 |
buf[20]=sum; |
- |
|
72 |
buf[21]=0xAA; |
- |
|
73 |
buf[22]=0xAA; |
- |
|
74 |
rf02_changeText( buf, 23); |
- |
|
75 |
|
- |
|
76 |
// rf02_changeText( buf, sizeof buf); |
35 |
rf02_txdata( _tx_buffer, sizeof(_tx_buffer)); |
77 |
// Serial.println("M0R0\n"); |
- |
|
78 |
rf02_sendData(); |
- |
|
79 |
} |
36 |
} |
80 |
|
37 |
|
81 |
|
38 |
|