Greets everybody this is my first post on the forum and first project with the arduino. In the end I'm looking to create a simple txt messaging network with 2-5 (phones) but so far I am unable to do even the simplest communication.
Hardware:
RF Link 4800bps Receiver - 315MHz
RF Link Transmitter - 315MHz
Transmitter Code:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
int val = 0; // variable to store the value
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin); //using softwareserial
void setup() {
rfSerial.begin(9600); //initialize softwareserial
Serial.begin(9600); // begin serial communication over USB to the computer for debugging purposes
}
void loop(){
val = 1020;
Serial.print(val); // send data to computer
rfSerial.print(val, DEC); // send data out tx
//PreVal = val;
delay(100);
}
Receiver Code:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
int val = 0;
void setup() {
pinMode(rxPin, INPUT); // set up pin for serial comm. with RF receiver
rfSerial.begin(9600); // begin serial connection with RF Link unit
Serial.begin(9600); // begin serial communication over USB to the computer
}
void loop(){
val = rfSerial.read(); //Read a Byte?? from the RX
if ( val == 1020 ) {
Serial.print(val, DEC); // send data to computer in Decimal
}
}
OK, you're transmitting the characters '1' '0' '2' '0'.
In hex, these characters are represented by the byte values 0x31, 0x30, 0x32, 0x30.
So four bytes.
You need to collect all four characters, and then convert the collection to decimal.
Search for "atoi".
You'll need to convert the four characters to a string first.
Well, my German's not great (all but non-existant), but "Bandbreite" has to translate as "Bandwidth" (Band-breadth, literally, I guess), so at 2kHz, I wouldn't expect to be able to push the bit-rate much past 1200 bps.
thx for the answer, but even with the changed baud rate i'm only getting
a zero as an output on both the receiver and transmitter even by putting them on one board??????? maybe there is a prob with the type of value i'm transmitting(byte, dec, int)....i'm getting nuts already!!!!!
thx
akira
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
int val = 0; // variable to store the value coming from the sensor
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin); //using softwareserial
void setup() {
pinMode(rxPin, INPUT); //set recieve as an input
pinMode(txPin, OUTPUT); //set transmit as an output
rfSerial.begin(1200); //initialize softwareserial
Serial.begin(9600); // begin serial communication over USB to the computer for debugging purposes
}
void loop(){
val = 1;
Serial.println(val, DEC); // send data to computer
rfSerial.print(val); // send data out tx
val = rfSerial.read();
Serial.print("reader: ");
Serial.println(val, DEC);
delay(100);
//}
}
Yes, but if you take a look at the software serial library, you'll see that everything takes place syncrhonously.
First, the "rfSerial.print ()" clocks out to the Tx pin all the data it has been given, then the "rfSerial.read()" looks for a start bit on the Rx.
But the start bit has already disappeared into the ether, via the Tx pin, as has all the data and the stop bit.
okay, so what would be the solution, a delay perhaps or would it work by just sticking it on two boards one for the receiver and one for the transmitter?
thx again and many more times
been there done that...here is my code 4 the two boards...still getting random values(mostly 0) on the receiver side
transmitter code:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
int val = 0; // variable to store the value coming from the sensor
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin); //using softwareserial
void setup() {
pinMode(rxPin, INPUT);//set recieve as an input
pinMode(txPin, OUTPUT);//set transmit as an output
rfSerial.begin(1200); //initialize softwareserial
Serial.begin(9600); // begin serial communication over USB to the computer for debugging purposes
}
void loop(){
//val = analogRead(potPin); // read the value from the sensor
val = 1;
Serial.print(val); // send data to computer
rfSerial.print(val, DEC); // send data out tx
delay(100);
}
receiver code:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
int val = 0;
void setup() {
pinMode(rxPin, INPUT); // set up pin for serial comm. with RF receiver
pinMode(txPin, OUTPUT); //set transmit as an output
rfSerial.begin(1200); // begin serial connection with RF Link unit
Serial.begin(9600); // begin serial communication over USB to the computer
}
void loop(){
val = rfSerial.read(); //Read a Byte?? from the RX
Serial.print(val, DEC); // send data to computer in Decimal
delay(100);
}
and these i get with 300 baud and no delay at the receiver:
10000004096406408648140480016016080009900286580324032480032130289713403312800192000166500006443238644000161032138489740328008974060003266001281600448132800410161290003200320160432006403341620644-1000028448006412000012880016130032048650330326480016194281136169700088
Can you write a simple Rx sketch to simply copy the state of the rx pin to a LED?
Just a simple "loop()" with a "digitalWrite (ledPin, digitalread (rxPin));"
Now turn off the Tx completely - what do you see?
I used to have a similar problem, eventually traced to a wireless door bell...
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
int ledPin = 13;
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
int val = 0;
void setup() {
//pinMode(rxPin, INPUT); // set up pin for serial comm. with RF receiver
//pinMode(txPin, OUTPUT); //set transmit as an output
rfSerial.begin(300); // begin serial connection with RF Link unit
Serial.begin(9600); // begin serial communication over USB to the computer
}
void loop(){
val = digitalRead(rxPin);
digitalWrite (ledPin, val);
//val = rfSerial.read(); //Read a Byte?? from the RX
Serial.print(val, DEC); // send data to computer in Decimal
delay(100);
}
i disconnected the transmitter board from the usb so there should be nothing coming in, however the led flashes now and then at a seemingly constant rate
here is the output of the output window:
00000000000000001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001