SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By thefatmoop
#62942
Hey i'm real sorry to post this on multiple forums and link em, but i wouldn't think this would be a hard question.

http://www.arduino.cc/cgi-bin/yabb2/YaB ... 1231284644

i'm trying to get a simple no error correction serial connection, but my RX pin is high on the receiver arduino.... but it works over wires, so the program is working.

original message:
Alright so i'm trying to send some serial data over wireless (yes not using much error correction right now... just doing a checksum)

i have these two wireless modules
http://www.sparkfun.com/commerce/produc ... ts_id=8945
http://www.sparkfun.com/commerce/produc ... ts_id=8948

transmitter is connected to 5v power, gnd, and tx pin.

receiver is connected to power, ground, and rx pin on the client. I'm just simply sending a short serial message over a 1200 baud. If i connect the tx -> rx and gnd of the two arduinos it works fine... so the program is running fine. I can't get anything at all over the wireless though.

When i connect an led to gnd and data pin on the reciever it blinks when i send the message on transmistter (so it's getting data.) Here is where i believe my problem is.. When i then leave the LED on the reciever and connect it to the receiver arduino the LED turns on... (so the RX pin on receiver arduino is high? why?)

here is the transmitter and receiver program

trans:
Code: Select all
int ledPin = 13;
void setup()
{
    Serial.begin(1200);	 
    Serial.println("setup");
    pinMode(ledPin, OUTPUT);
}

void loop()
{
  
    digitalWrite(ledPin, HIGH);
    delay(1000);
    Serial.println("2222");
    digitalWrite(ledPin, LOW);
    delay(1000);
   
}
receiver:
Code: Select all
int ledPin = 13;
int inByte = 0; 
long blinkTimer = 0;
int blinkInterval = 1000;

void setup()
{
    Serial.begin(1200);	  // Debugging only
    Serial.println("setup");
    pinMode(ledPin, OUTPUT);
}

void loop()
{
  if (Serial.available() > 0){
    inByte = Serial.read(); 
    Serial.print(inByte,BYTE);
  }
    if (millis() - blinkTimer>= blinkInterval/2){
	digitalWrite(ledPin,HIGH);
    }
	 if (millis() - blinkTimer>= blinkInterval){
	digitalWrite(ledPin,LOW);
	blinkTimer = millis();
    } 
  

}
By thefatmoop
#62946
alright so i connected an led to the tx pin of the transmitter and noticed that it's high when not broadcasting... so the receiver's electrical signal needs to be inversed (low when receiving, high when idle)

what would be the easiest way to do this?
By signal7
#62991
Well, there's the common 7404 hex inverter chip. Creatively wiring other 7400 series IC's would also give you an inverter. If nothing else, an NPN transistor will act as an inverter.

You can do it in software, but it's a somewhat harder thing to do when you can't use the built-in hardware to manage the timing for you.

With all of that in mind though, I would double check your wiring for errors. It's unlikely that you would need an inverter to get things working. After all, the reason the microcontroller has serial hardware in it is so that you don't have to add other components to get it working.

The data sheet could be improved. It doesn't give hardly any information about how the module works.
By thefatmoop
#63065
yeah i inverted the circuit, verified with LEDs.. still no go. i'm just going to get xbee
By metsfan
#63113
I'm using SoftwareSerial and have it working fairly well. You really need some sort of error correction/protocol, because whenever the transmitter is off or not transmitting, the receiver will just get random noise. So you need some sort of start/stop bytes.

Here's my code for something fairly simple:
Transmitter:
Code: Select all
#include <SoftwareSerial.h>

int rxPin = 2;
int txPin = 3;

int chanPin0 = 16;
int chanPin1 = 15;
int chanPin2 = 14;

byte channel = 0;


SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
byte outgoingByte = '#';

void setup() {
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);

 /* channel selection pins */
 pinMode(chanPin0, INPUT);
 pinMode(chanPin1, INPUT);
 pinMode(chanPin2, INPUT);
 digitalWrite(chanPin0, HIGH);
 digitalWrite(chanPin1, HIGH);
 digitalWrite(chanPin2, HIGH);

 /* channel byte */
 channel = ( (digitalRead(chanPin0) == HIGH ? (byte)1 : 0) |
             (digitalRead(chanPin1) == HIGH ? (byte)2 : 0) |
             (digitalRead(chanPin2) == HIGH ? (byte)4 : 0) );
 
 
 rfSerial.begin(2400);
}

void loop() {
     rfSerial.print(0xAA, BYTE);
     delay(10);
     rfSerial.print(channel, BYTE);
     delay(10);
     rfSerial.print(outgoingByte, BYTE);
     delay(10);
     rfSerial.print(0x11, BYTE);
     delay(10);
     
}
Receiver:
Code: Select all
#include <SoftwareSerial.h>

int rxPin = 17;
int txPin = 16;

int chanPin0 = 13;
int chanPin1 = 14;
int chanPin2 = 15;
byte channel = 0;

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);

byte recvChar()
{
  byte value;

  if (rfSerial.read() == 0xAA) {
    if (rfSerial.read() == channel) {
      value = rfSerial.read();
      if (rfSerial.read() == 0x11) {
        return value; 
      }
    }
  }
  return '\0';
}

void setup()
{
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  /* channel selection pins */
  pinMode(chanPin0, INPUT);
  pinMode(chanPin1, INPUT);
  pinMode(chanPin2, INPUT);
  digitalWrite(chanPin0, HIGH);
  digitalWrite(chanPin1, HIGH);
  digitalWrite(chanPin2, HIGH);
  
  rfSerial.begin(2400);
  
  /* channel byte */
  channel = ( (digitalRead(chanPin0) == HIGH ? (byte)1 : 0) |
              (digitalRead(chanPin1) == HIGH ? (byte)2 : 0) |
              (digitalRead(chanPin2) == HIGH ? (byte)4 : 0) );

}

void loop()
{ 
    rfKey = recvChar();
    /* do stuff with rfKey */
}
The channel stuff is so you can use more than one transmitter/receiver pair. Three pins are tied (or not) to ground with jumpers to allow up to 8 sets. I cut out a lot of code here not related to the transmitting/receiving. What I'm using it for is basically an activation button... connect power on the transmitter, and it tell the receiver to do its thing over and over. (wireless trigger for camera)