Show Posts
Pages: 1 ... 5 6 [7] 8 9
91  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 25, 2013, 04:54:54 pm
tried to post the full code but the forum spit it back saying it was over the max 9500 chars. here is the TX so ill have to split it in 2 or more posts
Part_01
Code:
#include <NewPing.h>
#include <Arduino.h>
#include <Wire.h>
#include <stdio.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
#include <TinyGPS.h>
//-+-+-+>>>> START Ultrasonic Sensor section<<<<<<-+-+-+
#define TRIGGER_PIN  23  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     22  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
//-+-+-+>>>> END Ultrasonic Sensor section<<<<<<-+-+-+
//-+-+-+>>>> START MotorDriver Vars section<<<<<<-+-+-+
#define Mspeed0 0
#define Mspeed1 100
#define Mspeed2 150
#define runs1 2
#define runs2 3
#define mDelay1 100
#define mDelay2 150
//-+-+-+>>>> END MotorDriver Vars section<<<<<<-+-+-+
//-+-+-+>>>> START GPS Vars section<<<<<<-+-+-+
#define WPT_IN_RANGE_M 1
//-+-+-+>>>> END GPS Vars section<<<<<<-+-+-+
//-+-+-+>>>> SRTART POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
// LSM303 accelerometer: 8 g sensitivity
// 3.8 mg/digit; 1 g = 256
#define GRAVITY 256  //this equivalent to 1G in the raw data coming from the accelerometer
#define ToRad(x) ((x)*0.01745329252)  // *pi/180
#define ToDeg(x) ((x)*57.2957795131)  // *180/pi
// L3G4200D gyro: 2000 dps full scale
// 70 mdps/digit; 1 dps = 0.07
#define Gyro_Gain_X 0.07 //X axis Gyro gain
#define Gyro_Gain_Y 0.07 //Y axis Gyro gain
#define Gyro_Gain_Z 0.07 //Z axis Gyro gain
#define Gyro_Scaled_X(x) ((x)*ToRad(Gyro_Gain_X)) //Return the scaled ADC raw data of the gyro in radians for second
#define Gyro_Scaled_Y(x) ((x)*ToRad(Gyro_Gain_Y)) //Return the scaled ADC raw data of the gyro in radians for second
#define Gyro_Scaled_Z(x) ((x)*ToRad(Gyro_Gain_Z)) //Return the scaled ADC raw data of the gyro in radians for second
// LSM303 magnetometer calibration constants; use the Calibrate example from
// the Pololu LSM303 library to find the right values for your board
#define M_X_MIN -602
#define M_Y_MIN -668
#define M_Z_MIN -592
#define M_X_MAX 391
#define M_Y_MAX 422
#define M_Z_MAX 524
#define Kp_ROLLPITCH 0.02
#define Ki_ROLLPITCH 0.00002
#define Kp_YAW 1.2
#define Ki_YAW 0.00002
//OUTPUTMODE=1 will print the corrected data,
//OUTPUTMODE=0 will print uncorrected data of the gyros (with drift)
#define OUTPUTMODE 1
//#define PRINT_DCM 0     //Will print the whole direction cosine matrix
#define PRINT_ANALOGS 0 //Will print the analog raw data
#define PRINT_EULER 1   //Will print the Euler angles Roll, Pitch and Yaw
#define STATUS_LED 13
//-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
//-+-+-+>>>> START MotorDriver Vars section<<<<<<-+-+-+
int DIR_A = 12;    //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3;     //L298 PWM A Analog
int ENA_A = 9;     //L298 Enable A Digital Hight/low on/off
int DIR_B = 13;    //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11;    //L298 PWM A Analog
int ENA_B = 8;     //L298 Enable A Digital Hight/low on/off
int oTime = 0;
//-+-+-+>>>> END MotorDriver Vars section<<<<<<-+-+-+
//-+-+-+>>>> SRTART POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
int SENSOR_SIGN[9] = {
  1,1,1,-1,-1,-1,1,1,1}; //Correct directions x,y,z - gyro, accelerometer, magnetometer
float G_Dt=0.02;    // Integration time (DCM algorithm)  We will run the integration loop at 50Hz if possible
long timer=0;   //general purpuse timer
long timer_old;
long timer24=0; //Second timer used to print values
int AN[6]; //array that stores the gyro and accelerometer data
int AN_OFFSET[6]={
  0,0,0,0,0,0}; //Array that stores the Offset of the sensors
int gyro_x;
int gyro_y;
int gyro_z;
int accel_x;
int accel_y;
int accel_z;
int magnetom_x;
int magnetom_y;
int magnetom_z;
float c_magnetom_x;
float c_magnetom_y;
float c_magnetom_z;
float MAG_Heading;
float Accel_Vector[3]= {
  0,0,0}; //Store the acceleration in a vector
float Gyro_Vector[3]= {
  0,0,0};//Store the gyros turn rate in a vector
float Omega_Vector[3]= {
  0,0,0}; //Corrected Gyro_Vector data
float Omega_P[3]= {
  0,0,0};//Omega Proportional correction
float Omega_I[3]= {
  0,0,0};//Omega Integrator
float Omega[3]= {
  0,0,0};
// Euler angles
float roll;
float pitch;
float yaw;
float errorRollPitch[3]= {
  0,0,0};
float errorYaw[3]= {
  0,0,0};
