Basic Arduino Clock

I do not have a pull up on the DHT11, but should I? I'm getting an output from it. And yes, I have a DMM, I was using it late yesterday to verify the buttons were working. When pressed in the setup I currently have, I get a reading of about 4.5-4.8V.

Normally the buttons are wired to ground without resistors if you use INPUT_PULLUP. Then you test for if (digitalRead(pin) == LOW) when the button is pressed.

What do yo get at the same point when the button is not pressed? Where are you measuring this voltage? In other words where are yo placing the two probes of your DMM?

I just double-checked the multimeter at the points at which ground and a digital pin (IE Digital pin 10) were connected to the push buttons. All have about 4.7V, and when pressed they output 0V.

Sounds right. is yout code checking for LOW?

The code I originally made is in my first post, the more I've been troubleshooting leads me to think I've messed up my code somewhere, but I'm unsure and I'm not great with coding, and even less familiar with C++.

The button code from post #16 should work, even though the debouncing follows the "just wait for an eternity after registering a press" variety. It will act like a PC keyboard auto repeat, except that there is no delay before the repetition starts. So you have to sort of "poke" the button if you only want to register once. That is because there is no state change logic.

If it still doesn't work, I suggest writing a simple test sketch that only reads the button states and reports them to serial.

That's actually something I tried to articulate in post #16 as well, as the hour and minutes can be set with the code attached. However, the seconds do not move, alarms do not appear to be set, the time is stationary (IE- I set it to 2:12 am, it will not move from 2:12, nor will it switch to pm), and I am unable to see if the date is changing.

Have you run the DS3231 library example sketches, to verify that the RTC is working and accessible?

Pin 20,21 are the secondary MCU pin assignments for I2C, not primary. Why are you using those and not the SDA, SCL pins?

I was under the impression based on this post:

That pins 20 and 21 were okay. Additionally, that's whats annotated on both Mega2560's that I have (Digital pins 20and 21 being SDA and SCL accordingly).

It's hard to interpret your answer. Are you rejecting my suggestion? The post you quoted seems to be advising against using pin 20,21... Here is the official pin out:


Also, you didn't answer the question.

Do you think, having a suspicious deviation from the norm pointed out to you, it makes more sense to investigate it, or to sit and find reasons to deny it?

I see that you are typing... myself, I would be trying the test. Then, when it fails, move the I2C pins to where they are supposed to be.

I apologize I'm not trying to reject anything I'm trying to gain a better understanding. The Pins 20 and 21 I'm using are D20 and D21 in accordance with the pin out you present, which may be why I failed to understand the original question and I apologize for that

It would be easier to understand once it is working. The pin out I present (official Arduino pin out) does not list I2C functions for pins 20,21. However it does list pins SDA and SCL which are the normal I2C pins.

Now do you understand?

Pin 20 is SDA & pin 21 is SCL on a Mega. It is actually printed on the board itself. One reason for the extra SDA/SCL header pins is so shields can work with both an UNO and a Mega without changing the wiring.

https://store-usa.arduino.cc/collections/boards/products/arduino-mega-2560-rev3

1 Like

Okay, but don't you agree it would be a good idea to test the RTC independently? Also why is it running on 3.3V?

Would be good to test each component individually if it is giving problems.

One problem I see with the schematic is running the RTC at 3.3V, usually that is run at 5V with a processor that runs at 5V, like the Mega does.

You beat me to it. I see the Mega has pull up resistors to 5V on board...

It's nice to use a library that will return an error code from the init() method, if the hardware isn't found... and to use it to print an error message...

Is there an Arduino Library that you suggest for me to use to test if the ds3231 is functioning correctly?

I've moved the DS3231 to a 5V input with the same results I had before

Sure, how about the library you already have installed? Usually, when you install a library, the example sketches become accessible via the IDE menu system.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.