Show Posts
Pages: 1 2 [3] 4 5 ... 16
31  Using Arduino / Programming Questions / Re: Problem with creatint small sub on: December 15, 2013, 07:41:41 am
newAxis and rotorAxis are both a int and here's the defining part:
Code:
/****************************************************************************************
 * These values define the speed trajectory to reach a certain position. *
 * The higher the difference the higher the speed to move the antenna. *
 * Range from 180-20-8-2-0 degrees */
#define SPEED_DEG_1 = 200;
#define SPEED_DEG_2 = 80;
#define SPEED_DEG_3 = 20;
/****************************************************************************************/
int newXAxis;
int newYAxis;
int rotorXAxis;
int rotorYAxis;
The routine should do the following:
if the distance lies belowe the 200 then go go full speed,
between 200 and 80 use 3/4 speed, between 80 and 20 half speed
and below 20 use the minimum speed.
32  Using Arduino / Programming Questions / Re: Connecting 2 Arduinos via TX/RX pins on: December 15, 2013, 06:10:43 am
Is the connection on the hardware side correct?
Arduino1 TX goes to Arduino2 RX vise versa as you are talking on connecting two arduino's
33  Using Arduino / Programming Questions / Re: Problem with creatint small sub on: December 15, 2013, 06:07:37 am
Code:
#define SPEED_DEG_1 = 200;
Wrong. 
Do you really want SPEED_DEG_1 replaced by = 200; in your code when it is compiled ?
Yes
34  Using Arduino / Programming Questions / Problem with creatint small sub on: December 15, 2013, 05:43:58 am
I am trying to get a routine into a singe INT but get a error i dont get.

Code:
#define SPEED_DEG_1 = 200;
int newAxis = 1230;
int rotorXAxis = 0;

  int XrotationSpeed = rotorSpeed(abs(newXAxis - rotorXAxis));

int rotorSpeed(int toMove) {
  int Speed;

  if(toMove >= SPEED_DEG_1) {
    Speed = rotationSpeed4;  }
  else {
    Speed = rotationSpeed1;  }

  return Speed;
}
This is the error i get :  error: expected primary-expression before '=' token

Any help?
35  Using Arduino / Programming Questions / Re: How to make this display a negative value correct on: December 10, 2013, 05:30:02 pm
You should read the document. If your maximal is 100.00 and possibly -100.00 as minimal, then you need 7 total spaces and DON'T pad it with spaces, cause dtostrf does it already.
I am surely missing something here as i dont see dtostrf padding spaces.
Now i have this code but stil no succes with the neg numbers.
I must bre dumber than dumb but i dont see it.
Code:
char * displayAxis(double axis)  {
  boolean isNeg = false;
  static char buffer[9];
  uint8_t idx = 0;
  uint8_t idl = 3;
  axis = axis/100;
  if(axis < 0.0) {
//    buffer[idx++] = '-';
    Serial << "NEG" << endl;
    isNeg = true;
  }
  if(axis < 100.0 && !isNeg) {
    buffer[idx++] = ' ';
    idl = 2;
  }
  if (axis < 10.0 && !isNeg) {
    buffer[idx++] = ' ';
    idl = 1;
  }
  dtostrf(axis,idl, 2, &buffer[idx]);
  return buffer;
}
36  Using Arduino / Programming Questions / Re: .toInt() doesnt return correct value on: December 10, 2013, 11:18:33 am
O stupid me  smiley-cool Testing by just using all the numbers on the keyboard.
37  Using Arduino / Programming Questions / .toInt() doesnt return correct value on: December 10, 2013, 11:03:15 am
Maybe i am missing something but in the code below the first .toInt() returns the correct value, but the second doesn't.
Code:
#include "Arduino.h"
#include <Streaming.h>

String axisValueString = "";

int commandCounter = 0;
int newXAxis;       // The new XY position
int newYAxis;       // 

void setup()
{
  Serial.begin(19200);
  while(!Serial);
  Serial << "System ready" << endl;
}

void loop()
{
  if(Serial.available())
  {
    readCommand(Serial.read()); 
  }
}

