Show Posts
Pages: [1] 2 3 ... 8
1  Using Arduino / Programming Questions / Re: Average coordinate points on: February 11, 2014, 10:49:30 pm
2 You are adding 6 readings, then dividing by 5.

the for loop is less than 6 so I think it makes five readings but no the six one because it is not equal to or less than

2  Using Arduino / Programming Questions / Re: Average coordinate points on: February 08, 2014, 11:07:22 pm
Thank you. But how would I collect multiple coordinate points and average them?
3  Using Arduino / Programming Questions / Re: Average coordinate points on: February 08, 2014, 10:12:04 pm
Code:
/*
 The circuit:
 * LCD RS pin to digital pin 9
 * LCD Enable pin to digital pin 8
 * LCD D4 pin to digital pin 7
 * LCD D5 pin to digital pin 6
 * LCD D6 pin to digital pin 5
 * LCD D7 pin to digital pin 4
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

//#include <Servo.h>
#include <PWMServo.h>

#include <SoftwareSerial.h>
#include <TinyGPS.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
#define RXPIN 2
#define TXPIN 3
#define GPSBAUD 4800
TinyGPS gps;
SoftwareSerial uart_gps(RXPIN, TXPIN);
void getgps(TinyGPS &gps);

const float pi = 3.14;
float targetlat = rad(39.52);
float targetlong = rad(-104.92139);
float newlat = 0;
float newlon = 0;
int off = 11;

PWMServo myservo;
void setup() {
  myservo.attach(SERVO_PIN_B);
myservo.write(100);
pinMode(off, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  //Serial.begin(115200);
  uart_gps.begin(GPSBAUD);
  // Print a message to the LCD.
  lcd.print("waiting for lock");
  delay(1000);

}

void loop() {

  if(uart_gps.available())     // While there is data on the RX pin...
  {

    int c = uart_gps.read();    // load the data into a variable...
    if(gps.encode(c))      // if there is a new valid sentence...
    {
      lcd.clear();
      getgps(gps);         // then grab the data.
      delay(500);
    }

  }
}

void getgps(TinyGPS &gps)
{
  // To get all of the data into varialbes that you can use in your code,
  // all you need to do is define variables and query the object for the
  // data. To see the complete list of functions see keywords.txt file in
  // the TinyGPS and NewSoftSerial libs.

  // Define the variables that will be used
  float latitude, longitude;
  gps.f_get_position(&latitude, &longitude);
  /* THIS WAS THE SECTION I WAS USING TO FIND THE MEAN
  lcd.clear();
  for(int mean = 0; mean < 6; mean++){
  lcd.print("processing data");// Then call this function
  gps.f_get_position(&latitude, &longitude);
    unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);
  float newlat = newlat + latitude;
  float newlon = newlon + longitude;
  delay(1);
  }
  newlat = newlat/5;
  newlon = newlon/5;
  */
  float lat = rad(latitude);
  float lon = rad(longitude);
  float x = (lon-targetlong)*cos(targetlat);
  float y = lat-targetlat;
  float d = 3959*sqrt(sq(x)+sq(y));
  if(d <= .05)
  {
    lcd.clear();
    lcd.print("Congrats!");
    lcd.setCursor(0,1);
    lcd.print("target reached");
    myservo.write(180);
    while(1)
    {
    }
  }
  // You can now print variables latitude and longitude
  lcd.clear();
  lcd.print("Lat: ");
  lcd.print(latitude,5);
  lcd.setCursor(0, 1);
  lcd.print("long: ");
  lcd.print(longitude,5);

  // Here you can print statistics on the sentences.
unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);
  //Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
  //Serial.println(); Serial.println();
  delay(5000);

  lcd.clear();
  lcd.print(d);
  lcd.setCursor(0, 1);
  lcd.print("Miles to target");
  delay(5000);
  lcd.clear();
  lcd.print("Turning off...");
  delay(2500);
digitalWrite(off, HIGH);


}

float rad(float n)
{
  float r = n*(pi/180);
  return r;
}

Are you certain that your math is correct? I'm not.
My math is semi-sound with a mock haversine formula. What formula does tiny gps use for its distance calculations?However, I still need to fix the mean problem.
4  Using Arduino / Programming Questions / Re: Average coordinate points on: February 06, 2014, 09:40:24 pm
I've tried a up and dividing them with a for loop but I get overflows on the float data type
5  Using Arduino / General Electronics / Re: Pro mini on: February 06, 2014, 03:49:30 pm
well if I removed the cap how would the performance of my arduino be affected? And it defiantly shorted out I took a multimeter to it to test.
6  Using Arduino / Programming Questions / Re: Average coordinate points on: February 06, 2014, 03:47:25 pm
Add them up and divide by the number of readings I would think.

A question for you.  How long does the program stay in this while loop ?
Code:
    while(1)
    {
    }

