Buongiorno a tutti,
ho un problema con il modulo receiver della comunicazione 433Mhz: il monitor seriale non visualizza nulla, invece doveva visualizzare un numero trasmesso dal trasmitter, e nell'arduino nano collegato il led L non lampeggia come in quello del transmitter.
Ho seguito precisamente i passi del seguente tutorial, anche con gli stessi pin (sempre il D2).
Per comodità però vi allego lo stesso entrambi i codici che ho caricato due 2 Arduino Nano.
Per verificare che il problema non fosse Arduino l'ho cambiato ma nulla da fare.
Codice Transmitter (dove il led L lampeggia correttamente)
/*
PIN DESCRIPTION ARDUINO PIN
1 GND GND
2 VCC (3.5-12V) VCC
3 TX DATA D2
*/
#include <VirtualWire.h>
const int TX_DIO_Pin = 2;
void setup() {
pinMode(13, OUTPUT);
initialize_transmitter();
}
/* Main program */
void loop() {
int counter;
for(counter=0; counter<100; counter++) {
digitalWrite(13, HIGH);
transmit_integer(counter);
digitalWrite(13, LOW);
delay(200);
}
}
/* DO NO EDIT BELOW */
void initialize_transmitter() {
/* 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
}
void transmit_integer(unsigned int Data) {
/* The transmit buffer that will hold the data to be
transmitted. */
byte TxBuffer[2];
/* ...and store it as high and low bytes in the transmit
buffer */
TxBuffer[0] = Data >> 8;
TxBuffer[1] = Data;
/* Send the data (2 bytes) */
vw_send((byte *)TxBuffer, 2);
/* Wait until the data has been sent */
vw_wait_tx();
}
Codice Receiver
/*
PIN DESCRIPTION ARDUINO PIN
1 GND GND
2 RX DATA D2
3 RX DATA N/A
4 VCC (5V) VCC
*/
#include <VirtualWire.h>
const int RX_DIO_Pin = 2;
int received;
void setup() {
Serial.begin(9600);
initialize_receiver();
}
/* Main program */
void loop() {
received = receive_integer();
if(received != -1) Serial.println(received);
}
/* DO NOT EDIT BELOW */
void initialize_receiver() {
/* Initialises the DIO pin used to receive data from the Rx module */
vw_set_rx_pin(RX_DIO_Pin);
/* Receive at 2000 bits per second */
vw_setup(2000);
/* Enable the receiver */
vw_rx_start();
}
int receive_integer() {
/* Set the receive buffer size to 2 bytes */
uint8_t Buffer_Size = 2;
/* Holds the recived data */
unsigned int Data;
/* The receive buffer */
uint8_t RxBuffer[Buffer_Size];
/* Has a message been received? */
if (vw_get_message(RxBuffer, &Buffer_Size)) // Non-blocking
{
/* Store the received high and low byte data */
Data = RxBuffer[0] << 8 | RxBuffer[1];
return Data;
}
return -1;
}
Thiago