unsigned int counter=0;
byte gyro_sat=0;
float DCM_Matrix[3][3]= {
  {
    1,0,0                  }
  ,{
    0,1,0                  }
  ,{
    0,0,1                  }
};
float Update_Matrix[3][3]={
  {
    0,1,2                }
  ,{
    3,4,5                }
  ,{
    6,7,8                }
}; //Gyros here
float Temporary_Matrix[3][3]={
  {
    0,0,0                  }
  ,{
    0,0,0                  }
  ,{
    0,0,0                  }
};
//-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
//-+-+-+>>>> START Ultrasonic Sensor section<<<<<<-+-+-+
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance, rightDistance, centerDistance; //distances on either side
//-+-+-+>>>> END Ultrasonic Sensor section<<<<<<-+-+-+
//-+-+-+>>>> Start Tac sensor contact section<<<<<<-+-+-+
int leftWiskerPin = 31;
int rightWiskerPin = 30;
int oldLeftWiskerValue;
int oldRightWiskerValue;
int numOfLeftWiskerhits = 0;
int numOfRightWiskerhits = 0;
int leftWiskerValue;
int rightWiskerValue;
//-+-+-+>>>> END Tac sensor contact section<<<<<<-+-+-+
//-+-+-+>>>> Start US PING averaging section<<<<<<-+-+-+
//------------------Avrageing-----------------------------------
const int numReadings = 5;
int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
//------------------Avrageing-----------------------------------
//-+-+-+>>>> END US PING averaging section<<<<<<-+-+-+
//-+-+-+>>>> START GPS INIT section<<<<<<-+-+-+
TinyGPS Tgps;
float flat, flon;
//-+-+-+>>>> END GPS INIT section<<<<<<-+-+-+
//-+-+-+>>>> Start VT100 INIT section<<<<<<-+-+-+
//-+-+-+>>>> END VT100 INIT section<<<<<<-+-+-+

void setup()
{
  Serial.begin(57600);
  Serial2.begin(57600); //GPS INPUT (LocoSYS LS20031)
  //**************Start Transiever (NRF24L01) config**************
  Serial.println("Radio Booting ... "); // Print some stuff to serial
  Mirf.cePin = 48;
  Mirf.csnPin = 49;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"robot");
  Mirf.payload = 16 * sizeof(byte);
  Mirf.config();
  Serial.println("Radio UP ... "); // Print some stuff to serial
  //**************End Transiever (NRF24L01) config**************
  //-+-+-+>>>> Start Tac sensor contact section<<<<<<-+-+-+
  pinMode(leftWiskerPin, INPUT);
  pinMode(rightWiskerPin, INPUT);
  digitalWrite(leftWiskerPin, HIGH);
  digitalWrite(rightWiskerPin, HIGH);  
  //-+-+-+>>>> END Tac sensor contact section<<<<<<-+-+-+
  //-+-+-+>>>> START MotorDriver Vars section<<<<<<-+-+-+
  pinMode(DIR_A, OUTPUT);  
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);  
  pinMode(DIR_B, OUTPUT);  
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);
  //-+-+-+>>>> START MotorDriver Vars section<<<<<<-+-+-+
  //-+-+-+>>>> Start US PING averaging section<<<<<<-+-+-+
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;        
  //-+-+-+>>>> END US PING averaging section<<<<<<-+-+-+
  //-+-+-+>>>> Start VT100 INIT section<<<<<<-+-+-+  
  Serial.print(BYB);
  Serial.println(CLR);  
  //-+-+-+>>>> END VT100 INIT section<<<<<<-+-+-+
  //-+-+-+>>>> START POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
  Serial.println("IMU INIT ... "); // Print some stuff to serial
  I2C_Init();
  delay(1500);
  Accel_Init();
  Compass_Init();
  Gyro_Init();
  delay(20);
  for(int i=0;i<32;i++)    // We take some readings...
  {
    Read_Gyro();
    Read_Accel();
    for(int y=0; y<6; y++)   // Cumulate values
      AN_OFFSET[y] += AN[y];
    delay(20);
  }
  for(int y=0; y<6; y++)
    AN_OFFSET[y] = AN_OFFSET[y]/32;
  AN_OFFSET[5]-=GRAVITY*SENSOR_SIGN[5];
  for(int y=0; y<6; y++)
    delay(2000);  
  timer=millis();
  delay(20);
  counter=0;
  Serial.println("IMU Stream active ... "); // Print some stuff to serial
  //-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
}

92  Using Arduino / Programming Questions / Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 25, 2013, 03:23:47 pm
HI there.
I have a problem with trying to transmit data from sensors from my bot using a mega with a NRF24L01 (long range 1,000m ver) to my base station using an UNO with same NRF24.
I "think" it has to do with sending various types of data at once like ints floats strings?
Can some one with experience in sending GPS or other like sensor data kind of guide me in this?
The TX sends some sort of data but it's all mucked up on the RX I do not know if it's getting messed up before (when being stuffed into the array for transmission) or after ti's being sent.
Here is my (TX) Code
Code:

void NrfTrans(){
  //****************************Info being Sent**********************
   // GPS NMEA data (3 vals)
  // IMU Roll Pitch Yaw (3 vals)
  //**************put values in array?**************
  byte vals[6];
  //**********Send IMU Roll Pitch Yaw values**********
  vals[0] =ToDeg(roll);   //example   + or - 134.987
  vals[1] =ToDeg(pitch); //example + or - 134.987
  vals[2] =ToDeg(yaw); // example  + or - 134.987
  vals[3] =flat;             //example 40.111111111
  vals[4] =flon;          //example -40.111111111
  vals[5] =Tgps.satellites(); //example 8
  //**************************************************
  //**************finish putting values in array?**************
  //**************Start Transmit package**************
  Mirf.setTADDR((byte *)"base1"); // set name of Reciever
  Mirf.send(vals); // data to send
  Serial.println(" Sent");
  while(Mirf.isSending()){
  }
  delay(10);
}
Here is my base station code (RX)

