Pages: [1]   Go Down
Author Topic: [solved] - VirtualWire - Best Use  (Read 538 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good Morning Folks, so from several times i'm play with virtual wire for send data via "ASK Amplitude Shift Keying".

What I have learned is that:

- the library send-out data using:
Code:
 const char *msg = "hello";
  vw_send((uint8_t *)msg, strlen(msg));
Where msg could be defined in this way:
Code:
char msg[6] = "hello";
or in this way:
Code:
char msg[6];
       msg[0]='h';
       msg[1]='e';
       msg[2]='l';
       msg[3]='l';
       msg[4]='0';
       msg[5]='\0';
and Receive message in this way:
Code:
   char msgrx[10];
    uint8_t buf[VW_MAX_MESSAGE_LEN];        // define the buffer
    uint8_t buflen = VW_MAX_MESSAGE_LEN;  // buffer length
     if (vw_get_message(buf, &buflen)) // Non-blocking
       {
int i;
  Serial.print("Got: ");
  for (i = 0; i < buflen; i++)
      {
        msgrx[i]=buf[i];
               }
        }
Well at the end inside my variable msgrx I will have "hello" + 5 + '\0' .
Then when I have my message into the variable i did all my check for example:
Code:
if (strcmp(msgrx, "hello")  == 0)
     {
       Serial.println("Work are equal..."
     }

- Is this the correct use for the library ?
- Could I improve in something ?

VirtualWire is the only library that can be used for send data via ASK Amplitude Shift Keying or could be used something else ?

thanks have nice day,
gnux


« Last Edit: February 03, 2013, 12:16:58 pm by gnusso » Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1057
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use the Manchester library

http://mchr3k-arduino.blogspot.dk/2012/02/wireless-sensor-node-part-6.html

I use it with a Attiny85
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the information,
for example if would like to send-out the number "156" like a byte is possible ?

thanks
Gnux
« Last Edit: February 01, 2013, 09:28:26 am by gnusso » Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1057
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
for example if would like to send-out the number "156" like a byte is possible ?

Yes, below are my test sketch.
It just sends numbers starting at 1000 and counting up.

I was going to use it as a outdoor wireless thermometer, but ehhhm my temp sensor suddenly send out smoke (I had it reversed)


Code:
#include <MANCHESTER.h>
unsigned int data = 1000;

void setup()


MANCHESTER.SetTxPin(PB4);
//  MANCHESTER.SetTimeOut(1000);
}

void loop(){
data++;

MANCHESTER.Transmit(data);

delay(500);
}
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But with virtual wire i mean ...

so I've seen this

char *array = (char*)byte_array;

for convert byte into char

could be correct ?

thanks
gnux
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so I've seen this

char *array = (char*)byte_array;

for convert byte into char
It does not convert the byte array to a char array. It uses a different kind of pointer (char) to point to the data in the byte_array. Whatever is using array treads the data in byte_array as though it is char data. This works when byte_array only contains data that can be interpreted as char data.

A byte and a char are the same size (8 bits), but the byte is unsigned and the char is signed, so the two do not have the same range of values. As long as the data is in the overlapping range (0 to 127), the byte data is interpreted the same when interpreting as a char.
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So then with virtual wire is only possible send out number from 0 to 127  correct in only one byte ...

is possible pass directly the value without pass from the past char variable since the moment that want a uint8_t ? in this way i think could be more linear ...

Thanks for the support
gnux
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So then with virtual wire is only possible send out number from 0 to 127  correct in only one byte ...
No, you can send any value from 0 to 255. However, if the byte contains a value like 240, interpreting that as a character will not give the desired results.

If you ARE sending bytes, why are you casting to char?
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul,
so I would like send-out a byte ... kindly could you give me an example-code for send-out for example the number "240" like a byte ? and receive it like a byte ?

I ask to this because with the code i think will be more clear and maybe i can provide to you more information :-)

thanks for the support,
gnux
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so I would like send-out a byte ... kindly could you give me an example-code for send-out for example the number "240" like a byte ?

Code:
byte stuff = 240;
vw_send(&stuff, 1);

Quote
and receive it like a byte ?

Code:
    uint8_t buf[VW_MAX_MESSAGE_LEN];        // define the buffer
    uint8_t buflen = VW_MAX_MESSAGE_LEN;  // buffer length
     if (vw_get_message(buf, &buflen)) // Non-blocking
       {

buf[0] will contain 240.
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks 1000000 :-)

very useful :-)

Then into buf I can assign it to another byte variable :-)

I'll try and i'll let you know :-)

enjoy the weekend,
Gnux
Logged

Pages: [1]   Go Up
Jump to: