Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 10
61  Using Arduino / Interfacing w/ Software on the Computer / Serial Communication C++ -->Arduino on: March 03, 2011, 03:40:19 pm
Hi, I am trying to get some help on interfacing the Arduino with a C++ program running on a computer.  Here is the "tutorial" I am trying to follow:  http://arduino.cc/playground/Interfacing/CPPWindows
I am a little confused on how to use it, do I create a new file for the actual program or do I just edit the Serial.cpp program?  I am using Visual Studio 2010 ultimate and have a Project called Serial_to_Arduino, with only two files, SerialClass.h and Serial.cpp.  Anybody have any suggestions?
Thanks a ton.
62  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 07:15:10 pm
UPDATE: I removed the delayMicroseconds().  Found a proper value to divide "time" by and now I get pretty accurate times.  For the final test, I will connect pin 9 on the uno to another OUTPUT pin on a Mega and write the pin LOW from the MEGA for varying small and large amounts of time to get an even more accurate value.  Below is my code that seems to work well (at least for now).  Thanks everyone for all your help for the hardware and software.
Code:
int speed1 = 9;
int tripped;
float time;
float Speed;

void setup()
{
  pinMode(speed1, INPUT);
  Serial.begin(9600);
  Serial.println("Ready to Test Speed");
  digitalWrite(speed1, HIGH);
}

void loop()
{
  tripped = digitalRead(speed1);
  if (tripped ==0)
  {
    time = 0;
    Serial.println();
    Serial.println("Reading...");
    while (tripped == 0)
    {
      time = time++;
      tripped = digitalRead(speed1);
    }
    time = (time)/70070;
    Serial.println(time);
//    Speed = (5.0/12.0) / time;  (5 in/12 in) / duration = X ft/s
    Serial.println(Speed);
  }
}
63  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 05:06:50 pm
yeah, thats all i would want the input pin (9) to read, HIGH or LOW, 1 or 0.  I don't see how that has anything to do with the timing problem
64  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 05:04:15 pm
Im sorry but i have no idea as to what you are referring to
65  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 04:38:39 pm
sensor pins will be approx 6-7" apart, enough for the rod to go through and not mess with the other sensors.  if i just do something like:
Code:
while (tripped == 0) { time++;  tripped = digitalRead(speed1);  }
  How many times would "time" increment?  Theoretically, the Arduino goes at 16MHz, so within 1 second, 16,000,000 lines of code would be run divided by two for the "tripped" checking...so it would be incremented 8,000,000 times?  of course it wouldn't exactly by this as a single line of code be a couple lines of code in the actual program counter...does this sound about right?  then maybe i could not do a delay
66  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 03:33:32 pm
I dont need all ten to work, if i can get one to work then the others wont be a problem.  at that speed (2800 ft/s or 33600 in/s, the rod will cover .0336" every one microsecond, and considering my rod is only 5" then the rod the speed measuring contact will be tied to gnd for 1388.88 microseconds (if i've done my simple math correctly   smiley-grin).  This should be easily measurable by the arduino
67  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 01:45:35 pm
Quote
I thought you had something fast occurring which is why you wanted to measure 10uS periods.

Basically I need ten of these "speed sensors" in cascading form, as the rod goes through each one of these speed traps i get a speed for that location, and the rod will be moving very fast, (~2800ft/s) so this needs to measure very quickly...10s was just a test for accuracy...
68  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 11:27:44 am
okay i did have a good understanding of things and now im lost again.  with the pullup resistor enabled, pin 9 is 1 by default so i need to test to see if 9 has gone to 0, if it has then start the while loop, as for the delay, i simply was using that give myself a specified time of increment instead of the 16mhz that the arduino is running on.  im a little confused about the start time microseconds and the end time microseconds thing.  i've gotten so many posts about different code im all confused now.

while i was typing crossroads added more stuff, so do you mean to use 2 pins for the measurement?  I plan on having at least 10 of these running simultaneously, so that would mean i would need a minimum of 20 pins, plus the 10 or so i will need for control (over other things in the project) so im up to 30+pins.  seems like a lot
69  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 02:31:42 am
okay, i have replace the while loop with this:
Code:
while (tripped == 0)
  {
    delayMicroseconds(5);
    time = time++;
    tripped = digitalRead(speed1);
  }
this seems to work pretty well, i just need to tinker with the delay a little bit to get a more exact value...not to mention i will never be as fast as the microsecond range, so i will never get exactly 10s lol
70  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 02:14:28 am
Also an update on the how the program is going...i get a good consistent time value after holding it to gnd for 10s...but when i untie it from gnd, i get between 4 and 4.5 seconds as opposed to 10.  I tried doubling and halving the delay and increment amount but that didnt really help much.  the halving gave me about 2.9 and doubling gave about 6-6.5s...any timing suggestions?

with regards to the switch bounce, i hope it wont cause problems but i will have to wait till im with the rest of my equipment to test that out.
71  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 02:05:09 am
yes i am aware of that problem.  we recently explored this in a class i had last quarter.  but if i recall correctly the only hardware ways we fixed it were with a flip flop and/or with some logic gates.  neither of which i want to have to use of course.  do you think switch bounce would really cause problems for me?
72  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 01:47:50 am
so let me see if i have the circuit concept down.  the internal pullup resistor for pin 9 is enabled thus creating a connection such that pin 9 is constantly held high, but if the rod connects pin 9 to gnd then pin 9 is pulled low thus giving me a clean 0.  On the flip side, when the gnd conneciton is not made then i have a clean 1.  this sound about right?
73  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 01:42:54 am
i have made a couple of changes, how about this:
74  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 01:29:01 am
this is what im goin for, please excuse my really bad drawing capabilities

75  Using Arduino / Programming Questions / Re: Simple While Loop Problem on: February 03, 2011, 01:16:51 am
what i actually plan on hooking up is a jumper to pin 9 and a jumper to arduino 5v and when a steel rod passes through the two jumpers it completes the circuit, Pin 9 is HIGH and the while loop is started.  then when the rod is gone pin 9 goes back to LOW and the while loop ends.  then with the appropriately incremented "time", I divide the length of my rod by "time" and there is my speed
Pages: 1 ... 3 4 [5] 6 7 ... 10