Code:
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//-+-+-+>>>> NRF24 Incoming data holders<<<<<<-+-+-+
float val0; // IMU Roll  
float val1; // IMU Pitch
float val2; // IMU Yaw  
float val3; // Latitude
float val4; // Longitude
int val5; // # of Satalites
//*********************************************
void setup(){
  Serial.begin(57600);
  //**************Start Transiever (NRF24L01) config**************
  Serial.println("...Radio Booting..."); // print somthing once to Serial to know your up
  Mirf.cePin = 8;
  Mirf.csnPin = 9;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"base1");
  Mirf.payload = 16 * sizeof(byte);
  Mirf.config();
  Serial.println("...Radio UP..."); // print somthing once to Serial to know your up
  //**************End Transiever (NRF24L01) config**************
}
void loop(){
  //-+-+-+>>>>Start data collection from transciever<<<<<<-+-+-+
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      //*********** Start array to collect pot/sensor data *********
      val0 = data[0]; //IMU Roll
      val1 = data[1]; //IMU Pitch
      val2 = data[2]; //IMU Yaw  
      val3 = data[3]; //IMU Latitude        
      val4 = data[4]; //IMU Longitude  
      val5 = data[5]; //IMU # of Satalites  
      //*********** End array to collect pot/sensor data *********    
      //**********Start Loop to print array to Serial Monitor
      /*
      int i;
       for (i = 0; i < 16; i = i + 1) {
       Serial.println(data[i], DEC);
       }          
       //*/

      //**********End Loop to print array to Serial Monitor        
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
  //++++++++ END data collection from transciever++++++++++++


  Serial.print("!");
  Serial.print("ANG:");
  Serial.print(val0);
  Serial.print(",");
  Serial.print(val1);
  Serial.print(",");
  Serial.print(val2);
  Serial.println();
  Serial.print("Lat: ");
  Serial.print(val3);
  Serial.print(" Long: ");
  Serial.print(val4);
  Serial.print(" SAT: ");
  Serial.print(val5);
  Serial.println();

} // end of program

93  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 28, 2012, 07:28:24 am
Looks like its working now. So i changed how the mapping was some because it was mucking with the base "vals" and recycling them so i made new vars for them for raw incoming data and then new "mapped" ones and now it works nice and smooth forward and back and left and right
Code:
//#include <Servo.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//**************Setup # servos to use*********
//Servo myservo0; 
//Servo myservo1;
// Servo myservo#;
//**************End Servo Setup***************
//***** set vars for each pots/sensor reading from transmitter
int val0; // servo 1   
int val1; // servo 2
int val2; // servo 3   
int val3; // servo 4   
//-------Remaped pot data-----------------
int val0ForwardMaped;
int val0ReverseMaped;
int val1LeftMaped;
int val1RightMaped;

//int oldVal0;
int DIR_A = 12; //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3; //L298 PWM A Analog
int ENA_A = 9; //L298 Enable A Digital Hight/low on/off
int DIR_B = 13; //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11; //L298 PWM A Analog
int ENA_B = 8; //L298 Enable A Digital Hight/low on/off
//*********************************************
void setup(){
  Serial.begin(57600);

  pinMode(DIR_A, OUTPUT);   
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);   
  pinMode(DIR_B, OUTPUT);   
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);   


  //************ Pin set for servos*************
  // myservo0.attach(4); 
  // End Pinset for servos
  //**************Start Transiever (NRF24L01) config**************
  Mirf.cePin = 48;
  Mirf.csnPin = 49;
  //  Mirf.cePin = 7;
  // Mirf.csnPin = 9;

  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"reci1");
  Mirf.payload = 4 * sizeof(byte);
  Mirf.config();
  //**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning..."); // print somthing once to Serial to know your up
}
void loop(){
  //+++++++++++Start data collection from transciever+++++++++
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      //*********** Start array to collect pot/sensor data *********
      val0 = data[0]; //Pot 1 on Transmitter 
      val1 = data[1]; //Pot 2 on Transmitter
      val2 = data[2]; //Pot 1 on Transmitter 
      val3 = data[3]; //Pot 2 on Transmitter
      //*********** End array to collect pot/sensor data *********   
      //**********Start Loop to print array to Serial Monitor
      /*
int i;
       for (i = 0; i < 4; i = i + 1) {
       Serial.println(data[i], DEC);
       }         
       //  */

      //**********End Loop to print array to Serial Monitor         
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
  //++++++++ END data collection from transciever++++++++++++

  //  int delta0 = abs(val0 - oldVal0);
  //      if(delta0 > 2){
  //        myservo0.write(val0);
  //  Serial.print("Servo:");
  //  Serial.println(val0);
  //    }
  //_________________________Drive___________________________
  //________________Forward / Reverse_____________

  //  Serial.println(val0);
  if(val0 > 135){
    motorForward();
  }
  else if(val0 < 110 ){
    motorReverse();
  }
  else if(val1 < 110 ){
    motorLeft();
  }
  else if(val1 > 135){
    motorRight();
  }
  else{
    motorStop();
  }
  //______________Left / Right________________ 


  //  if(val2 < 110 ){
  //    motorLeft();
  //  }
  //  else if(val2 > 135){
  //   motorRight();
  //  }
  //  else{
  //    motorStop();
  //  }
  //_____________________END DRIVE___________________


} // end of program
//***********************


//*************** External funct*********************
int motorForward() {

  val0ForwardMaped = map(val0, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val0ForwardMaped);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val0ForwardMaped);
  Serial.print("val0f: ");
  Serial.println(val0);
  Serial.print("Forward: ");
  Serial.println(val0ForwardMaped);

}

int motorReverse() {
  val0ReverseMaped = map(val0, 110, 0, 100, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val0ReverseMaped);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val0ReverseMaped);
  Serial.print("val0r: ");
  Serial.println(val0);
  Serial.print("Reverse: ");
  Serial.println(val0ReverseMaped);


}

int motorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
  Serial.println("Stop: ");
  // Serial.println(val1);

}


int motorLeft(){
  val1LeftMaped = map(val1, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val1LeftMaped);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val1LeftMaped);
  Serial.print("val1l: ");
  Serial.println(val1);
  Serial.print("Left: ");
  Serial.println(val1LeftMaped);
}

int motorRight(){
  val1RightMaped = map(val1, 110, 0, 100, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val1RightMaped);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val1RightMaped);
  Serial.print("val1r: ");
  Serial.println(val1);
  Serial.print("Right: ");
  Serial.println(val1RightMaped);
}
94  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 28, 2012, 12:35:25 am
Ok this seems to be more working than not so here goes. if you notice the output it's showing the incoming data is center pot post map so high 120's and because of that the else part of the if else kicks in to stop sending movement commands to motors ( without it the motors will stay turning in last direction rec till new value is given)
sticks centered
Code:
127
129
Stop
L/R Stop
Stop
L/R Stop
Stop
L/R Stop
127
129

