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! 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!
Transmitter
[code]#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;
}
[/code]
Receiver[code]#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
}
}[/code]