Show Posts
Pages: 1 2 3 [4] 5
46  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
47  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.
48  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 22, 2013, 12:07:51 pm
 Insert Quote
Code:

    if (command == 81 || command == 113) {      //If command = "Qq" RTC1307 Memory Functions
Quote
Why not make it easy to read this code?
Ok np but this is just temp code to get it running



  
Code:
         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
Quote
(What's) (with) (all) (the) (parentheses) (?)

Ok fixed

Code:
         if (magnum1 = magnum2){
Quote
Yeah, right. An assignment in the middle of an if statement...
Ah this is supposed to be
Code:
[code]
          if (magnum1 != magnum2){
[/code]

Code:

          Wire.write(zero);   // not sure what this is for
          Wire.write(0x20);         // not sure what this is doing
Quote
Don't you think you should figure these out?

Well being new to  the TWI I dont fully understand but I did find
    Issue 527 : Stream-based Wire library doesn't accept zero
and the fix  which I used.

and still after all of this I still cannot get this to upload unless I REM out the If statement.

49  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 21, 2013, 09:54:32 pm
Now enter maximum weirdness .
I took the older code and turned it into a couple of functions. I swear it worked last night very late. At work today this code froze at the uploading point and made  my serial programming port unreachable. I determined that the ReadRTCRAM() function is to blame. Does this make any sense to anybody
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 magnum1 = 90;      // dummy var
int magnum2 = 9;      //  dummy var

int  state   = 96;     // State machine variable
int  counter = 255;      // Master counter variable

void setup() {
   randomSeed(4);
  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 == 81 || command == 113) {      //If command = "Qq" RTC1307 Memory Functions
      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 is just too strange
50  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 21, 2013, 08:07:52 am
The example code uses noise from an unused analog pin seed the random() function. I think that will be good enough. My application does not require TRUE random numbers. The repeating pattern would really be good enough.
51  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 20, 2013, 06:57:04 pm
Indeed
52  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 20, 2013, 05:55:47 pm
OK, Some great help so far I have gotten this much running
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
int command = 0;       // This is the command char, in ascii form, sent from the serial port     
byte zero;
int  state   = 50;     // State machine variable
int  counter = 4;      // Master counter variable
int magnum1 = 99;      // dummy var
int magnum2 = 99;      //  dummy var

void setup() {
  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 == 81 || command == 113) {      //If command = "Qq" RTC1307 Memory Functions
      delay(100);     
      if (Serial.available()) {
        command = Serial.read();
        if (command == 49) {                //If command = "1"  load data to RAM
          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(magnum1);              // 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(magnum2);              // Write magic number after storing data
          Wire.endTransmission();

          Serial.println("Data Stored");
        }
        else if (command == 50) {      //If command = "2" Read data from RAM
          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");
        }
      } 
    }
  }
  command = 0;                 // reset command
  delay(100);
}
//********************************

now to figure out how to generate a random magic number
53  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 16, 2013, 07:03:26 pm
Quote
You can only store 0-255 in a byte.
To store 0-65535 (which is where 750 fits in) you need to use an int.

Check!
Makes sense. I was chopping it up in hundreds tens and ones. So 65535  is represented by two bytes. Int is doubleprecision ..Highbyte & Lowbyte.... Word puts them together.....got it

 Thank you for help!
54  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 16, 2013, 04:30:26 pm
Quote
You have the number stored using data type int, yes?
No I used Byte which was what the example showed. It seemed right should I change it?
I will post the trimmed down example I am working with.

Code:
/* Q(1-2) - (Q1) Memory initialization  (Q2) RTC - Memory Dump 
 
 */

#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address
#define I2C_WRITE Wire.write
#define I2C_READ Wire.read
// Global Variables
int command = 0;       // This is the command char, in ascii form, sent from the serial port     
int i;
long previousMillis = 0;        // will store last time Temp was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte test;
byte zero;
byte highbyte;
byte lowbyte;
byte state;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}


void setup() {
  Wire.begin();
  Serial.begin(57600);
  zero=0x00;
}

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


    if (command == 81 || command == 113) {      //If command = "Qq" RTC1307 Memory Functions
      delay(100);     
      if (Serial.available()) {
        command = Serial.read();
        if (command == 49) {        //If command = "1" RTC1307 Initialize Memory - All Data will be set to
          // 255 (0xff).  Therefore 255 or 0 will be an invalid value. 
          Wire.beginTransmission(DS1307_I2C_ADDRESS);   // 255 will be the init value and 0 will be considered
          // an error that occurs when the RTC is in Battery mode.

          Wire.endTransmission();
          Wire.beginTransmission(DS1307_I2C_ADDRESS);   

        // load dummy values to read back
          I2C_WRITE(0X08); // Set the register pointer to 33 for second half of registers. Only 32 writes per connection allowed.
          I2C_WRITE(24);
          I2C_WRITE(0X09); // Set the register pointer to 33 for second half of registers. Only 32 writes per connection allowed.
          I2C_WRITE(52);
          I2C_WRITE(0X0A); // Set the register pointer to 33 for second half of registers. Only 32 writes per connection allowed.
          I2C_WRITE(200);

          Wire.endTransmission();

          Serial.println(": RTC1307 Initialized Memory");
        }
        else if (command == 50) {      //If command = "2" RTC1307 Memory Dump

          Serial.println(": RTC 1307 Dump Begin");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          I2C_WRITE(0x08);                             // Set the register pointer to (0x08) to read first memory byte
          Wire.endTransmission();                     
          Wire.requestFrom(DS1307_I2C_ADDRESS, 1);     // In this case only read one byte
          state = Wire.read();
          //Serial.println(": RTC 1307 Dump Begin");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          I2C_WRITE(0x09);                             // Set the register pointer to (0x08) to read first memory byte
          Wire.endTransmission();                     
          Wire.requestFrom(DS1307_I2C_ADDRESS, 3);     // In this case only read one by
          highbyte
            = Wire.read();


          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          I2C_WRITE(0x20);
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 32); 
          for (i = 32; i <= 63; i++) {         //Register 32-63 - only 32 registers allowed per I2C connection
            test = I2C_READ();
            Serial.print(i);
            Serial.print(": ");
            Serial.print(test, DEC);
            Serial.print(" : ");
            Serial.println(test, HEX);
          }
          Serial.println(" RTC1307 Dump end");
        }
      } 
    }
    Serial.print("Command: ");
    Serial.println(command);     // Echo command CHAR in ascii that was sent
  }
  command = 0;                 // reset command
  delay(100);
}
//*****************************************************The End***********************