If i push UP on left stick i get wheel movement in one direction  ( tho a lil choppy "L/R Stop is disabled or i would just hang smiley-sad")
Code:
254
129
Forward
L/R Stop
Forward
L/R Stop
253
129
If i push DOWN the driver tries to move the left side wheels but the right side kinda hang and i get this for output ( as mentioned L/R STOP leads no ware)
Code:
1
129
Reverse
L/R Stop
Reverse
L/R Stop
1
129
If i press right on the right side stick i get this and movement much like foreword on the other stick (Stop IS tied to the motorStop() function)
Code:
127
254
Stop
Right
Stop
Right
127
253
If i pres LEFT on the right side stick i get sound with no movement erratic movement but in the right directions ( im sure it's cos of motorStop from the first if else jumping in and mucking things up)
Code:
127
33
Stop
Left
Stop
Left
127
33

So the triggers seem? to work but now i am having to worry about stop functions getting in the way?

here is the full code thus far.
Code:
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//***** set vars for each pots/sensor reading from transmitter
int val0; // UP/Down Left Stick   
int val1; // Left/Right Right stick
//int val2; // servo 3   
//int val3; // servo 4   

int DIR_A = 12; //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3; //L298 PWM A Analog
int ENA_A = 9; //L298 Enable A Digital Hight/low on/off
int DIR_B = 13; //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11; //L298 PWM A Analog
int ENA_B = 8; //L298 Enable A Digital Hight/low on/off
//*********************************************
void setup(){
  Serial.begin(57600);

  pinMode(DIR_A, OUTPUT);   
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);   
  pinMode(DIR_B, OUTPUT);   
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);   

  //**************Start Transiever (NRF24L01) config**************
  Mirf.cePin = 48;
  Mirf.csnPin = 49;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"reci1");
  Mirf.payload = 4 * sizeof(byte);
  Mirf.config();
  //**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning..."); // print somthing once to Serial to know your up
}
void loop(){
  //+++++++++++Start data collection from transciever+++++++++
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      //*********** Start array to collect pot/sensor data *********
      val0 = data[0]; //Pot 1 on Transmitter 
      val1 = data[1]; //Pot 2 on Transmitter
      //   val2 = data[2]; //Pot 1 on Transmitter 
      //   val3 = data[3]; //Pot 2 on Transmitter
      //*********** End array to collect pot/sensor data *********   
      //**********Start Loop to print array to Serial Monitor
    //  /*
      int i;
       for (i = 0; i < 2; i = i + 1) {
       Serial.println(data[i], DEC);
       }         
       //  */
      //**********End Loop to print array to Serial Monitor         
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
  //++++++++ END data collection from transciever++++++++++++

  //_________________________Drive___________________________
  //________________Forward / Reverse_____________
//  Serial.println(val0);
//  Serial.println(val1);
  // Serial.println(val2);
  // Serial.println(val3);

  if(val0 < 110 ){
    motorReverse();
    Serial.println("Reverse");
  }
  else if(val0 > 135){
    motorForward();
  Serial.println("Forward");
  }
  else{
   motorStop();
  Serial.println("Stop");
  }
  //______________Left / Right________________ 
  if(val1 < 110 ){
    motorLeft();
    Serial.println("Left");
  }
  else if(val1 > 135){
    motorRight();
  Serial.println("Right"); 
  }
 else{
 //   LRmotorStop();
   Serial.println("L/R Stop"); 
  }
  //_____________________END DRIVE___________________


} // end of program
//***********************
//*************** External funct*********************

int motorReverse() {
  val0 = map(val0, 0, 110, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val0);
}
int motorForward() {

  val0 = map(val0, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val0);
}
int motorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
}
int LRmotorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
}
int motorLeft(){
  val1 = map(val1, 0, 110, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val1);
}

int motorRight(){
  val1 = map(val1, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val1);
}

