Page 3 of 4

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Wed Jul 29, 2009 9:03 am
by jamie.wilson
I am now transmitting pretty well between the two...

But this "Out of memory, cannot create packet" is my main problem, it stops the connection being fast. It has this message between every receive.

Any ideas about clearing the memory??

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Wed Jul 29, 2009 4:27 pm
by Miles
jamie.wilson wrote:I am now transmitting pretty well between the two...

But this "Out of memory, cannot create packet" is my main problem, it stops the connection being fast. It has this message between every receive.

Any ideas about clearing the memory??
The problem is you are trying to send to much for the arduino to handle. It's still quite an early build so it uses quite a lot of memory to send data.

Try and reduce the amount of data you send....

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Wed Jul 29, 2009 4:32 pm
by Miles
jamie.wilson wrote:Well I feel pretty stupid, I didn't change the rf.send to include 'false'. That seems to have fixed the problem with the transmitter, but the receiver isn't happy.

I'm finally transmitting between the two which is exciting, but the receiver has 3 solid lights for a second, and then the green flashes (while it receives), then back to 3 solid lights. It does this over and over, receiving around one in every 5 sends from the transmitter.

I also have a question about speed, there is no delay in the transmitter sending its message, which is "T01.04.100" (this is the format i'll be sending in for my final app). It is probably firing 3-4 times a second. Is there a way to speed this up (i don't know too much about this stuff), as i'll be reading potentiometer values from a toy affecting sound and it needs to be realtime.

Something that has happened a couple of times since i've been working on this as well, is that there seems to be some sort of 'time-out' happening. Once the transmitter has been going hard for a while, it goes to 2 red blinks and 1 green blink, and the receiver gives up all together!

Cheers for all your help guys, i'd be screwed without you!

Hmm, it shouldn't really crap out. That could be a bug you've uncovered.

The lights are basically my implementation. green light means it's recieving a "packet stream". Blue means it's either pending recieving or sending and the blink green means it has been succesful.

If it takes "forever" and blinks red, that means it was expecting a confirmation but never recieved anything.

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Wed Jul 29, 2009 4:36 pm
by Miles
...Just while we're on the topic....


For everyones information the diference between HyperCom, VirtualWire and, for example, software serial is reliability.


My library inparticular is focused around assuring a message is recieved by the remote client. VirtualWire adds some extra data which adds a little redudancy so it's more likely the remote client will receive NON-CORRUPT data.

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Sat Aug 01, 2009 3:54 pm
by CaptainObvious
First off, I'd like to say thanks ALOT for the help Miles, I was tempted to just let my 2 pairs gather some dust! (along with a couple LCDs) I got it up and.. well receiving! Just not able to send what I want at the moment.
Well, I'm a little confused on how to ... send information! :D I've used a sample sketch for a button and receiver setup using SoftWareSerial.

I think I understand how to use rfSerial.send(); but not really sure how the send syntax is, if I could send say.. a few words and have the receiver receive, and print those words. Bit lost when it comes to that, and filtering out the noise. When I have the two running, transmitter and receiver, I only print.. cbcbcbc to serial and lcd, which is the 99 and 98 button state... Confusing! lol

Ultimately, I'd like to have.. say an Arduino connected via USB to the computer, sending data I input to the receiver, which will then print on an LCD. And also using potentiometer values on the Transmitting side, to change the value of LEDs on the receiving end. Psuedo(spelling?) code would be AMAZING. I've read the VirtualWire document and used the samples.. but also a bit confused on receiving the data I want to send.. and not the random RF waves. I'm just more comfortable at the moment with SoftWareSerial because the commands are so much like the Serial commands I've been working with.

I did try to edit some of the code I had to send values over, without any luck... Now all I'm reading is garbage. The sketch, previous to my edit was to read a button from the transmitter, and when I push the button, it would send a C rather than B, and vice versa (99 and 98 are B and C in decimal)

Any tips for.. optimizing the code, and well, getting it to work correctly, would be much appreciated!:D
Transmitter

Code: Select all

#include <SoftwareSerial.h>
/* 
Read a pushbutton and send a value
to another microcontroller.  
*/

#define rxPin 2
#define txPin 3
#define buttonPin 12
#define ledPin 13
#define potPin 0

// set up a new serial connection for communicating with RF transmitter 
// (this also frees up Arduino's built in serial port for PC communication)
SoftwareSerial rfSerial =  SoftwareSerial(rxPin, txPin);

