Salve a tutti sto provando ormai da diverso tempo che cerco un modo per far comunicare ricevitore e trasmettitore via radio in modo da trasmettere un segnale analogico (es potenziometro) e riceverlo in modo corretto..
Dico ciò poichè non riesco a capire quale potrebbe essere il problema riesco a ottenere il segnale analogico di un potenziometro ma questo poi viene inviato in maniera scorretta ricordando che il segnale del potenziometro varia da 0 a 1023 nel ricevitore anziche trovare 1023 trovo 3542
So già che avrò fatto qualche banale errore non insultatemi
ecco i codici
TRASMETTITORE
/*Include the VirtualWire library */
#include <VirtualWire.h>
/* Digital IO pin that will be used for sending data to the transmitter /
const int TX_DIO_Pin = 2;
int signalo=A0;
void setup()
{
pinMode(13, OUTPUT);
/ Initialises the DIO pin used to send data to the Tx module /
vw_set_tx_pin(TX_DIO_Pin);
/ Set the transmit logic level (LOW = transmit for this
version of module)*/
vw_set_ptt_inverted(true);
/* Transmit at 2000 bits per second */
vw_setup(2000); // Bits per sec
}
/* Main program /
void loop()
{
/ Temporarily holds the value read from analogue input A0 /
unsigned int Data;
/ BUFFER DI TRASMISSIONE CHE CONTERRA' I DATI DA TRASMETTERE. */
byte TxBuffer[2];
/* Read the analogue input A0... */
Data = analogRead(signalo);
/* ...and store it as high and low bytes in the transmit
buffer */
TxBuffer[0] = Data >> 8;
TxBuffer[1] = Data;
/* Turn on the LED on pin 13 to indicate that we are about
to transmit data /
digitalWrite(13, HIGH);
/ Send the data (2 bytes) */
vw_send((byte )TxBuffer, 2);
/ Wait until the data has been sent */
vw_wait_tx();
/* Turn off the LED on pin 13 to indicate that we have
now sent the data */
digitalWrite(13, LOW);
/* Do nothing for a second. Lower this delay to send
data quicker */
delay(1000);
}
RICEVITORE
/**
*/
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
vw_set_rx_pin(2);
// 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()
{
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, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
vw_wait_rx();
for (i = 0; i<buflen; i++)
{
Serial.print(buf*, DEC);*
}
Serial.println("");
-
digitalWrite(13, false);*
-
}*
}