Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 29 21:20
    Makuna unlabeled #110
  • Sep 29 21:20
    Makuna closed #110
  • Sep 29 21:15

    Makuna on master

    enable travis build using platf… (compare)

  • Sep 29 21:15
    Makuna closed #116
  • Sep 23 20:22
    Makuna closed #120
  • Sep 23 20:22
    Makuna updated the wiki
  • Sep 23 20:13
    Makuna updated the wiki
  • Sep 23 08:34
    T0m92 opened #120
  • Aug 27 15:58
    Makuna closed #119
  • Aug 27 15:58
    Makuna labeled #119
  • Aug 27 15:55
    Makuna closed #118
  • Aug 27 08:15
    Bredahl opened #119
  • Aug 03 15:39
    Flavian opened #118
  • Aug 01 19:24
    Makuna closed #117
  • Aug 01 17:19
    lucagrosshennig opened #117
  • Jul 31 17:46
    thijstriemstra opened #116
  • Jul 25 23:30

    Makuna on 2.3.5

    (compare)

  • Jul 25 23:28

    Makuna on NextRelease

    (compare)

  • Jul 25 23:28

    Makuna on master

    increment version (#115) (compare)

  • Jul 25 23:28
    Makuna closed #115
Marco
@marcolino7
@Makuna thanks for clarification. I'm writing a firmware that have a lot of code, so I prefer to split function in more files. This is the main reason.
Michael Miller
@Makuna
@marcolino7 My suggestion would be to then follow a design pattern that you abstract what you need the RTC to accomplish within your code behind an API (.h/.cpp) and then in that code include and instance the RTC object. It should accomplish your goals.
Sterminatore
@Sterminare
Hello, I'm looking for some help. Im a bit of a beginner. I am making a clock with three voltmeters, one for hour, minute, and second. I need to take the hour, minute, and seconds value, and convert it to a value between 0-255 so I can analogWrite it to each voltmeter. Basically I just need to know how I can have a variable equal to the hours, another equal to the minutes, another equal to seconds value and I can do the rest. Thanks
Michael Miller
@Makuna
Just use the accessors methods on the RtcDateTime object.
See wiki pages here
Sterminatore
@Sterminare
Im sorry i don't really understand the terminology well, am I supposed to write 'uint8_t' or is that a placeholder for something else?
Sterminatore
@Sterminare
analogWrite(secondsPin, (RtcDateTime.Second() / 60) * 255);
doesnt work
Michael Miller
@Makuna
@Sterminare do you know what a uint8_t is? How about byte? Search for these terms and you will learn them.
When you say it doesn't work, how does it not work? What did you do to investigate how it doesn't work? My first suggestion is take your little math routine and print out in debug the results. I think you will you find you get either a zero or 255, nothing else. You need to understand how C/C++ handles integer math types. What is 59/60 calculate out to be when doing integer math? Answer this and you will understand whats wrong.
Sterminatore
@Sterminare
So I need to figure out how to make sure it doesnt round, that
is something I can figure out, but is it right that RtcDateTime.Second() is the value of how many seconds have passed since the last minute? etc for RtcDateTime.Minute() since last hour and RtcDateTime.Hour() since midnight?
Sterminatore
@Sterminare
What I put above does not compile, it says 'primary expression expected before ".". I tried changing it to RtcDateTime().Second() but that doesnt seem right and unsurprisingly trying to print this to serial it is just blank (I assume undefined).
I've gotten it figured out. I was able to declare global seconds, minutes, hours variables and then in the printDateTime() function, after printing it to serial I have it seconds=dt.Second(); minutes=dt.Minute(); hours=dt.Hour();
Jay
@jay-ramani

Hi Michael, I'm working on a DS1302 based RTC on an Arduino Uno R3, and trying to reduce global storage while I'm already pressed for RAM with other global variables I cannot do away with. I'm not well versed in C++ (though I have worked on C), and having trouble doing away with a dedicated ThreeWire object with the statements below

ThreeWire interface_three_wire(PIN_ARDUINO_RTC_IO, PIN_ARDUINO_RTC_SCLK, PIN_ARDUINO_RTC_CE);

RtcDS1302<ThreeWire> Rtc(interface_three_wire);

to

RtcDS1302<ThreeWire> Rtc(ThreeWire(PIN_ARDUINO_RTC_IO, PIN_ARDUINO_RTC_SCLK, PIN_ARDUINO_RTC_CE));

With passing an object like this, I'm getting this error:

RTC_DS1302:373:29: error: cannot bind non-const lvalue reference of type 'ThreeWire&' to an rvalue of type 'ThreeWire'

Would be great if you could help. Thanks.

Michael Miller
@Makuna
C++ is not C# (or Java/Python/etc), objects DO NOT have reference counts or lifetimes based on held references.
The issue is that the argument is defined to be a "reference" to the object. The compiler is catching that you are passing a temporary object. After the construction of the RtcDS1302, the object you pass will no longer exist and the rtc object would have had an invalid reference.
Michael Miller
@Makuna
Due to how Arduino defines most wire as a global object rather than let the user create it, the interface of the Rtc libraries requires the passing of the reference.
VoicelessProximity1701
@VoicelessProximity1701
Hi
I am having a problem with my DS3231 module, in that it keeps on saying etc not declared in this scope
Here is the code I am using

include <RTClib.h>

include <SD.h>

include <SPI.h>

include <DS3231.h>

File myFile;
int pinCS = 53; // Pin 10 on Arduino Uno
void setup() {

Serial.begin(9600);
pinMode(pinCS, OUTPUT);

// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
rtc.begin();
}
void loop() {
Serial.print(rtc.getTimeStr());
Serial.print(",");
Serial.println(int(rtc.getTemp()));

myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.print(rtc.getTimeStr());
myFile.print(",");
myFile.println(int(rtc.getTemp()));
myFile.close(); // close the file
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
delay(3000);

I am using an Arduino/Elegoo Mega 2560
Michael Miller
@Makuna
@VoicelessProximity1701 Your sketch has many issues and does not match my library in the calls you are using. Please review the samples included with the library and you will should discover all the issues I spot.
VoicelessProximity1701
@VoicelessProximity1701
Ok thanks 👍
Luca Grosshennig
@lucagrosshennig
Hey I have a question. I have to use the DS3231 in parallel with an other i2c sensor. But I dont know where to specify the i2c address of the rtc. Can you help me?.
Ps: Sorry for the bad language
Michael Miller
@Makuna
@lucagrosshennig You don't need to supply the i2c address as the DS3231 only supports one address and the library defines this internally. While some i2c devices support more than one address, the DS3231 does not.
Does your device support more than one? What addresses does it support?
Luca Grosshennig
@lucagrosshennig
@Makuna I want to use the DS3231 in parallel with a BME280 over the same i2c pins. Seperatly they work properly but when I try to use both of them the sensor outputs are nuts.
Michael Miller
@Makuna
What address are you using for the BME280? The DS3231 is 0x68(hex).
Michael Miller
@Makuna
The spec sheet states the BME280 is 0x60, so no overlap there. What library are you using to read data for it?
And what platform? You can't access the same I2C bus with different threads (tasks) without using some blocking mechanism on top of the APIs.
Ivan Maltarić
@jasamico_twitter
Hi, I'm using your library with my DS1302. It's about 30 late but thats not a big deal, minutes and hours are the important thing I should watch for. Although I managed to print time in a nice format using Serial.print after every measurement (I'm building a WeatherStation), I also want to use MicroSD card adapter which I had successfully booted and connected and measurements are being written normally onto the txt file I created. Now the problem starts with printing formatted Date and Time onto the SD card. I tried everything and every one of yours functions but the furthest I got was the 9 digit number which I suppose "is" the date and time only formatted to total number of days since the met and agreed Arduino starting time or how should I call it.

include <SoftwareSerial.h>

include <SD.h>

include <SPI.h>

include <ThreeWire.h>

include <RtcDS1302.h>

ThreeWire myWire(4, 5, 2); // IO, SCLK, CE
RtcDS1302<ThreeWire> Rtc(myWire);

float temp, hum, pres;
int i = 0;
byte buff[4];
File myFile;

void setup()
{

Serial.begin(115200);
Serial.println("Starting...");
Serial.print("Initializing SD card...");
delay(3000);
if (!SD.begin (15, SD_SCK_MHZ(1))) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
Serial.print("compiled: ");
Serial.print(DATE);
Serial.println(TIME);

Rtc.Begin();

RtcDateTime compiled = RtcDateTime(DATE, TIME);
printDateTime(compiled);
Serial.println();

if (!Rtc.IsDateTimeValid())
{
// Common Causes:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing

Serial.println("RTC lost confidence in the DateTime!");
Rtc.SetDateTime(compiled);

}

if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");
Rtc.SetIsWriteProtected(false);
}

if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}

RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}

}