55  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 16, 2013, 03:45:58 pm
Quote
Did you bother looking at the reference page?
http://arduino.cc/en/Reference/WordCast
I did and found it rather terse.
 I have established two way communications with the RTC that is working with only a few bugs.
The code is ugly and I don't understand everything going on yet  but the real issue is the smashing and reconstruction of the data.

56  Using Arduino / Storage / Re: power outage recovery using DS1307 Real Time Clock on: January 16, 2013, 01:51:19 pm
Word!
have you got any example code showing how to implement such a thing?
57  Using Arduino / Storage / power outage recovery using DS1307 Real Time Clock on: January 16, 2013, 10:15:08 am
I have a project that uses a state machine with a master counter. The counter will have a maximum value of 750 or so. The state will be no larger than 50. As the counter updates every second it needs to be stored along with the state. The life span of the EEPROM rules him out so I decided to use the  leftover space on the RTC memory map. On power up I will read the contents of the ram to get state and counter values (If there was a power outage the numbers will not be state = 0 and counter = 0) and plug those values into the program during setup so that the state machine can resume where it left off.

.....So the question is how best to cut up that 750 number to store it in a couple of bytes on the RTC and then to reassemble the number after reading from the RAM.   
58  Using Arduino / Programming Questions / Re: Adafruit 2.8 TFT Shield Slow after adding touch feature on Mega on: December 07, 2012, 09:04:55 pm
"The stone age ended a long time ago. Pick up the pace!"



Well my wixel gave me problems over 9600 so Ihave been doing everything at that speed. And it is only for debugging.


Code:
tft.setCursor(0, 0);
       tft.fillScreen(BLACK);
      tft.setTextColor(GREEN);
      tft.setTextSize(5);
      tft.println("Waiting");

On every pass through loop()? Again, I doubt it.
 

 No I have a counter that only bulds the screen the first time through the loop. This was just a frag to show the effect.

Code:
   // if sharing pins, you'll need to fix the directions of the touchscreen pins
      //pinMode(XP, OUTPUT);
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      //pinMode(YM, OUTPUT);

On every pass through loop()? I doubt it.

So maybe poll every 10th or 100th iteration of the loop ?


59  Using Arduino / Programming Questions / Adafruit 2.8 TFT Shield Slow after adding touch feature on Mega on: December 07, 2012, 03:01:36 pm
I have 2 of the 2.8" TFT Shields from Adafruit plugged into 2 Mega 2560 Arduinos I have my program written and working for the most part.The valves are popping the pumps are pumping. The agitator is running. The timers are timing. Got the display up and displaying. Sweet, I have Two buttons plugged in right now , YES and ABORT.
Everything is peachy. I have it running for a few days as I play with the other Mega/TFT and the touch screen examples. Now I have my two touch buttons mapped and Printing to the serial monitor "Button 1" and "Button 2" on the second platform. Upon moving this piece of code into the unit I get the touch screen working but the display whites out. Ahhh the shared pins! Using The paint example as a guide I get the pin sharing working.

Now....the program is so slow you have to hold the soft button and wait for the update. Not good.
The Paint Program did not seem to have this problem

do I need to get rid of the shared pins?
Is there some clever code that I am missing?
Do I need a dedicated Arduino for the display? I have an Uno I could use.Maybe a SPI connection.

HELP!
HELP!