So some how i need to free the motors when center pot move F/R and L/R( combo LR skid steering) i guess with out repeatedly calling motorStop? any input would help guys thanks.
95  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 10:38:30 pm
Transmitter code to see how i am getting and mapping the values.
Code:
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//**************Start Pin Setup***************
int LS_U_D = 3;  // analog pin used for the pot Left U/D
//int LS_L_R = 2;  // analog pin used for the pot Left L/R
//int RS_U_D = 5;  // analog pin used for the pot Right U/D
int RS_L_R = 4;  // analog pin used for the pot Right L/R
//**************End Pin Setup***************
//**************Global vars Setup***************
int LS_U_Dval;
//int LS_L_Rval;   
//int RS_U_Dval;
int RS_L_Rval;   
//**************END vars Setup***************
void setup(){
  Serial.begin(57600); // start serial communications
  //**************Start Transiever (NRF24L01) config**************
  Mirf.cePin = 9;
  Mirf.csnPin = 10;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"clie1");
  Mirf.payload = 4 * sizeof(byte);
  Mirf.config();
  //**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning ... "); // Print some stuff to serial
}
void loop(){
  //****************************Read Sticks**********************
  LS_U_Dval = analogRead(LS_U_D); // set val to read analog pin 2
  //  LS_L_Rval = analogRead(LS_L_R);// set val to read analog pin 3
  //  RS_U_Dval = analogRead(RS_U_D); // set val to read analog pin 4
  RS_L_Rval = analogRead(RS_L_R);// set val to read analog pin 5
  //*****************************End Read Sticks*******************
  //**************convert pot to PWM values**************
  LS_U_Dval = map(LS_U_Dval, 0, 1023, 0, 254);
  //     LS_L_Rval = map(LS_L_Rval, 0, 1023, 0, 254);   
  //     RS_U_Dval = map(RS_U_Dval, 0, 1023, 0, 254);
  RS_L_Rval = map(RS_L_Rval, 0, 1023, 0, 254);
  Serial.println(LS_U_Dval);
  //**************convert pot to PWM values**************
  //**************put values in array?**************
  byte vals[2];
  //**********Send only 2 pots from sticks for now**********
  vals[0] =LS_U_Dval;
  vals[1] =RS_L_Rval; 
  //**********Send only 2 pots from sticks for now**********
  //  vals[0] =LS_L_Rval;
  //  vals[1] =LS_U_Dval; 
  //  vals[2] =RS_L_Rval; 
  //  vals[3] =RS_U_Dval;
  //**************finish puting values in array?**************
  //**************Start Transmit package**************
  Mirf.setTADDR((byte *)"reci1"); // set name of Reciever
  Mirf.send(vals); // data to send
  //**************Start For loop to print array to local serial**************
  /*
  int i;
   for (i = 0; i < 4; i = i + 1)
   {
   Serial.println(vals[i], DEC);
   }
   // */
  //**************End For loop to print array to local serial**************
  while(Mirf.isSending()){
  }
  delay(10);



96  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 10:34:31 pm
Ok been messing with it for a while and now i got it so that the sticks get transmitted already mapped redid the maps on the rec end and now as it stands it will register forward back left and right. is there a better way of getting the pot vals from the NRF24's and taking action based on the values?



code so far
Code:
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//***** set vars for each pots/sensor reading from transmitter
int val0; // UP/Down Left Stick   
int val1; // Left/Right Right stick
//int val2; // servo 3   
//int val3; // servo 4   

int DIR_A = 12; //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3; //L298 PWM A Analog
int ENA_A = 9; //L298 Enable A Digital Hight/low on/off
int DIR_B = 13; //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11; //L298 PWM A Analog
int ENA_B = 8; //L298 Enable A Digital Hight/low on/off
//*********************************************
void setup(){
  Serial.begin(57600);

  pinMode(DIR_A, OUTPUT);   
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);   
  pinMode(DIR_B, OUTPUT);   
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);   

  //**************Start Transiever (NRF24L01) config**************
  Mirf.cePin = 48;
  Mirf.csnPin = 49;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"reci1");
  Mirf.payload = 4 * sizeof(byte);
  Mirf.config();
  //**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning..."); // print somthing once to Serial to know your up
}
void loop(){
  //+++++++++++Start data collection from transciever+++++++++
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      //*********** Start array to collect pot/sensor data *********
      val0 = data[0]; //Pot 1 on Transmitter 
      val1 = data[1]; //Pot 2 on Transmitter
      //   val2 = data[2]; //Pot 1 on Transmitter 
      //   val3 = data[3]; //Pot 2 on Transmitter
      //*********** End array to collect pot/sensor data *********   
      //**********Start Loop to print array to Serial Monitor
      /*
      int i;
       for (i = 0; i < 4; i = i + 1) {
       Serial.println(data[i], DEC);
       }         
       //  */
      //**********End Loop to print array to Serial Monitor         
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
  //++++++++ END data collection from transciever++++++++++++

  //_________________________Drive___________________________
  //________________Forward / Reverse_____________
  Serial.println(val0);
  Serial.println(val1);
  // Serial.println(val2);
  // Serial.println(val3);

  if(val0 < 110 ){
    motorReverse();
    Serial.println("Reverse");
  }
  else if(val0 > 135){
    motorForward();
    Serial.println("Forward");
  }
  else{
   motorStop();
    Serial.println("Stop");
  }
  //______________Left / Right________________ 
  if(val1 < 110 ){
    motorLeft();
    Serial.println("Left");
  }
  else if(val1 > 135){
    motorRight();
    Serial.println("Right"); 
  }
 // else{
 //   LRmotorStop();
 //   Serial.println("L/R Stop"); 
//  }
  //_____________________END DRIVE___________________


} // end of program
//***********************
//*************** External funct*********************

int motorReverse() {
  val0 = map(val0, 109, 0, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val0);
}
int motorForward() {

  val0 = map(val0, 136, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val0);
}
int motorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
}
int LRmotorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
}
int motorLeft(){
  val1 = map(val1, 109, 0, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val1);
}

int motorRight(){
  val1 = map(val1, 136, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val1);
}

97  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 08:51:37 pm
Is there any better way of looking at the incoming values and determining the motor direction and speed than this IF/ELSE? i just need to look at val0-4 and take action on if it's stick up/down/left/right and engage the motor driver on those findings. Maybe some buttons in the future.
98  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 12:51:46 pm
Changing as in from post to post.  I suspect you're making many changes to your code without letting anyone here know.

ahh that's from different positions from where the values are being read. in function, in IF statement, before IF just trying to get them where im asked. if you look at the code you will see where they are from. ( did that to keep it simple and noticeable where they are coming out of arduino IDE serial term is not what i would call robust.)
----------------------------------
code as of now.
Code:
//#include <Servo.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//**************Setup # servos to use*********
//Servo myservo0; 
//Servo myservo1;
// Servo myservo#;
//**************End Servo Setup***************
//***** set vars for each pots/sensor reading from transmitter
int val0; // servo 1   
int val1; // servo 2
int val2; // servo 3   
int val3; // servo 4   
//int oldVal0;
int DIR_A = 12; //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3; //L298 PWM A Analog
int ENA_A = 9; //L298 Enable A Digital Hight/low on/off
int DIR_B = 13; //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11; //L298 PWM A Analog
int ENA_B = 8; //L298 Enable A Digital Hight/low on/off
//*********************************************
void setup(){
  Serial.begin(57600);

  pinMode(DIR_A, OUTPUT);   
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);   
  pinMode(DIR_B, OUTPUT);   
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);   


  //************ Pin set for servos*************
  // myservo0.attach(4); 
  // End Pinset for servos
  //**************Start Transiever (NRF24L01) config**************
  Mirf.cePin = 48;
  Mirf.csnPin = 49;
  //  Mirf.cePin = 7;
  // Mirf.csnPin = 9;

  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"reci1");
  Mirf.payload = 4 * sizeof(byte);
  Mirf.config();
  //**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning..."); // print somthing once to Serial to know your up
}
void loop(){
  //+++++++++++Start data collection from transciever+++++++++
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      //*********** Start array to collect pot/sensor data *********
      val0 = data[0]; //Pot 1 on Transmitter 
      val1 = data[1]; //Pot 2 on Transmitter
      val2 = data[2]; //Pot 1 on Transmitter 
      val3 = data[3]; //Pot 2 on Transmitter
      //*********** End array to collect pot/sensor data *********   
      //**********Start Loop to print array to Serial Monitor
      /*
int i;
       for (i = 0; i < 4; i = i + 1) {
       Serial.println(data[i], DEC);
       }         
       //  */

      //**********End Loop to print array to Serial Monitor         
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
  //++++++++ END data collection from transciever++++++++++++

  //  int delta0 = abs(val0 - oldVal0);
  //      if(delta0 > 2){
  //        myservo0.write(val0);
  //  Serial.print("Servo:");
  //  Serial.println(val0);
  //    }
  //_________________________Drive___________________________
  //________________Forward / Reverse_____________

  Serial.println(val1);
  if(val1 < 110 ){
    motorReverse();
  }
  else if(val1 > 135){
    motorForward();
  }
  else{
    motorStop();
  }
  //______________Left / Right________________ 


  if(val2 < 110 ){
    motorLeft();
  }
  else if(val2 > 135){
    motorRight();
  }
  else{
    motorStop();
  }
  //_____________________END DRIVE___________________


} // end of program
//***********************


