I've spent hours looking for a basic tutorial that shows how to set up a RTC 3231. After installing the 3232 library, the red light on the 3231 came on. I opened the serial monitor to set time and added 17,1,8,11,45,30, When I clicked send it disappeared-I don't know if the time is set or not.
This sketch works for manually dimming the LEDs with a pot. Now, I need to turn the LEDs on and off with the 3231. Any help would be much appreciated.
#include <DS3232RTC.h>
int nemLED = 3;
int nemPOT = A1;
int rightrockLED = 5;
int rightrockPOT = A2;
int leftrockLED = 6;
int leftrockPOT = A3;
int purpLED = 9;
int purpPOT = A4;
int FANS = 4;
void setup() {
pinMode(nemPOT, INPUT);
pinMode(nemLED, OUTPUT);
pinMode(rightrockPOT, INPUT);
pinMode(rightrockLED, OUTPUT);
pinMode(leftrockPOT, INPUT);
pinMode(leftrockLED, OUTPUT);
pinMode(purpPOT, INPUT);
pinMode(purpLED, OUTPUT);
pinMode(FANS, OUTPUT);
}
void loop(void) {
analogWrite(nemLED, (analogRead(nemPOT)/ 4));
analogWrite(rightrockLED, (analogRead(rightrockPOT)/ 4));
analogWrite(leftrockLED, (analogRead(leftrockPOT)/ 4));
analogWrite(nemLED, (analogRead(nemPOT)/ 4));
analogWrite(purpLED, (analogRead(purpPOT)/ 4));
digitalWrite(FANS, HIGH);
}
Post the sketch that you used to set the time on the DS3231 then some one will help you to add a serial print statement to it which will confirm that the time has been correctly set.
I went to that link and clicked on the Download RTClib and selected save. Then, I went to documents, then downloads and found RTClib-master.zip.
The directions say to rename the uncompressed file, but the only option I can find to rename is with the compressed file.
Where have I gone wrong?
Thanks for that link. I was looking at YouTube videos and between people flying around on computer screens and poor images, I was having an awful time. Reading something is better. Still stuck, but not as bad.
saltyjoe:
...
Have I done something the wrong way?
...
Obviously, cause if you hadn't, it would be working to your satisfaction, right?
We don't know what you are doing. You need to use code tags and post your code - the code you are using to set the time, not your LED dimming code! I don't get why you typed 17,1,10,8,56,30 into the serial monitor. If you were running the sketch you posted in the OP, then you have certainly NOT set the time.
Add a link to the RTC you are using. I don't know of any that have a red LED on them.
Here's the code I used this morning. Sorry, I'm not sure what a code tag is...
I followed the instructions Jack Christianson included with the example. I got no indication time was set. That's why I wondered if maybe I have bad hardware.
letter to Creative Commons, 171 Second Street, Suite 300, *
San Francisco, California, 94105, USA. *
*----------------------------------------
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h> //http://arduiniana.org/libraries/streaming/
#include <Time.h> //http://playground.arduino.cc/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire
void setup(void)
{
Serial.begin(115200);
//setSyncProvider() causes the Time library to synchronize with the
//external RTC by calling RTC.get() every five minutes by default.
setSyncProvider(RTC.get);
Serial << F("RTC Sync");
if (timeStatus() != timeSet) Serial << F(" FAIL!");
Serial << endl;
}
void loop(void)
{
static time_t tLast;
time_t t;
tmElements_t tm;
//check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
if (Serial.available() >= 12) {
//note that the tmElements_t Year member is an offset from 1970,
//but the RTC wants the last two digits of the calendar year.
//use the convenience macros from Time.h to do the conversions.
int y = Serial.parseInt();
if (y >= 100 && y < 1000)
Serial << F("Error: Year must be two digits or four digits!") << endl;
else {
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else //(y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = Serial.parseInt();
tm.Day = Serial.parseInt();
tm.Hour = Serial.parseInt();
tm.Minute = Serial.parseInt();
tm.Second = Serial.parseInt();
t = makeTime(tm);
RTC.set(t); //use the time_t value to ensure correct weekday is set
setTime(t);
Serial << F("RTC set to: ");
printDateTime(t);
Serial << endl;
//dump any extraneous input
while (Serial.available() > 0) Serial.read();
}
}
t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
if (second(t) == 0) {
float c = RTC.temperature() / 4.;
float f = c * 9. / 5. + 32.;
Serial << F(" ") << c << F(" C ") << f << F(" F");
}
Serial << endl;
}
}
//print date and time to Serial
void printDateTime(time_t t)
{
printDate(t);
Serial << ' ';
printTime(t);
}
//print time to Serial
void printTime(time_t t)
{
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}
//print date to Serial
void printDate(time_t t)
{
printI00(day(t), 0);
Serial << monthShortStr(month(t)) << _DEC(year(t));
}
//Print an integer in "00" format (with leading zero),
//followed by a delimiter character to Serial.
//Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) Serial << '0';
Serial << _DEC(val);
if (delim > 0) Serial << delim;
return;
}
The fact that the scanner hangs instead of returning "No devices found" is a bad sign.
What does the scanner program give you with nothing connected to the I2C lines. If it hangs, there is a problem with the arduino. If it says no devices found, then there is most likely a short between SDA and SCL or between either one of them and ground or to 5v on the module.
You have a hardware problem which must be solved before you can make any progress.
I found my unopened UNO and unopened RTC3231 and uploaded the SetSerial example from post #7 with the exact same results. I ran the I2C scanner with the same results.
The baud rate is the same in sketch and serial monitor-115200. Autoscroll is checked and No line ending is selected.
I entered the time in the top space in line with the send button as, 17,1,11,8,10,30, then clicked send.
The same thing twice in a row with different hardware makes me think I must be doing something wrong. Any ideas?
ChrisTenone:
You need to use code tags
Ok, now I know those code brackets are called code tags. I didn't put the comments and instructions in the code tags because I thought they were strictly for code. Next time, comments will be included.
AREF can not be used as a general I/O pin like you are attempting. If you wish to plug the module directly into a header, use A2,A3,A4,A5 and run the following code. A4 is SDA and A5 is SCL. A2 will be gnd, and A3 will supply 5v.
#include <Wire.h>
void setup() {
pinMode(A2, OUTPUT);//setup for rtc on A2,A3
digitalWrite(A2, LOW);
pinMode(A3, OUTPUT);
digitalWrite(A3, HIGH);
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {
}
Thank you cattledog, that was the problem alright. I appreciate that sketch, but I am using A1, A2, A3 and A4 for dimming my LEDs so I straightened the VCC pin from the 3231 and soldered a wire to it and hooked it to 5V.
In order to make the RTC turn my LEDs on and off, would I use the SetSerial example as a foundation sketch and add my dimming LED sketch to it, as well as some command for on and off?
In order to make the RTC turn my LEDs on and off, would I use the SetSerial example as a foundation sketch and add my dimming LED sketch to it, as well as some command for on and off?
Once you set the RTC, you will more likely be using the ds3232 library example TimeRTC as the model. You will actually be using the syntax from the Time Library for much of how you deal with time. The time Library will update/synchronize the internal arduino clock to the actual time contained in the RTC. You might also wish to use the Time Alarms Library depending on what timing you want for the leds.
Now that you have the RTC functioning, you will be better off posting the code you have for the LED's and their timing of turning on and off in a new sketch. The sketch you originally posted made no use of time, and it was not at all clear how you wanted to turn the led's on and off. Make an effort to incorporate timing, and post a new sketch in a new thread. You mention "dimming", and that is not something typically done with the rtc, and is more likely to use a "blink without delay" approach where you change the analogWrite() duty cycle at fixed intervals. The rtc is more likely to be used if you want to start "dimming" as a specific time of day.