I have a set of 433Mhz RF transmitter and receiver. My reciving code works fine. Any thing I sent up as: const char *msg = "Hello Shawn "; is sent over and works well. What I need to do is get *msg to = what ever was typed into the serial monitor. I'm kind of stuck at the line with all the ??????????????
Thanks for any and all help.
// Transmitter Code
#include <VirtualWire.h>
//Grove - 315(433) RF link kit Demo v1.0
//by :http://www.seeedstudio.com/
//connect the sent module to D2 to use
#include <VirtualWire.h>
String readString;
int RF_TX_PIN = 12;
int Boot1 = 0;
void setup()
{
Serial.begin(9600);
vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
vw_setup(9600); // Transmission speed in bits per second.
}
void loop()
{
while (Serial.available())
{
delay(2); //delay to allow byte to arrive in input buffer
char c = Serial.read();
readString += c;
if (readString.length() >0 )
{
// const char *msg = "Hello Shawn \n";
/////???????????????????????????
const char *msg = readString
vw_send((uint8_t *)msg, strlen(msg)); // Send message
readString = "";
delay(400);
Serial.println(" Message sent!");
// delay(1000);
Serial.flush();
}
}
}
I'm kind of stuck at the line with all the ??????????????
I am, too. Were all those ? necessary?
delay(2); //delay to allow byte to arrive in input buffer
A load of crap!!!!!!!!
(Does the extra punctuation help? I didn't think so).
You need to read and store data until an end of packet marker arrives (the carriage return that the Serial Monitor can add is a good choice). When the end of packet marker arrives, then you send the data.
The line is missing a ;, for one thing. For another, readString is a String. You can not make a char pointer point to anything but a char (or char array).
The String class has a toCharArray method that looks to be what you need. Notice that is expects an ARRAY, not a pointer. Yes, there IS a difference.
Go to the directory where the reference information is stored on your computer. Delete the folder where the String documentation is stored, and forget that such a resource wasting class exists. People have been writing text handling applications using C strings for more than 40 years. The crutches provided by the String class are simply not needed. Learn to use NULL terminated char arrays, and save yourself a ton of grief.
That's rude. I hope someday when you ask someone a question they stomp on you to. You should never expect anyone should have the same level of level of skills as you. Some people are just starting out and others know just a bought enough to be dangerous to them selves. but that's no reason to be a jerk a bought it. You need to grow up and stop belting people so you can feel better a bought your self. Don't give a long drawn out synthetic explanation of the problem, only to tell the poor guy what he already knows. Don't give out tiny little crumbs designed to be thought provoking. Give the poor guy the hole cookie, the real fix. When just give out crumbs or re explaining his problem in a more scientific way, it only shows that you really have no idea on how to fix the problem in the first place. Do you really need to put others down to make your self fell better? Just grow up.
will say that msg is a pointer to a char. Above that it is a const char pointer saying it is immutable.
The size (#bytes) is determined by the compiler compile time.
#include <VirtualWire.h>
char buffer[64];
int idx = 0;
int RF_TX_PIN = 12;
int Boot1 = 0;
void setup()
{
Serial.begin(9600);
vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
vw_setup(9600); // Transmission speed in bits per second.
}
void loop()
{
// fill buffer with chars from
while (Serial.available() > 0)
{
char c = Serial.read();
buffer[idx] = c;
idx++;
buffer[idx] ='\0' ; // keep the char array null terminated.
}
if (idx > 0 )
{
vw_send((uint8_t *)buffer, idx); // Send message
idx = 0;
buffer[idx] = '\0';
delay(400);
Serial.println(" Message sent!");
}
}