Show Posts
Pages: 1 2 3 [4] 5 6 ... 285
46  Using Arduino / Programming Questions / Re: Function dtostrf() on: August 17, 2014, 01:34:48 am
I do not understand the Function dtostrf () Please explain.
What is it that you do not understand ?  Have you tried to use it and got unexpected results ?
47  Using Arduino / Programming Questions / Re: skaarhoj ATEM arduino Control Code on: August 16, 2014, 12:25:24 pm
I know nothing about the library that you are using or how it works, but this
Code:
AtemSwitcher.delay(5000);
looks very much like it waits for 5 seconds during which time it will not respond to any input.  If that is the case then no wonder
Quote
sometimes it takes a few seconds to respond, sometime it is instant.

What is the delay there for ?
48  Using Arduino / Programming Questions / Re: Push Buttons not working as expected to toggle RGB LED on and off. on: August 16, 2014, 05:19:43 am
Code:
    if (purpleCounter % 2 == 0) {
      setColor(255,0,255);
Code:
    if (redCounter % 2 == 0) {
      setColor(255,0,255);
Both of these can't be true because they use the same output values for two different colours.
49  Using Arduino / Programming Questions / Re: PC Shutdown/Startup controller on: August 15, 2014, 11:29:38 am
Put it in the loop() function.  You said that you intended to keep the Arduino running, which may not be a great idea due to battery drain.  If the Arduino is not to be kept running then I don't see the need for it anyway.  Just use a toggle switch to power the PC on/off.  Either way, how are you going to deal with shutting down the PC nicely rather than simply turning it off when commanded ?
50  Using Arduino / Programming Questions / Re: a little help more like a lot on: August 15, 2014, 11:23:57 am
Quote
iPodInfoSystem_v03_redo:154: error: 'class AdvancedRemote' has no member named 'setup'
Have you got any examples of code using AdvancedRemote.setup() ?  If not then why do you believe that it exists and should be used ?  There is no setup() function in AdvancedRemote.h so it is no surprise that your program will not compile.

It is possible that more than one version of the library exists or that there are two or more different libraries with the same name.
51  Using Arduino / Programming Questions / Re: Controlling LED's with Trackbar in VS on: August 15, 2014, 08:30:51 am
Quote
I am just trying to get this first slider to work and know that it is working correctly then I was thinking about adding another two sliders for the RGB.
If that is the case then I would strongly advise that you proceed each of the individual RGB values with an identifier so that on the Arduino you can spilt the serial input and adjust the appropriate R, G or B value.  So, the Arduino logic becomes
Code:
if serial input is available
  read a byte
  if the byte is R, G or B
    read the next byte when it is available
    call a function to adjust R, G or B output passing the colour identifier and byte value as parameters
  end if
end if
Using that logic will allow you to send the R, G or B value only when it changes and for the Arduino to react to the changes.  That way the serial traffic is much reduced compared with constantly sending the 3 values and the colour identifier allows the Arduino to get back in step if some serial data is missed or corrupted.

In your test code
Code:
    *int red = Serial.parseInt();
    int green = Serial.parseInt();
    int blue = Serial.parseInt();
why is the red value a pointer and the green and blue ones not ?
52  Using Arduino / Programming Questions / Re: Controlling LED's with Trackbar in VS on: August 15, 2014, 06:51:19 am
Quote
Is this sending the textbox values (0-255) to the arduino, the Rx light is certainly flashing.
I don't know enough about VS to give advice on this.  To start with how about just sending a byte with a fixed value to the serial port from VS rather than the value from the slider ?  That way you know what you are sending and, therefore, what you expect to receive.

Quote
Is this the correct way of doing this, reading as an integer? Or should it be as Byte, Char etc.
Serial data arrives one byte at a time so that is what you need to read. 

Code:
if(sliderVal >= '0' && sliderVal < '11')
This will not work because you are receiving bytes but testing for chars.

Write a program to wait until there is serial data available then read a byte and print it. If you follow my suggestion to send a known value then you will know if what you are getting is correct.  Next step, send a series of known values, receive them and print them.  Now you know that what you are sending is what you are receiving.  Next step, send the slider value, receive it and only print it when it changes (or only send it when it changes). 

Come back and post the Arduino code when you have got that working. 

In the meantime can you describe what the relationship should be between the slider value received and the RGB value or are there going to be 3 sliders in VS, one each for R, G and B ?
53  Using Arduino / Programming Questions / Re: Controlling LED's with Trackbar in VS on: August 15, 2014, 04:49:19 am
Quote
I need to be able to read a byte then start fading. Read second byte from slider and start fading again and keep doing this until the slider is all the way to ten.
I don't get this.  Please can you describe the actions that will be taken on the PC and the result you want to achieve on the Arduino as a result of the actions ?

Quote
Is this sending ten bytes i.e: A byte for each tick on the slider?
I don't know, but I still think that all you need to send is TrackBar1.Value..  Then on the Arduino read the incoming value when Serial data is available and call a function to set the RGB values appropriately for the value received, assuming that the slider position is to control the RGB output.  However, once you describe what you want to happen more advice can be given.
54  Using Arduino / Programming Questions / Re: How to display on serial monitor? (Questions and Answer Input) on: August 15, 2014, 02:44:29 am
Code:
   int qNumber = Serial.read()// code to get a question number and save it in qNumber
   if (qNumber == '0')// put 0 in qNumber if there is no response or an invalid number
Both lines are missing the terminating semi-colon

Code:
      case 2:
           questionB();
           break;
There is no questionB() function in the program

Code:
  correctAnswer = '';
The correctAnswer variable is not declared in the program.
55  Using Arduino / Programming Questions / Re: PC Shutdown/Startup controller on: August 15, 2014, 01:40:47 am
Quote
I don't want the script to loop because it would just keep pulsing the header.
Have the code controlled by if statements.
Code:
if pcRunning is false
  code to read car ignition voltage and start the PC if the ignition is on
  set pcRunning to true
end if
else
  code to read car ignition voltage and stop the PC if the ignition is off
  set pcRunning to false
end else
A car is a pretty rough electrical environment so it may not be simple to get this working.
56  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 ?
57  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.
58  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
}
59  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--;
  }
}
60  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.
Pages: 1 2 3 [4] 5 6 ... 285