Show Posts
Pages: 1 2 [3] 4 5 ... 13
31  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 08:47:55 pm
Capture the whole lot into a buffer. You could look for a terminating "/" character, since that is what you are sending.

There's an example of doing that here: http://gammon.com.au/serial

Then you could use strtok to break the resulting string apart at the commas, and use atoi to convert the ASCII strings into numbers you can send to the servos.
Ahh didn't scroll all the way to the bottom smiley
32  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 08:38:52 pm
Hmmm ....

From your first post:

Code:
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);

So most numbers are in the range 0 to 255, right?

So let's work through an example. You send:

Code:
.123,100,92,42,99/

Now once you get the first dot you read like this:

Code:
if (Serial.available() >8)
   {
  
   vals[0] = Serial.read();  // <-- this will be 1
   Serial.read();            // skip the 2
   vals[1] = Serial.read();  // <-- this will be 3
   Serial.read();            // skip the comma
   vals[2] = Serial.read();  // <-- this will be 1
   Serial.read();            // skip the 0
   vals[3] = Serial.read();  // <-- this will be 0
   Serial.read();            // skip the comma
   vals[4] = Serial.read();  // <-- this will be 9
   }

So you get the values: 1, 3, 1, 0, 9.

Is that really what you want?

(edit)

Plus the values are ASCII values (so '1' is really 49, '3' is 52, '0' is 48 and '9' is 57).

So you will set your 5 servos to: 49, 52, 49, 48 and 57.
Hmmm alright. I understand this better now. But with that said hows the best way to read the values?
33  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 08:12:30 pm
You are not thinking about this, you are trying stuff at random.

Look at that code and work through in your mind what will happen when it runs, bearing in mind that the code runs much faster than the serial port can receive data. Think about it in terms of a real-world analogy if it helps.

Somebody is sending you postcards. You can check the letterbox as often as you like. Sometimes there will be a postcard there, sometimes there won't. Now, how are you going to make sure you receive the complete set of cards and keep them all in order?

Nick Gammon has told you what you're doing wrong and how to do it right. Either take his advice and do it like he showed you, or stop and THINK about what you need to do to read a sequence of bytes from a serial port.

Great! thank you this helped! i think im understanding it now. Would something like this work?

Send:
Code:
   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("/");

Receive:
Code:
   while((char)Serial.read() !='.');
   
   if (Serial.available() >8)
   {
   
   vals[0] = Serial.read();
   Serial.read();
   vals[1] = Serial.read();
   Serial.read();
   vals[2] = Serial.read();
   Serial.read();
   vals[3] = Serial.read();
   Serial.read();
   vals[4] = Serial.read();
   }
   while((char)Serial.read() !='/')
   {
    myservo1.write(vals[0]);
    myservo2.write(vals[1]);
    myservo3.write(vals[2]);
    myservo4.write(vals[2]);
    myservo5.write(vals[3]);
    myservo7.write(vals[4]);
   }
34  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 07:52:35 pm
Quote
but after a few minutes it got all weird.
Because you are not checking that there IS something to read before EVERY read.

So something like this?
Code:
   

 
   if (Serial.available())
   vals[0] = Serial.read();
if (Serial.available())
   Serial.read();
if (Serial.available())
   vals[1] = Serial.read();

   
35  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 07:34:07 pm
What do you suggest about doing it a different way? I need this to work for a few hours or so. I had code that worked before but after a few minutes it got all weird.
36  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 07:17:02 pm

Are you talking about something like this?


Why do you keep ignoring what Nick Gammon tells you? You code looks nothing like what he is suggesting.
I'm trying to understand what he's saying and learn. I need to start somewhere
37  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 06:27:16 pm
Something like this?

No. Did my site have code like that there? Look,you have this:

Code:

   while((char)Serial.read() !='.');

   byte vals[5];
   vals[0] = Serial.read();
   Serial.read();
   vals[1] = Serial.read();
   Serial.read();
   vals[2] = Serial.read();
   Serial.read();
   vals[3] = Serial.read();
   Serial.read();
   vals[4] = Serial.read();

If there is no data Serial.date will return -1, so the "while" part will work OK. It will sit there until a dot arrives. Then, very quickly, you grab 5 more bytes, which since your processor is much faster than a serial port, will almost certainly be -1. So you have filled vals array with -1 (turned into 0xFF since vals is not an int).

Look at the code on the link I posted. First you just read and fill an array with data (using Serial.available() for every byte). Then when some delimiter comes, you go back and process it.
Are you talking about something like this?

