Saturday, 24 June 2017

arduino - Problem with RF transmitter/reciever and VirtualWire


I'm trying to get an RF transmitter/reciever pair from digikey to work with my Arduino Uno/Mega ADK. But it seems neither the transmitter nor the reciever example are working with any of my Arduinos. At the moment I focused on the transmitter for now (hooked up the UNO) as its more obvious to tell when its working or not. I'm using Arduino IDE 1.0.1 with VirtualWire 1.9 (the one coming with 1.0.1 didn't compile).


Now when I understand the sketch correctly this should send "hello" in an infinite loop and blink the onboard LED everytime. When I reset the Arduino UNO I can see the TX LED blink once for a very short amount of time (which is the serial.print I guess) and after that the onboard LED is just constantly glowing. I have honestly no idea why this isn't working. Everything looks correct to me.


The model name of the transmitter is QAM-TX2-433-ND but I guess this is more of a code than a hardware problem? Though here is the datasheet of the transmitter if thats of any help: http://www.quasaruk.co.uk/acatalog/DSQAM-TX2-2.pdf


This is the code of the transmitter example from the VirtualWire libary


#include 

void setup()
{

Serial.begin(9600); // Debugging only
Serial.println("setup");

// Initialise the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}

void loop()
{

const char *msg = "hello";

digitalWrite(13, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, LOW);
delay(200);
}

And here two pictures of the hook up to the arduino: enter image description here



close up of the transmitters pin-out


EDIT: Ok so the LED problem was super simple, I just didn't specified PIN13 as output. Though I still don't know if the transmitter is acutally sending something, I have my ADK hooked up to the reciever and its running the reciever example from the VirtualWire libary. It should blink and print the "hello" message via serial but its not doing that. Now its hard to say if this is a reciever or transmitter problem now.


Reciever sketch:


#include 

void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
pinMode(13,OUTPUT);

// Initialise the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec

vw_rx_start(); // Start the receiver PLL running
}

void loop()
{
//Serial.println("Recieving...");

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;

digitalWrite(13, HIGH); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");


for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
digitalWrite(13, LOW);
}
}


Deleting the if (vw_get_message(buf, &buflen)) statment gives me alot of garbage on the serial monitor, so I can recieve atleast something.


And here two pictures of the circuit again (forgot to insert the data cable for the photo, it was connected to the second pin from left to the reciever and to pin 0 on the arduino):


enter image description here


enter image description here


And the datasheet: http://www.quasaruk.co.uk/acatalog/DSQAM-RX4-1.pdf



Answer



The problem seems to be rather banal.


You forgot to properly set:


pinMode(13,OUTPUT);


in the setup() function.




Incidentally, your code should actually be working, with the exception that the LED state is likely constant. It should be transmitting anyways.




Further Edit:


Ok, I've dug into the virtualwire library a bit more, and I think I see the problem


Mainly, the default configuration for the VirtualWire library TX pin is pin 12.


Basically, you have connected the transmitter to the wrong pin (in the pictures, you have it connected to pin 1).





Adding a TX activity LED to the module:



Note that this will only work properly with vw_set_ptt_inverted(true); commented out.


No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...