Pages: [1]   Go Down
Author Topic: virtual wire  (Read 900 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

guys could u help me???
im having a problem with virtual wire.!!
this is the code the first time i used it the led was lighting up constant when i press the button on the transmitter but now after a few months the led is blinking instead of lighting up constant (this is the receiver code)
Code:
#include <SoftwareServo.h>
#include <VirtualWire.h>

SoftwareServo servo1;


void setup()
{
  Serial.begin(9600); // Debugging only
    Serial.println("setup");
  servo1.attach(9);
 
  vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec
    vw_set_rx_pin(2);
    vw_rx_start();       // Start the receiver PLL running

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(13, OUTPUT);
pinMode(1, OUTPUT);

  

  }

void loop()
{
  digitalWrite(3, LOW);
   digitalWrite(4, LOW);
   digitalWrite(5, LOW);
   digitalWrite(1, HIGH);
  servo1.write(71);
  SoftwareServo::refresh();

  
  
  
 uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
int i;

        digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{
   Serial.print(buf[i]);
        if(buf[i] == '1'){digitalWrite(3, HIGH);}//fwd
        if(buf[i] == '2'){digitalWrite(4, HIGH);}//bck
        if(buf[i] == '5'){digitalWrite(5, HIGH);}//lit
        
        if(buf[i] == '3')//lft
 {
  servo1.write(0);
 
    SoftwareServo::refresh();
  }

if(buf[i] == '4')//rht
 {
   servo1.write(150);
 
    SoftwareServo::refresh();
  }
  Serial.println("");
   digitalWrite(13, false);
   SoftwareServo::refresh();
  
}
    }
}
     
i  remodeled this code from sparkfuns example code!!!
this is the transmitter code(which is working properly)
Code:
//transmitter

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);  // Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec
        vw_set_tx_pin(3);
        
        pinMode(7, INPUT);
        pinMode(8, INPUT);
        pinMode(9, INPUT);
        pinMode(10, INPUT);
        pinMode(11, INPUT);
        pinMode(12, OUTPUT);

digitalWrite(7, HIGH);//fwr
digitalWrite(8, HIGH);//bkwr
digitalWrite(9, HIGH);//lft
digitalWrite(10, HIGH);//rht
digitalWrite(11, HIGH);//lit
digitalWrite(12, HIGH);//pwr

}

void loop()
{
  char *msg;
  
  if(digitalRead(7) == LOW){
    char *msg = "1";
      digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);}
  if(digitalRead(8) == LOW){
    char *msg = "2";
      digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);}
  if(digitalRead(9) == LOW){
    char *msg = "3";
      digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);}
  if(digitalRead(10) == LOW){
    char *msg = "4";
      digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);}
  if(digitalRead(11) == LOW){
    char *msg = "5";
      digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);}
  
  }

  pls help!


Moderator edit: [code] [/code] tags added.
« Last Edit: April 06, 2012, 09:14:10 am by CrossRoads » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is the code the first time i used it the led was lighting up constant when i press the button on the transmitter but now after a few months the led is blinking instead of lighting up constant
Would that be the LED on pin 3, 4, 5, 13, or 1?

Why are you diddling with pin 1 AND using Serial at the same time?

What are you doing on the sender? What do your Serial.print()s show you?

How are the LEDs connected? Are there resistors, too?

How are the Arduinos powered? Via USB? How is the servo powered?

Nowhere near enough detail to help you.

PS. Before posting code again, use Tools + Auto Format. That code is a mess. Also, use the # icon when posting code, so the moderators don't have to, making one block of code where there should be two.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 533
Posts: 26934
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, which LED(s)?
It would seem the Tx/Rx LED would only be on continuously if you pressing a button continuously.

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey guys now i fixed half the problem by changing the pins for the pwr to the rx module now the led is flickering (both tx and pin 11)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 533
Posts: 26934
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Being miswired always tends to complicate things smiley-wink

Are you using RF module with PTT pins?
If not, take this line out of both codes

    vw_set_ptt_inverted(true); // Required for DR3100
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: