Pages: 1 2 3 [4] 5   Go Down
Author Topic: Wireless control system problem  (Read 4703 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So luckily i was reading this over and i saw that there was more code that you posted. code doesnt seem to be very mobile friendly.

It was indeed lucky that you read the code I posted. Otherwise my time would have been wasted.
So does everything look good in that code then? It's still not working :/ the receiving LED comes on but in the serial monitor of the receiving side there is nothing.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So luckily i was reading this over and i saw that there was more code that you posted. code doesnt seem to be very mobile friendly.

It was indeed lucky that you read the code I posted. Otherwise my time would have been wasted.
Do I still use that flash function if im sending at 9600? Does the code look like it has everything there?
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you explain to me in your own words what you think the flash() function does? Here, I'll reproduce it:

Code:
void flash ()
  {
  digitalWrite (LED, HIGH);
  digitalWrite (LED, LOW);
  }  // end of flash

Once you have told me what it does, can you tell me if your program needs it to do that or not?
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you explain to me in your own words what you think the flash() function does? Here, I'll reproduce it:

Code:
void flash ()
  {
  digitalWrite (LED, HIGH);
  digitalWrite (LED, LOW);
  }  // end of flash

Once you have told me what it does, can you tell me if your program needs it to do that or not?
It just slows it down so you can get all 5 values at the same time. Because i am using 9600 i believe i do. This is just what i understood from the pictures a few pages back and your website.
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No. I put it there to flash the LED. That's all. I did that to show how fast the data is coming in. That's all.

If I had thought it necessary to put it in, I would have in the code I pasted on the previous page.

You seem to have incorporated the servo controls into the code. Well, does it work or not? If not, what does it do?
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No. I put it there to flash the LED. That's all. I did that to show how fast the data is coming in. That's all.

If I had thought it necessary to put it in, I would have in the code I pasted on the previous page.

You seem to have incorporated the servo controls into the code. Well, does it work or not? If not, what does it do?
No servos move or anything but the receiving light does turn on. So its receiving something but i dont know what.

Here is my sending code:
Code:
int pwm_a = 3;  //PWM control for motor outputs 1 and 2 is on digital pin 3
int dir_a = 12;  //direction control for motor outputs 1 and 2 is on digital pin 12

int Finger1 = 2;
int Finger2 = 3;
int Finger3 = 4;
int Finger4 = 5;
int Rotation =  0;


void setup()
{
   Serial.begin(9600);
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(dir_a, OUTPUT);
  digitalWrite(dir_a, LOW);
 
}

void loop()


   int FingerV1 = analogRead(Finger1);
   int FingerV2 = analogRead(Finger2);
   int FingerV3 = analogRead(Finger3);
   int FingerV4 = analogRead(Finger4);
   int RotationV1 = analogRead(Rotation);
   
   if (FingerV1 < 30) FingerV1 = 30;
   else if (FingerV1 > 80) FingerV1 = 80;
   
   if (FingerV2 < 45) FingerV2 = 45;
   else if (FingerV2 > 69) FingerV2 = 69;
   
   if (FingerV3 < 22) FingerV3 = 22;
   else if (FingerV3 > 87) FingerV3 = 87;
   
   if (FingerV4 < 12) FingerV4 = 12;
   else if (FingerV4 > 62) FingerV4 = 62;
   
   if (RotationV1 < 300) RotationV1 = 300;
   else if (RotationV1 > 600) RotationV1 = 600;
 
   byte servoVal1 = map(FingerV1,30, 80, 0, 255);//middle
   byte servoVal2 = map(FingerV2,69, 45, 0, 100);//thumb
   byte servoVal3 = map(FingerV3,87, 22, 0, 255);//ring
   byte servoVal4 = map(FingerV4,12, 62, 0, 255);//pointer
   byte servoVal5 = map(RotationV1,300, 600, 0, 255);//Rotation
   
   Serial.print(".");
   Serial.print(servoVal1);
   Serial.print(",");
   Serial.print(servoVal2);
   Serial.print(",");
   Serial.print(servoVal3);
   Serial.print(",");
   Serial.print(servoVal4);
   Serial.print(",");
   Serial.print(RotationV1);
   Serial.print("/");
   
   delay(10);
}
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

On the receiving end, what do the serial prints show?
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the receiving end, what do the serial prints show?
This is a small bit of what i get.
Code:
middle = 163
thumb = 4
ring = 23
pointer = 255
rotation = 5883
middle = 1555
thumb = 441
ring = 0
pointer = 0
rotation = 0
middle = 435
thumb = 0
Those values are way way way off. My sending code keeps all of them between 0 and 100 and the rotation is between 300 and 600.
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your current sending code please?
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your current sending code please?
Sending:
Code:
int pwm_a = 3;  //PWM control for motor outputs 1 and 2 is on digital pin 3
int dir_a = 12;  //direction control for motor outputs 1 and 2 is on digital pin 12