void readCommand(char ch)
{
  if (ch == ',' || ch == '\n' || ch == '\r') {
    if(ch == ',') {
      newXAxis = axisValueString.toInt();
      Serial << "Received comma" << endl;
      Serial << "Got the first axis value = " << axisValueString << endl;
      Serial << "Converted to INT = " << newXAxis << endl;
      axisValueString = "";
    }
    if(ch == '\n' || ch == '\r') {
      newYAxis = axisValueString.toInt();
      Serial << "Received end of line" << endl;
      Serial << "Got the second axis value = " << axisValueString << endl;     
      Serial << "Converted to INT = " << newYAxis << endl;
      axisValueString = "";
    }
  }
  else
  {
    if(ch != '.') {
      axisValueString += ch;
    }
  }
}
Entered the following sequence:  123.45,678.90

This is the result:
Quote
System ready
Received comma
Got the first axis value = 12345
Converted to INT = 12345
Received end of line
Got the second axis value = 67890
Converted to INT = 2354

The second axis value is correct but the int is not correct

Harry.
38  Using Arduino / Programming Questions / Re: How to make this display a negative value correct on: December 10, 2013, 10:00:27 am
The tests for the magnitude of axis only work for positive axis, not negative - the absolute
value should be taken before comparing to 10.0 or 100.0
But then remains the question how to print the -n sign?
39  Using Arduino / Programming Questions / How to make this display a negative value correct on: December 09, 2013, 02:40:31 pm
I am using this little routine to display a value on a LCD display:
Code:
String displayAxis(double axis)  {
  static char Buffer[7];
  String SString = "";
  if(axis < 10.0)   {
    SString += " ";
  }
  if(axis < 100.0)  {
    SString += " ";
  }
  dtostrf(axis,4, 2, Buffer);
  return SString += Buffer;
}

this is the calling code:
Code:
      lcdSerial.setCursor(0,1);
      lcdSerial << " X/Y  " << displayAxis((float)newXAxis) << " " << displayAxis((float)newYAxis);
      lcdSerial.setCursor(0,2);
      lcdSerial << "Rotor " << displayAxis((long)rotorXAxis) << " " << displayAxis((long)rotorYAxis);

But if the number is negative it jumps to the next line.
The LCD used is a 20x4 character display and the maximum number to be displayed is 180.00 and the negative number  looks like -9.00.

Any help would be welcome
40  Using Arduino / Programming Questions / INT0 and INT1 and internal resistor on: December 09, 2013, 12:44:53 pm
I know that the the input has a pull-up resistor that can be activated.
Can this also be done with the Interrupts and if so how as i cant find anything in the reference.

Harry
41  Using Arduino / Programming Questions / Re: The best place to put the Interrup routines in a sketch on: September 18, 2013, 12:24:18 pm
Thnx
42  Using Arduino / Programming Questions / The best place to put the Interrup routines in a sketch on: September 18, 2013, 05:55:41 am
As i know from long time ago when using a PIC, the interrupt routines should be placed at the start of the program space.
Is this the same for the Arduino?
43  Using Arduino / Programming Questions / Re: ABS() gives strange result on: September 17, 2013, 03:02:37 pm
Thnx for pointing out. I now changed the code to this:
Code:
 long difX = rotorXAxis - newXAxis;
  long difY = rotorYAxis - newYAxis;

  Serial << "X " << abs(difX) << endl;
  Serial << "Y " << abs(difY) << endl;
*EDIT*
After some reading i found the solution to the problem. Its a simple change by changing from unsigned long to long.
Code:
unsigned long newXAxis   = 100000L;       // The new XY position
long newYAxis   = 145000L;       // 
long rotorXAxis = 123000L;     // This is the acual XY rotor position
long rotorYAxis = 123000L;
Now i can use the math inside the abs function.
44  Using Arduino / Programming Questions / ABS() gives strange result on: September 17, 2013, 01:21:27 pm
I want to know the absolut value of two different numbers.
Code:
unsigned long newAxis;        // Contains the new axle value * 1000
unsigned long newXAxis   = 100000L;       // The new XY position
unsigned long newYAxis   = 145000L;       // 
unsigned long rotorXAxis = 123000L;     // This is the acual XY rotor position
unsigned long rotorYAxis = 123000L;

  Serial << "X " << abs(rotorXAxis - newXAxis) << endl;
  Serial << "Y " << abs(rotorYAxis - newYAxis) << endl;
But the result of the Y value is strange.
X 23000
Y 4294945296

The X value is correct but the Y value should be 22000.
Is therer something wrong with the types?
45  Using Arduino / Programming Questions / Re: Dit i mis something using atol on: September 17, 2013, 12:14:22 pm
Thnx but that wont work for the second routine where i added some extra code to tackle the presents of 2 decimals.
But i wil give it a go
Pages: 1 2 [3] 4 5 ... 16