Show Posts
Pages: 1 2 [3] 4 5 ... 15
31  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
32  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
33  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?
34  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.
35  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?
36  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
37  Using Arduino / Programming Questions / Re: Dit i mis something using atol on: September 17, 2013, 10:01:39 am
Although you want to help me but just saying use this or that function doesnt help me.
As i dont know where to use this proposed function i cant do anything with the reply.
Please dont feel offended but thats how it is.
As i told before i am not a programmer thats using C++ for life.
Its not even that i am working with this every week, more once in a few months.
38  Using Arduino / Programming Questions / Re: Dit i mis something using atol on: September 17, 2013, 02:33:52 am
Quote
Maybe i could do things more streamline but it works for me.
A lot less code if you just used toInt() or toFloat().
I can find something on the toInt() but nothing on the toFloat().
Not even sure how to use these as i am not a C++ programmer with years of knowledge.
Its all try and error to work my way to writing a program.
39  Using Arduino / Programming Questions / Re: Periodical call of a function on: September 16, 2013, 02:41:55 pm
In a sketch that i am building, i have to call the motor function more than the display update.
So i constructed this:
Code:
void loop() {
  unsigned long rtcCurrent = millis();
  if (Serial.available())  {
    readCommand(Serial.read());
  }
  if(rtcCurrent > rtcLastDisplayUpdate) {
    if(rtcCurrent - rtcLastRotorUpdate > rtcLastRotorUpdateInterval) {
      rtcLastRotorUpdate = rtcCurrent;
      updateRotorMovement();

    }
    if(rtcCurrent - rtcLastDisplayUpdate > rtcLastDisplayUpdateInterval) {
      rtcLastDisplayUpdate = rtcCurrent;
      displayMessages();
    }
  }
  else  {
    rtcLastDisplayUpdate = rtcCurrent;
    videreCommand = false;
  }
}
Its just a example
40  Using Arduino / Programming Questions / Re: Dit i mis something using atol ]:D on: September 16, 2013, 02:36:21 pm
Thanks guy's but i managed to create something that works for me now.
After posting this i realized i have to handle som decimals in that string as well.
So i came up with this:
Code:
String readString = "";
unsigned long newAxis;
int XY = 0;

void readCommand(char character)
{
  int decCount = 0;
  if (character == ',' || character == '\n' || character == '\r')
  {
    if(character == ',')
    {
      XY++;
    }
//    Serial << "Got a String" << endl;
    if(readString.length() > 0)
    {
//      Serial << "Received " << readString << endl;
      for(int i=0; i < readString.length(); i++)
      {
        if(readString[i] == '.')
        {
          decCount++;
        }
        else
        {
          newAxis = newAxis * 10 + (readString[i]-48);
          if(decCount > 0) decCount++;
        }
      }
//      Serial << "Decimals " << decCount << endl;
      switch(decCount)
      {
      case 0:
        {
          newAxis = newAxis *1000;
          break;
        }
      case 2:
        {
          newAxis = newAxis *100;
          break;
        }
      case 3:
        {
          newAxis = newAxis *10;
          break;
        }
      }
//      Serial << "XY " << XY << endl;
      if(XY == 3)
      {
        Serial << "New Y Axis " << newAxis << endl;
        XY = 0;
      }
      if(XY == 2)
      {
        Serial << "New X Axis " << newAxis << endl;
        XY++;
      }
      readString = "" ;
      newAxis=0;
    }
  }
  else {     
    readString += character; //builds the string readString
  }
}

Maybe i could do things more streamline but it works for me.
41  Using Arduino / Programming Questions / Dit i mis something using atol on: September 16, 2013, 12:51:48 pm
I have a smal piece of code that should convert a string containing a number, eg 179, to a number like 179000.
Thinking i could use atol constructed this routine:
Code:
unsigned long NewXaxis;

void readCommand(char character)
{
  if (character == ',' || character == '\n' || character == '\r')
  {
    Serial << "Got a String" << endl;
    if(readString.length() > 0)
    {
      Serial << "Received " << readString << endl;
      readString += "0";  // make it 0 terminated
      NewXaxis = atol(readString) * 1000;
      Serial << "New X Axis " << NewXaxis << endl;
      readString = "" ;
    }
  }
  else {     
    readString += character; //builds the string readString
  }
}

I know that atol only can work with 0 terminated strings, so i added that ad the end of readString.
But wont compile saying:
error: cannot convert 'String' to 'const char*' for argument '1' to 'long int atol(const char*)'
Am i thinking to simple and if so how to solve this.
42  Using Arduino / Programming Questions / New Topic name, How to convert from a decimal to a numbrer on: September 15, 2013, 09:14:20 am
As i am not so good of translating whats in the head en writing it down i give it a try.
Froma program on a computer i am getting a number like 179.99 and i want to change that to  179990.
I have to compare this with a number later on that is created from a rotationg axle pulse.
Not wanting to write all the code in one go i am trying to write all the single pieces and then combine them.
43  Using Arduino / Programming Questions / How to convert a string to a long on: September 15, 2013, 08:54:03 am
As i know ATOL can nul terminated string convert to a long.
But my string is NOT terminated by a NUL.
Created a sketch i thought that would work but is does nor produce te result i want.
Code:
#include <Streaming.h>

unsigned long NewXaxis;

String readString = "";

void setup()
{
  Serial.begin(19200);
  delay(1000);
  Serial << "Ready" << endl;
}

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

void readCommand(char character)
{
  if (character == ',' || character == '\n' || character == '\r')
  {
    Serial << "Got a String" << endl;
    if(readString.length() > 0)
    {
       Serial << "Received " << readString << endl;
       NewXaxis = stringToNumber(readString);
       Serial << "New X Axis " << NewXaxis << endl;
       readString = "" ;
    }
  }
  else {     
    readString += character; //makes the string readString
  }
}

int stringToNumber(String thisString) {
  int i, value = 0, length;
  length = thisString.length();
  for(i=0; i<length; i++) {
    value = (10*value) + thisString.charAt(i)-(int) '0';;
  }
  return value;
}

The maximum number that the program must handle = 179.99.
Anny suggetsions?
44  Using Arduino / Installation & Troubleshooting / Re: Strange UNO USB problem on: August 07, 2013, 03:02:58 am
Wrong COM port perhaps?
Post the code
It has nothing to do with the Arduino code.
Seems to be a Windows7 USB problem.
45  Using Arduino / Installation & Troubleshooting / Strange UNO USB problem on: July 30, 2013, 12:13:15 am
I have for about a week a UNO smd-edition. Inside the Arduino IDE it works fine but when i tried to connect to it by a terminal is wont work.
Also with a program that writes something to the UNO says that the com port doesnt response.
Mine whas connected to Com5, but even changing it to another port doesnt help.

Anny suggestions?
Pages: 1 2 [3] 4 5 ... 15