Go Down

Topic: EEPROM overwite previous data? (Read 9044 times) previous topic - next topic

John_Smith

That was the plan originally Bob, but I I was put off by the 10 digit length of the number, but I think I can do it now
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Sure, just store as  2 bytes:
upperbyte = highByte(unix_time);
lowerbyte = lowByte(unix_time);

then put back together
old_unix_time = word (upperbyte, lowerbyte);
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

right, I was getting confused by changing it to binary, but I can keep it decimal.
45 years of editing projects with a knife and soldering iron, then I found Arduino !

John_Smith

I could get the unix time, convert it to days, and subtract most of  the days to make say Aug 1 2011 the datum , then I will have more manageable number to play with for many years to come.....
45 years of editing projects with a knife and soldering iron, then I found Arduino !

PaulS

Quote
I could go back to my original idea of splitting the unix code for the previous event, into bytes and saving them in the RTC ram, but its a big number ( 10 digits decimal )

The number of characters used when printed out is irrelevant. The unix time fits in a long, which is 4 bytes.
The art of getting good answers lies in asking good questions.

John_Smith

#35
Aug 15, 2011, 01:52 pm Last Edit: Aug 15, 2011, 02:00 pm by Boffin1 Reason: 1
Of course, thanks Paul

Would the Wire.requestFrom(RTC_address,4 )   be the same, as the number of files is the same ( 4 ) , but one is 4 bytes ?
45 years of editing projects with a knife and soldering iron, then I found Arduino !

John_Smith

The only library I have open is Wire,  how do I get Unixtime?
I have tried now() and (unix_time);
but it says not defined...
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Looks like Unix time is part of this library
http://www.arduino.cc/playground/Code/DateTime
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

Thanks Bob,, that's been superseded by Time.h  which I tried, but it didnt like hours and minutes, so I think I must just rename them in the sample you gave me, and I should be rolling.....
45 years of editing projects with a knife and soldering iron, then I found Arduino !

John_Smith


I am back on the RTC project again, and am having trouble writing to the DS1307s RAM,  I have tried a basic sketch just to store and retreive some data ( below )
Am I doing something stupid here?  It just gives me the old data back from the RAM

Code: [Select]


/*  just loading the ram for testing
*/
#include <Time.h> 
#include <Wire.h> 
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
byte prevday ;          //  prev days of month for display
byte prevmonth ;         //prev month for display
byte prevyear ;         //prev year  for display
byte prevbest ;   // highest longest interval up to 99
byte upperbyte;   //  of previous unix days
byte lowerbyte;   //  -"-
unsigned long old_unix_days;
unsigned long  unidays;
unsigned long  unisecs;
//*************************************************************************************
void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");     
     Wire.begin(); // no address, we are master
  Serial.begin (9600);     
}
void loop()
{

 
    prevday = 12;
  prevmonth= 10;
  prevyear = 33;
  prevbest = 87;
  upperbyte = 22;
  lowerbyte = 44;
 
Wire.beginTransmission(0x68); 
  Wire.send(0x08);  // to start of RAM
  Wire.endTransmission(); 

 
 
  Wire.send (prevday);
  Wire.send (prevmonth);
  Wire.send (prevyear);
  Wire.send (prevbest);
  Wire.send (upperbyte);
  Wire.send (lowerbyte);
  Wire.endTransmission();
Serial.println("finished loading"); 

  Wire.beginTransmission(0x68); 
  Wire.send(0x08);  // to start of RAM
  Wire.endTransmission(); 
  Wire.requestFrom(0x68,6 );  // Read back first six RAM addresses
  prevday = Wire.receive();
  prevmonth = Wire.receive();
  prevyear= Wire.receive();
  prevbest = Wire.receive(); 
  upperbyte = Wire.receive(); 
  lowerbyte = Wire.receive();
  Serial.print ("prev day read " );
  Serial.println (prevday, HEX);
  Serial.print ("prev month read " );
  Serial.println (prevmonth, HEX);
  Serial.print ("prev year read " );
  Serial.println (prevyear, HEX);
  Serial.print ("prev best read " );
  Serial.println (prevbest, HEX);
  Serial.print ("upperbyte read " );  Serial.print (upperbyte, HEX); Serial.print (" ,  upperbyte read " );  Serial.println (upperbyte, HEX);
  Serial.print ("lowerbyte read " );  Serial.print (lowerbyte, HEX);  Serial.print (",   lowerbyte read " ); Serial.println (lowerbyte, BIN);
  long old_unix_days = word (upperbyte, lowerbyte);
  Serial.print(" old_unix_days = ");  Serial.print (old_unix_days); Serial.print(",   old_unix_days = "); Serial.println(old_unix_days, BIN);
}
45 years of editing projects with a knife and soldering iron, then I found Arduino !

John_Smith

I found the problem.....

I had  Wire.endTransmission();    after setting the pointer , removed it and it works
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

I blame it on being hard to read the screen after 3 days testing the previous project with 1000 ultra bright white LEDs :-)   I could literally switch off the rooms normal lights without seeing any difference - depending on the numbers being displayed of course !
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Shades, John 8), protect yourself 8)
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

True Bob,  I do have prescription glasses that darken in sunlight, I forgot to test them on the white LEDs, I must check that.

On a serious note, one of my suppliers has a display with all the different colour LEDs on all day, including the blue ones that I use for illuminating flourescent targets,( they have so much ultra violet content.)
I have warned him about damage to his counterstaffs' eyes, I temporary ( 2 hours or so ) lost the sight of one eye a couple of years back when experimenting with a couple of ultraviolet LEDs, so I am very wary now.
45 years of editing projects with a knife and soldering iron, then I found Arduino !

Go Up