Show Posts
Pages: 1 ... 66 67 [68] 69 70 ... 97
1006  Using Arduino / Networking, Protocols, and Devices / Re: indoor gps no problem :-) on: December 10, 2011, 11:29:24 am
Wow this is strange,  turming the module upside down only makes it skip the odd reaading while I am moving it around, then it settles down and locks on solid.
I need it to drop out 100%
So then I tried wrapping the whole Arduino and GPS module in plastic and cooking foil, with the GPS receiver upside down ( antenna looking down into the foil )  i.e.

it only takes a minute to lock on and give solid data.

If I then completely wrap the upside down receiver and Ardunio in foil,



it stays locked on, giving perfect time, but sometimes give garbled position data .
If I power down and reboot it, it doesnt lock on ( I tried it for 5 minutes )

It does lock on with it half wrapped upside down.
1007  Using Arduino / Networking, Protocols, and Devices / indoor gps no problem :-) on: December 10, 2011, 09:59:21 am
I made up a small board to attach a UP501D GPS receiver to an Arduino board to test my GPS clock project.

I have been testing the project indoors, and had no problem with the Rx locking on to the satellites.

Then I wanted to check that the clock would keep time with the GPS receiving no signals, so I put a metal plate ( the sidepanel  of my PC - dont ask ) right over the GPS receiver/antenna. and it still happily receives the signals !



I put it in the drawer under the PC and it works.

The only way I can make it lose signal is to turn the thing upside down !

I am very impressed and surprised......
1008  Using Arduino / Project Guidance / Re: simple averaging troubles on: December 09, 2011, 09:49:38 am
Thanks GoForSmoke -   I completely forgot to comment out all the zillion SerialPrints again !
I will try it with just printing the interval and see how it looks .

I will never get old , only in numbers , kid at heart :-)

1009  Using Arduino / Project Guidance / Re: simple averaging troubles on: December 09, 2011, 06:21:49 am


That averaging works very well,   I have incorporated a MacGuyvered rounding up or down the decimal places to keep the interval of the freerunning timer within 1 millisecond , which ( ideally  ,  if the temperature of the xtal didnt change too much )would equate to 43 seconds error a month !
Hopefully the GPS will not drop out for anything like that !

But the reading from the GPS between minute changes varies quite a few milliseconds, I suppose it depends on where the loop my sketch was when the next data packet is ready.
An interrupt would sort that out, but doesn't it mess up the millis count?

I am not really concerned as any delay in reading the minute change would be cancelled out the next minute anyway.

I am using the 5% averaging swaps, which I think relates to averaging over 20 samples ( although the history is never erased, just slowly modified )  but as I am smoothing a very steady level, I could take it down to 1% perhaps , I have days to let it settle.

it looks like my freerunning clock would have been 6 milliseconds fast every minute without this calibration.  If the GPS drops out it will carry on with the corrected interval.


Heres the code and below it the readings as it averages with 5% swaps


Code:
/*
   GPS clock by John Smith aka Boffin1  based on  http://tronixstuff.com/tutorials > Chapter 19
 and code by Aaron Weiss of SparkFun Electronics;  http://bit.ly/99YnI6
 and code and libaries by arduiniana.org. and the patirnt people of the Arduino forum !
 Thank you :)
 */

#include <NewSoftSerial.h>
#include <TinyGPS.h>


long error;
long clockmillis = 0;
long rxmillis = 0;
long interval = 60000;
int x =0;
unsigned long since;
unsigned long times [10];
const byte digitTable [10] = {                     //   patterns for 7 segment displays
  B11111110, B10110000, B11101101, B11111001, B10110011,  //  first bit for switching on display
  B11011011, B11011111, B11110000, B11111111, B11111011};

float average = 60000;
int clockmins;
int clockhours;

#define RXPIN 14 //   
#define TXPIN 15 //
#define GPSBAUD 9600 // baud rate of our UP501D GPS module. Change for your GPS module if different

// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the NewSoftSerial library to the pins you defined above
NewSoftSerial uart_gps(RXPIN, TXPIN);

// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);

int hourtens;
int hourunits;
int mintens;
int minunits;
int rxhours;
int rxmins;

void setup()
{
  uart_gps.begin(GPSBAUD); // setup sketch for data output speed of GPS module
  Serial.begin(115200);
  interval = 60000;
}
//  ========================================================================


void getgps(TinyGPS &gps)    // The getgps function will get the values we want.
{
  int year,a,t;
  byte month, day, hour, minute, second, hundredths;
  gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  hour=hour+2; // my zone is GMT +2
  if (hour>23) {
    hour=hour-24;
  }

  rxhours = ( int ) hour;
  rxmins = (int) minute;

  if ( rxmins != clockmins ) {                    // ===================MINUTES HAVE CHANGED THIS SECOND ==================
    unsigned long  present = millis ();          //  set actual millis time of minute change for all subsequent calcs and timings
    since = (present - rxmillis) ;              // the millis count since the last minute change ( GPS accuracy on average )
    rxmillis = present;                        //  millis count at update
    Serial.print("rxmin has just changed,");  //  update clock, at secs = zero
    clockmins = rxmins; 
    clockhours = rxhours;     
    clockmillis = present ;                    // reset freerun clock counter millis
    Serial.print("  time = ");   
    Serial.print(clockhours);
    Serial.print(":");   
    Serial.print(clockmins);
    if ( (since > 59000 ) && ( since < 61000 )) {  //  only calibrate the freerun timer if consecutive GPS minutes
      Serial.print(" since = ");  Serial.print(since);
      average = average * 0.95 + since * 0.05;  // deduct 5% of the average, and add 5% of the new reading
      Serial.print("  averaged since = ");   
      Serial.print(average);
      if ( (average < 61000 ) && ( average > 59000)) //  if its already locked on
     
      { float error = (average - ( long ) average);
        Serial.print(" error = "); Serial.println(error);
        if ( error >= .5 ) { average ++ ; }
        if (error <= -.5 ) { average --;  }
               interval = (long ) average ;
      } //  end of if locked on
      Serial.print(" interval rounded for free running timer = "); Serial.println(interval);
    }   

    showtime ();       
    // =====================================================================================================       
  }

}

//********************************************************************************************

void loop()
{
  while(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...
    {
      getgps(gps);         // then grab the data,
    }
  }

  //Serial.println("running clock    ");
  unsigned long currentMillis = millis();
  if(currentMillis - clockmillis > interval) {
    clockmillis = currentMillis;
    clockmins ++;
    if ( clockmins >59 ) {
      clockmins = 0;
      clockhours ++;
      if (clockhours >59 ) {
        clockhours = 0 ;
      }
    }// end of if mins>59
    Serial.print("  interval= ");
    Serial.print(interval);
    Serial.print("clock time   == ");
    Serial.print(clockhours);
    Serial.println(clockmins);
    showtime ();

  }//  end of if current - clock > interval

  // Serial.print("clock time   == "); Serial.print(clockhours); Serial.println(clockmins);
}  // end of loop


and heres some of the data being averaged ,


 interval rounded for free running timer = 60000
rxmin has just changed,  time = 12:49 since = 60008  averaged since = 60000.54 error = 0.54
 interval rounded for free running timer = 60001
rxmin has just changed,  time = 12:50 since = 59980  averaged since = 60000.46 error = 0.46
 interval rounded for free running timer = 60000
rxmin has just changed,  time = 12:51 since = 60013  averaged since = 60001.08 error = 0.09
 interval rounded for free running timer = 60001
rxmin has just changed,  time = 12:52 since = 60013  averaged since = 60001.68 error = 0.68
 interval rounded for free running timer = 60002
rxmin has just changed,  time = 12:53 since = 60008  averaged since = 60002.94 error = 0.95
 interval rounded for free running timer = 60003
