Ce site contient essentiellement des notes de travail. Le contenu est en constante évolution, et loin d'être achevé. (+ d'infos)
La plupart des documentations informatiques sont orientées Debian / Ubuntu.

Electronique/Hardware/Communication/433MHz/Arduino - Virtualwire

De Ordinoscope.net
Sauter à la navigation Sauter à la recherche

Test

Emetteur
#include <VirtualWire.h>

void setup () {
  Serial.begin(115200);	        // Debugging only
  Serial.println("setup");

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

void loop () {
  const char *msg = "hello";

  digitalWrite (13, true); // 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, false);
  delay (200);
}
Seeedstudio TX433.png
Récepteur
#include <VirtualWire.h>

void setup () {
  Serial.begin (115200);	// Debugging only
  Serial.println ("setup");

  // 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
  //vw_set_rx_pin (11);         // pin 11 by default
}

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: ");
	
    for (i = 0; i < buflen; i++) {
      Serial.print (buf[i], HEX);
      Serial.print (" ");
    }

    for (i = 0; i < buflen; i++) {
      Serial.print (buf[i]);
    }

    Serial.println ("");
      digitalWrite (13, false);
    }
}
Seeedstudio RX433.png

Emission d'un string

void loop () {
  static int count;
  count++;
  String msg = "Hello ";
  msg += count;
  ...
  vw_send((uint8_t *)stoi (msg), strlen(msg));
  ...
}

int stoi (String msg) {
  char m[msg.length ()];
  msg.toCharArray (m, msg.length ());
  return atoi (m);
}

Références