Show Posts
Pages: 1 ... 8 9 [10] 11 12 ... 290
136  Using Arduino / Programming Questions / Re: Serial.read() is reading values that are unintentionally sent on: August 14, 2014, 01:03:22 pm
Can we see the code that you are using to read and display the input ?
137  Using Arduino / Programming Questions / Re: Using Quadrature Encoder Library - Issue on: August 14, 2014, 11:03:23 am
What happens to the output if you change the order in which the 3 values are read ?  Does the first one always work ?

What happens if you change the pins used by the encoders so that mKnob, for instance, is on pins 20 and 21 ?

In passing
Code:
  if ((millis() % 100) == 0)
relies on millis() returning all values when checked, but I am sure that this is not always the case, so the output may not always happen at regular intervals.  It would be more certain if you used the
Code:
if (millis() - startTime >= interval)
technique although in your test program it will not matter I assume if a few readouts are missed.
138  Using Arduino / Programming Questions / Re: About the "int" data type variable on: August 14, 2014, 09:33:30 am
Quote
So my question is, what is it about the int variable that lets you store "LOW" or "HIGH" in it, and not a number?
You have the question the wrong way round.  HIGH and LOW (no quote marks) are defined as numbers behind the scenes so that they can be stored in an int.  Even better because it saves space, they can be saved in a byte if you want to.  A boolean takes a byte of space to store true or false so would also save space compared with an int.  Better still it makes the program more readable if good variable names, such as
Code:
boolean ledOn = true;
and you can also shorten tests as in
Code:
if (ledOn)
{
  //do stuff if the led is on
}
139  Using Arduino / Programming Questions / Re: Programming the Odometry of Rover 5 on: August 14, 2014, 09:25:37 am
Does the program produce the results as you would expect ?  You are not outputting any of the values calculated so how do you know what is happening ?

Code:
  pinMode(encoder1A, INPUT);
  digitalWrite(encoder1A, HIGH);       // turn on pullup resistor
is easier to understand if you write it as
Code:
  pinMode(encoder1A, INPUT_PULLUP);

Code:
float ER = 333.3;      //encoder resolution (in pulses per revolution)  where in Rover 5,  1000 state changes per 3 wheel rotations
I am intrigued by this as it implies that you can have a third of a pulse.  Can you please provide a link to the hardware that you are using.

Code:
  attachInterrupt(0, doEncoder, CHANGE);       // encoder pin on interrupt 0 - pin 3
What is attached to pin 3 ?  It would appear to be signal B of the right encoder.  Shouldn't the left encoder also trigger the interrupt ?

Code:
Pi * dia
Consider making the result of this multiplication a constant to avoid repeatedly calculating it as it is not going to change whilst the program is running.

Code:
/* If pinA and pinB are both high or both low, it is spinning   
   * forward. If they're different, it's going backward.
   */
Are you sure that this is true ?  I am not saying that it isn't, because I don't know, but you need to be sure.

Is there any way in which you can avoid the floating point calculations which by the nature of the Arduino are slow.  Multiply all units by 100 and work in integers perhaps ?

I have taken the liberty of removing the unnecessary blank lines from your program to make it easier to read and it now looks like this
Code:
#define encoder1A  0       //signal A of left encoder  (white wire)
#define encoder1B  1      //signal B of left encoder  (yellow wire)
#define encoder2A  2      //signal A of right encoder  (white wire)
#define encoder2B  3      //signal B of right encoder  (yellow wire)
volatile int encoderLPos = 0;      // counts of left encoder
volatile int encoderRPos = 0;     // counts of right encoder
float  dia = 61  ;         // wheel diameter (in mm) 
float Dl, Dr, Dc, Ori_ch;
float ER = 333.3;      //encoder resolution (in pulses per revolution)  where in Rover 5,  1000 state changes per 3 wheel rotations
int x = 0;           // x initial coordinate of mobile robot
int y = 0;           // y initial coordinate of mobile robot
float Ori  = 0;       // The initial orientation of mobile robot
float Pi = 3.14;
float b=183  ;       // b is the wheelbase of the mobile robot in mm

void setup()
{
  pinMode(encoder1A, INPUT);
  digitalWrite(encoder1A, HIGH);       // turn on pullup resistor
  pinMode(encoder1B, INPUT);
  digitalWrite(encoder1B, HIGH);       // turn on pullup resistor
  pinMode(encoder2A, INPUT);
  digitalWrite(encoder2A, HIGH);       // turn on pullup resistor
  pinMode(encoder2B, INPUT);
  digitalWrite(encoder2B, HIGH);       // turn on pullup resistor
  attachInterrupt(0, doEncoder, CHANGE);       // encoder pin on interrupt 0 - pin 3
  Serial.begin (9600);
}

void loop()
{
  Dl= Pi * dia * (encoderLPos/ ER);       // Dl & Dr are travel distance for the left and right wheel respectively
  Dr= Pi * dia * (encoderRPos/ ER);     // which equal to pi * diameter of wheel * (encoder counts / encoder resolution )
  Dc=( Dl + Dr) /2 ;            // incremental linear displacement of the robot's centerpoint C
  Ori_ch=(Dr - Dl)/b;          // the robot's incremental change of orientation , where b is the wheelbase of the mobile robot ,
  Ori = Ori + Ori_ch ;          //  The robot's new relative orientation
  x = x + Dc * cos (Ori);      // the relative position of the centerpoint for mobile robot
  y = y + Dc * sin(Ori);
}

