Hello,
I use two transceiver pairs with the VirtualWire library.
My problem is that I use blocking functions like vw_wait_rx () and vw_wait_rx_max () and that the spurious emissions of my transmitters activate these functions while I do not emit any message. How can I avoid these spurious emissions. Can I change the state of the transmitter data pins when I don't want to transmit? But I don't know if it's possible because my knowledge in electronics is somewhat limited.
Thanks for your help.
MarkT
April 6, 2020, 2:11pm
2
This is why you need a checksum in each packet - bad checksum, wasn't a real packet.
MarkT:
This is why you need a checksum in each packet - bad checksum, wasn't a real packet.
Ok thanks for your answer but how I do this
The problem is probably not caused by YOUR transmitter. 433MHz is noisy and many devices use it. And even when nothing is transmitting the AGC (automatic gain control) of the receiver ramps the sensitivity up and tries to find data in the background noise. In other words you cannot get rid of receiving those false messages. You must implement some mechanism how to decide if the received message is from your transmitter or from some other source.
MrMark
April 6, 2020, 5:39pm
5
to0n7:
Ok thanks for your answer but how I do this
VirtualWire has packet error detection built in, though it is not infallible and it may be necessary to add an additional layer of error detection.
If you were to post your code rather than leaving us to guess what exactly might be going on, you'd likely get better advice on how to proceed.
Here my code
#include <VirtualWire.h>
#include <avr/wdt.h>
int ThermistorPin = 0;
int tension;
int valeurTableau;
int tempPourEnvoyer;
const bool okR = 1;
const bool okE = 0 ;
float R1 = 10000;
float logR2, R2, T, Tc ;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
void setup() {
Serial.begin(9600);
vw_set_tx_pin(12);
vw_set_rx_pin(11);
vw_setup(2000);
vw_rx_start();
}
void loop() {
int temp[2001];
unsigned long valeur;
int msg;
Serial.println("Attente réception");
vw_wait_rx();
if (vw_get_message((byte *) &valeur, sizeof(unsigned long))) {
Serial.println(valeur);
}
if (valeur == 10 || valeur == 30 || valeur == 60 || valeur == 120 || valeur == 300)
{
vw_send((byte *)&okR, sizeof(okR));
vw_wait_tx();
Serial.println(okR);
unsigned long incrementTemps = valeur * 1000;
for (int n = 0; n < 2000; n++)
{
tension = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)tension - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
Tc = T - 273.15;
tempPourEnvoyer = Tc * 100;
temp[n + 1] = tempPourEnvoyer;
Serial.println(tempPourEnvoyer);
Serial.println(incrementTemps);
vw_wait_rx_max(incrementTemps);
if (vw_get_message((byte *) &msg, sizeof(int)))
{ Serial.println(msg);
if (msg == 477) //à définir pour collecter
{ Serial.println(okR);
delay(1000);
vw_send((byte *) & okR, sizeof(okR));
vw_wait_tx();
temp[0] = n;
for (int a = 0; a < n + 1; a++)
{ valeurTableau = temp[a];
vw_send((byte *) &valeurTableau, sizeof(valeurTableau));
vw_wait_tx();
}
vw_wait_rx_max(2000);
if (vw_get_message((byte *) msg, sizeof(int)))
{
if (msg = okE)
{ break;
}
}
}
}
}
}
if (valeur == 1 )//à définir pour collecter
{
}
if (valeur == 0 )//à définir pour reset carte
{
}
}
And here a solution I find
#include <VirtualWire.h>
#include <avr/wdt.h>
int ThermistorPin = 0;
int tension;
int valeurTableau;
int tempPourEnvoyer;
const bool okR = 1;
const bool okE = 0 ;
float R1 = 10000;
float logR2, R2, T, Tc ;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
void setup() {
Serial.begin(9600);
vw_set_tx_pin(12);
vw_set_rx_pin(11);
vw_setup(2000);
vw_rx_start();
}
void loop() {
int temp[2001];
unsigned long valeur;
int msg = 0;
Serial.println("Attente réception");
vw_wait_rx();
if (vw_get_message((byte *) &valeur, sizeof(unsigned long))) {
Serial.println(valeur);
}
if (valeur == 10 || valeur == 30 || valeur == 60 || valeur == 120 || valeur == 300)
{
vw_send((byte *)&okR, sizeof(okR));
vw_wait_tx();
Serial.println(okR);
unsigned long incrementTemps = valeur * 1000;
unsigned long moment = millis();
Serial.print("Temps nécessaire avant de commencer le relevé : ");
Serial.println(moment);
for (unsigned long n = 0; n < 2000; n++)
{
tension = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)tension - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
Tc = T - 273.15;
tempPourEnvoyer = Tc * 100;
temp[n + 1] = tempPourEnvoyer;
Serial.print("Temperature ");
Serial.print(n);
Serial.print(" ");
Serial.println(tempPourEnvoyer);
Serial.print("Increment : ");
Serial.println(incrementTemps);
unsigned long calcul = moment + ((n + 1) * incrementTemps);
while ( millis() <= calcul || msg == 477)
{ Serial.print("Calcul : ");
Serial.println(calcul);
Serial.print("Millis : ");
Serial.println(millis());
vw_wait_rx();
if (vw_get_message((byte *) &msg, sizeof(int)))
{
Serial.println(msg);
}
}
if (msg == 477) //à définir pour collecter
{ Serial.println(okR);
delay(1000);
vw_send((byte *) & okR, sizeof(okR));
vw_wait_tx();
temp[0] = n;
for (int a = 0; a < n + 1; a++)
{ valeurTableau = temp[a];
vw_send((byte *) &valeurTableau, sizeof(valeurTableau));
vw_wait_tx();
}
vw_wait_rx_max(2000);
if (vw_get_message((byte *) msg, sizeof(int)))
{
if (msg = okE)
{ break;
}
}
}
}
}
if (valeur == 477)//à définir pour collecter
{
}
if (valeur == 666 )//à définir pour reset carte
{
}
}
srnet
April 6, 2020, 8:54pm
7
MrMark:
VirtualWire has packet error detection built in, though it is not infallible and it may be necessary to add an additional layer of error detection.
How does the error detection work ?
And how does it fail ?
to0n7:
My problem is that I use blocking functions like vw_wait_rx () and vw_wait_rx_max () and that the spurious emissions of my transmitters activate these functions while I do not emit any message. How can I avoid these spurious emissions.
By not using blocking functions that aren't required.
MrMark
April 7, 2020, 12:29am
9
srnet:
How does the error detection work ?
And how does it fail ?
Looking at some of the source for VirtualWire , I mostly misspoke above. VirtualWire ASK does 4 to 6 bit symbol encoding, but it doesn't hard fail the message if it gets an unrecognized symbol.
A few years back i did a partial port of the Manchester library which does have more redundancy in the coding scheme. I think I've confused the two.
MarkT
April 7, 2020, 8:33am
10
to0n7:
Ok thanks for your answer but how I do this
Compute the checksum of each packet you send, appending it to the message.
On receiving a packet check that the checksum matches that calculated for the packet - completely
ignore the packet if it fails the test.
Then the occasional spurious reception won't confuse the rest of your code.
16 bit checksum is recommended (ie 2 bytes), 8 bit is a little flimsy.