Go Down

Topic: Sparkfun RF Transmitter/Receiver (Read 2923 times) previous topic - next topic

bocochoco

I've got them communicating, I think. Using my Nano as a Transmitter and my Mega as the Receiver. The Sparkfun site says that the transmitter transmits on either 2400baud or 4800baud. I've tried both, to no avail. It seems to be working, as if I disconnect the nano, the mega prints 0's, but i can't make it send any kind of useful information.

Code: [Select]
#include <SoftwareSerial.h>

// Receiver

#define rxPin 2
#define txPin 3

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);

int received = 0;

void setup()
{
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 
 rfSerial.begin(4800);
 Serial.begin(2400);
}


void loop()
{
 received = rfSerial.read();
 Serial.println(received);

}


Code: [Select]
#include <SoftwareSerial.h>

// Transmitter

#define txPin 3
#define rxPin 2

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);

byte val = 0;
int counter = 1111;

void setup()
{
 rfSerial.begin(4800);
}

void loop()
{
 rfSerial.print(counter);
 //counter++;
 delay(10);
}


That's my code. The output is very erratic, I can't decipher a meaning out of it. It just prints random numbers.

Code: [Select]

64
16
240
196
101
48
177
9
32
0
25
59
47
14
1
158
24
112
6
25
19
9
2
130
4
231
196
13
8
38
168
32
204
128
0
66
15
132
188
115
53
-1
161
9
12
4
130
78
164
2
16
67
131
137
31
96
240
0
201
196
195
128
30
62
11
168
48
-1
100
0
23
135
88
26
2
8
69
132
72
4
57
0
144
29
98
137
206
152
48
196
192
68
234
64
51
144
32
228
64
226
24
0
131
32
105
238
243
160
128
33
14
8
100
239
25
16
6
-1
147
-1
152
4
196
16
29
8
2
68
20
232
163
8
204
0
199
130
176
56
192
11
17
96
16
32
129
239
130
12
16
129
3
115
247
66
41
56
128
16
209
15
128
84
16
18
0
48
16
24
39
196
148
186
123
0
0
128
200
31
19
129
224
128
197
146
80
4
0
224
14
0
35
48
16
12
232
0
138
5
96
200
130
5
241
194
46
0
239
0
131
96
217
0
41
53
31
7
16
148
225
0
1
66
136
22
145
80
32
32
146
204
154
0
192
189
19
239
0
64
98
208
41
33
0
56
72
194
3
224
224
1
32
64
1
97
140
208
69
132
0
12
16
33
0
0
100
7
49
49
192
15
120
231
10
192
0
64
1
129
96
145
1
142
108
4
128
-1
6
224
224
56
31
55
6
168
132
64



I found another thread about this on the board, that's where I got the basis for this code, but it just doesn't seem to work. Anyone know what is going wrong? I can't tell if its the code thats wrong or the transmitter or receiver, or if its something else.

Leon Heller

#1
May 02, 2010, 03:41 am Last Edit: May 02, 2010, 03:42 am by leon_heller Reason: 1
You might need to use Manchester code.
Leon Heller
G1HSM

bocochoco

#2
May 02, 2010, 03:45 am Last Edit: May 02, 2010, 03:52 am by bocochoco Reason: 1
I haven't seen any examples or anything that would indicate that you need that type of encoding. All the examples I've seen show it just transmitting the data as is.

weirdo557

http://www.open.com.au/mikem/arduino/


try the virtualwire library

Leon Heller

#4
May 02, 2010, 04:52 am Last Edit: May 02, 2010, 04:54 am by leon_heller Reason: 1
That uses a technique to balance the ones and zeros, like Manchester code does.
Leon Heller
G1HSM

bocochoco

#5
May 02, 2010, 05:58 am Last Edit: May 02, 2010, 08:54 am by bocochoco Reason: 1
VirtualWire library didn't work at first. Then I read a comment on sparkfun that said "Also, make sure receiver and transmitter are not sharing the same power supply or ground.". After switching them to be independent, it works great. Thank you for your help.

However, now I am running into a problem I've never really faced before.

Basically I've got two potentiometers (One http://www.sparkfun.com/commerce/product_info.php?products_id=9032) and I want to transmit its H and V values via the wireless link to the other arduino. I can't seem to get virtualwire to transmit the two values in one message.

My friend suggested that I re-range the values I get from the pots from 0-1023 to 0-127. This gives me even stranger results:

Code: [Select]

#include <VirtualWire.h>


// Transmitter

int Hpin = 5;
int Vpin = 7;
int Hval = 0;
int Vval = 0;
char Hchar = 0;
char Vchar = 0;

void setup()
{
 Serial.begin(1200);
 vw_setup(1200);
}

void loop()
{
 Hval = analogRead(Hpin);
 Vval = analogRead(Vpin);
 Hchar = char((float(Hval) / 1023) * 127);
 Vchar = char((float(Vval) / 1023) * 127);
 Serial.print(Hchar, DEC);
 Serial.print(" ");
 Serial.println(Vchar, DEC);
 const char msg[] = {Hchar, Vchar};
 vw_send((uint8_t *)msg, strlen(msg));
 delay(10);
}


This works fine for values that aren't 0. If Hchar is 0, the receiver doesn't work at all. If Vchar is 0, the receiver doesn't print any value for it. If both are non-zero, it receives 3 numbers. Hchar, Vchar, and 147. I don't understand why it's getting a third value when I am only sending two. Any idea why this is happening?

PaulS

Arrays of integers can be sent in one transmission. Have a look at this thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268969540

bocochoco

That worked great. Exactly what I needed. Thanks!

Manny

Im having a problem also.This is the sensor im using(http://www.parallax.com/dl/docs/prod/audiovis/PIRSensor-V1.2.pdf). The sensor is attached to the transmitter and the receiver is attached to a my arduiono atmegea328.i just want a basic high/low signal to be sent from the transmitter to receiver when my sensor is triggered.
Code: [Select]
int pin3=3
void setup()
{
       Serial.begin(9600);
        pinMode(pin3,INPUT);
}
void loop()
{
      x=digitalRead(pin3);
      if(x==HIGH);
        {

Manny

Sorry for my prior post I pressed tab then enter.I just want to see if its high and then do something if not then do nothing. I keep getting random numbers like bocochoco...any advice?

PaulS

Need to see more of (all) your code.

Manny

Code: [Select]
int pin3=3
int x;
void setup()
{
       Serial.begin(9600);
        pinMode(pin3,INPUT);
}
void loop()
{
      x=digitalRead(pin3);
        Serial.print(x)
      if(x==HIGH);
        {
              then do something
           }
}

when I look into the serialprint I just see 1010111010001010001010 it's pretty much random.
any help.The PIR is supposed to show low when idle and high when triggered and only when triggered.

Go Up