Show Posts
Pages: 1 ... 10 11 [12] 13 14 ... 16
166  Forum 2005-2010 (read only) / Interfacing / Re: Using EEPROM chips? on: February 06, 2010, 01:30:34 pm
I made a mistake and had made an assumption.  Your chip does not communicate via I2C.  The one I'm using is.  The following probably won't help you at all.  Sorry.

Maybe this will be of some help.  I recently got a DS1307 sample from Dallas Semiconductor.  It has 56 bytes of memory.  Once I was able to read and write the clock, I learned how to write and read back from its internal memory.  Look at the attached code.  I made a few changes to read and write to memory.  In particular, look at the routines putMemDs1307 and getMemDs1307.

Does this help?


Code:
/*
 * RTC Control v.01
 * by <http://www.combustory.com> John Vaughters
 * Credit to:
 * Maurice Ribble - http://www.glacialwanderer.com/hobbyrobotics for RTC DS1307 code
 *
 * With this code you can set the date/time, retreive the date/time and use the extra memory of an RTC DS1307 chip.  
 * The program also sets all the extra memory space to 0xff.
 * Serial Communication method with the Arduino that utilizes a leading CHAR for each command described below.
 *
 * Commands:
 * T(00-59)(00-59)(00-23)(1-7)(01-31)(01-12)(00-99) - T(sec)(min)(hour)(dayOfWeek)(dayOfMonth)(month)(year) - T Sets the date of the RTC DS1307 Chip.
 * Example to set the time for 02-Feb-09 @ 19:57:11 for the 3 day of the week, use this command - T1157193020209
 * Q(1-2) - (Q1) Memory initialization  (Q2) RTC - Memory Dump
 *
 * If command = "C" RTC1307 Get Time and Date
 * If command = "P" RTC1307 Get Time and Date and put in memory
 * If command = "G" RTC1307 Get Time and Date from memory and display
 * Analog pin 4 - SDA (pin 5 on DS1307)
 * Analog pin 5 - SCL (pin 6 on DS1307)
 */  

#include <Wire.h>

int clockAddress = 0x68;  // This is the I2C address
int command = 0;  // This is the command char, in ascii form, sent from the serial port    
long previousMillis = 0;  // will store last time Temp was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte test;
byte trial;
// 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) );
}

  // 1) Sets the date and time on the ds1307
  // 2) Starts the clock
  // 3) Sets hour mode to 24 hour clock
  // Assumes you're passing in valid numbers,
  // Probably need to put in checks for valid numbers.

void setDateDs1307()                
{
                              // Use of (byte) type casting and ascii math to achieve result.  
  second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
  minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  dayOfWeek = (byte) (Serial.read() - 48);
  dayOfMonth = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  Wire.beginTransmission(clockAddress);
  Wire.send(0x00);
  Wire.send(decToBcd(second));  // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));    // If you want 12 hour am/pm you need to set
  // bit 6 (also need to change readDateDs1307)
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.endTransmission();
}

                              // Gets the date and time from the ds1307 and prints result

void getDateDs1307() {        // Reset the register pointer
  Wire.beginTransmission(clockAddress);
  Wire.send(0x00);
  Wire.endTransmission();

  Wire.requestFrom(clockAddress, 7);

                              // A few of these need masks because certain bits are control bits

  second     = bcdToDec(Wire.receive() & 0x7f);
  minute     = bcdToDec(Wire.receive());
  
                              // Need to change this if 12 hour am/pm
  hour       = bcdToDec(Wire.receive() & 0x3f);  
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());

  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);

}

void getTimeDs1307() {
  Wire.beginTransmission(clockAddress);
  Wire.send(0x00);                        // Reset the register pointer
  Wire.endTransmission();

  Wire.requestFrom(clockAddress, 7);

  second     = (Wire.receive() & 0x7f);
  minute     = (Wire.receive());
  hour       = (Wire.receive() & 0x3f);  
  dayOfWeek  = (Wire.receive());
  dayOfMonth = (Wire.receive());
  month      = (Wire.receive());
  year       = (Wire.receive());
}

void putMemDs1307() {
  //get the time from the clock and then put into memory address 0x08
  //this routine can be used for data logging purposes
  Wire.beginTransmission(clockAddress);
  Wire.send(0x08);
  Wire.send(second);
  Wire.send(minute);
  Wire.send(hour);
  Wire.send(dayOfWeek);
  Wire.send(dayOfMonth);
  Wire.send(month);
  Wire.send(year);
  
  Wire.endTransmission();
  
/*  The following is commented out.  It was originally used to see what was being put into memory
    and then compared to what I pulled from memory.  One I was comfortable with the results,
    I no longer used this code.
 
  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
*/
}

