Help using VirtualWire and Servo


well, incrdible users out there, i'm excited introduce weird problem having @ moment. i've setup easy virtualwire connection with:
rf transmittors: http://www.dx.com/p/433mhz-rf-transmitter-module-receiver-module-link-kit-for-arduino-arm-mcu-wl-green-220194#.u960axgzwb4
tower pro micro sg90 servos

setup pretty easy, problem connecting servo sg90 virtual wire connection gets stuck, , when disconnect pin connection runs , expected.
using servo, not sg90 ones (http://www.servodatabase.com/servo/springrc/sm-s2309s), works expected everything...

the servo sg90 works maybe two-three first connections gets stuck. functionality nromal wired excellent , no problem those...

i'll attach code i'm using transmitter , reciever:


reciever code
code: [select]
#include <virtualwire.h>
#include <servotimer2.h>

string anglestring;
string angle;
int angledigit;
servotimer2 servomotor;

void setup()
{
  serial.begin(9600);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_set_rx_pin(7);
  vw_rx_start();
 
  servomotor.attach(3);
}

void loop()
{
  uint8_t buflen = vw_max_message_len;
 
  uint8_t buf[buflen];;
 
  if(vw_get_message(buf, &buflen))
  {
    for(int = 0; < buflen; i++)
    {
        angledigit = int(buf[i]) - 48;
        angle += string(angledigit);
    }
   
    char anglechar[angle.length()];
    angle.tochararray(anglechar,angle.length());
 
  (int = 0; < anglechar.lenght; i++) {
    anglestring += anglechar[i];
  }
  // microseconds
  servomotor.write(map(anglestring.toint(), 0, 180, 500, 2400));

  angle = "";
  anglestring[i] = "";
}


transmitter code

code: [select]

#include <virtualwire.h>

int sensor;
string anglestring;

void setup()
{
  serial.begin(9600);
 
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_set_tx_pin(6);
 
  pinmode(a0, input);
}

void loop()
{
  sensor = analogread(a0);

  int angle = map(sensor, 0, 1023, 0, 180);

  if (angle < 100) {
    if (angle < 10) {
      anglestring = "00";
    }
    else {
      anglestring = "0";
    }
    anglestring += (string) angle;
  }
  else {
    anglestring = (string) angle;
  }

  const char *anglechar = anglestring.c_str();
  vw_send((uint8_t *)anglechar, strlen(anglechar));
  vw_wait_tx();
 
  anglestring = "";
 
  delay(100);
}


any appreciated , respected of course! said, towerpro servor connected pin 3 (or other attached) stuck reciever program, while other servo doesn't. need towerpro servor work! help

one thing consider:

http://www.airspayce.com/mikem/arduino/virtualwire/
"this virtualwire library has been superceded radiohead library http://www.airspayce.com/mikem/arduino/radiohead radiohead , rh_ask driver provides features supported virtualwire, , more besides, including reliable datagrams, addressing, routing , meshes. platforms virtualwire supported supported radiohead."

how powering servo?  many servo problem happen because can draw more power +5v pin can supply.


Arduino Forum > Using Arduino > Programming Questions > Help using VirtualWire and Servo


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support