void loop() {
RtcDateTime now = Rtc.GetDateTime();

if (Serial.available() > 0) {

byte b0 = Serial.read();
delay(10);
byte b1 = Serial.read();
delay(10);
byte b2 = Serial.read();
delay(10);
byte b3 = Serial.read();
delay(10);
//Serial.println(b0, HEX);
//Serial.println(b1, HEX);
//Serial.println(b2, HEX);
//Serial.println(b3, HEX);
buff[0] = b0;
buff[1] = b1;
buff[2] = b2;
buff[3] = b3;
float *fp = (float*) buff;

switch (i) {
  case 0:
    temp = *fp;
    Serial.print("Temp je ");
    Serial.println(temp);
    printDateTime(now);
    Serial.println();
    myFile = SD.open("test.txt", FILE_WRITE);
    myFile.println(temp);
    myFile.println(RtcDateTime(now));
    myFile.close();
    break;
  case 1:
    hum = *fp;
    Serial.print("hum je ");
    Serial.println(hum);
    printDateTime(now);
    Serial.println();
    myFile = SD.open("test.txt", FILE_WRITE);
    myFile.println(hum);
    myFile.close();
    break;
  case 2:
    pres = *fp;
    Serial.print("tlak je ");
    Serial.println(pres);
    printDateTime(now);
    Serial.println();
    myFile = SD.open("test.txt", FILE_WRITE);
    myFile.println(pres);
    myFile.close();
    break;
  default:
    temp = *fp;
    Serial.print("Temp je ");
    Serial.println(temp);
    printDateTime(now);
    Serial.println();
    myFile = SD.open("test.txt", FILE_WRITE);
    myFile.println(temp);
    myFile.close();
    i = 0;
    break;

}
i++;

}

}

