Show Posts
Pages: 1 2 [3] 4 5
31  Using Arduino / Programming Questions / Re: Averaging Digital input. on: February 05, 2013, 08:32:01 am
This is one of the final hurdles before taking this to Beta test. So time is of the essence.
Quote
Write the values in an array, sum them all up and divide by the number of measurements. Round the result.
This looks like a good avenue and the least to learn.


Quote
The best thing would be to find out why the false readings happen and eliminate the problem.
I have only seen one false bit of data, and I may have caused it. However I don't want this device kicking out over a bit of noise.
Quote
No need to average the readings.  If you cannot prevent the false readings then you could, perhaps, take 100 readings, adding each to a running total and if the total is not zero or 100 then discard that set, otherwise regard the set as valid and record/display the value as wet or dry as appropriate.
The logic is to check if the tank is wet before filling ( not empty ) If wet redirect to manual drain, so the culling process would not need to be so severe. This is mainly a safety to prevent overflow.
Quote
How often are the readings taken ?
Right now in the main loop. I am only using it for filling but I might want it in other states also like  draining, abort fill and such.

Quote
You could also utilize a debounce to ensure that the reading is only valid if it's been that way for X # of milli/microseconds.
This is where I started and soon got frustrated.
Creative juices running low at this time.

Quote
Another simple filter for a isolated spikes is to require a data value change to be presented for two or three readings before believing it.

"Tell me once, tell me twice; what you tell me three times I believe is true."

