RC Receiver into Arduino as PC Controller (UnoJoy)


my plan take rc car transmitter & receiver connect receiver arduino , convert raw data on pwm 2 channels usable joystick can use on pc play vrc pro (virtual rc pro).

however i'm trying troubleshoot why arduino jumping around when set joystick using unojoy. current code this.

code: [select]

#include "unojoy.h"

const int numreadings = 16;

int ch1index = 0;
int ch2index = 0;
int ch1t = 0; //channel 1 total
int ch2t = 0; //channel 2 total
int ch1a = 0; //channel 1 average
int ch2a = 0; //channel 2 average
int ch1raw[numreadings]; //raw ch1 data
int ch2raw[numreadings]; //raw ch2 data
int ch1 = 0; //final ammount /255
int ch2 = 0; //same ch2

void setup(){
  setuppins();
  setupunojoy();
  (int ch1read = 0; ch1read < numreadings; ch1read++)
    ch1raw[ch1read] = 0;
  (int ch2read = 0; ch2read < numreadings; ch2read++)
    ch2raw[ch2read] = 0;
}

void loop(){
  // getting fresh data
  dataforcontroller_t controllerdata = getcontrollerdata();
  setcontrollerdata(controllerdata);
  ch1t= ch1t - ch1raw[ch1index];
  ch2t= ch2t - ch2raw[ch2index];
  ch1raw[ch1index] = ch1;
  ch2raw[ch2index] = ch2;
  ch1 = pulsein(2, high, 20000);
  ch2 = pulsein(3, high, 20000);
  ch1 = map(ch1, 965, 1965, 0, 255);
  ch2 = map(ch2, 960, 1955, 0, 255);
 
  //adding total.
  ch1t= ch1t + ch1raw[ch1index];
  ch2t= ch2t + ch2raw[ch2index];
 
  //indexing + 1
  ch1index = ch1index + 1;
  ch2index = ch2index + 1;
 
  if (ch1index >= numreadings)
    ch1index =0;
  if (ch2index >= numreadings)
    ch2index =0;
   
  ch1a = ch1t / numreadings;
  ch2a = ch2t / numreadings;
 

 
  //serial.print("channel 1:");
  //serial.println(ch1a);
 
  //serial.print("channel 2:");
  serial.println(ch2a);
 
  //delay(10);
 
}

void setuppins(void){
  // set digital pins inputs
  // pull-up enabled, except
  // 2 serial line pins
pinmode(2, input);
pinmode(3, input);
}

dataforcontroller_t getcontrollerdata(void){
 
  // set place our controller data
  //  use getblankdataforcontroller() function, since
  //  declaring fresh dataforcontroller_t tends
  //  1 filled junk other, random
  //  values in memory locations before
  dataforcontroller_t controllerdata = getblankdataforcontroller();
  // since our buttons held high and
  //  pulled low when pressed, use "!"
  //  operator invert readings pins
 
  // set analog sticks
  //  since analogread(pin) returns 10 bit value,
  //  need perform bit shift operation to
  //  lose 2 least significant bits , an
  //  8 bit number can use 
  controllerdata.leftstickx = ch1a;
  //controllerdata.leftsticky = analogread(a1) >> 2;
  controllerdata.rightstickx = ch2a;
  //controllerdata.rightsticky = analogread(a3) >> 2;
  // , return data!
  return controllerdata;
}


using serial print i'm watching data i'm sending controllerdata. i've gotten stable , not jump around. once change unit dfu , update firmware turn joystick. reads unstable on windows. hovering , forth between 130 , 138 channel 1. suspect problem might not code unojoy. don't know coding , use assistance. 1 of first projects i've been wanting do.

regardless of i've tried nothing seems make improve. guidance appreciated.


Arduino Forum > Using Arduino > Project Guidance > RC Receiver into Arduino as PC Controller (UnoJoy)


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