define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
char datestring[20];

snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Day(),
dt.Month(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}

Ivan Maltarić
@jasamico_twitter
and on SD card it looks like this:
25.61 (temperature)
650394413 (supposed to be date and time)
Michael Miller
@Makuna
@jasamico_twitter That 30 seconds off is due to how you set the RTC date and time. In Setup, you are using DATE and TIME. This "macros" are Arduino defined values of when the project was compiled. So in your case it takes about 30 seconds from start of compile to the running sketch to actual call the set date time using those Macros. If you have the ability to have another trusted time source (Wifi call to a time server), that is a better way to set time and date but it more complicated and less common ability in Arduino so the examples use this simple and common method.
Ivan Maltarić
@jasamico_twitter
I already did that, using a website to fetch time and date, but the thing is I have microSD card adapter/module and I write the measurements in it so if by any chance the station is not connected to WiFi you can still see what it measured so I wanna print the date in the SD card next to the certain values
egge12
@egge12
Hi, I'm using DS3231 RTC together with RTC by Makuna... thanks for great work! Now it looks that I have a problem with eeprom... so I wanted to test DS3231_Memory.ino in the examples folder... unfortunately I'm getting an error while compiling: "DS3231_Memory:194:25: error: 'snprintf_P' was not declared in this scope dt.Second() );" any suggestions, what I'm doning wrong?
Michael Miller
@Makuna
what platform?
What Arduino are you building for?
egge12
@egge12
Hi Michael, it is not an Arduino but an STM32 blue pill (automatic telescope control): https://onstep.groups.io/g/main/wiki/6408. With the Arduiono-SAM Boards (32 bit ARM Cortex 3); Arduino_STM32 Package; RTC by Makuna library and digitalWriteFast library it should run like an arduione... setup itself works fine... e.g. bink-sketch can be executed normally... the eeprom of DS3231 is recognized, however it seems that there might be some issues with writing procedures... therefore I'm looking for test procedures... thanks for your support.
Michael Miller
@Makuna
@egge12 The STM32 is not very Arduino compatible, they didn't implement the _p variants of functions (one of the few platforms that didn't).
Replace that line with
    snprintf(datestring, 
            countof(datestring),
            "%02u/%02u/%04u %02u:%02u:%02u",
            dt.Month(),
            dt.Day(),
            dt.Year(),
            dt.Hour(),
            dt.Minute(),
            dt.Second() );