(Edit: You could say this is a way to implement Arrch's proposal.)

This is a viable approach but more like tell me 50 times that you are wet I will act.
And I guess it would work pretty much the same if dry
32  Using Arduino / Programming Questions / Re: Meddling with the runtime clock on: February 05, 2013, 08:12:14 am
Quote
Use micros(), instead.Works the same way,

Instead of the run-time clock?
Please explain.
Quote
  but a much shorter fuse.
Fuse?
33  Using Arduino / Programming Questions / Re: Meddling with the runtime clock on: February 04, 2013, 04:45:35 pm
Quote
Just build your own time machine:
This might take longer than 49 days.
34  Using Arduino / Programming Questions / Averaging Digital input. on: February 04, 2013, 04:36:19 pm
I have a digital input that is 0 volts when dry and 5 volts when wet. I have it showing in my software. Every now and then I get a false wet or dry. I think what I want to do is average the input after a hundred samples or so. What would be the proper way of doing this?
35  Using Arduino / Programming Questions / Meddling with the runtime clock on: February 04, 2013, 03:00:35 pm
Is there some way to set the run-time clock other than waiting 49 days for the clock to turn over. I need to certify that the rollover will be uneventful.
36  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: February 04, 2013, 02:51:29 pm
Quote
I don't understand why people feel it necessary to send more data than is necessary.
What is not necessary?
37  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: February 01, 2013, 06:04:27 pm
As it turns out !!! is the culprit.
Quote
Actually all arduino mega1280 and mega2560 boards both past and present suffer from the !!! bootloader monitor 'bug'. Doesn't matter what version board or version of IDE, the only fix is to upgrade the bootloader to one that has fixes that and other shortcomings of that bootloader.

Lefty
 
 
 
 
38  Using Arduino / Storage / Re: If you have an arduino mega 2560 and a ds1307 could you test some code? on: February 01, 2013, 05:44:51 pm
Cool, Mystery solved.
 This is my first serious project in the arduino arena.  I am past the issue that brought me here.Thanks guys. I really needed an answer.I dont like a mystery, and the Serial.print statement stopping the compilation had me befuddled. I use "!!!" as a visual flag all of the time. Who woulda thunk it would bite me like this. But this only makes me wonder about other "easter eggs" might be in the mega. I am building a comercial product.
Quote
Doesn't matter what version board or version of IDE, the only fix is to upgrade the bootloader to one that has fixes that and other shortcomings of that bootloader.
Is there a list of the other shorcomings That I need to watch out for. And I will look into upgrading the bootloader.
Also.
Is there some way to set the runtime clock other than waiting 49 days for the clock to turn over. I need to certify that the rollover will be uneventfull.


just for giggles.


39  Using Arduino / Storage / Re: If you have an arduino mega 2560 and a ds1307 could you test some code? on: January 30, 2013, 09:15:35 am
Riva you are correct. Go figure that I would stumble upon the three bytes that will hang it. Thanks for the information. You sir, rock!!!
40  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 29, 2013, 06:58:06 pm
"crickets"
41  Using Arduino / Storage / If you have an arduino mega 2560 and a ds1307 could you test some code? on: January 25, 2013, 10:04:06 pm
I have some weird code that I would like someone else to run to see if you get the same results.
Code:
/*
* Q(1-2) - (Q1) Memory Load  (Q2) RTC - Memory Read  
 
 */
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address


// Global Variables
long randNumber;
int command = 0;       // This is the command char, in ascii form, sent from the serial port    
byte zero;
int  state   = 96;     // State machine variable
int  counter = 255;      // Master counter variable
int magnum1 = 90;      // dummy var
int magnum2 = 9;      //  dummy var

void setup() {
   randomSeed(analogRead(0));
  Wire.begin();           // join i2c bus
  Serial.begin(57600);
  zero=0x00;             // not sure what this is for
}

void loop() {
  if (Serial.available()) {      // Look for char in serial que and process if found
    command = Serial.read();

    if (command == 'Q' || command == 'q') {  
      delay(100);    
      if (Serial.available()) {
        command = Serial.read();
        if (command == 49) {                //If command = "1"  load data to RAM
         WriteRTCRAM();
        }
        else if (command == 50) {      //If command = "2" Read data from RAM
          ReadRTCRAM();
        }
      }  
    }
  }
  command = 0;                 // reset command
  delay(100);
}
//********************************
void WriteRTCRAM(){
    randNumber = random(250);
  Serial.println(randNumber);  

 Wire.beginTransmission(DS1307_I2C_ADDRESS);   // 255 will be the init value and 0 will be considered
          Wire.write(32);                   // Set the register pointer to before data location
          Wire.write(randNumber);              // Write magic number before storing data
          Wire.write(state);                // Store State variable
          Wire.write(counter >> 8);         // writes the high byte of counter
          Wire.write(counter & 0xFF);       // writes the low byte of counter
          Wire.write(randNumber);              // Write magic number after storing data
          Wire.endTransmission();

          Serial.println("Data Stored");
}

void ReadRTCRAM(){
Serial.println("Begin Read");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(zero);   // not sure what this is for
          Wire.endTransmission();

          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(0x20);         // not sure what this is doing
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 32);  // Set pointer to the first byte of data

          magnum1 = Wire.read();  //magic number written before data write
          state = Wire.read();    // Read state data
          counter = Wire.read() << 8 + Wire.read(); // Read first byte shift left read second byte
          magnum2 = Wire.read();  // Read Magic number written after data write
          Serial.print(" Magic Number = ");
          Serial.println(magnum1);
          Serial.print(" State = ");
          Serial.println(state);
          Serial.print(" Counter = ");
          Serial.println(counter);
          Serial.print(" Magic Number = ");
          Serial.println(magnum2);
          Serial.println(" RTC1307 Dump end");
          if (magnum1 != magnum2){
          Serial.print (" Write Error!!!");
          }
}


This compiles but will not upload

Code:
/*
* Q(1-2) - (Q1) Memory Load  (Q2) RTC - Memory Read  
 
 */
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address


// Global Variables
long randNumber;
int command = 0;       // This is the command char, in ascii form, sent from the serial port    
byte zero;
int  state   = 96;     // State machine variable
int  counter = 255;      // Master counter variable
int magnum1 = 90;      // dummy var
int magnum2 = 9;      //  dummy var

void setup() {
   randomSeed(analogRead(0));
  Wire.begin();           // join i2c bus
  Serial.begin(57600);
  zero=0x00;             // not sure what this is for
}

