Hey community,
first off, I'm impressed by the quality of answers found in this forum and the widespread use of Arduino in general - it's nice to have these heaps of information right at your fingertips.
But even though there's quite a lot of information out there, I think I'm facing a pretty unusual problem here (what has been the last time somebody asked you about asynchronicity, eh?
)
As my bio suggests, I'm coming from a sort of "higher level" (=much more abstraction [and thus easier] from the sheer hardware) of programming, web development, client programming and so on. If I think about all the underlying things that are "already built" (Browser, Runtimes, OS, graphics layer and so on) and their complexity, I feel like an ape with a keyboard when programming a website.
Enough of the preface, I'm starting playing around with an Arduino UNO at the moment. More specifically, an Arduino and wireless (radio frequency) modules. It's the type of 433MHz "superregeneration" module everyone around here propably knows about, FS1000DA. They look exactly like this:
(image courtesy of robertoinzerillo.com)
However, even though I only own one Arduino at the moment I still want to play around with both modules. What I'm basically trying to do is: send with the transmitter module, receive the sent message with the receiver. Nothing special about it, I think.
I have wired the modules to my Arduino like so:
Receiver
Data to pin 3 (PWM-enabled), GND to GND on the other hand side, VCC to 5V (modules are rated up to 12V)
Transmitter
Data to pin 9 (PWM-enabled), GND to GND on the same side, VCC to the remaining 5V port).
The modules are about 10 centimeters apart. When running my Arduino sketch, which is patched together from a tutorial on these RF modules it just outputs sending but the receiver somehow never seems to receive data.
I'm using the VirtualWire library and not RadioHead as I think there are more potential users for this library and it's easier to install than the more modular RadioHead library - I don't need the new features provided by it anyway ![]()
However my Arduino sketch (at the end of this post) leads to me a thought..the program flows like this:
- Check for received data
- Send new message (isolated into an extra void)
- Repeat
Which is propably also why I'm never seeing data:
Assuming that the sendmessage() void is blocking (i.e. the processor will wait for it to terminate before starting the loop), the data is being sent while the receiver module isn't "listening" for it. I would somehow need a second "activity" in my Arduino, possibly a thread or any sort of asynchronous task. The then accruing program flow would be more like this:
Thread A
Sending the same message continously
Thread B
Looking for all messages (signals) on the frequency of 433MHz
Here's the sketch finally
#include <VirtualWire.h>
#include <VirtualWire_Config.h>void setup()
{
vw_set_ptt_inverted(true); // Required by the RF module
vw_setup(2000); // bps connection speed
vw_set_tx_pin(3); // Arduino pin to connect the receiver data pinSerial.begin(9600); // Configure the serial connection to the computer
vw_set_rx_pin(9); // Arduino pin to connect the receiver data pin
vw_rx_start(); // Start the receiver}
void loop()
{
if(vw_have_message()){
Serial.println('ACK A');
}
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // We check if we have received data
{
Serial.println('ACK');
int i;
// Message with proper check
for (i = 0; i < buflen; i++)
{
Serial.write(buf*); // The received data is stored in the buffer*
// and sent through the serial port to the computer*
}*
_ Serial.println();_}else{*
}*
sendmessage();*
}
void sendmessage()
{//Message to send:*
_ const char *msg = "HELLO WORLD";_
vw_send((uint8_t *)msg, strlen(msg));vw_wait_tx(); // We wait to finish sending the message*
_ Serial.println("sent..");_
}
[/quote]
I hope anyone around here can help me - Thank you in advance!
Please don't bash me if this is the wrong section for this topic or if I didn't know about some of the forum netiquette here or my question is just dumb - I tried my best!
P.S.: I know it's kind of pointless to send and receive RF on the same device (except for when building a range extender / relay but I think it's a nice exercise to do until I get my second Arduino hopefully soon)
greets,
rjhllr