egge12
@egge12
@Makuna Thanks a lot Michael! Worked perfectly... after flashing, I got from serial monitor at 57600baud: 22:04:14.319 -> data read (29) = "What time is it in Greenwich?"
22:04:19.333 -> 08/23/2020 22:04:13... does this mean my DS3231 works properly including eeprom??? is there a write/read sequence to/from eeprom included in DS3231_Memory.ino?
Michael Miller
@Makuna
@egge12 If you read the sketch, there is a section that writes everytime. To confirm it is storing after reboot, you need to comment out the complete section as it states. Remove the * / at the end of this first line will do that.
/* comment out on a second run to see that the info is stored long term */
    // Store something in memory on the Eeprom

    // store starting address of string
    RtcEeprom.SetMemory(0, stringAddr); 
    // store the string, nothing longer than 32 bytes due to paging
    uint8_t written = RtcEeprom.SetMemory(stringAddr, (const uint8_t*)data, sizeof(data) - 1); // remove the null terminator strings add
    // store the length of the string
    RtcEeprom.SetMemory(1, written); // store the 
/* end of comment out section */
Note that this code is demonstrating a technique to store offsets at the front to different data and lengths of those data sets. Sort of a cheap FAT.
Ivan Maltarić
@jasamico_twitter
Hi, another question, which init part do I need to comment out for DS1302, because each time i reset my NodeMCU the time goes back to when the program was uploaded
Michael Miller
@Makuna
@jasamico_twitter That is what this code in the examples does
    RtcDateTime now = Rtc.GetDateTime();
    if (now < compiled) 
    {
        Serial.println("RTC is older than compile time!  (Updating DateTime)");
        Rtc.SetDateTime(compiled);
    }
Ivan Maltarić
@jasamico_twitter
So it means that it's necessary to leave that part in? Because even with that part if I decide to hit reset button, after 10 mins of measuring, the time goes back as if those 10 mins didn't happen, and the update never happens, it just loops back to the starting point.
Michael Miller
@Makuna
Thats one example. Do you have any other code that calls SetDateTime, comment it out. Most of the examples when they call it like the above, they output a message so you know why, are you getting any of those messages?
egge12
@egge12
@Makuna Thanks Michael, worked perfectly... I flashed DS3231_Memory.ino and after that I did it again, with the complete section commented out... serial monitor gave 22:54:56.018 -> 08/24/2020 22:54:50
22:55:01.007 -> data read (29) = "What time is it in Greenwich?"
22:55:06.007 -> 08/24/2020 22:55:00
22:55:10.998 -> data read (29) = "What time is it in Greenwich?"
22:56:03.398 -> data read (29) = "What time is it in Greenwich?"
22:56:08.420 -> 08/24/2020 22:56:02
22:56:13.413 -> data read (29) = "What time is it in Greenwich?"
22:56:18.400 -> 08/24/2020 22:56:12; first 4 lines were with section and second 4 lines were without section... so no differences... is this a good sign? Does this mean write/read works on the eeprom?
Michael Miller
@Makuna
yup, it read the string "What time is it in Greenwich" from the EEPROM on the RTC.
egge12
@egge12
@Makuna Thanks a lot, so this seems to prove, that my DS3231 works??? In this case my problem seems to be somewhere else... One last possibility could be the STM32 itself (I'm using blue pill). They are sold with 64kB flash - usually all of them have 128kB... the application OnStep also requires 128kB... in some rare cases the STM32 only have 64kB, however I don't have any idea how to test this... are you familar with STM32 and have a good hint? thanks in advance.
Michael Miller
@Makuna
No, not very familiar with the STM32. Is there a forum/channel for it?