void doEncoder()
{

  /* If pinA and pinB are both high or both low, it is spinning   
   * forward. If they're different, it's going backward.
   */

  if (digitalRead(encoder1A) == digitalRead(encoder1B))
  {
    encoderLPos++;
  }
  else
  {
    encoderLPos--;
  }

  if (digitalRead(encoder2A) == digitalRead(encoder2B))
  {
    encoderRPos++;
  }
  else
  {
    encoderRPos--;
  }
}
140  Using Arduino / Programming Questions / Re: how to print 3 ds18b20 values to lcd on: August 14, 2014, 07:57:09 am
My suggested solution of passing an extra parameter to the function that displays the temperatures will allow you to put each temperature on its own line of the LCD by passing the required line number to the function.  You could expand the idea further by passing both the row and column if required. 

An alternative approach would be to keep an row number counter in a variable and to increment it in the function each time you output a value, resetting it to its initial value once the final temperature had been printed, but this would be less flexible.
141  Using Arduino / Programming Questions / Re: how to print 3 ds18b20 values to lcd on: August 14, 2014, 01:24:16 am
Which part are you having trouble with ?
If it is positioning the LCD output on the right line then consider adding a separate parameter to the function so instead of
Code:
  printTemperature(sumpProbe);
use
Code:
  printTemperature(sumpProbe, 0);
and in the function
Code:
void printTemperature( DeviceAddress deviceAddress, byte LCDrow)
and then
Code:
    lcd.setCursor(1, LCDrow); 
    lcd.print(" sumpProbe F: ");
    lcd.print(DallasTemperature::toFahrenheit(tempC));
142  Using Arduino / Programming Questions / Re: Servo rotation angle on: August 13, 2014, 02:52:22 pm
Quote
So, how can i do this function , I need something to rotate only 45 degrees and stop rotating ( High torque motor and be small )
The answer is in my first reply.  Use a normal servo, not one that has been bastardised to rotate continuously.
143  Using Arduino / Programming Questions / Re: Servo rotation angle on: August 13, 2014, 02:14:12 pm
What you have is not a servo, hence it does not have a feedback mechanism so cannot be stopped at a particular angle without external hardware.  Why not use a real servo ?
144  Using Arduino / Programming Questions / Re: 7-Segment Time Display on: August 13, 2014, 02:41:50 am
Quote
I understand that I can use the Time library

(http://playground.arduino.cc/Code/Time)

to obtain the current time without any external hardware
Stop right there.  You can certainly use the Time library without any external hardware but don't expect the clock to be accurate to more than a few seconds a day and maybe worse.  Start by getting an RTC to keep time for you.
145  Using Arduino / Programming Questions / Re: RPM using hall effect sensor on: August 12, 2014, 04:26:09 pm
Quote
I'm not good programmer
Have you tried using the sensor at all ?
146  Using Arduino / Programming Questions / Re: Arduino does not recognize new line from Matlab fprintf on: August 12, 2014, 03:31:23 pm
Code:
  pinMode(1, OUTPUT);      // sets the digital pin as output
Code:
  pinMode(0, OUTPUT);
Pins 0 and 1 are used by used by hardware Serial so I forsee a problem with using them as outputs
147  Using Arduino / Programming Questions / Re: Arduino as Datalogger- Sketch logs date but not theanalog voltage on SD card! on: August 12, 2014, 02:01:49 pm
To me that makes no sense. 
Without the comma the data in the file would have been formatted differently but it should still have been present.
148  Using Arduino / Programming Questions / Re: Sketch to slow servo speed when using flex sensor on: August 12, 2014, 07:28:17 am
Try this as a start point
Code:
#include <Servo.h>

int flexpin=A0;
int pos;

Servo myServo;
int flexSum;

void setup()
{
  myServo.attach(7);
}

void loop()
{
  flexSum = 0;
  for(int x=0; x < 20; x++)
  {
    flexSum = flexSum + analogRead(flexpin);
    delayMicroseconds(14);
  }
  flexSum = flexSum / 20;

  pos = map(flexSum,870,800,0,90);
  moveServo(pos);
}

void moveServo(int targetPos)
{
  for(int servoPos = 0; servoPos <= targetPos; servoPos++)
  {                     
    myServo.write(servoPos);
    delay(70);
  }

  for(int servoPos = targetPos; servoPos >= 0; servoPos--)
  {                               
    myServo.write(servoPos);
    delay(70);
  }
}
I do not have the hardware to try it on so there may be problems with it.  Note that it only deals with one sensor and servo but that can be extended using arrays, and that I have changed some of your variable names to make more sense.
149  Using Arduino / Programming Questions / Re: Controlling LED's with Trackbar in VS on: August 12, 2014, 07:09:41 am
You have changed the subject slightly by wanting to accept a string rather than a value from the slider but this should get you started.
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=11425&page=1
You need to terminate the incoming string in some way so that the Arduino can recognise that a complete command has been received and act on it.  You could use fixed length messages but using serial there is no guarantee that every character will be received as sent, so a delimited string is a safer way to do it.
150  Using Arduino / Programming Questions / Re: Sketch to slow servo speed when using flex sensor on: August 12, 2014, 04:25:10 am
Quick and dirty method.
Put all the code in the loop() function of the second program in a function in the first program and call it instead of
Code:
myservo.write(pos);
in the first program.  Do you want/need the servos to move at the same time ?  If so then it is a little more complicated but I suggest that you get one working first.

Incidentally, what does this do for you in the first program ?
Code:
if(Serial.available())
{
Serial.println(flexsum);
Serial.println(flexsum1);
delay(100);
}
You have no serial input so the test will always fail.

I assume that you know that the second program does not do exactly what the comments say
Code:
  for(pos = 0; pos <= 85; pos += 1)  // goes from 0 degrees to 180 degrees
Pages: 1 ... 8 9 [10] 11 12 ... 290