Go Down

Topic: RF433 (Read 103 times) previous topic - next topic

ankushg989

Hello,
i'm using virtual library and two arduino boards

transmitter code
Code: [Select]
// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

const int led_pin = 11;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;

void setup()
{
    // Initialise the IO and ISR
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_set_ptt_pin(transmit_en_pin);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);       // Bits per sec
    pinMode(led_pin, OUTPUT);
}

byte count = 1;

void loop()
{
  char msg[7] = {'h','e','l','l','o',' ','#'};

  msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msg, 7);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  delay(1000);
  count = count + 1;
}


Receiver code
Code: [Select]
// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;

void setup()
{
    delay(1000);
    Serial.begin(9600); // Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_set_ptt_pin(transmit_en_pin);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec

    vw_rx_start();       // Start the receiver PLL running

    pinMode(led_pin, OUTPUT);
}

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(led_pin, HIGH); // 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(' ');
}
Serial.println();
        digitalWrite(led_pin, LOW);
    }
}


Output-
Code: [Select]
setup
Got: 68 65 6C 6C 6F 20 25
Got: 68 65 6C 6C 6F 20 26
Got: 68 65 6C 6C 6F 20 27
Got: 68 65 6C 6C 6F 20 28
Got: 68 65 6C 6C 6F 20 29
Got: 68 65 6C 6C 6F 20 2A
Got: 68 65 6C 6C 6F 20 2B
Got: 68 65 6C 6C 6F 20 2C
Got: 68 65 6C 6C 6F 20 2D
Got: 68 65 6C 6C 6F 20 2E
Got: 68 65 6C 6C 6F 20 2F
Got: 68 65 6C 6C 6F 20 30
Got: 68 65 6C 6C 6F 20 31
Got: 68 65 6C 6C 6F 20 32
Got: 68 65 6C 6C 6F 20 33
Got: 68 65 6C 6C 6F 20 34
Got: 68 65 6C 6C 6F 20 35
Got: 68 65 6C 6C 6F 20 36
Got: 68 65 6C 6C 6F 20 37
Got: 68 65 6C 6C 6F 20 38
Got: 68 65 6C 6C 6F 20 39


what should i do to get result as string or in above ex. "hello" in output

Riva

Change
Code: [Select]
Serial.print(buf[i],HEX);
to
Code: [Select]
Serial.print(buf[i]);
and if that does not work then
Code: [Select]
Serial.print((char)buf[i]);
Don't PM me for help as I will ignore it.

Go Up