Show Posts
Pages: 1 [2] 3
16  Using Arduino / Programming Questions / Read a 2-variable 'MAP' on: February 20, 2012, 05:35:32 am
Is it possible, using a library or just straight coding, for 2 variables (inputs)  to be read and then an output decided on a 'MAP' of values and the 2 variables??

Something Like;



     1    2    3    4    5    6    7    8
1   a    b    c    d    e    f    g     h
2   i     j     k    l     m  n    o    p
3   q    r     s     t    u    v    w   x
4   y    z   etc   etc 

6
7
8

therefore, if input A = 2, and input B = 4, output = z.

Cheers!
17  Using Arduino / Programming Questions / Looped Timer with display on: February 10, 2012, 02:39:17 am
Hey all,
Working on something here and part of it calls for a routine to be run every x seconds. . (in reality, it will end up being somewhere around 15 minutes or so). This routine needs to be timed as well, also to x seconds (again in reality, probably 1 min 30 secs or there abouts).

I need to have the LCD displaying the 'time until next cycle', counting down in seconds (or mins:secs but this project won't have a RTC so probably just keep it in seconds?).

When the cycle is run, it needs to switch on an output, monitor an input (which will end the sequence early if the input changes state) and display the 'elapsed time' on the LCD.

Has anyone done anything similar or know of a library which will get me close?
I have seen a couple of Timer libraries which can handle the simple "every 15 minutes, turn the output on" part, but displaying the 'time until next' and the 'elapsed time' and handling the input to exit the cycle early are what's got me stuck.

Cheers!
18  Development / Other Software Development / Re: Frequency / period counter on: February 06, 2012, 04:28:39 am
Is there a way to run 2 instances of this counter at once?
I need to measure 2 discreet frequencies.
One can be an interrupt, the other would have to be with polling (as my other interrupt pin is doing another job in this project).

I try and compile with;

FreqPeriodCounter counter(counterPin, micros, 0);
FreqPeriodCounter counter2(shaftPin, micros, 0);

but it throws up errors as all the variables (counter.hertz, counter.period etc etc) are being defined twice.

Can I copy the library files to another one, call it FreqPeriodCounter2, and add a 2 to all the variable names? Would that work??
19  Development / Other Software Development / Re: Frequency / period counter on: February 04, 2012, 08:54:05 pm
Hi,
is there any way with this library to get Hertz in a decimal?
I need accuracy up to about 850Hz, to calculate engine RPM.
Having hertz only as a whole number is reducing the accuracy.

Thanks!
20  Using Arduino / Project Guidance / Re: Motorcycle Data Monitoring project ( need guidance ) on: February 04, 2012, 08:14:06 pm
Hi,
I'm making a similar project, but for a V8 car engine.

I used your RPM code but have found an issue;

if i change the pulses per cycle to 4 (V8, 4 pulses per revolution), I get accurate RPM at 400Hz (6000rpm in a V8).
This is correct.

But if RPM goes over 7500rpm (~490hz), the RPM goes back to ~3700rpm and then climbs again as frequency increases. . I get another 6000rpm reading at 800Hz. . so somewhere there is an issue, but I'm not a cluey-enough debugger to see it??
21  Using Arduino / Sensors / 0.5 - 4.5v pressure sensor on: February 04, 2012, 04:30:03 am
Hi all,
I'm wanting to log/capture data from a pressure sensor into the Arduino.
The sensor gets +5v and ground and gives a 0.5v - 4.5v voltage back, linearly from 0 - 15psi.
(it's an automotive style sensor where the controller perceives < 0.5v is open circuit and > 4.5v is a short).

I can't get my head around the scaling to give me an answer in psi???

I can read from the analog pin and get a 0 - 1023 result,
but I'm stuck at the maths where I use the reference voltage to convert it to meaningful psi, especially when 4.5v is full scale and not 5v.

Any ideas??
Thanks!
22  Using Arduino / Programming Questions / Change variable by buttons, see on LCD on: February 03, 2012, 06:19:49 am
Hi all,
I'm currently working on a delayed latching switch, and would like to display the delay setting on LCD, and have it changeable with an up/down/enter type button setup? Is that possible??

Do you have to make some sort of special menu code,
or would a simple

void loop() {

print  the variable to LCD
if switch a pressed, variable = variable + 1
if switch b pressed, variable = variable - 1
}

do the job??

Cheers,
Ryan.
23  Using Arduino / Programming Questions / Re: Latched switch with delay on: February 03, 2012, 04:35:14 am
Attempted added debounce;
is this close??

Code:
const int ledpin =  13;              // LED mirrors output for visual testing purposes
const int switchpin = 22;            // input from trigger switch
const int tbrakepin = 24;            // output to transbrake
int setting = 750;                   // delay setting in milliseconds
int currState = 0;                   // current switch state
int prevState = HIGH;                // last switch state
unsigned long releasemillis = 0;     // value to store release point
unsigned long debouncemillis = 50;   // debounce time in milliseconds
unsigned long lastdebouncetime = 0;  // last time debounce was true

void setup() {
  pinMode(ledpin, OUTPUT);
  pinMode (switchpin, INPUT);
  pinMode (tbrakepin, OUTPUT);
  digitalWrite (switchpin, HIGH);
}

void loop() {
  int reading = digitalRead(switchpin);
  if(reading != prevState) {
    lastdebouncetime = millis();
  }

  if((millis() - lastdebouncetime) > debouncemillis) {
    currState = reading;
  }

  // currState = digitalRead(switchpin); //commented out when added debounce
  if(currState != prevState);             // there has been a change
  {
    if(currState == LOW);                 // switch has been pressed
    {
      digitalWrite (ledpin, HIGH);
      digitalWrite (tbrakepin, HIGH);     // activate outputs
      releasemillis = 0;
    }
    if(currState == HIGH);                // switch has been released after having been activated
    {
      releasemillis = millis();           // store the current time
    }
  }
  if((millis() - releasemillis) >= setting); // has the delay period elapsed?
  {
    digitalWrite (ledpin, LOW);
    digitalWrite (tbrakepin, LOW);        // turn outputs off
  }
  prevState = currState;

}
24  Using Arduino / Programming Questions / Re: Latched switch with delay on: February 03, 2012, 03:39:56 am
Added a reset of releasemillis to the 'switch pressed' routine. .
My attempt is to re-set the count and hold the output high if the switch is released but then re-pressed before the timer elapses. . the idea is if the operater releases but then re-presses the switch, nothing should happen to the outputs; they remain high and the counter doesn't start until the switch is released again.
Does that look like this??

Code:
const int ledpin =  13;              // LED mirrors output for visual testing purposes
const int switchpin = 22;            // input from trigger switch
const int tbrakepin = 24;            // output to transbrake
int setting = 750;                   // delay setting in milliseconds
int currState = 0;                   // current switch state
int prevState = HIGH;                // last switch state
unsigned long releasemillis = 0;     // value to store release point
unsigned long lockoutmillis = 0;     // value to store time to lockout re-activation

void setup() {
  pinMode(ledpin, OUTPUT);
  pinMode (switchpin, INPUT);
  pinMode (tbrakepin, OUTPUT);
  digitalWrite (switchpin, HIGH);
}

void loop() {
  currState = digitalRead(switchpin);
  if(currState != prevState);             // there has been a change
  {
    if(currState == LOW);                 // switch has been pressed
    {
      digitalWrite (ledpin, HIGH);
      digitalWrite (tbrakepin, HIGH);     // activate outputs
      releasemillis = 0;
    }
    if(currState == HIGH);                // switch has been released after having been activated
    {
      releasemillis = millis();           // store the current time
    }
  }
  if(millis() - releasemillis >= setting); // has the delay period elapsed?
  {
    digitalWrite (ledpin, LOW);
    digitalWrite (tbrakepin, LOW);        // turn outputs off
  }
  prevState = currState;

}

Looks OK to me.

However as someone else said, bounces will annoy you.

If the code is functionally right, my next issue is the debounce. How is that achieved?
25  Using Arduino / Programming Questions / Re: Latched switch with delay on: February 03, 2012, 02:10:07 am
Is this getting somewhere close??

Code:
const int ledpin =  13;          // LED mirrors output for visual testing purposes
const int switchpin = 22;        // input from trigger switch
const int tbrakepin = 24;        // output to transbrake
int setting = 750;               // delay setting in milliseconds
int currState = 0;               // current switch state
int prevState = HIGH;            // last switch state
unsigned long releasemillis = 0;          // value to store release point

void setup() {
  pinMode(ledpin, OUTPUT);
  pinMode (switchpin, INPUT);
  pinMode (tbrakepin, OUTPUT);
  digitalWrite (switchpin, HIGH);
}

void loop() {
  currState = digitalRead(switchpin);
  if(currState != prevState); // there has been a change
  {
    if(currState == LOW); // switch has been pressed
    {
      digitalWrite (ledpin, HIGH);
      digitalWrite (tbrakepin, HIGH); // activate output
    }
    if(currState == HIGH); // switch has been released after having been activated
    {
      releasemillis = millis();
    }
  }
  if(millis() - releasemillis >= setting);
  {
    digitalWrite (ledpin, LOW);
    digitalWrite (tbrakepin, LOW);
  }
  prevState = currState;

}

Thanks for the help. . hopefully I'll start to get a handle on this stuff soon!! smiley-red
26  Using Arduino / Programming Questions / Re: Latched switch with delay on: February 02, 2012, 05:39:37 am
OK;

Code:
const int ledpin =  13;      // LED mirrors output for visual testing purposes
const int buttonpin = 22;    // input from trigger switch
const int tbrakepin = 24;    // output to transbrake
int setting = 750;           // delay setting in milliseconds
int buttonstate = 0;         // current button state
int lastbuttonstate = HIGH;  // last button state

void setup() {
  pinMode(ledpin, OUTPUT);
  pinMode (buttonpin, INPUT);
  pinMode (tbrakepin, OUTPUT);
  digitalWrite (buttonpin, HIGH);
}

void loop()
{
 buttonstate = digitalRead(buttonpin);
  if (buttonstate == LOW && lastbuttonstate == HIGH) {
    digitalWrite(ledpin, HIGH);
    digitalWrite (tbrakepin, HIGH);
    lastbuttonstate = LOW;
That's my first test. .
"if the button wasn't pushed before, and now it is, then turn the output on".
Is that on the right track??

Not sure where to go after that though? I'm stuck on the release button one;
"button was pushed before, and now it's not, so wait 'interval' milliseconds then turn the output off, unless the button is pushed again in that time, in which case, just continue with the output on.
27  Using Arduino / Programming Questions / Re: Latched switch with delay on: February 02, 2012, 04:57:38 am
Quote
I am still waiting on my Arduino board to get here to test it live, but does that look like it would work?
(The 3 second delay at the end is to prevent the re-activation of the output for a period as a protection for the device the output is driving)
Make a copy of the reference page. Use FrontPage or suitable html editor and remove the entry for delay(). Forget that it even exists.

Look at the blink without delay example to learn how to get along (better) without it.

You need two switch states - one for what the state is this time through loop(), and one for what the state was last time through loop().

That will allow you to detect transitions - the switch was not pressed but now is or the switch is not pressed but was.

Knowing whether this pass through loop represents a transition (from pressed to released or from released to pressed) will allow you to determine and handle the "not pressed", "just pressed", "still pressed", and "just released" states.

The states, along with the time that a state change occurred, and the current time are what you need to make this project work correctly.

Please, learn these concepts from the beginning. Then, you won't need to come back here and say stuff like "How do I do two things at once" or "I have to press my switch too many times to make stuff happen" or "How do I interrupt a delay".
Thanks!
That was my hope; to learn how to do it properly.
I see straight away the delay() is no good at all; whilever it's counting, nothing else will happen.

I'll study some more on the 'blinkwithoutdelay' example and see if i can use it in my situation.
Cheers!
28  Using Arduino / Programming Questions / Latched switch with delay on: February 02, 2012, 04:34:18 am
Hi all,
I'm just trying to work out some simple ideas before I get stuck into my first major Arduino project.

Starting out building a device that will monitor the state of a swtich;
if this switch is pressed, it will turn an output on;
once the switch is released, it will turn the output back off after a settable delay period.
if the switch is held down, the output is on, and the delay isn't triggered until the switch is released.

My first attempt at this is as follows;

Code:
const int ledPin =  13;      // LED mirrors output for visual testing purposes
const int buttonpin = 22;    // input from trigger switch
const int tbrakepin = 24;    // output
int setting = 750;           // delay setting in milliseconds
int buttonstate = 0;          // is button depressed?

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode (buttonpin, INPUT);
  pinMode (tbrakepin, OUTPUT);
  digitalWrite (buttonpin, HIGH);
}

void loop()
{
  buttonstate = digitalRead(buttonpin);
  if (buttonstate == LOW) {
    digitalWrite (tbrakepin, HIGH);
    digitalWrite (ledPin, HIGH);
    buttonstate = digitalRead(buttonpin);
    if (buttonstate == HIGH) {
      delay(setting);
      digitalWrite (tbrakepin, LOW);
      digitalWrite (ledPin, LOW);
      delay(3000);
  }
}
}

I am still waiting on my Arduino board to get here to test it live, but does that look like it would work?
(The 3 second delay at the end is to prevent the re-activation of the output for a period as a protection for the device the output is driving)
29  Using Arduino / Programming Questions / Re: Timestamp/Counter with settable reference/zero point on: February 01, 2012, 01:12:45 am
How do you get negative time?
Out of the logger, you don't. This data has already passed through the other brand logger's PC software, where you manually set its zero point.
You can't see the raw data from it, but when you first do a download (before you set the zero), the zero is the start of the file (when the logger gets turned  on).
Once you set a zero point in the software, 'negative time' is everything in the data before the zero point.


On another point,
what are some good data display/graphing packages that would suit this data?
I'm currently working with LiveGraph which seems OK, but will be a bit fiddly if I want to overlay one run over another to compare differences.
30  Using Arduino / Project Guidance / Re: Motorcycle Data Monitoring project ( need guidance ) on: January 31, 2012, 03:12:17 am
Looks like a cool project!
I'm about to undertake something similar but for car. (one race, one 4x4).

One thing that caught my eye;
I am using this circuit to pickup capacitive pulses from the spark-plug of the engine and feeding it to the interrupt pin 2 of arduino to determine RPM. As mine is a single cylinder engine, so every spark means one rotation.
2 stroke or 4?
If it's 4 stroke, then one spark actually means two rotations (one power stroke every 2 rotations). .
Unless it's a wasted spark setup, where it fires the plug on the exhaust stroke too?

I'm also wondering how you create multiple 'pages' to show different values/sensors on an LCD, with a 'mode' or 'next/previous' buttons so will be interested to see any suggestions offered here.
Pages: 1 [2] 3