void getMemDs1307() {
  // Get the contents of memory location 0x08 and send to the PC for display
  Wire.beginTransmission(clockAddress);
  Wire.send(0x08);
  Wire.endTransmission();

  Wire.requestFrom(clockAddress, 7);  //request 7 bytes from the clock

                              // A few of these need masks because certain bits are control bits

  second     = bcdToDec(Wire.receive() & 0x7f);   //byte #1
  minute     = bcdToDec(Wire.receive());          //byte #2
  hour       = bcdToDec(Wire.receive() & 0x3f);   //byte #3...
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());
  
  Serial.print(hour, DEC);                   //print the values to the PC
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);

}  

void setup() {
  Wire.begin();
  Serial.begin(57600);

}

void loop() {
  if (Serial.available()) {   // Look for char in serial que and process if found
    command = Serial.read();
    if (command == 84) {      //If command = "T" Set Date
      setDateDs1307();
      getDateDs1307();
      Serial.println(" ");
    }
    else if(command == 67){ //If command = "C" RTC1307 Get Time and Date
      getDateDs1307();
      Serial.println(" ");
    }
    else if(command == 80){ //If command = "P" RTC1307 Get Time and Date and put in memory
      getTimeDs1307();
      putMemDs1307();
      Serial.println(" ");
    }
    else if(command == 71){ //If command = "G" RTC1307 Get Time and Date from memory and display
      getMemDs1307();
      Serial.println(" ");
    }
    
    else if (command == 81) { //If command = "Q" RTC1307 Memory Functions
      delay(100);    
      if (Serial.available()) {
        command = Serial.read();
        
                              // If command = "1" RTC1307 Initialize Memory - All Data will be set to 255 (0xff).  
                              // Therefore 255 or 0 will be an invalid value.  
        if (command == 49) {
          
                              // 255 will be the init value and 0 will be cosidered an error that
                              // occurs when the RTC is in Battery mode.
          Wire.beginTransmission(clockAddress);
          
                              // Set the register pointer to be just past the date/time registers.
          Wire.send(0x08);  
          for (int i = 1; i <= 27; i++) {
            Wire.send(0xff);
            delay(100);
          }  
          Wire.endTransmission();
          getDateDs1307();
          Serial.println(": RTC1307 Initialized Memory");
        }
        else if (command == 50) {      //If command = "2" RTC1307 Memory Dump
          getDateDs1307();
          Serial.println(": RTC 1307 Dump Begin");
          Wire.beginTransmission(clockAddress);
          Wire.send(0x00);
          Wire.endTransmission();
          Wire.requestFrom(clockAddress, 64);
          for (int i = 1; i <= 64; i++) {
            test = Wire.receive();
            Serial.print(i);
            Serial.print(":");
            Serial.println(test, DEC);
          }
          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);
}
167  Forum 2005-2010 (read only) / Interfacing / Re: Finding Certain Connector on: February 07, 2010, 10:41:27 pm
I would start by looking through the Digikey website and Allied Electronics site.  Both should have something close to what you are looking for.  I have a catalog at work.  Maybe I'll remember to thumb through it tomorrow.
168  Forum 2005-2010 (read only) / Interfacing / Re: Problems with analogRead() on: February 07, 2010, 01:35:23 pm
Without seeing your code, it is difficult to say.  One reason could be because you don't have a delay in your code after taking a reading and then displaying.  It is taking readings and updating as fast as it can.  The other answer could be that you may need to use a capacitor and resistor on your accelerometer output to "slow it down".  The accelerometer output can change pretty fast.  I had experimented with one a while back and I wound up using a capacitor and resistor from the output of the accelerometer to ground.  By sizing the cap and resistor appropriately, you can keep the output from changing so quickly.
169  Forum 2005-2010 (read only) / Interfacing / Re: Sanguino help on: February 04, 2010, 03:56:24 pm
kishore, were you able to get your test up and running?  Did you find the problem?  Hope it is working now.
170  Forum 2005-2010 (read only) / Interfacing / Re: Sanguino help on: February 01, 2010, 01:51:01 pm
How do you have your potentiometer connected?  You should have one end tied to ground, the other to +5V and the wiper should be tied to your analog input.  Let's start there and work from that.  I think once you have some confidence that you're reading what you expect to read, then you can move on to the sensor.
171  Forum 2005-2010 (read only) / Interfacing / Re: Sanguino help on: February 01, 2010, 10:52:17 am
I've been looking over the datasheet on this, but haven't found a definite answer to your question.  I suggest looking at this thread as it may provide some useful information for you:  http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224321879
172  Forum 2005-2010 (read only) / Interfacing / Re: How to flash a led without stopping the loop? on: December 20, 2009, 12:00:23 am
You could write your loop so that increments and integer each time through.  Set up an IF statement that is dependent on the value of the incremented integer.  For example, if you were counting from 0 to 1023, you could say IF x < 511, LEDPin = HIGH.  IF x > 512, LEDPin = LOW.  The loop would continue running, but the value of your integer would determine the state of your output pin.

At 16MHz, it would get to 1023 pretty quickly, so you may have to other things to make it slow enough for human perception, but this should give you something to work with.

I'm sure there are other ways to do this as well.  This is just one of many.
173  Forum 2005-2010 (read only) / Interfacing / Re: PTC Thermistor? on: October 28, 2009, 07:06:40 pm
I think the easiest thing to do is use your volt meter.  If it is a 10k resistor, it will measure 10k at 77 deg F.  As you heat, the resistance should go up, if it is PTC.  If the resistance goes down with increasing temperature, it is NTC.  Hope this helps.
174  Forum 2005-2010 (read only) / Interfacing / Re: 3-wire phased motor (cd-rom) on: September 12, 2009, 08:08:30 pm
I don't know how to control one, but a CDROM motor is a brushless dc motor (BLDC).  Search around the forum.  You should find some postings about them.
175  Forum 2005-2010 (read only) / Interfacing / Re: camera remote on a timer (lots of help needed) on: September 12, 2009, 08:14:18 pm
I'm working on this same project.  I have the code nearly finished, and I had planned on using software to fire an infrared LED in the correct sequence.  Unfortunately, that part has failed.  I plan to use the Nikon remote, as you are planning.  I haven't acquired a proper relay yet, but I plan to use the arduino to fire the relay, which will provide the contact at the contact points on the remote control circuit board.  The relay should have a pretty consistent delay time, so I don't think it will throw too much of a wrench into things.  I'm using buttons and an LCD screen to choose millisecond and microsecond delay timing.  Once an input, such as a light beam, triggers the arduino, it waits for the specified time and then fires the remote, which fires the camera.

As to the remote control input voltage.  It is a 3VDC lithium battery.  You could use the 3.3V power supply on the Arduino to power it with not problem.

Good luck!
176  Forum 2005-2010 (read only) / Interfacing / Re: Adding buttons to Arduino on: August 23, 2009, 08:48:45 am
The entire code is not listed here, so I put some snippets in for you.

I did something like this:

int backBtn = 14;          //These are the input buttons
int incBtn = 15;
int decBtn = 17;
int nextBtn = 18;
int escapeBtn = 16;

void setup()
{
   pinMode(backBtn,INPUT);         //set pin as input
   digitalWrite(backBtn, HIGH);    //turn on the internal pull-up
   pinMode(incBtn,INPUT);
   digitalWrite(incBtn, HIGH);     //turn on the internal pull-up

ETC.

then when I read buttons:

void readBtns()
{
   back = digitalRead(backBtn);      //Read the value of backBtn
   next = digitalRead(nextBtn);      //Read the value of nextBtn
   escape = digitalRead(escape_Button);  //Read the value of escape_Button
   inc = digitalRead(incBtn);        //Read the value of incBtn
   dec = digitalRead(decBtn);        //Read the value of decBtn
   delay(debounce);                  //Wait a short time

The buttons are tied to ground on one side and to the input pin on the other side.  In the setup, I defined the pin as an input and then set the pull up with digitalWrite to HIGH.

Hopefully, this makes a bit more sense.
177  Forum 2005-2010 (read only) / Interfacing / Re: Adding buttons to Arduino on: August 22, 2009, 05:39:24 pm
I built a board for my arduino that I can plug an LCD into and it has buttons as well.  See it here:  http://www.flickr.com/photos/flyboy19/3418741211/in/set-72157616348500003/
I use the analog pins in digital mode, turned on the internal pullups and then used the buttons to ground the inputs when the buttons are pushed.  It took some time, but it has been a very useful development tool.
178  Forum 2005-2010 (read only) / Interfacing / Re: LCD stays blank - debugging? on: July 25, 2009, 07:43:42 am
Jonas,

Check your contrast adjustment.  The first time I tried and LCD, I thought it was messed up.  Turned out, I was the one messed up.  It caught me again later on too, so that's the first thing I'd check.  Unless you put voltage in the wrong place of give it too much voltage, it should be pretty robust.
179  Forum 2005-2010 (read only) / Interfacing / Re: humidity sensors cheap and accurate on: June 22, 2009, 08:50:49 pm
I have several SHT-11 Sensirion temperature / humidity sensors mounted on a board with 0.1" male pins.  I've been thinking about putting them on ebay.

You may like these:  http://www.flickr.com/photos/flyboy19/3651924379/in/photostream/
180  Forum 2005-2010 (read only) / Interfacing / Re: Best way to log mA/V for a NiMh solar charger? on: May 02, 2009, 05:56:02 pm
I've never dealt with battery charging, but I would like to get into that in the very near future.

Regarding the task at hand, I think a temperature limit safety would be an excellent idea.  I'm not sure how high the limit should be, but that would be one thing I'd recommend.  Another good idea would be to use current limiting.  I believe C/10 is typically the charging current you want.  You could implement a digital resistor to control a transistor.  You could use your voltage divider circuit to monitor the voltage and current.
Pages: 1 ... 10 11 [12] 13 14 ... 16