byte potVal = 0;
byte val = 0;
byte onState = 99;
byte offState = 98;

byte prevpotVal = 0;

void setup() {
  pinMode(buttonPin, INPUT);    // declare pushbutton as input
  pinMode(ledPin, OUTPUT);    // declare led as output
  rfSerial.begin(2400); // our RF Link is a 2400 baud model (make sure you check this!)
  // start by blinking high and then low so we can tell the setup routine has been completed
  digitalWrite(ledPin,HIGH);
  delay(1000);
  digitalWrite(ledPin,LOW);
}

void loop(){
  val = digitalRead(buttonPin);
  potVal = analogRead(potPin) /4;
  delay(20);
  
  if ( potVal != prevpotVal ) {         // check if the input is HIGH (button pressed)
    rfSerial.print(onState, BYTE); // OK send it to the RF transmitter
    digitalWrite(13, HIGH);
  } else {
    rfSerial.print(offState, BYTE); // send a 0 through Transmitter
    digitalWrite(13, LOW);
 }
 prevpotVal=potVal;
}
Receiver

Code: Select all

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>


#define rxPin 11
#define txPin 12
#define ledPin 13

LiquidCrystal lcd(9, 8, 2, 4, 5, 6, 7);

// set up a new serial connection for communicating with RF receiver 
// (this also frees up Arduino's built in serial port for PC communication)
SoftwareSerial rfSerial =  SoftwareSerial(rxPin, txPin);

char prevChar = 0;

void setup() {
  lcd.begin(4, 20);
  delay(100);
  lcd.print("Loading...");
  // set up the input and output pins
  pinMode(rxPin, INPUT); // set up pins for serial comm. with RF receiver
  pinMode(ledPin, OUTPUT);
  // initialize serial comm
  rfSerial.begin(2400); // begin serial connection with RF Link unit
  Serial.begin(2400); // begin serial communication over USB to the computer
  // blink LED on and then off just to let us know the setup routine is complete
  digitalWrite(ledPin,HIGH); // turn on LED
  delay(1000);
  digitalWrite(ledPin,LOW); // turn off LED
  delay(2000);
  lcd.clear();
  lcd.print("Ready2Receive:");
  Serial.print("Ready2Receive:");
  lcd.setCursor(0,1);
}

void loop(){
  char someChar = '0'; 
  someChar = rfSerial.read(); // read whatever the RF Link has to offer
  // print out the character: 
  if (someChar!=prevChar) { // only print out new data (don't print 0 a billion times in a row)
     // send data to computer
    Serial.print(someChar);
    lcd.print(someChar);
    prevChar=someChar; // store what we just read
  }
}

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Sun Aug 02, 2009 3:13 am
by Miles
Hi Mate,

what you're asking doesn't really relate to the aformentioned library and isn't really something I know all that much about. I'm surprised Serial is even working at all.

Can I suggest you move this post to the Arduino forums www.arduino.cc?

-Miles

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Fri Aug 07, 2009 8:41 pm
by CaptainObvious
Cheers,
sorry for the mixed up questions, a bit confused, as always! :)

Some questions I did have though, I noticed on your page you posted about a wireless LCD screen, I've tried using the VirtualWire library to send information to another Arduino and print it out on the LCD. Just constantly sending a 255 to try get the two to connect.. well I'm able to get the examples to work just fine, but I can't seem to... well send my own information! Is there any way you could.. newb-i-fy some uber psuedo code on how I would go about doing such a thing?:)

Tried using vw_send to send, along with vw_get_message.. completely confused and not sure what information to put in the ( ), reading the instructions I see stuff like int8_t stuff that's just a bit over my head.

I'd like to, at a later time (obviously, first things first..) send information I input from my computer, just like "hellooooo" :)

Thanks in advance.

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Sun Aug 09, 2009 8:02 am
by Miles
Hi Captain,

There's not much outside of the inital example that I can suggest for you. You simple state the characters you wish to send and the reciever, signal strength permitting, will output the string. You may need to cast the uint8_t object to a char but aside from that nothing complicated.

I'd suggest using the library I developed as that handles strings in an easier maner.

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Sun Aug 09, 2009 8:36 am
by CaptainObvious
Thanks for the reply!

