Show Posts
Pages: 1 [2] 3 4 ... 11
16  Using Arduino / Programming Questions / Re: Need help please ... small programming issue for a new user :( on: July 31, 2012, 03:21:00 am
Of corse it will  smiley-cry

A small "," is needed between the to variables.

-Fletcher

Mental note: Never trust anyone to have compiled the code they post
17  Using Arduino / Programming Questions / Re: Need help please ... small programming issue for a new user :( on: July 31, 2012, 03:04:40 am
Hi Hani

Code:
int led1 state = 0;
This will give you 2 variables and not 1.

How about this code
Code:
void setup(){
  pinMode(13,OUTPUT);
  pinMode(2,OUTPUT);
  digitalWrite(13,HIGH);
}

void loop(){
  delay(500);
  digitalWrite(13,!digitalRead(13));
  digitalWrite(2,!digitalRead(2));
}
Compiled but not testet.

-Fletcher
18  Using Arduino / Programming Questions / Re: small problem with float on: May 28, 2012, 02:52:46 pm
Hi louish

I think you are doing it wrong - you should keep the high resolution numbers as long as possible.

Recalculate the distance even if the responce from the gps is noisy and then you should decide if the new distance has changed enough -or you could make a running average.

-Fletcher
19  Using Arduino / Programming Questions / Re: Serial.println to external device drops characters on: May 15, 2012, 01:40:18 pm
Hi Kaj

Final glide, total energy compensated vario and driving an analog vario - you got a cool project there  smiley-cool Please remember to document it all and write a nice presentation  smiley I guess a lot of people could be interested in "upgrading" old instruments to better performance.

Last week I tried a Duo Discus with a LX9000. It was really nice to see which part of the circle I was gaining and loosing.

I'm not sure it's worth to recalculation the load factor and change in polar based on a G sensor. It's a rather short time that you pull the high G ... exept for the wind launch of corse.

Good luck getting the two devices to talk to each other.

-Fletcher
20  Using Arduino / Programming Questions / Re: Serial.println to external device drops characters on: May 15, 2012, 09:39:29 am
Hi Kai

I think you should try to figure out why the Vertica V1 is not receaving correctly.

Why do you want to take the total energi ballanced vario signal into XCSoar - does it has a better audio responce compared to the system you allready (LX ?000 or what ever) you have in the plane?

How do you obtain the dynamic pressure digitally? Is total energy ballanced vario done in arduino?


For those not familiar with gliding:
The vario is an instrument that tells if the plane is going up or down. It helps alot when you want to fly in the thermal upwinds. The instrument is often a flask where an instrument is meshuring if the air is going in or out - and at what rate. The instrument often has an audio output - with high pitch bib-bib-bib when you go up and low pitch buuup buuuuuuuuppppppp when going down (look out of the windshield - there are other gliders out there ... says the instructor!). A system like this has a build in error. If you fly fast and pull up (decreasing speed) you will gain altitude and therfore the vario indicates upwind. This is fals - the total energi of the plane has not gone up - you have only exchanged speed into altitude. To compensate for this the vario is connected to the tupe with dynamic pressure going to the speedometer. The vario signal is compensated with change in speed and up/down is only indicated if the total energy of the plane is changed.

-Fletcher

21  Using Arduino / Project Guidance / Re: drawing shapes on lcd panel using hand movement on: May 14, 2012, 04:40:15 pm
Have you tried using a permanent marker attached to your hand?

-Fletcher
22  Using Arduino / Programming Questions / Re: Serial.println to external device drops characters on: May 14, 2012, 03:55:06 pm
Hi detonation

You could make your own serial print function:

Code:
const int delayTime = 10;

void setup(){
  Serial.begin(9600);
}

void loop(){
  myPrint(String("$GPRMC,184331.200,A,4856.3930,N,12247.4841,W,0.07,0.00,080112,,,A*71"));
  delay(5000);
  }

void myPrint(String message){
  for (int i=0; i <= message.length(); i=i+1){
    Serial.print(message.charAt(i));
    delay(delayTime);
  }
  Serial.println();
}


What glider are you flying?

I took 33 min yesterday between 900 and 1200 ft in a DG400 ... yep base was low  smiley-razz

-Fletcher
23  Using Arduino / Programming Questions / Re: Reading 2 characters of serial on: May 14, 2012, 03:06:38 pm
Others may search the forum for answers

Code:
void setup(){
  Serial.begin(9600);
}

void loop(){
  if (Serial.available() > 0) {
    Serial.println (serialNumber());
  }
}

long serialNumber(){             //any '-' will render the number negativ
  long number = 0;
  int sign = 1;
  while (Serial.available() > 0){
    char inc = Serial.read();
    if (inc == 45) sign = -1; // negativ number
    inc = inc - '0';
    if ((inc >= 0) and (inc <= 9)){
      number = number * 10 + inc;
    }
    delay(10);
  }
  return sign*number;
}

-Fletcher
24  Using Arduino / Programming Questions / Re: How to code a button function with 60 sec delay? on: April 23, 2012, 09:54:33 am
Hi

Nah, I'm not sure what you mean.

Is this what you want?

Code:
const int ledPin = 13;
const int inputPin = 12;

void setup(){
  pinMode(ledPin,OUTPUT);
  pinMode(inputPin,INPUT);
  digitalWrite(inputPin,HIGH); // Enabler pull-up
}

void loop(){
  if(digitalRead(inputPin) == LOW){
    digitalWrite(ledPin,HIGH);
    delay(1000L*60L);
    digitalWrite(ledPin,LOW);
  }
}
25  Using Arduino / General Electronics / Re: Using a car battery to run Arduino for about six thousand years, need to design on: April 19, 2012, 11:01:58 am
Hi Draythomp

If it's a question about DIY pride - I rest my case  smiley-razz

I fly gliders and from time to time we forget to turn off the radio in the cable retracting cars (is it called that? - and they are also used to tow the gliders on ground) and the next weekend the battery is flat. We can start the engines with aid from a power source but at the end of the day the batter is still more or less flat. It's nice to know that we can put the charger on the battery sunday and the better will be OK the next saturday - no water level drop due to electrolysis.

Btw, nice blok about the dessert house. Have you considered using PV panels to lower the electrical bill? How about insulation the house? In my part of the world we have 20 mm (or more) on the sealing to keep the heat in  smiley-cool

-Fletcher
26  Using Arduino / Programming Questions / Re: problem with my if statment on: April 19, 2012, 10:40:34 am
Hi

I don't see any internal pull-up's on the input - are you using external pull-ups?

-Fletcher
27  Using Arduino / Programming Questions / Re: Speed up arduino on: April 19, 2012, 10:35:43 am
Hi

Quote
It's important to have the feedback from the force sensor as fast as possible to allow the system to responce immediately. By the time, the sampling rate have to be high to avoid of lost counting from tha hall sensor.

So I guess the magnet is mounted on a rotating shaft - well how fast is this shaft rotating? 1-2 kHz is rather fast. I have seen 2-stroke motors for RC model airplanes rotate at this speed, but it's a rare speed with substantial shaft mass.

Do you need to export the force sensor and hall count in real time to matlab simulink or do you need to export at a certain event like: The force is above a critical value?

-Fletcher
28  Using Arduino / General Electronics / Re: Using a car battery to run Arduino for about six thousand years, need to design on: April 19, 2012, 08:36:31 am
Hi there

Quote
so I've been looking into a float charger that doesn't let the battery discharge or boil the water out over time.

If this is important you should reconsider the price issue.

I have good experience with chargers from ctec. I know they are expencive but they will keep your battery in good condition.

-Fletcher
29  Using Arduino / Programming Questions / Re: Speed up arduino on: April 19, 2012, 03:38:39 am
Hi Nick

I did the analysis to see where time was draining away. It surprised me that the map function was takeing so much time. With the map(myValue, 0,A,0,B) the conversion would be a simple B/A ratio. I might look into the engine room of the function to see how much optimization could be applyed.

I'm not sure why Hong89 needs to sample with 2 kHz. In this thread
http://arduino.cc/forum/index.php/topic,101718.msg763256.html#msg763256

He is pointing to a Force Sensor Resistor:
http://dshop.ch/osc/product_info.php?cPath=23_37&products_id=109375

where they write:
These sensors are simple to set up and great for sensing pressure, but they aren't incredibly accurate. Use them to sense if it's being squeezed, but you may not want to use it as a scale.


I guess a change of pree scale won't harm the readings  smiley-razz
We are not talking high res super fast sound analysis here. So why the 2 kHz issue?

It's also hard to figure out what the force result from the 3 sensors are used for. Motorcontrole? datalogging?

-Fletcher
30  Using Arduino / Programming Questions / Re: Speed up arduino on: April 18, 2012, 05:31:44 pm
Hi Hong89

What are you making and why do you need to sample with 2kHz?

Let's look at your sampling and calculations. This is more or less a test run with 10000 samples:
Code:
int fsrPin = 0;
int fsrReading, fsrVoltage;
unsigned long fsrResistance, fsrConductance;
long fsrForce;

unsigned long time1, time2;
unsigned long loopNumber= 10000;

void setup(){
  Serial.begin(9600);
  time1 = micros();
  for(long i = 0; i < loopNumber; i++){
    fsrReading = analogRead(fsrPin);
    fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
 
    fsrResistance = 5000-fsrVoltage;
    fsrResistance *= 10000;
    fsrResistance /=fsrVoltage;
   
    fsrConductance = 1000000 / fsrResistance;                  // don't divide by 0 - add check!
   
    if (fsrConductance <= 100) fsrForce = fsrConductance / 20; // be aware some bad integer math can happen here
    if (fsrConductance >  100) fsrForce = fsrConductance / 50; // same same problem
  }
  time2=micros();
  Serial.println((time2-time1)*1.0/loopNumber);         // uS
  Serial.println(1000.0/((time2-time1)/loopNumber));    // kHz
}

void loop(){
}

Result:
281.33 uS
3.56 kHz


3.5 kHz is not that bad but there is problems in your code. This one:
Code:
fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
is draining time

There is a potential risk of divide by zero here:
Code:
fsrConductance = 1000000 / fsrResistance;
If you read 5V on the pin fsrResistance = 0.

You are loosing most of the accuracy of your reading and calculations here:
Code:
fsrForce = fsrConductance / 20;


First thing first. Let's drop the map function. 5000 / 1023 is more or less 5. We keep integer math for now:

Code:
int fsrPin = 0;
int fsrReading, fsrVoltage;
unsigned long fsrResistance, fsrConductance;
long fsrForce;

unsigned long time1, time2;
unsigned long loopNumber= 10000;

void setup(){
  Serial.begin(9600);
  time1 = micros();
  for(long i = 0; i < loopNumber; i++){
    fsrReading = analogRead(fsrPin);
//  fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
    fsrVoltage = fsrReading * 5;

    fsrResistance = 5000-fsrVoltage;
    fsrResistance *= 10000;
    fsrResistance /=fsrVoltage;
   
    fsrConductance = 1000000 / fsrResistance;                  // don't divide by 0 - add check!
   
    if (fsrConductance <= 100) fsrForce = fsrConductance / 20; // be aware some bad integer math can happen here
    if (fsrConductance >  100) fsrForce = fsrConductance / 50; // same same problem
  }
  time2=micros();
  Serial.println((time2-time1)*1.0/loopNumber);         // uS
  Serial.println(1000.0/((time2-time1)/loopNumber));    // kHz
}

void loop(){
}

Output:
232.01 uS
4.31 mHz


Wow - 750 Hz up - let's how much we loose on float math:

Code:
int fsrPin = 0;
int fsrReading;
float fsrVoltage, fsrResistance, fsrConductance, fsrForce;

unsigned long time1, time2;
unsigned long loopNumber= 10000;

void setup(){
  Serial.begin(9600);
  time1 = micros();
  for(long i = 0; i < loopNumber; i++){
    fsrReading = analogRead(fsrPin);
    fsrVoltage = fsrReading*(5000.0/1023.0);
 
    fsrResistance = 5000.0-fsrVoltage;
    fsrResistance *= 10000.0;
    fsrResistance /=fsrVoltage;
   
    fsrConductance = 1000000.0 / fsrResistance;  // don't divide by 0 add check!
   
    if (fsrConductance <= 100) fsrForce = fsrConductance / 20.0;
    if (fsrConductance >  100) fsrForce = fsrConductance / 50.0;
  }
  time2=micros();
  Serial.println((time2-time1)*1.0/loopNumber);
  Serial.println(1000.0/((time2-time1)/loopNumber));
}

void loop(){
}

Result:
240.05 uS
4.17 kHz


Only 140 Hz down. Not a lot.

Well, time to bring in the big canon. I did a search for "Faster analog read", and to be honest I don't get much of it except: Yeah -prescale can be set to 16 with no significant loss of quality. Cut and paste code from that thread:

Code:
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

int fsrPin = 0;
int fsrReading;
float fsrVoltage, fsrResistance, fsrConductance, fsrForce;

unsigned long time1, time2;
unsigned long loopNumber= 10000;

void setup(){
  // set prescale to 16
  sbi(ADCSRA,ADPS2) ;
  cbi(ADCSRA,ADPS1) ;
  cbi(ADCSRA,ADPS0) ;
 
  Serial.begin(9600);
  time1 = micros();
  for(long i = 0; i < loopNumber; i++){
    fsrReading = analogRead(fsrPin);
    fsrVoltage = fsrReading*(5000.0/1023.0);
 
    fsrResistance = 5000.0-fsrVoltage;
    fsrResistance *= 10000.0;
    fsrResistance /=fsrVoltage;
   
    fsrConductance = 1000000.0 / fsrResistance;  // don't divide by 0 add check!
   
    if (fsrConductance <= 100) fsrForce = fsrConductance / 20.0;
    if (fsrConductance >  100) fsrForce = fsrConductance / 50.0;
  }
  time2=micros();
  Serial.println((time2-time1)*1.0/loopNumber);
  Serial.println(1000.0/((time2-time1)/loopNumber));
}

void loop(){
}

Result:
142.81 uS
7.04 kHz


Wow, that kinda did the trick. Even with 3 * analogRead you should be surfing above the 2 kHz level.

-Fletcher
 
Pages: 1 [2] 3 4 ... 11