void loop() {
  if (Serial.available()) {      // Look for char in serial que and process if found
    command = Serial.read();

    if (command == 'Q' || command == 'q') {  
      delay(100);    
      if (Serial.available()) {
        command = Serial.read();
        if (command == 49) {                //If command = "1"  load data to RAM
         WriteRTCRAM();
        }
        else if (command == 50) {      //If command = "2" Read data from RAM
          ReadRTCRAM();
        }
      }  
    }
  }
  command = 0;                 // reset command
  delay(100);
}
//********************************
void WriteRTCRAM(){
    randNumber = random(250);
  Serial.println(randNumber);  

 Wire.beginTransmission(DS1307_I2C_ADDRESS);   // 255 will be the init value and 0 will be considered
          Wire.write(32);                   // Set the register pointer to before data location
          Wire.write(randNumber);              // Write magic number before storing data
          Wire.write(state);                // Store State variable
          Wire.write(counter >> 8);         // writes the high byte of counter
          Wire.write(counter & 0xFF);       // writes the low byte of counter
          Wire.write(randNumber);              // Write magic number after storing data
          Wire.endTransmission();

          Serial.println("Data Stored");
}

void ReadRTCRAM(){
Serial.println("Begin Read");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(zero);   // not sure what this is for
          Wire.endTransmission();

          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(0x20);         // not sure what this is doing
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 32);  // Set pointer to the first byte of data

          magnum1 = Wire.read();  //magic number written before data write
          state = Wire.read();    // Read state data
          counter = Wire.read() << 8 + Wire.read(); // Read first byte shift left read second byte
          magnum2 = Wire.read();  // Read Magic number written after data write
          Serial.print(" Magic Number = ");
          Serial.println(magnum1);
          Serial.print(" State = ");
          Serial.println(state);
          Serial.print(" Counter = ");
          Serial.println(counter);
          Serial.print(" Magic Number = ");
          Serial.println(magnum2);
          Serial.println(" RTC1307 Dump end");
          if (magnum1 != magnum2){
        //  Serial.print (" Write Error!!!");
          }
}

This compiles and uploads



No error code green progress bar fills up to the last 3 white spaces and holds, to the left it says uploading.
Eventually I get a time out message.


Quote
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
42  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 25, 2013, 09:45:43 pm
Hello???
43  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 22, 2013, 12:35:50 pm
Strangely yes commenting out the serial print statement did work.
????
Any Idea as to why this should act so?
44  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 22, 2013, 12:22:44 pm
Code:
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_command(): failed miserably to execute command 0x13
avrdude: stk500v2_paged_write: write command failed
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
45  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 22, 2013, 12:18:25 pm
Code:
/*
* Q(1-2) - (Q1) Memory Load  (Q2) RTC - Memory Read 
 
 */
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address


// Global Variables
long randNumber;
int command = 0;       // This is the command char, in ascii form, sent from the serial port     
byte zero;
int  state   = 96;     // State machine variable
int  counter = 255;      // Master counter variable
int magnum1 = 90;      // dummy var
int magnum2 = 9;      //  dummy var

void setup() {
   randomSeed(analogRead(0));
  Wire.begin();           // join i2c bus
  Serial.begin(57600);
  zero=0x00;             // not sure what this is for
}

void loop() {
  if (Serial.available()) {      // Look for char in serial que and process if found
    command = Serial.read();

    if (command == 'Q' || command == 'q') {   
      delay(100);     
      if (Serial.available()) {
        command = Serial.read();
        if (command == 49) {                //If command = "1"  load data to RAM
         WriteRTCRAM();
        }
        else if (command == 50) {      //If command = "2" Read data from RAM
          ReadRTCRAM();
        }
      } 
    }
  }
  command = 0;                 // reset command
  delay(100);
}
//********************************
void WriteRTCRAM(){
    randNumber = random(250);
  Serial.println(randNumber); 

 Wire.beginTransmission(DS1307_I2C_ADDRESS);   // 255 will be the init value and 0 will be considered
          Wire.write(32);                   // Set the register pointer to before data location
          Wire.write(randNumber);              // Write magic number before storing data
          Wire.write(state);                // Store State variable
          Wire.write(counter >> 8);         // writes the high byte of counter
          Wire.write(counter & 0xFF);       // writes the low byte of counter
          Wire.write(randNumber);              // Write magic number after storing data
          Wire.endTransmission();

          Serial.println("Data Stored");
}

