I got a question, my DS1302 keeps resetting his hour to 1/1/2000 with hour of: 0:00:00
Now I do have a battery in it, which is throwing 3V when the connection is offline, so backup power is not the issue, can somebody explain me what can be the issue?
Now I do have a battery in it, which is throwing 3V
I've seen batteries throw voltage before exploding. Not a pretty sight. Are you sure that your battery is throwing voltage? Not a gentle underhand toss?
PaulS:
I've seen batteries throw voltage before exploding. Not a pretty sight. Are you sure that your battery is throwing voltage? Not a gentle underhand toss?
When I mean throwing (word of speech), I mean that I get steady 3v from the battery, which is the expected rating from the Li-on battery, I measured it using my multimeter and I got 3.01V from it. which is fine rating.
PaulS:
So, if the device is working, it must be your code. You DID post in the Programming section, which means that you are expected to POST YOUR CODE!
As my code exceeds 9000 chars, it will be a link to a pastebin:
Your sketch is too long to include between code tags but you could have attached it to your post as a file.
The real question is why a sketch that purports to demonstrate that the RTC isn't working is more than 9000 characters. I could have demonstrated that in less than 1000.
PaulS:
The real question is why a sketch that purports to demonstrate that the RTC isn't working is more than 9000 characters. I could have demonstrated that in less than 1000.
Okay well here is the issue:
I'm working on an irrigation project, that includes RTC, Relay, LCD, Keypad, Bermad Water Taps, and an Arudino Mega 2560 R3.
I pasted all my code that I wrote in here.
I'll add my code as a file.
For whoever is asking from where I'm getting my hour:
DS1302 has on its own library a set time code, which I use to set the time.
It's past time that you read the stickies at the top of the forum. If you want help from google.com, post your question there If you want help here, post your code here.
If it exceeds the 9000 character limit, you have two choices. The best one is to strip out all the crap that has nothing to do with the problem. If the problem goes away, then clearly it wasn't related to the hardware the way you thought it was. The other is explained in the stickies that you will read before posting again.
PaulS:
There are other things you need to do to get the RTC ready to be used. That snippet is useless.
Alright, so I'm trying to figure out what you need (sorry for being retarded if that's what is happening)
I set the time using the Set Time function that is given within the DS1302 library, this is the code:
// Example sketch for interfacing with the DS1302 timekeeping chip.
//
// Copyright (c) 2009, Matt Sparks
// All rights reserved.
//
// http://quadpoint.org/projects/arduino-ds1302
#include <stdio.h>
#include <DS1302.h>
namespace {
// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip. See the DS1302
// datasheet:
//
// http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Sunday";
case Time::kMonday: return "Monday";
case Time::kTuesday: return "Tuesday";
case Time::kWednesday: return "Wednesday";
case Time::kThursday: return "Thursday";
case Time::kFriday: return "Friday";
case Time::kSaturday: return "Saturday";
}
return "(unknown day)";
}
void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Name the day of the week.
const String day = dayAsString(t.day);
// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
// Print the formatted string to serial so we can see the time.
Serial.println(buf);
}
} // namespace
void setup() {
Serial.begin(9600);
// Initialize a new chip by turning off write protection and clearing the
// clock halt flag. These methods needn't always be called. See the DS1302
// datasheet for details.
rtc.writeProtect(false);
rtc.halt(false);
// Make a new time object to set the date and time.
// Sunday, September 22, 2013 at 01:38:50.
Time t(2013, 9, 22, 1, 38, 50, Time::kSunday);
// Set the time and date on the chip.
rtc.time(t);
}
// Loop and print the time every second.
void loop() {
printTime();
delay(1000);
}
Then I use the hour I set in the code I sent before.
noweare:
Does your program increment time correctly when you the program is running, even though its the wrong time ?
My application shows the correct time. and increments everything perfectly.
PaulS:
There are other things you need to do to get the RTC ready to be used. That snippet is useless.
Well after going over my code, apparently now everything works fine and it saves the hour, I got another question tho.
I'm trying to work with a bluetooth module, HC-05 to receive data from an app I made, and compare it with the hour from the RTC. what do I need to do so I can make the arduino receive data from the bluetooth?
what do I need to do so I can make the arduino receive data from the bluetooth?
Threaten to take a sledgehammer to the device if it doesn't behave. I'm sure that the bluetooth device will shape right up.
If that should fail to work, I suspect that Mr. Google has other advice that might be more useful.
You know, stupid sh*t like how to connect the device to the Arduino, how to set up a HardwareSerial instance or to create a SoftwareSerial instance so that the Arduino can talk to the bluetooth device, and get data from it.
PaulS:
Threaten to take a sledgehammer to the device if it doesn't behave. I'm sure that the bluetooth device will shape right up.
If that should fail to work, I suspect that Mr. Google has other advice that might be more useful.
You know, stupid sh*t like how to connect the device to the Arduino, how to set up a HardwareSerial instance or to create a SoftwareSerial instance so that the Arduino can talk to the bluetooth device, and get data from it.
Thanks for the effective answer.. I know that Mr.Google has some great answers, but I thought you come into this forum to get helps and tips on how to make better codes and ask questions about code.
I'm very sorry that my question is not as expected, as I'm working on a big project that I need to present in the next couple of weeks, and I just need some explanation on how to use the serial communication. I just don't understand how can I read data from a phone and guess it's baud rate. (Or for instance, I can set my baud rate on the Arduino to 9600 which is pretty fine and the phone will auto tune to that baud rate).
I just don't understand how can I read data from a phone and guess it's baud rate.
You are not reading data from a phone. You are reading data from a bluetooth device. You do NOT need to guess the baud rate that the device communicates at. That is documented on the manufacturer's web site.
for instance, I can set my baud rate on the Arduino to 9600 which is pretty fine and the phone will auto tune to that baud rate).
What the phone does is not important. What the bluetooth device does is.
I'm working on a big project that I need to present in the next couple of weeks
So, you have a very complicated project, with lots of new stuff you've never used before, and it's taking longer than you guessed to get it all working. That bit about guessing is the problem. You should be tackling each piece of hardware with its own dedicated sketch, and no other hardware in the mix. Then, you'll understand, in the end, how to get it all to play together, and you'd have some experience to estimate how long the project will take. I can't get all worked up about you waiting too long to get started.
PaulS advice about attacking the project piece by piece is good advice. Get one thing working at a time. Divide and conquer if you will. That keeps the code that your trying to make work much easier to fix.
I would start a new thread about your Blue tooth issues. The title of your post will have Blue tooth in it (I assume). Doing that will give your thread responses from people that have blue tooth experience.
You never said what you fixed in the DS1302 problem.