It stays in the while loop forever, and well how would I implement a mean or median into my code?
7  Using Arduino / General Electronics / Re: Pro mini on: February 06, 2014, 10:49:14 am
It shorted out when fried
8  Using Arduino / Programming Questions / Average coordinate points on: February 06, 2014, 09:54:51 am
Hi I built a reverse geo-cache box and to get the best accuracy I want to take the average of the incoming coordinates. How would I do this?

Code:
/*
 The circuit:
 * LCD RS pin to digital pin 9
 * LCD Enable pin to digital pin 8
 * LCD D4 pin to digital pin 7
 * LCD D5 pin to digital pin 6
 * LCD D6 pin to digital pin 5
 * LCD D7 pin to digital pin 4
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

//#include <Servo.h>
#include <PWMServo.h>

#include <SoftwareSerial.h>
#include <TinyGPS.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
#define RXPIN 2
#define TXPIN 3
#define GPSBAUD 4800
TinyGPS gps;
SoftwareSerial uart_gps(RXPIN, TXPIN);
void getgps(TinyGPS &gps);

const float pi = 3.14;
float targetlat = rad(39.52);
float targetlong = rad(-104.92139);

int off = 11;

PWMServo myservo;
void setup() {
  myservo.attach(SERVO_PIN_B);
myservo.write(100);
pinMode(off, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  //Serial.begin(115200);
  uart_gps.begin(GPSBAUD);
  // Print a message to the LCD.
  lcd.print("waiting for lock");
  delay(1000);

}

void loop() {

  if(uart_gps.available())     // While there is data on the RX pin...
  {

    int c = uart_gps.read();    // load the data into a variable...
    if(gps.encode(c))      // if there is a new valid sentence...
    {
      lcd.clear();
      getgps(gps);         // then grab the data.
      delay(500);
    }

  }
}

void getgps(TinyGPS &gps)
{
  // To get all of the data into varialbes that you can use in your code,
  // all you need to do is define variables and query the object for the
  // data. To see the complete list of functions see keywords.txt file in
  // the TinyGPS and NewSoftSerial libs.

  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  gps.f_get_position(&latitude, &longitude);

  float lat = rad(latitude);
  float lon = rad(longitude);
  float x = (lon-targetlong)*cos(targetlat);
  float y = lat-targetlat;
  float d = 3959*sqrt(sq(x)+sq(y));
  if(d <= .05)
  {
    lcd.clear();
    lcd.print("Congrats!");
    lcd.setCursor(0,1);
    lcd.print("target reached");
    myservo.write(180);
    while(1)
    {
    }
  }
  // You can now print variables latitude and longitude
  lcd.print("Lat: ");
  lcd.print(latitude,5);
  lcd.setCursor(0, 1);
  lcd.print("long: ");
  lcd.print(longitude,5);

  // Here you can print statistics on the sentences.
  unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);
  //Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
  //Serial.println(); Serial.println();
  delay(5000);

  lcd.clear();
  lcd.print(d);
  lcd.setCursor(0, 1);
  lcd.print("Miles to target");
  delay(5000);
  lcd.clear();
  lcd.print("Turning off...");
  delay(2500);
digitalWrite(off, HIGH);


}

float rad(float n)
{
  float r = n*(pi/180);
  return r;
}

9  Using Arduino / General Electronics / Pro mini on: February 06, 2014, 09:52:06 am
hi I have a pro mini from:
https://www.sparkfun.com/products/11113#comment-52f3156a757b7f650b8b4567
and I fried one of the c106 caps on the board. In what ways will this affect the performance of the chip?
10  Using Arduino / Programming Questions / Re: Servo moves when not prompted to on: January 19, 2014, 08:30:46 pm
So how would the code look? import the library?
11  Using Arduino / Programming Questions / Re: Servo moves when not prompted to on: January 19, 2014, 02:09:23 pm
I would say that uart_gps is an instance of software serial
12  Using Arduino / Programming Questions / Re: Servo moves when not prompted to on: January 19, 2014, 01:46:34 pm
Ok I went through the code and found that as soon as I initialize the gps the servo starts to move
Code:
uart_gps.begin(GPSBAUD);
Is there a way to get around this line of code?
13  Using Arduino / Programming Questions / Re: Servo moves when not prompted to on: January 19, 2014, 12:15:56 pm
The sweep code with just the servo works fine and if I write a simple code that just attaches the servo and does nothing with it is fine. Ill start commenting out sections.
14  Using Arduino / Programming Questions / Re: Servo moves when not prompted to on: January 19, 2014, 11:35:21 am
I tried that but still nothing. All I need is for the servo to move from 0 to 180 and back is there a simple controller circuit that might do this?
15  Using Arduino / Programming Questions / Re: Servo moves when not prompted to on: January 19, 2014, 11:31:01 am
I tried that and it didn't work. What if I built a separate controller circuit that moves the servo from 0 to 180 with the input of a 2 second high pulse from the arduino? or something like that because I do not need specific control of my servo
Pages: [1] 2 3 ... 8