Go Down

Topic: Serial Communication without computer? (Read 5802 times) previous topic - next topic


Read the VirtualWire document - it does not use the serial ports, it uses D11 & D12 as defualt, they can be changed.
Put the data you want in an array, it sends it  out. Here is heart of the code that would go in void loop().
There is more that goes in setup, read the document, the demo worked as-is for me sending characters. Very straightforward.
I reduced it a little as I was only sending 1 byte out.

#include <VirtualWire.h>    // Wireless transmitter/receiver library

Code: [Select]

    msg[0]=key;                               // load the array with the key character
    // msg[1]=NULL;                           // Rx side seems to work without this for me (I only send 1 byte from a keypad)

    digitalWrite(ledPin, true);               // Flash a light to show transmitting

    vw_send((uint8_t *)msg, strlen(msg));     // send the character out

//    Serial.println(key);                // for debugging only

    vw_wait_tx();                             // Wait until the whole message is gone

On the receive side:
Code: [Select]

// look for wireless input or for unsolicited message from arduino2

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(ledPin, LOW); // Turn on LED to show working a message

  // Message with a good checksum received, dump it.
  //Serial.println("Got: ");  // Show on PC for debugging

  //    for (i = 0; i < buflen; i++)
  //    {
  //    }
  //Serial.println(""); // spaces it out for the monitor

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up