I'm sure I'm... overthinking this stuff, but I just.. am so confused! lol :/ I do understand a bunch of the commands (for the most part, at least what they do, not so much how they operate).

But in terms of the vw_send() and get messages, I don't understand the terms they're using to connect the two.

vw_send((uint8_t *)msg, strlen(msg));

In loop, there's a const char *msg = "hello"; So I'm assuming that's what's being sent out of the transmitter. I don't get the use of the *, but that's for next time!
strlen(msg) Message length, I'm assuming. Not TOO confusing, but now, I don't understand how the receiving end picks up just the message, without the noise. I figured it would be something along the lines if message == ("hello") ... (psuedocode)
But I don't see a "hello" or anything of the sorts in receiving end.

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))

I just searched for uint8_t and I found (I think I read it right) that it's equal to unsigned byte?

I understand that we're buf and buflen integers, but I don't get why VW_MAX_MESSAGE_LEN, and how that opens up the ability to communicate with the transmitter!

Oi, I'm sorry if this isn't the right place.. or I'm a hassle, not really sure where else to ask these kind of questions, I've been asking around Arduino forums some, everyone just points me to VirtualWire, just not understanding alot about how it works.

Sorry for the long post, and thanks again for taking time to even read these, probably lots of repeating myself. :D

Re: RF Reciever & transmitter [433Mhz, 315Mhz] Library.

Posted: Sun Aug 09, 2009 6:21 pm
by Miles
CaptainObvious wrote:Thanks for the reply!

I'm sure I'm... overthinking this stuff, but I just.. am so confused! lol :/ I do understand a bunch of the commands (for the most part, at least what they do, not so much how they operate).

But in terms of the vw_send() and get messages, I don't understand the terms they're using to connect the two.

vw_send((uint8_t *)msg, strlen(msg));

In loop, there's a const char *msg = "hello"; So I'm assuming that's what's being sent out of the transmitter. I don't get the use of the *, but that's for next time!
strlen(msg) Message length, I'm assuming. Not TOO confusing, but now, I don't understand how the receiving end picks up just the message, without the noise. I figured it would be something along the lines if message == ("hello") ... (psuedocode)
But I don't see a "hello" or anything of the sorts in receiving end.

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))

I just searched for uint8_t and I found (I think I read it right) that it's equal to unsigned byte?

I understand that we're buf and buflen integers, but I don't get why VW_MAX_MESSAGE_LEN, and how that opens up the ability to communicate with the transmitter!

Oi, I'm sorry if this isn't the right place.. or I'm a hassle, not really sure where else to ask these kind of questions, I've been asking around Arduino forums some, everyone just points me to VirtualWire, just not understanding alot about how it works.

Sorry for the long post, and thanks again for taking time to even read these, probably lots of repeating myself. :D
Ah now I'm starting to understand your troubles.

I'd STRONGLY suggest you read some C++ 101. Pointers will confuse the crap out of you otherwise.

For your own sanity:

vw_send((uint8_t *)msg, strlen(msg));

Let me break that down. Your message *msg = "hello" means hello is an array of CHAR. Without going into detail (I'm no teacher) * basically means, in this case, make "msg" point to the memory address of "hello".

Internally lots of the Arduino stuff uses uint8_t instead of char. They are basically the same if you were to look at the memory which makes up that variable. What that line means "I want to look at msg as if it were an array of uint8_t". uint8_t is just a standard whole number.

As you can probably guess strlne is the string length. The curve ball here is C++ doesn't understand arrays. All it knows is memory addresses. What vw_send will do is take your msg, which is actually ponting to "h" in "hello" and then read each memory after 'h' and stop after "strlen(msg)".

So basically:

It recives the pointer to 'h'

'h' is now at memory address 10. You've told me the array (what's known as a string) is 4 bytes long (a char is one byte, which is 8 bits). So it'll read h then e... etc etc

The dangerous thing about c and c++ is vw_send doesn't realy know what it's reading from memory! You have to be careful to tell it what to read.



Okay, that's a little c++ 101. The problem you're having is char msg is what's called a constant. That means it CANNOT change. It's stuck. If you remove that keyword you can then change msg to say what you like.

The problem is, virtualwire gets a little funny when you fiddle with it (I ran into some problems). Without sounding like a broken record, I'd strongly suggest you use HyperCom as that handles all that confusing stuff.

rf.send("your message", false); << doesn't get much more simple than that ;)