//*************** External funct*********************
int motorForward() {

  val1 = map(val1, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val1);
 // Serial.println("Forward: ");
  //  Serial.println(val1);

}

int motorReverse() {
  val1 = map(val1, 110, 0, 100, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val1);
//  Serial.println("Reverse: ");
  // Serial.println(val1);


}

int motorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
//  Serial.println("Stop: ");
  // Serial.println(val1);

}


int motorLeft(){
  val2 = map(val2, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val2);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val2);
//  Serial.println("Left: ");
  // Serial.println(val0);
}

int motorRight(){
  val2 = map(val2, 110, 0, 100, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val2);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val2);
 // Serial.println("Right: ");
  // Serial.println(val0);
}


99  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 12:23:19 pm
Why does your serial output keep changing so much?

If you print the value of val1 (or val2) right before your if-else blocks, you should see the value it received and the action that was taken.  You need to see that pattern to find out what values are causing stop to be triggered.

dunno why there changing so much the transmitter arduino with the thumb sticks is sending out solid 0-254 depending on where the stick is the flux happens in transit or on the rec side
100  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 11:57:38 am
Before the if-then segment starts, print the value of val1.
val1 is this
Code:
UP
------------
251
247
239
254
254
254
254
-------------
Down
---------
0
254
254
254
0
254
254
254
i checked my transmitter it's sending solid 0 - 254 for each pot on the remote arduino with 2x parallax thumb sticks
101  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 11:39:14 am
You are printing values AFTER the subroutines have mucked with them. That tells you nothing. Print them BEFORE calling the subroutines.

The value printed after motorReverse() looks screwy. After this code:
Code:
int motorReverse() {
  val1 = map(val1, 135, 254, 0, 254);
val1 is -503. This means that the input was not in the range 135 to 254, which is clear from the fact that you call this function only when val1 is less than 110.

You need to explain the screwy mapping.

in loop
Code:
if(val1 < 110 ){
    motorReverse();
  }
  else if(val1 > 135){
    motorForward();
}
  else{
    motorStop();
  }
Forward now
Code:
int motorForward() {

  val1 = map(val1, 135, 0, 100, 254);
Reverse now
Code:
int motorReverse() {
  val1 = map(val1, 110, 254, 0, 254);
Serial output  is called in the external as just Forward/Back/Stop/L/R to see if and when they are triggering.
this is what it is now outputting.
Code:
Up
--------
Reverse:
Stop:
Forward:
Stop:
Reverse:
Stop:
Reverse:
Stop:
Forward:
Stop:
_________
Down
-------
Reverse:
Stop:
Reverse:
Stop:
Reverse:
Stop:
Reverse:
Stop:
Reverse:
_________
Left
-------
Right:
Stop:
Right:
Stop:
Right:
Stop:
Right:
Stop:
Right:
__________
Right
--------
Right:
Stop:
Right:
Stop:
Right:
Stop:
Right:
Stop:
Right:
__________



Why is stop injecting between each call FsFsF RsRsRs etc with out skipping a beat and why is L/R only calling right function.
102  Using Arduino / Programming Questions / Re: Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 11:21:14 am
Please make use of the IDEs auto format function and repost the code.  (CTRL-T)
**Fixed some errors..

this better?
 
Code:
//#include <Servo.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//**************Setup # servos to use*********
//Servo myservo0; 
//Servo myservo1;
// Servo myservo#;
//**************End Servo Setup***************
//***** set vars for each pots/sensor reading from transmitter
int val0; // servo 1   
int val1; // servo 2
int val2; // servo 3   
int val3; // servo 4   
//int oldVal0;
int DIR_A = 12; //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3; //L298 PWM A Analog
int ENA_A = 9; //L298 Enable A Digital Hight/low on/off
int DIR_B = 13; //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11; //L298 PWM A Analog
int ENA_B = 8; //L298 Enable A Digital Hight/low on/off
//*********************************************
void setup(){
  Serial.begin(57600);

  pinMode(DIR_A, OUTPUT);   
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);   
  pinMode(DIR_B, OUTPUT);   
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);   


  //************ Pin set for servos*************
  // myservo0.attach(4); 
  // End Pinset for servos
  //**************Start Transiever (NRF24L01) config**************
  Mirf.cePin = 48;
  Mirf.csnPin = 49;
  //  Mirf.cePin = 7;
  // Mirf.csnPin = 9;

  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"reci1");
  Mirf.payload = 4 * sizeof(byte);
  Mirf.config();
  //**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning..."); // print somthing once to Serial to know your up
}
void loop(){
  //+++++++++++Start data collection from transciever+++++++++
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      //*********** Start array to collect pot/sensor data *********
      val0 = data[0]; //Pot 1 on Transmitter 
      val1 = data[1]; //Pot 2 on Transmitter
      val2 = data[2]; //Pot 1 on Transmitter 
      val3 = data[3]; //Pot 2 on Transmitter
      //*********** End array to collect pot/sensor data *********   
      //**********Start Loop to print array to Serial Monitor
      /*
int i;
       for (i = 0; i < 4; i = i + 1) {
       Serial.println(data[i], DEC);
       }         
       //  */
     
      //**********End Loop to print array to Serial Monitor         
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
  //++++++++ END data collection from transciever++++++++++++

  //  int delta0 = abs(val0 - oldVal0);
  //      if(delta0 > 2){
  //        myservo0.write(val0);
  //  Serial.print("Servo:");
  //  Serial.println(val0);
  //    }
  //_________________________Drive___________________________
  //________________Forward / Reverse_____________


  if(val1 < 110 ){
    motorReverse();
  }
  else if(val1 > 135){
    motorForward();
  }
  else{
    motorStop();
  }
  //______________Left / Right________________ 


  if(val2 < 110 ){
    motorLeft();
  }
  else if(val2 > 135){
    motorRight();
  }
  else{
    motorStop();
  }
  //_____________________END DRIVE___________________


} // end of program
//***********************