rxmin has just changed,  time = 12:54 since = 59980  averaged since = 60002.75 error = 0.75
 interval rounded for free running timer = 60003
rxmin has just changed,  time = 12:55 since = 59995  averaged since = 60003.31 error = 0.31
 interval rounded for free running timer = 60003
rxmin has just changed,  time = 12:56 since = 60011  averaged since = 60003.69 error = 0.69
 interval rounded for free running timer = 60004
rxmin has just changed,  time = 12:57 since = 59984  averaged since = 60003.66 error = 0.66
 interval rounded for free running timer = 60004
rxmin has just changed,  time = 12:58 since = 60014  averaged since = 60005.12 error = 0.12
 interval rounded for free running timer = 60005
rxmin has just changed,  time = 12:59 since = 60011  averaged since = 60005.41 error = 0.41
 interval rounded for free running timer = 60005
rxmin has just changed,  time = 13:0 since = 59995  averaged since = 60004.89 error = 0.89
 interval rounded for free running timer = 60005
rxmin has just changed,  time = 13:1 since = 60008  averaged since = 60006.00 error = 1.00
 interval rounded for free running timer = 60006
rxmin has just changed,  time = 13:2 since = 59991  averaged since = 60006.19 error = 0.20
 interval rounded for free running timer = 60006
rxmin has just changed,  time = 13:3 since = 60012  averaged since = 60006.49 error = 0.49
 interval rounded for free running timer = 60006
rxmin has just changed,  time = 13:4 since = 59981  averaged since = 60005.21 error = 0.21
 interval rounded for free running timer = 60005
rxmin has just changed,  time = 13:5 since = 60006  averaged since = 60005.25 error = 0.25
 interval rounded for free running timer = 60005
rxmin has just changed,  time = 13:6 since = 59992  averaged since = 60004.59 error = 0.59
 interval rounded for free running timer = 60005
rxmin has just changed,  time = 13:7 since = 60006  averaged since = 60005.61 error = 0.61
 interval rounded for free running timer = 60006
rxmin has just changed,  time = 13:8 since = 60000  averaged since = 60006.28 error = 0.28
 interval rounded for free running timer = 60006
rxmin has just changed,  time = 13:9 since = 59998  averaged since = 60005.86 error = 0.86
 interval rounded for free running timer = 60006
1010  Using Arduino / Project Guidance / Re: simple averaging troubles on: December 09, 2011, 12:48:04 am
I have just spotted a simple running averager by macegr on adafruits forum I might play with, it looks like it might be quite smooth :-

Code:
float adcResult = 0;
void setup()
{  Serial.begin(9600); }

void loop()
{
  adcResult = adcResult * 0.95 + analogRead(0) * 0.05;
  Serial.println(adcResult);
  delay(50);
}
1011  Using Arduino / Project Guidance / Re: simple averaging troubles on: December 09, 2011, 12:39:18 am
Thanks James,  you are spot on -  both counts :-)

If I had posted all of the sketch, you ( and 50,000 other Arduino heads ) would immediately have seen that when I had captured the time of receiving the minute change from the GPS module, I had called it    "int present = millis () "  instead of unsigned long !

( giving me 43 million as "since" .)

Its working well now, except I must tell it to ignore any " since" over 61000 so that it only averages counts  between subsequent minutes.

