Show Posts
|
|
Pages: 1 ... 5 6 [7]
|
|
91
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 08, 2011, 11:09:18 pm
|
Had not chaned it since last post so i just never sent it. here is the trans code as of tonight Transmitter: #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
//**************Start Pin Setup*************** int pot1pinX = 0; // analog pin used for the pot 1 int pot2pinY = 1; // analog pin used for the pot 2 //**************End Pin Setup***************
//**************Global vars Setup*************** int val0; int val1; //**************END vars Setup*************** void setup(){ Serial.begin(9600); // start serial communications //**************Start Transiever (NRF24L01) config************** Mirf.csnPin = 9; Mirf.cePin = 8; 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(){ val0 = analogRead(pot1pinX); // set val0 to read analog pin 0 val1 = analogRead(pot2pinY);// set val1 to read analog pin 1 //**************convert pot to PWM values************** val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 254); //**************convert pot to PWM values************** //**************put values in array?************** byte vals[2]; vals[0] =val0; vals[1] =val1; //**************finish puting values in array?************** //**************Start Transmit package************** Mirf.setTADDR((byte *)"reci1"); // set name of Reciever Mirf.send(vals); // data to send //**************put values in array?************** //**************Start For loop to print array to local serial************** // int i; // for (i = 0; i < 2; i = i + 1) // { // Serial.println(vals[i], DEC); // } //**************End For loop to print array to local serial************** while(Mirf.isSending()){ } delay(10); }
|
|
|
|
|
92
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 08, 2011, 06:08:21 pm
|
OK still haveing issues controling the motor. As it stands now it goes in rev when i pull back and climes in speed the farther back i pull till max but hwen i let co and it centers the stick the motor is still in full speed in REV if i nudge it a lil FWD it changes dir to FWD and starts out at one speed and decreases as the more forword i push the stick. if i push all the way FWD it comes to a slow stop then if i let go of the stick it snaps to center and stays off.. I need to re build the "MAP?" to make (Down(REV)),(Up(FWD))? r somthting to make it go from 0-254 IN1 LOW IN2 HIGH then 0-254 IN1 HIIGH IN2 LOW. maby should remap on the transmitter and send the full pot across and map it on reciever end? Servo is working fine now. Reciever: #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 IN1 = 2; //L298 int IN2 = 4; //L298 int ENA = 5; //L298 Enable A //********************************************* void setup(){ Serial.begin(9600); pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); //************ Pin set for servos************* myservo0.attach(3); // myservo1.attach(6); // End Pinset for servos //**************Start Transiever (NRF24L01) config************** Mirf.csnPin = 9; Mirf.cePin = 8; 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 //*********** 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++++++++++++
//++++++++ Do Stuff here++++++++++++
if(val0 < 84){ myservo0.write(val0); } if(val0 > 90){ myservo0.write(val0); } if(val1 < 120){ motorFoward(); } if(val1 > 125){ motorReverse(); }
}// end of program
int motorFoward() { Serial.println("Forword"); analogWrite(ENA, val1); digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); Serial.println(val1); }
int motorReverse() { Serial.println("Backward"); analogWrite(ENA, val1); digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); Serial.println(val1); }
|
|
|
|
|
93
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 08, 2011, 11:48:54 am
|
Welp kinda odd here is the code i have and ill explain what it's doing after. #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 IN1 = 5; //L298 int IN2 = 6; //L298 //********************************************* void setup(){ Serial.begin(9600); //************ Pin set for servos************* myservo0.attach(3); // myservo1.attach(6); // End Pinset for servos //**************Start Transiever (NRF24L01) config************** Mirf.csnPin = 9; Mirf.cePin = 8; 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 //*********** 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++++++++++++
//++++++++ Do Stuff here++++++++++++ //Serial.println("***********"); //Serial.print("Val0:"); //Serial.println(val0); //Serial.println("-----------"); //Serial.print("Val1:"); //Serial.println(val1); //Serial.println("***********");
if(val0 < 84) Serial.print("Servo R:"); Serial.println(val0); myservo0.write(val0); if(val0 > 90) Serial.print("Servo L:"); Serial.println(val0); myservo0.write(val0); if(val1 < 120) Serial.print("Forword:"); Serial.println(val1); digitalWrite(IN2,HIGH); analogWrite(IN1, val1); //PWM Speed Control if(val1 > 125) Serial.print("Reverse:"); Serial.println(val1); digitalWrite(IN2,LOW); analogWrite(IN1, val1); //PWM Speed Control
//************************* Old code************************************ // myservo0.write(val0); //Apply Pot 1 from trans to servo on pin 5
// digitalWrite(IN2,HIGH); // analogWrite(IN1, val1); //PWM Speed Control
// myservo1.write(val1);//Apply Pot 2 from trans to servo on pin 6 //++++++++++++++++++++++++++++++++++
} // end of program
So when i power up the Reciever Ard the small motor i have attached starts to spin in the (Forword) when i move the stick up it starts to slow down in the forword if i pull back on the stick it foes forward even faster odd. BUT i have print code at each IF statment and when the sticks are centerd all that prints are the # no Servo l or R or no Forword or Backword thos trigger when i move the sticks up or down or left and right. The servo seems to dance a lot when i move it to the right but not left. 1.Why is the base # printing to serial in the first place with out tripping and if statement?. ( should only get print from F/B L/R) 2.Why is the servo dancing on right but not left? 3.Why is the motor in motion at center.? 4.Why does the code for the motor not move it forword/reverse. ( prob same reason its running at center).
|
|
|
|
|
94
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 06, 2011, 01:51:56 pm
|
|
the serial data is already there the output was about 87 ish avrage. I used like 70/100,,,75/50,,, 50/50 even they the servos moved no matter what it seems.
|
|
|
|
|
95
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 06, 2011, 12:44:15 pm
|
Odd,, i have tried with diffrent values and does not seem to matter. Tried: //++++++++ Do Stuff here++++++++++++ if(val0 < 88 || val0 > 94) myservo0.write(val0); //Apply Pot 1 from trans to servo on pin 5 if(val1 < 88 || val1 > 94) myservo1.write(val1);//Apply Pot 2 from trans to servo on pin 6 //++++++++++++++++++++++++++++++++++
And tried: //++++++++ Do Stuff here++++++++++++ if(val0 < 88 || val0 > 94) { myservo0.write(val0); //Apply Pot 1 from trans to servo on pin 5 } if(val1 < 88 || val1 > 94) { myservo1.write(val1);//Apply Pot 2 from trans to servo on pin 6 } //++++++++++++++++++++++++++++++++++
#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 //********************************************* void setup(){ Serial.begin(9600); //************ Pin set for servos************* myservo0.attach(5); myservo1.attach(6); // End Pinset for servos //**************Start Transiever (NRF24L01) config************** Mirf.csnPin = 9; Mirf.cePin = 8; 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 //*********** 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++++++++++++
//++++++++ Do Stuff here++++++++++++ Serial.println(val0); Serial.println(val1); if(val0 < 90 || val0 > 80){ // <-- Add this myservo0.write(val0); //Apply Pot 1 from trans to servo on pin 5 } if(val1 < 100 || val1 > 50){ myservo1.write(val1);//Apply Pot 2 from trans to servo on pin 6 } //++++++++++++++++++++++++++++++++++
} // end of program
dunno.. Also is there away to use difrent pins for the SPI lik 2-8 or so? i have a motor driver board called motomama that also had a port on it for the NRF24L01 but the main L298 uses the 8-13 pins for some damn reason. Link to the motomama http://iteadstudio.com/store/index.php?main_page=product_info&cPath=18&products_id=361
|
|
|
|
|
96
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 06, 2011, 09:46:33 am
|
centerpot is so that when i touch the sticks they dont move servos/motors till i move it intentionaly. so like 89-91 seems to be middle (center) say dont move till it's 82-99. >82 = up and < 99 = down etc. Code so far. #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
//**************Start Pin Setup*************** int pot1pinX = 0; // analog pin used for the pot 1 int pot2pinY = 1; // analog pin used for the pot 2 //**************End Pin Setup***************
//**************Global vars Setup*************** int val0; int val1; //**************END vars Setup*************** void setup(){ Serial.begin(9600); // start serial communications //**************Start Transiever (NRF24L01) config************** Mirf.csnPin = 9; Mirf.cePin = 8; 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(){ val0 = analogRead(pot1pinX); // set val0 to read analog pin 0 val1 = analogRead(pot2pinY);// set val1 to read analog pin 1 //**************convert pot to PWM values************** val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 179); //**************convert pot to PWM values************** //**************put values in array?************** byte vals[2]; vals[0] =val0; vals[1] =val1; //**************finish puting values in array?************** //**************Start Transmit package************** Mirf.setTADDR((byte *)"serv1"); // set name of Reciever Mirf.send(vals); // data to send //**************put values in array?************** //**************Start For loop to print array to local serial************** int i; for (i = 0; i < 2; i = i + 1) { Serial.println(vals[i], DEC); } //**************End For loop to print array to local serial************** while(Mirf.isSending()){ } delay(10); }
Reciever: #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 //********************************************* void setup(){ Serial.begin(9600); //************ Pin set for servos************* myservo0.attach(5); myservo1.attach(6); // End Pinset for servos //**************Start Transiever (NRF24L01) config************** Mirf.csnPin = 9; Mirf.cePin = 8; 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 //*********** End array to collect pot/sensor data ********* //**********End 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++++++++++++
//++++++++ Do Stuff here++++++++++++ myservo0.write(val0); //Apply Pot 1 from trans to servo on pin 5 myservo1.write(val1);//Apply Pot 2 from trans to servo on pin 6 //++++++++++++++++++++++++++++++++++
} // end of program
as it stands now they flux between say 88-94 ish on there own so i want to set up a "dead zone" to keep them from making micro movments on servos/motors and make it so i have to move it a little bit BEFOR the motors/servos acutly start
|
|
|
|
|
97
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 05, 2011, 04:16:43 pm
|
Woot!.. ( all 4 servos now working (bit twitchy tho for osme reason)). I see so the data comes in as an array already by defualt or is it becase we sent it as an array from the transmitter? Transmitter: #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
int pot1pinX = 0; // analog pin used for the pot 1 int pot1pinY = 1; // analog pin used for the pot 1 int pot2pinX = 2; // analog pin used for the pot 2 int pot2pinY = 3; // analog pin used for the pot 2
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"clie1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning ... "); } void loop(){ val0 = analogRead(pot1pinX); val1 = analogRead(pot1pinY); val2 = analogRead(pot2pinX); val3 = analogRead(pot2pinY); val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 179); val2 = map(val2, 0, 1023, 0, 179); val3 = map(val3, 0, 1023, 0, 179); byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; Mirf.setTADDR((byte *)"serv1"); Mirf.send(vals);
int i; for (i = 0; i < 4; i = i + 1) { Serial.println(vals[i], DEC); }
while(Mirf.isSending()){ } delay(10); }
Reciever #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
int pot1pinX = 0; // analog pin used for the pot 1 int pot1pinY = 1; // analog pin used for the pot 1 int pot2pinX = 2; // analog pin used for the pot 2 int pot2pinY = 3; // analog pin used for the pot 2
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"clie1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning ... "); } void loop(){ val0 = analogRead(pot1pinX); val1 = analogRead(pot1pinY); val2 = analogRead(pot2pinX); val3 = analogRead(pot2pinY); val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 179); val2 = map(val2, 0, 1023, 0, 179); val3 = map(val3, 0, 1023, 0, 179); byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; Mirf.setTADDR((byte *)"serv1"); Mirf.send(vals);
int i; for (i = 0; i < 4; i = i + 1) { Serial.println(vals[i], DEC); }
while(Mirf.isSending()){ } delay(10); }
any ideas on how to setup a (center pot) nutral position ? say %5 or so? thanks agin for all the help. i almost choked when i saw the # of posts you have nice job.
|
|
|
|
|
98
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 05, 2011, 03:35:40 pm
|
so use "data" inplace of "vals" like this? the array prints 0's agin. //#include <Servo.h> #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
//byte vals; //byte sent; //Servo myservo0; //Servo myservo1; //Servo myservo2; //Servo myservo3;
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); // myservo0.attach(3); // myservo1.attach(5); // myservo2.attach(6); // myservo3.attach(10);
Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"serv1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning..."); } void loop(){ byte data[Mirf.payload]; if(Mirf.dataReady()){ do{ Mirf.getData(data);
byte data[4]; data[0] =val0; data[1] =val1; data[2] =val2; data[3] =val3; int i; for (i = 0; i < 4; i = i + 1) { Serial.println(data[i], DEC); } delay(10); }while(!Mirf.rxFifoEmpty()); } // myservo0.write(val0); // myservo1.write(val1); // myservo2.write(val2); // myservo3.write(val3);
}
|
|
|
|
|
99
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 05, 2011, 02:20:49 pm
|
Somew wierd stuffs is going on one is the pot values are not maching on each ard. Trans will transmit like 80-90ish in center pot on all and the Rec is showing like 2 at 80-90 and 2 at 0 for some reason? also if i unremark the servo code the whol thing goes kaput i get 0's on the reciever end. Trans #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
int pot1pinX = 0; // analog pin used for the pot 1 int pot1pinY = 1; // analog pin used for the pot 1 int pot2pinX = 2; // analog pin used for the pot 2 int pot2pinY = 3; // analog pin used for the pot 2
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"clie1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning ... "); } void loop(){ val0 = analogRead(pot1pinX); val1 = analogRead(pot1pinY); val2 = analogRead(pot2pinX); val3 = analogRead(pot2pinY); val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 179); val2 = map(val2, 0, 1023, 0, 179); val3 = map(val3, 0, 1023, 0, 179); byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; Mirf.setTADDR((byte *)"serv1"); Mirf.send(vals);
int i; for (i = 0; i < 4; i = i + 1) { Serial.println(vals[i], DEC); }
while(Mirf.isSending()){ } delay(10); }
Rec: //#include <Servo.h> #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
byte vals; //byte sent; //Servo myservo0; //Servo myservo1; //Servo myservo2; //Servo myservo3;
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); // myservo0.attach(3); // myservo1.attach(5); // myservo2.attach(6); // myservo3.attach(10);
Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"serv1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning..."); } void loop(){ byte data[Mirf.payload]; if(Mirf.dataReady()){ do{ Mirf.getData(&vals);
byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; int i; for (i = 0; i < 4; i = i + 1) { Serial.println(vals[i], DEC); } delay(10); }while(!Mirf.rxFifoEmpty()); } // myservo0.write(val0); // myservo1.write(val1); // myservo2.write(val2); // myservo3.write(val3);
}
So two things. why are they not matching up and why does it fail when i activate the servo code? thanks for everything so far Paul
|
|
|
|
|
100
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 05, 2011, 01:28:48 pm
|
Seems like it is storing them fine now. now i just need to "Read?" them on the reciever end correctly? Transmitter: #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
int pot1pinX = 0; // analog pin used for the pot 1 int pot1pinY = 1; // analog pin used for the pot 1 int pot2pinX = 2; // analog pin used for the pot 2 int pot2pinY = 3; // analog pin used for the pot 2
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"clie1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning ... "); } void loop(){ val0 = analogRead(pot1pinX); val1 = analogRead(pot1pinY); val2 = analogRead(pot2pinX); val3 = analogRead(pot2pinY); val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 179); val2 = map(val2, 0, 1023, 0, 179); val3 = map(val3, 0, 1023, 0, 179); byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; // unsigned long time = millis(); // long time_long = long(time); Mirf.setTADDR((byte *)"serv1"); Mirf.send(vals); // Serial.println(vals); int i; for (i = 0; i < 3; i = i + 1) { Serial.println(vals[i], DEC); }
while(Mirf.isSending()){ Serial.println("Sent packet"); } delay(10); }
I guess i just need to read them into an "array?" and use them now? Rec: #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h> byte vals; //byte sent;
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"serv1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning..."); } void loop(){ byte data[Mirf.payload]; if(Mirf.dataReady()){ do{ Mirf.getData(&vals); // Mirf.getData(&sent);
// Serial.println(vals, DEC);
byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; int i; for (i = 0; i < 3; i = i + 1) { Serial.println(vals[i], DEC); } // Serial.print("Val0: "); // Serial.println(val0); // Serial.print("Val1: "); // Serial.println(val1); // Serial.print("Val2: "); // Serial.println(val2); // Serial.print("Val3: "); // Serial.println(val3); delay(15);
}while(!Mirf.rxFifoEmpty()); } }
Seems to be working ish i get output on the Rec end now. gunna experiment a bit with the pots and ill report back. agin thanks sooo much for this help
|
|
|
|
|
101
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 05, 2011, 12:48:08 pm
|
Ok so far seems good ( how do i print vals after it has been sent to make sure it has the values of the pots? serialprintln sont seem to like it. ( because it has become an array?)) thanks Transmitter #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
int pot1pinX = 0; // analog pin used for the pot 1 int pot1pinY = 1; // analog pin used for the pot 1 int pot2pinX = 2; // analog pin used for the pot 2 int pot2pinY = 3; // analog pin used for the pot 2
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"clie1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning ... "); } void loop(){ byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; val0 = analogRead(pot1pinX); val1 = analogRead(pot1pinY); val2 = analogRead(pot2pinX); val3 = analogRead(pot2pinY); val0 = map(val0, 0, 1023, 0, 179); val1 = map(val1, 0, 1023, 0, 179); val2 = map(val2, 0, 1023, 0, 179); val3 = map(val3, 0, 1023, 0, 179);
// unsigned long time = millis(); // long time_long = long(time); Mirf.setTADDR((byte *)"serv1"); Mirf.send(vals); // Serial.println(vals); while(Mirf.isSending()){ } delay(10); }
Reciever #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h> #include <Servo.h> byte vals; //byte sent; Servo myservo1; Servo myservo2; //Servo myservo3; //Servo myservo4;
int val0; int val1; int val2; int val3;
void setup(){ Serial.begin(9600); myservo1.attach(5); myservo2.attach(6); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"serv1"); Mirf.payload = 4 * sizeof(byte); Mirf.config(); Serial.println("Beginning..."); } void loop(){ byte data[Mirf.payload]; if(Mirf.dataReady()){ do{ Mirf.getData(&vals); // Mirf.getData(&sent); byte vals[4]; vals[0] =val0; vals[1] =val1; vals[2] =val2; vals[3] =val3; Serial.print("Val0: "); Serial.println(val0); Serial.print("Val1: "); Serial.println(val1); Serial.print("Val2: "); Serial.println(val2); Serial.print("Val3: "); Serial.println(val3); myservo1.write(val0); myservo2.write(val1); // myservo3.write(val3); // myservo4.write(val4);
delay(15);
}while(!Mirf.rxFifoEmpty()); } }
Seems to output 0's in all the vals. or hav i completly misunderstood your comments?
|
|
|
|
|
102
|
Using Arduino / Networking, Protocols, and Devices / Re: Need help transmitting 2x thumbstick data
|
on: October 05, 2011, 11:21:34 am
|
I know it is sad bu you did ask for it. me think it's geting mashed up in Mirf.getdata or maby i can "point?" (sent) to each val1-4 in series? dunno guess that's why im here. Transmitter #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h>
int pot1pinX = 0; // analog pin used for the pot 1 int pot1pinY = 1; // analog pin used for the pot 1 int pot2pinX = 2; // analog pin used for the pot 2 int pot2pinY = 3; // analog pin used for the pot 2
int val1; int val2; int val3; int val4;
void setup(){ Serial.begin(9600); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"clie1"); Mirf.payload = sizeof(long); Mirf.config(); Serial.println("Beginning ... "); } void loop(){ val1 = analogRead(pot1pinX); val2 = analogRead(pot1pinY); val3 = analogRead(pot2pinX); val4 = analogRead(pot2pinY); val1 = map(val1, 0, 1023, 0, 179); val2 = map(val2, 0, 1023, 0, 179); val3 = map(val3, 0, 1023, 0, 179); val4 = map(val4, 0, 1023, 0, 179);
unsigned long time = millis(); long time_long = long(time); Mirf.setTADDR((byte *)"serv1"); Mirf.send((byte *)&val1); Mirf.send((byte *)&val2); Mirf.send((byte *)&val3); Mirf.send((byte *)&val4);
// Serial.println(val1); // Serial.println(val2); // Serial.println(val3); // Serial.println(val4); while(Mirf.isSending()){ } delay(10); }
Reciever #include <Mirf.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <nRF24L01.h> #include <SPI.h> #include <Servo.h>
byte sent; Servo myservo1; Servo myservo2; Servo myservo3; Servo myservo4;
int val; int val1; int val2; int val3; int val4;
void setup(){ Serial.begin(9600); myservo1.attach(5); myservo2.attach(6); myservo3.attach(3); myservo4.attach(11); Mirf.csnPin = 9; Mirf.cePin = 8; Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"serv1"); Mirf.payload = sizeof(long); Mirf.config(); Serial.println("Beginning..."); } void loop(){ byte data[Mirf.payload]; if(Mirf.dataReady()){ do{ Mirf.getData(&sent); long time_long = long(data); val1 = int(sent); val2 = int(sent); val3 = int(sent); val4 = int(sent); Serial.print("Val1: "); Serial.println(val1); Serial.print("Val2: "); Serial.println(val2); Serial.print("Val3: "); Serial.println(val3); Serial.print("Val4: "); Serial.println(val4); myservo1.write(val1); myservo2.write(val2); myservo3.write(val3); myservo4.write(val4);
delay(15);
}while(!Mirf.rxFifoEmpty()); } }
i added a nother servo on the rec end pins 5,6 have them now. i could put the other two on if you think it would help. thanks for looking PaulS.
|
|
|
|
|
103
|
Using Arduino / Networking, Protocols, and Devices / Need help transmitting 2x thumbstick data [Solved] Thanks PaulS
|
on: October 05, 2011, 10:13:08 am
|
Thanks for reading this. The equipment i have 2x Arduinos 2x Nrf24L01+PA,LNA with 2DB atenna 2x Thumbsticks 1x Motordriver L298n brick 1x Standard hobby servo ........... I have read just about every post in arduino forum and i could find with google on Nrf24l01+'s and tho useful i could not seem to transmit more than one reading from one pot on one stick at a time ( not verry handy me thinks). I have been trying transmitting strings, messageing systems and others. i have to be honist my prograqming skills are lacking a bit so i need all the help i can get i guess. to be honist i have been toying with the for about 4 months and just get so frustrated with trying to combine the pot values and transmit the data that i just walk away till i think ( Oh i wonder if....) and well let's just say i would not be posting if i had a sucess  . anywho i like Mirf it seems simple to use so i hope i can keep using it. Welp there is my request i hope i have added all the info i need. i know it is going to be somthing simple but i am just to burnt to keep trying its boarderline pathetic by now LOL. We agine thanks for reading and hope i get some guidence
|
|
|
|
|