void ReadRTCRAM(){
Serial.println("Begin Read");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(zero);   // not sure what this is for
          Wire.endTransmission();

          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(0x20);         // not sure what this is doing
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 32);  // Set pointer to the first byte of data

          magnum1 = Wire.read();  //magic number written before data write
          state = Wire.read();    // Read state data
          counter = Wire.read() << 8 + Wire.read(); // Read first byte shift left read second byte
          magnum2 = Wire.read();  // Read Magic number written after data write
          Serial.print(" Magic Number = ");
          Serial.println(magnum1);
          Serial.print(" State = ");
          Serial.println(state);
          Serial.print(" Counter = ");
          Serial.println(counter);
          Serial.print(" Magic Number = ");
          Serial.println(magnum2);
          Serial.println(" RTC1307 Dump end");
          if (magnum1 != magnum2){
          Serial.print (" Write Error!!!");
          }
}

This compiles but will not upload

Code:
/*
* Q(1-2) - (Q1) Memory Load  (Q2) RTC - Memory Read 
 
 */
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address


// Global Variables
long randNumber;
int command = 0;       // This is the command char, in ascii form, sent from the serial port     
byte zero;
int  state   = 96;     // State machine variable
int  counter = 255;      // Master counter variable
int magnum1 = 90;      // dummy var
int magnum2 = 9;      //  dummy var

void setup() {
   randomSeed(analogRead(0));
  Wire.begin();           // join i2c bus
  Serial.begin(57600);
  zero=0x00;             // not sure what this is for
}

void loop() {
  if (Serial.available()) {      // Look for char in serial que and process if found
    command = Serial.read();

    if (command == 'Q' || command == 'q') {   
      delay(100);     
      if (Serial.available()) {
        command = Serial.read();
        if (command == 49) {                //If command = "1"  load data to RAM
         WriteRTCRAM();
        }
        else if (command == 50) {      //If command = "2" Read data from RAM
          ReadRTCRAM();
        }
      } 
    }
  }
  command = 0;                 // reset command
  delay(100);
}
//********************************
void WriteRTCRAM(){
    randNumber = random(250);
  Serial.println(randNumber); 

 Wire.beginTransmission(DS1307_I2C_ADDRESS);   // 255 will be the init value and 0 will be considered
          Wire.write(32);                   // Set the register pointer to before data location
          Wire.write(randNumber);              // Write magic number before storing data
          Wire.write(state);                // Store State variable
          Wire.write(counter >> 8);         // writes the high byte of counter
          Wire.write(counter & 0xFF);       // writes the low byte of counter
          Wire.write(randNumber);              // Write magic number after storing data
          Wire.endTransmission();

          Serial.println("Data Stored");
}

void ReadRTCRAM(){
Serial.println("Begin Read");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(zero);   // not sure what this is for
          Wire.endTransmission();

          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(0x20);         // not sure what this is doing
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 32);  // Set pointer to the first byte of data

          magnum1 = Wire.read();  //magic number written before data write
          state = Wire.read();    // Read state data
          counter = Wire.read() << 8 + Wire.read(); // Read first byte shift left read second byte
          magnum2 = Wire.read();  // Read Magic number written after data write
          Serial.print(" Magic Number = ");
          Serial.println(magnum1);
          Serial.print(" State = ");
          Serial.println(state);
          Serial.print(" Counter = ");
          Serial.println(counter);
          Serial.print(" Magic Number = ");
          Serial.println(magnum2);
          Serial.println(" RTC1307 Dump end");
         // if (magnum1 != magnum2){
        //  Serial.print (" Write Error!!!");
         // }
}

This compiles and uploads

No error code green progress bar fills up to the last 3 white spaces and holds, to the left it says uploading.
Eventually I get a time out message. Waiting now so I can quote it.
Pages: 1 2 [3] 4 5