Hi there!
I am using virtual wire + ATtiny 85 to send data over an RF Link that then gets received by an Arduino UNO.
If I use the standard example everythink works fine, and it sends every string I want.
But now I want to be able to send changing string and Numbers (int?); e.g. sensor data, counters, ...
I do program (mostly java atm) and I learned C++ some years ago but here I get confused...
They convert a String into an array of chars and send them. I tried to dublicate that by creating my own array and trying things like
char *myarray;
myarray[0] = i; // i = counter
but nothing reaches the receiver.
How do I send numbers and changing stuff?
// 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@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
#include <VirtualWire.h>
void setup()
{
// Initialise the IO and ISR
vw_set_tx_pin(3);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}
void loop()
{
const char *msg = "hello";
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
}
I agree with Arrch...get rid of the String objects. Instead of:
String test = "hello";
const char *msg = test;
can't you use:
char test[] = "hello";
const char *msg = test;
instead? Always remember that a pointer can only hold two things: null ('\0'), which means it's not a valid pointer, or a memory address (the lvalue of a data item).