//*************** External funct*********************
int motorForward() {

  val1 = map(val1, 135, 0, 100, 254);

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val1);
  Serial.println("Forward: ");
//  Serial.println(val1);

}

int motorReverse() {
  val1 = map(val1, 110, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val1);
  Serial.println("Reverse: ");
 // Serial.println(val1);


}

int motorStop(){

  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, 0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, 0);
  Serial.println("Stop: ");
 // Serial.println(val1);

}


int motorLeft(){
  val2 = map(val2, 135, 0, 100, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val2);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val2);
  Serial.println("Left: ");
 // Serial.println(val0);
}

int motorRight(){
  val2 = map(val2, 110, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val2);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val2);
  Serial.println("Right: ");
 // Serial.println(val0);
}



103  Using Arduino / Programming Questions / Need help with IF ELSE trigger for Nrf24L01+ Arduino Motor Shield on: December 27, 2012, 10:48:08 am
TIA anyone.
I worked on this project a while back and just got some new stuffs to put on it and a new motor controller and motors.
The problem i am having is the IF ELSE seems to be triggering the correct function ( tho with some odd PWM values i have no idea why they are going neg now) as well as the last function ( motorStop).
This is causing the motor driver to try and start and stop at the same time. could some one have a look and see why. TIA
--------------------
Inside the (Drive section in the F/R and L/R code)
Code:
//#include <Servo.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
//**************Setup # servos to use*********
//Servo myservo0; 
//Servo myservo1;
// Servo myservo#;
//**************End Servo Setup***************
//***** set vars for each pots/sensor reading from transmitter
int val0; // servo 1   
int val1; // servo 2
int val2; // servo 3   
int val3; // servo 4   
//int oldVal0;
int DIR_A = 12; //L298 DIR A  Digital High/Low = left/right
int PWM_A = 3; //L298 PWM A Analog
int ENA_A = 9; //L298 Enable A Digital Hight/low on/off
int DIR_B = 13; //L298 DIR A  Digital High/Low = left/right
int PWM_B = 11; //L298 PWM A Analog
int ENA_B = 8; //L298 Enable A Digital Hight/low on/off
//*********************************************
void setup(){
    Serial.begin(57600);

  pinMode(DIR_A, OUTPUT);   
  pinMode(PWM_A, OUTPUT);
  pinMode(ENA_A, OUTPUT);   
  pinMode(DIR_B, OUTPUT);   
  pinMode(PWM_B, OUTPUT);
  pinMode(ENA_B, OUTPUT);   

 
//************ Pin set for servos*************
// myservo0.attach(4); 
// End Pinset for servos
//**************Start Transiever (NRF24L01) config**************
   Mirf.cePin = 48;
   Mirf.csnPin = 49;
  //  Mirf.cePin = 7;
   // Mirf.csnPin = 9;
 
    Mirf.spi = &MirfHardwareSpi;
    Mirf.init();
    Mirf.setRADDR((byte *)"reci1");
    Mirf.payload = 4 * sizeof(byte);
    Mirf.config();
//**************End Transiever (NRF24L01) config**************
  Serial.println("Beginning..."); // print somthing once to Serial to know your up
}
void loop(){
//+++++++++++Start data collection from transciever+++++++++
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
Mirf.getData(data);
//*********** Start array to collect pot/sensor data *********
        val0 = data[0]; //Pot 1 on Transmitter 
        val1 = data[1]; //Pot 2 on Transmitter
        val2 = data[2]; //Pot 1 on Transmitter 
        val3 = data[3]; //Pot 2 on Transmitter
//*********** End array to collect pot/sensor data *********   
//**********Start Loop to print array to Serial Monitor
 /*
int i;
  for (i = 0; i < 4; i = i + 1) {
  Serial.println(data[i], DEC);
}         
//  */
//**********End Loop to print array to Serial Monitor         
  delay(10);
    }while(!Mirf.rxFifoEmpty());
  }
//++++++++ END data collection from transciever++++++++++++

//  int delta0 = abs(val0 - oldVal0);
//      if(delta0 > 2){
//        myservo0.write(val0);
      //  Serial.print("Servo:");
      //  Serial.println(val0);
  //    }
//_________________________Drive___________________________
//________________Forward / Reverse_____________


if(val1 < 110 ){
       motorReverse();
Serial.print("REV,Val1: ");
Serial.println(val1); 
     }
      else if(val1 > 135){
       motorForward();
Serial.print("FOR,Val1: ");
Serial.println(val1);
       }
    else{
    motorStop();
Serial.print("STOP,Val1: ");
Serial.println(val1);
    }
//______________Left / Right________________ 


  if(val2 < 110 ){
       motorLeft();
Serial.print("LEFT,Val2: ");
Serial.println(val2); 
     }
      else if(val2 > 135){
Serial.print("RIGHT,Val2: ");
Serial.println(val2);
        motorRight();
       }
     else{
Serial.print("STOP,Val2: ");
Serial.println(val2);
        motorStop();
   }
//_____________________END DRIVE___________________


} // end of program
//***********************