The gist of it is here
Code:
   #include <stdint.h>
    #include <Adafruit_GFX.h>    // Core graphics library
    #include <Adafruit_TFTLCD.h> // Hardware-specific library
    #include <TouchScreen.h>

    #ifndef USE_ADAFRUIT_SHIELD_PINOUT
    #error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file."
    #endif

    // These are the pins for the shield!
    #define YP A1  // must be an analog pin, use "An" notation!
    #define XM A2  // must be an analog pin, use "An" notation!
    #define YM 7   // can be a digital pin
    #define XP 6   // can be a digital pin

    #define TS_MINX 150
    #define TS_MINY 120
    #define TS_MAXX 920
    #define TS_MAXY 940


    TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

    #define LCD_CS A3
    #define LCD_CD A2
    #define LCD_WR A1
    #define LCD_RD A0

    // Assign human-readable names to some common 16-bit color values:
    #define   BLACK   0x0000
    #define   BLUE    0x001F
    #define   RED     0xF800
    #define   GREEN   0x07E0
    #define CYAN    0x07FF
    #define MAGENTA 0xF81F
    #define YELLOW  0xFFE0
    #define WHITE   0xFFFF


    Adafruit_TFTLCD tft;

    #define BOXSIZE   40
    #define PENRADIUS  4
    int oldcolor, currentcolor;

    void setup(void) {
      Serial.begin(9600);
      //progmemPrintln(PSTR("Paint!"));
      tft.reset();
      uint16_t identifier = tft.readID();
      tft.begin(identifier);
    tft.fillScreen(BLACK);
    pinMode(13, OUTPUT);
    }

    #define MINPRESSURE 10
    #define MAXPRESSURE 1000

    void loop()
    {
      tft.setCursor(0, 0);
       tft.fillScreen(BLACK);
      tft.setTextColor(GREEN);
      tft.setTextSize(5);
      tft.println("Waiting");
      digitalWrite(13, HIGH);
      Point p = ts.getPoint();
      digitalWrite(13, LOW);

      // if sharing pins, you'll need to fix the directions of the touchscreen pins
      //pinMode(XP, OUTPUT);
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      //pinMode(YM, OUTPUT);

      // we have some minimum pressure we consider 'valid'
      // pressure of 0 means no pressing!

      if (p.z > ts.pressureThreshhold) {
         Serial.print("X = "); Serial.print(p.x);
         Serial.print("\tY = "); Serial.print(p.y);
         Serial.print("\tPressure = "); Serial.println(p.z);
      }

    
    }





This is the offending code. This function bogs every thing down When added.
Code:
digitalWrite(13, HIGH);
Point p = ts.getPoint();
digitalWrite(13, LOW);
It was suggested that i had "reached the practical limits of what you can do on a Mega." But on the uno it was only marginally better.

Anybody familiar with this issue?
60  Using Arduino / Displays / Re: 2.8 tft ILI9325 touch menu's? on: December 05, 2012, 08:03:57 pm
I think I have the same display from electrodragon. I bought them as backups while the adafruit displays were on back order. But then we got the last two 2.8 TFTs from Ada. So in a week or so I will try my hand at the cheap ones.
However I did find this
Code:

/**
 * Touch Control Panel
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
 * Copyright 2009 Hugh Blemings <hugh@blemings.org>
 *
 * Reads touch coordinates on a Nintendo DS touch screen attached to an
 * Arduino and compares them to defined hot zones representing buttons
 * and sliders. If a touch occurs within a hot zone a matching event
 * message is sent to the host via the serial port.
 *
 * Based on the ReadTouchscreen example included in the TouchScreen
 * library.
 *
 *   www.practicalarduino.com/projects/touch-control-panel
 */
#include <TouchScreen.h>

TouchScreen ts(3, 1, 0, 2);

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

void loop()
{
  int coords[2];
  ts.read(coords);
  Serial.print(coords[0]);
  Serial.print(",");
  Serial.print(coords[1]);

  if((coords[0] > 696) && (coords[0] < 866)
  && (coords[1] > 546) && (coords[1] < 831)) {
    Serial.print(", Fan ON");
  }
  if((coords[0] > 696) && (coords[0] < 866)
  && (coords[1] > 208) && (coords[1] < 476)) {
    Serial.print(", Fan OFF");
  }
  if((coords[0] > 420) && (coords[0] < 577)
  && (coords[1] > 540) && (coords[1] < 866)) {
    Serial.print(", Drapes OPEN");
  }
  if((coords[0] > 420) && (coords[0] < 577)
  && (coords[1] > 208) && (coords[1] < 476)) {
    Serial.print(", Drapes CLOSE");
  }
  if((coords[0] > 139) && (coords[0] < 327)
  && (coords[1] > 208) && (coords[1] < 866)) {
    Serial.print(", Illumination:");
    Serial.print(constrain(map(coords[1], 318, 756, 0, 100), 0, 100));
    Serial.print("%");
  }

  Serial.println();
  delay (100);
}

Pages: 1 2 3 [4] 5