1 |
/* |
1 |
/* |
2 |
RF02 TX duckweed collector |
2 |
RF02 TX duckweed collector |
3 |
|
3 |
|
4 |
in arduino version 022 |
4 |
in arduino version 022 |
5 |
|
5 |
|
6 |
tested with MLAB modules with ATmega 328 at 16MHz |
6 |
tested with MLAB modules with ATmega 328 at 16MHz |
7 |
see RF02 library for a Band and Frequency |
7 |
see RF02 library for a Band and Frequency |
8 |
*/ |
8 |
*/ |
9 |
|
9 |
|
10 |
//connections RF01: (RX) |
10 |
//connections RF01: (RX) |
11 |
// RF01 SDI, arduino 13, ATmega PB5, cannot be changed |
11 |
// RF01 SDI, arduino 13, ATmega PB5, cannot be changed |
12 |
// RF01 SCK, arduino 12, ATmega PB4, cannot be changed |
12 |
// RF01 SCK, arduino 12, ATmega PB4, cannot be changed |
13 |
// RF01 nSEL, arduino 11, ATmega PB3, cannot be changed |
13 |
// RF01 nSEL, arduino 11, ATmega PB3, cannot be changed |
14 |
// RF01 SDO, arduino 10, ATmega PB2, cannot be changed |
14 |
// RF01 SDO, arduino 10, ATmega PB2, cannot be changed |
15 |
// RF01 niRQ, arduino 02, ATmega PD2, cannot be changed |
15 |
// RF01 niRQ, arduino 02, ATmega PD2, cannot be changed |
16 |
// RF01 nFFS: 1-10k Pullup too Vcc |
16 |
// RF01 nFFS: 1-10k Pullup too Vcc |
17 |
|
17 |
|
18 |
|
18 |
|
19 |
// receiving words with RF01 |
19 |
// receiving words with RF01 |
20 |
|
20 |
|
21 |
#include <RF01.h> |
21 |
#include <RF01.h> |
- |
|
22 |
#include <Servo.h> |
- |
|
23 |
|
- |
|
24 |
Servo servo_motor; |
- |
|
25 |
Servo servo_rudder; |
22 |
|
26 |
|
23 |
void setup() |
27 |
void setup() |
24 |
{ |
28 |
{ |
25 |
Serial.begin(9600); |
29 |
Serial.begin(9600); |
26 |
Serial.println("\nRFM01 init"); |
30 |
Serial.println("\nRFM01 init"); |
27 |
delay(250); |
31 |
delay(250); |
28 |
|
32 |
|
- |
|
33 |
servo_motor.attach(3); |
- |
|
34 |
servo_rudder.attach(4); |
- |
|
35 |
|
29 |
rf01_prepAll(); |
36 |
rf01_prepAll(); |
30 |
|
37 |
|
31 |
Serial.println("done"); |
38 |
Serial.println("done"); |
32 |
} |
39 |
} |
33 |
|
40 |
|
34 |
void loop() |
41 |
void loop() |
35 |
{ |
42 |
{ |
36 |
int n; |
43 |
int n; |
- |
|
44 |
unsigned int Motor, Rudder, Check, Check2; |
- |
|
45 |
|
37 |
char* buf = (char*) _rx_buffer; |
46 |
char* buf = (char*) _rx_buffer; |
38 |
|
47 |
|
39 |
rf01_rxdata(_rx_buffer, 10); |
48 |
rf01_rxdata(_rx_buffer, 3); |
- |
|
49 |
Serial.print(buf); |
- |
|
50 |
Serial.print(' '); |
- |
|
51 |
|
- |
|
52 |
Motor=_rx_buffer[0]; |
- |
|
53 |
Motor-=(Motor>'9')?('a'-10):'0'; |
- |
|
54 |
Serial.print(Motor, DEC); Serial.print(' '); |
- |
|
55 |
Rudder=_rx_buffer[1]; |
- |
|
56 |
Rudder-=(Rudder>'9')?('a'-10):'0'; |
- |
|
57 |
Serial.print(Rudder, DEC); Serial.print(' '); |
40 |
buf[11]=0; |
58 |
Check=_rx_buffer[2]; |
- |
|
59 |
Check-=(Check>'9')?('a'-10):'0'; |
- |
|
60 |
Serial.print(Check, DEC); Serial.print(' '); |
- |
|
61 |
|
- |
|
62 |
Check2=Motor+Rudder; |
- |
|
63 |
if (Check2>32) Check2-=32; |
- |
|
64 |
if (Check!=Check2) |
- |
|
65 |
{Serial.print(' Error');} |
- |
|
66 |
else |
- |
|
67 |
{ |
- |
|
68 |
servo_motor.write(Motor); |
- |
|
69 |
servo_rudder.write(Rudder); |
- |
|
70 |
} |
41 |
|
71 |
|
42 |
Serial.println(buf); |
- |
|
43 |
for(n=0;n<32;n++) {Serial.print(buf[n], HEX); Serial.print(' ');} |
- |
|
44 |
Serial.println(); |
72 |
Serial.println(); |
45 |
} |
73 |
} |