//*************** External funct*********************
int motorForward() {
   
  val1 = map(val1, 110, 0, 100, 254);
       
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val1);
//  Serial.print("Forward: ");
//  Serial.println(val1);

 }

int motorReverse() {
  val1 = map(val1, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val1);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val1);
//  Serial.print("Reverse: ");
//Serial.println(val1);
 

}

int motorStop(){

 digitalWrite(ENA_A, LOW);
 digitalWrite(DIR_A, LOW);
 analogWrite(PWM_A, 0);
 digitalWrite(ENA_B, LOW);
 digitalWrite(DIR_B, LOW);
 analogWrite(PWM_B, 0);
// Serial.print("Stop: ");
// Serial.println(val1);
 
}


int motorLeft(){
  val2 = map(val1, 110, 0, 100, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, HIGH);
  analogWrite(PWM_A, val2);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, LOW);
  analogWrite(PWM_B, val2);
//  Serial.print("Left: ");
//  Serial.println(val0);
}

int motorRight(){
  val2 = map(val1, 135, 254, 0, 254);
  digitalWrite(ENA_A, LOW);
  digitalWrite(DIR_A, LOW);
  analogWrite(PWM_A, val0);
  digitalWrite(ENA_B, LOW);
  digitalWrite(DIR_B, HIGH);
  analogWrite(PWM_B, val2);
 // Serial.print("Right: ");
 // Serial.println(val0);
}
This is the output i am getting
Code:
---------------------
Up on left stick
---------------------
REV,Val1: -503
STOP,Val2: 129
FOR,Val1: -101
STOP,Val2: 129
**********************
---------------------
Down on left stick
------------------------
REV,Val1: -471
STOP,Val2: 129
FOR,Val1: -86
STOP,Val2: 129
*************************
-------------------------
Right on right stick
--------------------------
STOP,Val1: 127
RIGHT,Val2: 253
STOP,Val1: 127
LEFT,Val2: 77
STOP,Val1: 127
RIGHT,Val2: 253
****************************
-------------------------
Left on right stick
-------------------------
LEFT,Val2: 77
STOP,Val1: 127
LEFT,Val2: 77
STOP,Val1: 127
LEFT,Val2: 77
*************************
Hope some one sees something simple there.
104  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Nrf24L01p mbed help( want Arduino to ping mbed over Nrf24's) on: May 22, 2012, 02:46:04 am
i did get the Arduino and mbed to talk and exchange data now i can remote controll it with thumbsticks.

yeah way out of my simple programing range im afraid. could you point me to the shockburst and enhanced shockbust mode features in the RF24 lib would be verry interested. BTW if you want to take a stab at porting RF24 to

mbed i would help where i could ( not a lot due to my programing skills being simple yet) but i could bench test it for you if you dont have one.
105  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Nrf24L01p mbed help( want Arduino to ping mbed over Nrf24's) on: May 19, 2012, 04:34:50 pm
yeah that a bit much for this test. i just need to init the Nrf24's on both the arduino and mbed with the same settings and send a packet from the arduino to the mbed and open it.

i want the thinnest code to eliminate possible errors and conflicts. getting two radios to talk on two different hardware platforms with two different code bases is more than a little challenging for me.

i used the RF24 lib because it had the most custom radio inits and i use the nrf24l01 lib for mbed cos it's the only one available that i have found.
what i have so far.
Arduino.
Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

  RF24 radio(9,10);
  const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(void)
{
  Serial.begin(57600);
  printf_begin();
  printf("\n\rRadio Setup\n\r");
  radio.begin();
  radio.setDataRate(RF24_2MBPS);
  radio.setCRCLength(RF24_CRC_8);
  radio.setPayloadSize(10);
  radio.setChannel(101);
  radio.setAutoAck(true);
  radio.printDetails();
}
void loop(void)
{
    radio.stopListening();
    radio.openWritingPipe(0x00F0F0F0F0);
    unsigned long time = millis();
    printf("Now sending %lu...",time);
    bool ok = radio.write( &time,sizeof(unsigned long));
      if (ok)
        printf("ok...\n\r");
       else 
        printf("failed.\n\r");
      delay(100);
  }
reports back that it's "ok" when i have the other radio powerd so it seems it is getign ACk back.

now for the mbed. does not seem to print to the serial.
Code:
#include "mbed.h"
#include "nRF24L01P.h"

Serial pc(USBTX, USBRX); // tx, rx
nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10);    // mosi, miso, sck, csn, ce, irq

int main() {
#define TRANSFER_SIZE 10

char rxData[TRANSFER_SIZE];
    my_nrf24l01p.powerUp();
    my_nrf24l01p.setRfFrequency (2501);
    my_nrf24l01p.setTransferSize(10);
    my_nrf24l01p.setCrcWidth(8);
    my_nrf24l01p.enableAutoAcknowledge(NRF24L01P_PIPE_P0);
    my_nrf24l01p.setRxAddress(0x00F0F0F0F0);
    my_nrf24l01p.setTxAddress(0xF0F0F0F0D2LL);
      // Display the setup of the nRF24L01+ chip
       pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
       pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
       pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
       pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
       pc.printf( "nRF24L01+ CrC Width    : %d CrC\r\n", my_nrf24l01p.getCrcWidth() );
       pc.printf( "nRF24L01+ TransferSize : %d Paket Size\r\n", my_nrf24l01p.getTransferSize () );
    my_nrf24l01p.setReceiveMode();
    my_nrf24l01p.enable();
       pc.printf( "Setup complete, Starting While loop\r\n");
   
 while (1) {
         if(my_nrf24l01p.readable(NRF24L01P_PIPE_P0)){
               do{
                 my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
                 int i;
                 for (i = 0; i > 0; i ++) {
                 pc.printf("Vals : %d\n\r", rxData[i]); 
                 }   
              }while(my_nrf24l01p.readable(NRF24L01P_PIPE_P0)== true );
        }                                           
 }
}

the radio seems to be geting the packets if i turn off the mbed radio the arduino will fail on transfer so i guess im not checking the radio properly to see IF there is a packet and what to do with it after. any help would be great thanks
Pages: 1 ... 5 6 [7] 8 9