int Finger1 = 2;
int Finger2 = 3;
int Finger3 = 4;
int Finger4 = 5;
int Rotation =  0;


void setup()
{
   Serial.begin(9600);
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(dir_a, OUTPUT);
  digitalWrite(dir_a, LOW);
 
}

void loop()


   int FingerV1 = analogRead(Finger1);
   int FingerV2 = analogRead(Finger2);
   int FingerV3 = analogRead(Finger3);
   int FingerV4 = analogRead(Finger4);
   int RotationV1 = analogRead(Rotation);
   
   if (FingerV1 < 30) FingerV1 = 30;
   else if (FingerV1 > 80) FingerV1 = 80;
   
   if (FingerV2 < 45) FingerV2 = 45;
   else if (FingerV2 > 69) FingerV2 = 69;
   
   if (FingerV3 < 22) FingerV3 = 22;
   else if (FingerV3 > 87) FingerV3 = 87;
   
   if (FingerV4 < 12) FingerV4 = 12;
   else if (FingerV4 > 62) FingerV4 = 62;
   
   if (RotationV1 < 300) RotationV1 = 300;
   else if (RotationV1 > 600) RotationV1 = 600;
 
   byte servoVal1 = map(FingerV1,30, 80, 0, 255);//middle
   byte servoVal2 = map(FingerV2,69, 45, 0, 100);//thumb
   byte servoVal3 = map(FingerV3,87, 22, 0, 255);//ring
   byte servoVal4 = map(FingerV4,12, 62, 0, 255);//pointer
   byte servoVal5 = map(RotationV1,300, 600, 0, 255);//Rotation
   
   Serial.print(".");
   Serial.print(servoVal1);
   Serial.print(",");
   Serial.print(servoVal2);
   Serial.print(",");
   Serial.print(servoVal3);
   Serial.print(",");
   Serial.print(servoVal4);
   Serial.print(",");
   Serial.print(RotationV1);
   Serial.print("/");
   
   delay(10);
}
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you think to open the serial monitor on the sending side and check what was actually being sent? I did and saw this:

Code:
,350/35/<some gibberish>

Hardly the numbers you expect, eh?

Now if we change the sending code to send "decimal" numbers like this:

Code:
  Serial.print(".");
   Serial.print(servoVal1, DEC);
   Serial.print(",");
   Serial.print(servoVal2, DEC);
   Serial.print(",");
   Serial.print(servoVal3, DEC);
   Serial.print(",");
   Serial.print(servoVal4, DEC);
   Serial.print(",");
   Serial.print(RotationV1, DEC);
   Serial.print("/");

Then we get better results:

Code:
.255,0,0,255,340/.255,0,0,255,344/.255,0,0,255,368/
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you think to open the serial monitor on the sending side and check what was actually being sent? I did and saw this:

Code:
,350/35/<some gibberish>

Hardly the numbers you expect, eh?

Now if we change the sending code to send "decimal" numbers like this:

Code:
  Serial.print(".");
   Serial.print(servoVal1, DEC);
   Serial.print(",");
   Serial.print(servoVal2, DEC);
   Serial.print(",");
   Serial.print(servoVal3, DEC);
   Serial.print(",");
   Serial.print(servoVal4, DEC);
   Serial.print(",");
   Serial.print(RotationV1, DEC);
   Serial.print("/");

Then we get better results:

Code:
.255,0,0,255,340/.255,0,0,255,344/.255,0,0,255,368/
Ah perfect! Now another problem... So i have 5 of these: http://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=6221

I am using an arduino for all this also. Now should i just power these servos with the 5v and gnd from the arduino or something else? When i power it with the arduino it powers then restarts then repeats all that. I have a 7.2v 2200mah lipo battery that im using for all this. I am also powering the xbee too.
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I certainly would not power them from the Arduino 5V line. That goes through a voltage regulator that is not designed to handle that amount of current. I assume (hope) you are using some kind of motor board to actually drive the motors. That should be independently powered, not from the Arduino's 5V line.
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I certainly would not power them from the Arduino 5V line. That goes through a voltage regulator that is not designed to handle that amount of current. I assume (hope) you are using some kind of motor board to actually drive the motors. That should be independently powered, not from the Arduino's 5V line.
I made a custom shield that i have the digital lines from the arduino tied to then the power from the lipo battery. I have common grounds connected also. Should this work?
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18811
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this different to what you said earlier?

Quote
should i just power these servos with the 5v and gnd from the arduino or something else?

Certainly you should have the grounds common. I agree with that. And from the battery I would run a wire to the Arduino's "power in" socket (so it gets voltage regulated). And also direct from the battery to the motor shield.

Sounds OK, subject to seeing a schematic.
Logged


Pages: 1 2 3 [4] 5   Go Up
Jump to: