RF Module -- Serial.read Solved**

I’m trying to take a massage through Serial.read and send it with RF Module and print it 16x2 LCD at other side but i had some trouble with it.

Solved**
With this codes you can take message through Serial.read ,send it with RF Module and print it to lcd or strcmp and control other things if u want at the other side(receiver)

Transmitter Code;

#include <VirtualWire.h>

char msg[64];
int i= 0;
void setup()
{
Serial.begin(9600);
vw_set_tx_pin(12);
vw_set_ptt_inverted(true);
vw_setup(2000);
}

void loop()
{
if( Serial.available() > 0)
{
msg = Serial.read();
i++;
}
if( msg[i-1] == ‘.’)
{
msg[i-1] = ‘\0’;
i=0;
vw_send((byte *)msg, strlen(msg));
delay(400);
}
}
[/td]
[/tr]
[/table]
Receiver Code;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <VirtualWire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{

  • Serial.begin(9600); // Debugging only*

  • Serial.println(“setup”);*

  • lcd.init();*

  • lcd.backlight();*

  • vw_set_rx_pin(12);// 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*
    }
    void loop()
    {

  • byte buf[VW_MAX_MESSAGE_LEN];*

  • byte buflen = VW_MAX_MESSAGE_LEN;*

  • if (vw_get_message(buf, &buflen)) // Non-blocking*

  • {*

  • int i;*

  • for (i = 0; i < buflen; i++)*

  • {*

  • if (i<=15)*

  • {lcd.setCursor(i , 0);}*

  • else*

  • {lcd.setCursor(i-16 , 1);}*
    _ lcd.write(buf*);_
    _
    }*_

* }*
}
[/td]
[/tr]
[/table]

Also tried this one, didn’t worked too, i just started to suspect about IDE

#include <VirtualWire.h>

const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data

boolean newData = false;

void setup()
{
Serial.begin(9600);
vw_set_tx_pin(12);
vw_set_ptt_inverted(true);
vw_setup(2000);
}

void loop()
{
recvWithEndMarker();
sendNewData();
}

void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = ‘\n’;
char rc;

while (Serial.available() > 0 && newData == false) {
rc = Serial.read();

if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = ‘\0’; // terminate the string
ndx = 0;
newData = true;
}
}
}

void sendNewData() {
if (newData == true) {
const char *msg = receivedChars;
vw_send((byte *)msg, strlen(msg));
vw_wait_tx();
newData = false;
delay(200);
}
}

   const char *msg = (const char*)Serial.read();

Serial.read() returns an int. Casting that to a character pointer, constant or not, is wrong. You must read all the characters, one by one, and store them in an array, until the end of message marker (whatever that is in your case) arrives. Then, you can send the array, casting it as needed.

i just started to suspect about IDE

With absolutely no proof? Why?

PaulS:
With absolutely no proof? Why?

It's too late here, sorry , i wasn't serious about it. I got this code from Robin2's Serial Input Basics topic http://forum.arduino.cc/index.php?topic=396450

It didn't work as well. What do u think about second receiver code?

What do u think about second receiver code?

Which problem are you trying to solve? There are three parts to the situation. You need to collect some serial data. You don't know that you are doing that correctly. You need to send that data via the radio. Doing that without knowing that the data to be sent over the air is good seems pointless. Then, on the receiver end, you need to deal with the received data. Again, doing anything with the data you get over the air, without knowing if it is good data, seems pointless.

So, just before the vw_send() call, put:

Serial.print("I am going to send: [");
Serial.print(msg);
Serial.println("]");

If the stuff in the is not what you expect to send, worrying about the sending and receiving code is pointless.

If it is what you expect, then you need to explain what is actually sent and what appears to be actually received.

PaulS:
Which problem are you trying to solve?

I can't explain myself good with my english..

This is untouched Transmitter code for RF

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);
}

I just trying to Serial.read the massage instead of "hello".
I dont have much experience
My problem was "invalid conversion from 'int' to 'const char*' [-fpermissive]" const char *msg = Serial.read();
Then i learned Serial.read returns an integer and searched on net, found Robin2's topic
I learned as you can see before ur first reply i have to get chars one by one but it didnt worked i dont know why, i want to know why?

in the code in Reply #1 (your second attempt), you do implement Robin2's serial reading process. So, what DID you read from the serial port? I suggested a way, in reply #5, to know what you did read/plan to send.

Add that code, and see just where the problem is. Is it reading the serial data? Is it sending the data read? Or, is it on the receiving end?

I TRIED that before too it doesnt shows anything
It is reading the serial data isnt that obvious even topic title "RF Module -- Serial.read"
All other parts working i tried them without serial.read
STOP disdaining me i said i dont have much experience.
You know what just forget it u made me sick for i just started that topic i just want to know how to delete it
it was my first post in a forum ......

I TRIED that before too it doesnt shows anything

But you haven't shown any code to prove that.

I find it difficult to believe that you can read from the serial port but not write to it. Post the code that illustrates this problem. My Arduino is sitting here waiting.

STOP disdaining me i said i dont have much experience.

You misspelled "trying to help me". I'll overlook that, though. I'm done.

Got the solution if someone else want to Serial.read the message

#include <VirtualWire.h>

char msg[64];
int i= 0;
void setup()
{
Serial.begin(9600);
vw_set_tx_pin(12);
vw_set_ptt_inverted(true);
vw_setup(2000);
Serial.println("Finish message with “.” ");
}

void loop()
{
if( Serial.available() > 0)
{
msg = Serial.read();
i++;
}
if( msg[i-1] == ‘.’)
{
msg[i-1] = ‘\0’;
i=0;
vw_send((byte *)msg, strlen(msg));
delay(400);
}
}[/td]
[/tr]
[/table]

I just wanted to add this quote

Slee_The_Sloth:
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.