Bilder Upload
Follow Me!
#1

VirtualWire.h

in Software 16.08.2010 13:38
von Kingpin3k | 6 Beiträge

Ich wollte euch hier unbedingt mal die Library VirtualWire vorstellen, die ich für absolut genial halte
Diese Library ist dazu gedacht 2 Arduinos über RF zuverbinden.

Die Hardware dafür bekommt ihr ganz günstig z.B von Watterot
Sender = 3.42€
Empfänger = 4.28€

Die Library an sich kann man sich hier runterladen
VirtualWire.h
..und ein PDF das sie nochmal genau erklärt
Anleitung


Hier mal ein bisschen Beispielcode (Das Beispiel ist nicht von mir, ich habs es aber ausprobiert)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 

// Code für den Sender
 
// RF Link using VirtualWire to Transmit messages
// simplex (one-way) receiver with a 315MHz RF Link Transmitter module
// tx pin 3 on Duemilanova (arduino)
 
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RF Link module
vw_setup(2000); // Bits per sec
vw_set_tx_pin(3); // pin 3 is used as the transmit data
}
 
void loop()
{
const char *msg = "LMR-II Rocks";
// this is your message to send
 
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
// Wait for message to finish
delay(200);
}
 




Und hier der Code für den Empfänger:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
// RF Link using VirtualWire to receive messages
// simplex (one-way) receiver with a 315MHz RF Link Receiver module
// rx pin 23 on mega
 
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
Serial.begin(9600);
 
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(0); // We will be receiving on pin 0
vw_rx_start(); // Start the receiver
}
 
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
 
if (vw_get_message(buf, &buflen)) // check to see if anything has been received
{
int i;
// Message with a good checksum received.

for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]); // the received data is stored in buffer
}
Serial.println("");
}
}
 



Wenn ihr noch Fragen habt nur raus damit, ich hab jetzt schon ein bisschen mit dieser Library rumgespielt und 2 Projekte damit realisiert.

Heut abend lad ich mal nen paar Fotos von diesen hoch.

nach oben springen


Besucher
0 Mitglieder und 2 Gäste sind Online

Wir begrüßen unser neuestes Mitglied: hobbit23
Forum Statistiken
Das Forum hat 139 Themen und 222 Beiträge.

Xobor Forum Software von Xobor.de
Einfach ein Forum erstellen