( I didn't post the whole sketch as it was 75%  commented out lines    smiley-sad-blue  )
1012  Using Arduino / Project Guidance / Re: simple averaging troubles on: December 08, 2011, 10:03:47 am
Yes Bob,  I defined it as unsigned long times [10];

I have since reduced the samples to 3, but the total is still all over the place
1013  Using Arduino / Project Guidance / simple averaging troubles on: December 08, 2011, 09:01:55 am
I have got my GPS clock running fine,   it generally runs on a 60 second " blink without delay" sketch relying on the 16 MHz xtal, but every time there is a new minute from the GPS module, it synchronises with that.

Thats working fine, but then I tried counting the milliseconds between minutes from the GPS, which would be 60000 if the sketch and xtal were perfect.

I then used this count, which was always within 10 mS of the 60000, as the "interval" count for the Arduino timer

If I lost GPS lock, it would carry on using the corrected interval for the Arduino timer.

The "error" drifts around a bit, so I want to average out the last 10 readings, and threw together a simple test sketch ( below )

I assumed that by assigning a value to an array cell, it would overide the previous data there, but it seems to add to it?. the total10times just gets up to the millions.

There are some averaging sketches I found, but more complicated than I thought I need - it looked a simple task - what have I missed ?

(The last line is to ignore the result if its out of range.)


Code:
       times [x] = since;   // times is the array holding all the millis "since" the previous minute
                  x++;                     //  index increment 0 -  9
                  if ( x==10 ){ x = 0;}
                        Serial.print("x =  "); Serial.println(x);       
                  unsigned long total10times = times [0] + times [1] + times [2] + times [3] + times [4] + times [5] + times [6]
                   + times [7] + times [8] + times [9];
                    Serial.print("total10times == "); Serial.println(total10times);
                   
                  unsigned long average = total10times / 10;
                    Serial.print("average == "); Serial.println(average);
             if ( (average < 61000 ) && ( average > 59000)) { interval = average ; }  else { interval = 60000 ; }
       
1014  Development / Suggestions for the Arduino Project / Re: Arduino 1.0 produces 25% larger binary? on: December 08, 2011, 01:39:29 am
I download 1.0, and copied my 0022 libraries to the library ( TinyGps for example ) but it doesn't run, and I don't have the experience or time to try and modify the library.
However, looking at the notes about 1.0, there was a useful looking library for parsing text and data from character stream, and changing the data type in one go.

Would it be wasting my time to see if this library work in 0022 ?
1015  Using Arduino / General Electronics / Homebrew "shields" for beginners. on: November 29, 2011, 09:02:24 am
Theres been some posts from beginners about what to buy to get their Arduino doing more than blink the LED  smiley-razz

There has also been good advice on buying packs of resistors, diodes etc..   but before splashing out on particular shields, you can try the project out with some perforated board ( veroboard ) and some header pins.( if you can solder )

Here are a few I made along the way, they are not very pretty, but all worked.
 I have mislaid some others like the stepper motor controller and SD card reader ( I couldn't recognise them in the junk box )

 

I just hang the header pins along one side of the Arduino where possible,( like the eeprom )  or arrange it across the top , like the 433MHz receiver.

Once you have the hang of writing a sketch to the prototype, then you might want to buy the full shield to use all of it's functions.

I fit 28 pin dip sockets to all my projects, and load the sketch using the Arduino board, then plug the chip in the prototype ( because I havn't learnt how to program it in circuit yet )

You can also design your own little pcb to take the dip socket and your favourite conectors etc :-



I have left solder pads on the spare data pins for whatever is needed.

 Strip an old car alarm and salvage the transducers for a distance measuring thingy, or whatever, be brave and try stuff, this forum is wonderful, you can always " phone a friend" if you get stuck and can't find the answer by Googling.
1016  Using Arduino / Project Guidance / Re: New Arduino project on: November 25, 2011, 07:17:58 pm
Samuel,  dont worry about feeding the cats, find a more rewarding project.
 Cats will never starve, they will rub themselves against some neighbours legs, purring loudly, pretending to be affectionate, and get rewarded.
Then they leave.   smiley-lol
1017  Using Arduino / Project Guidance / Re: simplest gps clock on: November 25, 2011, 07:04:16 pm
Thanks guys,   I realise that the code I copied was more for initial testing, and I have now switched to the TinyGps library, and not only has it kept going for the last couple of hours, but it has also located my house correctly.
( I was looking forward to a weekend up the coast where the previous software placed me, right next to our favourite seafood restaurant  smiley-lol  )
I will leave this running, but it looks pretty stable, considering the gps module is indoors nowhere near a window.

It has had 54 failed checksums in 2 hours, checking evey 5 seconds, which is more than enough for keeping a clock accurate
1018  Using Arduino / Project Guidance / Re: Ambitious New project on: November 25, 2011, 06:50:59 pm
I dont know about Red Spider controller, but Arduino has nearly 60,000 people to help and guide you when you get stuck ( it was only 30,000 a year ago when I joined )

As Radman said, there is no section to tell you how to make your project,  the routine is :-
 1 Google similar projects,
  2 try some examples , and modify them for your use,   
  3  see if you can debug the code.   
  4  if no luck, then "phone a friend" - i.e.  post your sketch in a message asking for guidance
Code:
( highlight the actual code and select the # at the top of the screen, which will make the sketch scrollable within the message , like this )

Break the project into workable sections and get one going at a time, you can make each a function like gosub in the old Basic.
Good luck
1019  Using Arduino / Project Guidance / Re: Hardware for the beginner. on: November 25, 2011, 01:22:43 pm
Re the LED voltage, if you have a general purpose multimeter switched to continuity, and connect the leads across the LED, It will light dimly ( the right way round ) and the display will give you an idea of the forward voltage ( for a dim LED ) add 10% to the reading displayed.

Of course modern multimeters might be different, mine is 20 years old !  ( thats when I upgraded to a digital meter ! )
1020  Using Arduino / Project Guidance / Re: simplest gps clock on: November 25, 2011, 11:49:27 am
Hmm, while it runs fine for 10 minutes, reading out the time etc, it freezes after 10 minutes or so.
Am I filling some buffer or something?

Heres the test sketch :-
Code:
#include <NewSoftSerial.h>

NewSoftSerial GPS1(14, 15);


char data[300];
char GPSsignature[7] = "$GPRMC";
int comma[13];
int ledPin = 13;                  // LED test pin
int GPSbyte;
int count;
int correctData;

void setup() {
  pinMode(ledPin, OUTPUT);       // Initialize LED pin
  Serial.begin(115200); 
   GPS1.begin(9600);
 
}

void loop() {
  digitalWrite(ledPin, HIGH);

  if (GPS1.available() > 0){
    GPSbyte=GPS1.read();         // Read a byte of the serial port
   
    data[count]=GPSbyte;        // If there is serial port data, it is put in the array
    count++;                     

    if (GPSbyte==13){            // If the received byte is = to 13, end of transmission
      digitalWrite(ledPin, LOW);
      count=0;
      correctData=1;

      for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
        if (data[i]!=GPSsignature[i-1])
          correctData=0;
      }

      if(correctData){               // If yes, countinue and process the data
        for (int i=0;i<300;i++){
          if (data[i]==','){    // check for the position of the  "," separator
            comma[count]=i;
            count++;
          }
          if (data[i]=='*'){    // ... and the "*"
            comma[12]=i;
            count++;
          }
        }
          count = 0;

          Serial.println("---------------");
          for (int i=0;i<9;i++){
            switch(i){
            case 0 : Serial.print("Time in UTC (HhMmSs): "); break;
            case 1 : Serial.print("Status (A=OK,V=!OK): "); break;
            case 2 : Serial.print("Latitude: "); break;
            case 3 : Serial.print("Direction (N/S): "); break;
            case 4 : Serial.print("Longitude: "); break;
            case 5 : Serial.print("Direction (E/W): "); break;
            case 6 : Serial.print("Velocity in knots: "); break;
            case 7 : Serial.print("Heading in degrees: "); break;
            case 8 : Serial.print("Date UTC (DdMmAa): "); break;
            }

           for (int j=comma[i];j<(comma[i+1]-1);j++){
             Serial.print(data[j+1]);
           }
            Serial.println("");
          }
        }   
      }
    }
  else delay(100);
}
Pages: 1 ... 66 67 [68] 69 70 ... 97