Code:
void loop()
{

   while((char)Serial.read() !='.');
   
   if (Serial.available() >0)
   {
   byte vals[5];
   vals[0] = Serial.read();
   Serial.read();
   vals[1] = Serial.read();
   Serial.read();
   vals[2] = Serial.read();
   Serial.read();
   vals[3] = Serial.read();
   Serial.read();
   vals[4] = Serial.read();
   }
   
    myservo1.write(vals[0]);
    myservo2.write(vals[1]);
    myservo3.write(vals[2]);
    myservo4.write(vals[2]);
    myservo5.write(vals[3]);
    myservo7.write(vals[4]);
38  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 03:27:07 pm
Quote
Well that shouldnt matter to much should it?
I guess that it doesn't matter that they are compatible. Doesn't matter that they might be attached to shields that are configured to use something other than the Serial port. Doesn't matter that they might not be configured correctly.

You have two Arduinos that are failing to properly exchange data. Ignoring the mechanism that is used to exchange the data hardly seems like a good idea.
I have tested those radios before and they can talk to each other and communicate. The shields are xbee shields and those have worked before also. Its not a problem with the radios or anything physical i have had all of it working before. Its just code issues.
39  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 03:15:38 pm
Something like this?
Code:
void loop()
{
  if (Serial.available ())

   while((char)Serial.read() !='.');
   
   byte vals[5];
   vals[0] = Serial.read();
40  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 03:10:13 pm
Quote
So im using two xbees.
About which you have told us what? Nothing. Nothing about the type. Nothing about how they are attached to the Arduino. Nothing about how they are configured. Nothing about whether you know that they are communicating.
Well that shouldnt matter to much should it? they are just standard xbees attached with a shield. I have config them with a custom channel so only they can talk to eachother.
41  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 12:49:27 pm

Let me know if you have any questions.


Does it compile?

Does it do what you intend?

Does it do it reliably for as long as you need?
it does compile. Other than that nothing works.
42  Using Arduino / Programming Questions / Re: Wireless control system problem on: January 28, 2012, 03:43:06 am
Quote
Let me know if you have any questions.

What question are you asking?

In both sketches, you are doing Serial.reads, without checking that there is anything to read.
So do I just use if serial available? If so where would I put it?
43  Using Arduino / Programming Questions / Wireless control system problem on: January 28, 2012, 01:04:41 am
So im using two xbees. i need this code to work for a few hours so it needs to be solid. Let me know if you have any questions. Here is what i have:

Send:

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()
{  
    while((char)Serial.read() !='.');
    
    byte val = Serial.read();
    
    analogWrite(pwm_a, val);  
    
   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);
  

   delay(10);
}

Receive:

Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;

int potpin = A0;
int val;

void setup()
{
   Serial.begin(9600);
  
   myservo1.attach(2); //middle
   myservo2.attach(3); //thumb
   myservo3.attach(4); //ring
   myservo4.attach(5); //pinky
   myservo5.attach(6); //pointer
   myservo7.attach(7); //swivel
  
   Serial.print(".");
}

void loop()
{

   while((char)Serial.read() !='.');
  
   byte vals[5];
   vals[0] = Serial.read();
   Serial.read();
   vals[1] = Serial.read();
   Serial.read();
   vals[2] = Serial.read();
   Serial.read();
   vals[3] = Serial.read();
   Serial.read();
   vals[4] = Serial.read();
  
    myservo1.write(vals[0]);
    myservo2.write(vals[1]);
    myservo3.write(vals[2]);
    myservo4.write(vals[2]);
    myservo5.write(vals[3]);
    myservo7.write(vals[4]);
    
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  byte val = map(val, 0, 950, 0, 255);     // scale it to use it with the servo (value between 0 and 180)                 // sets the servo position according to the scaled value
  if (val>250){val=250;}
  Serial.print(".");
  Serial.print(val);
  
}

44  Using Arduino / Motors, Mechanics, and Power / Re: Double BTS7960B 43A Motor Driver question on: January 19, 2012, 09:45:16 pm
I actually just got it working. I had to have enable on high for both of L and R. hahah i know welcome to ebay lol
45  Using Arduino / Motors, Mechanics, and Power / Double BTS7960B 43A Motor Driver question on: January 19, 2012, 07:26:29 pm
I just got one of these in: http://www.ebay.com/itm/Double-BTS7960B-43A-Motor-Driver-High-power-module-smart-car-driver-Arduino-/150713543689?pt=LH_DefaultDomain_0&hash=item23173a2c09#ht_4319wt_1344

My question is how connect this to arduino. I tried just connecting it by powering the logic (5v, GND) and sending PWM signals to PWM R and PWM L (R=0,L=255) but nothing happened. I also tried putting the enables to HIGH.

Thank you
Pages: 1 2 [3] 4 5 ... 13