ความรู้แน่น ฟรีสำหรับชุมชน ArduinoAll ที่นี่เท่านั้น

ฟรีและดีที่สุด คอร์สอบรม Arduino + NodeMCU
ทำเพื่อแบ่งปัน ห้ามนำไปจำหน่าย หรือเก็บเงินค่าเรียน
  !!!


  


AllNewStep รับประกันคุณภาพทุกชิ้น วันจันทร์-ศุกร์แจ้งชำระสินค้าก่อน 14.00 จัดส่งทันทีวันนี้ค่ะ

กรุงเทพ /ภาคกลาง ได้พรุ่งนี้


*** สินค้าทุกชิ้น ถ้าสามารถทำรายการสั่งซื้อได้ แสดงว่ามีครบทุกรายการค่ะ *** 

พิมพ์ค้นหาบทความ หัวข้อกระทู้ และสินค้าในเว็บ AllNewStep ได้ที่นี่
QUOTE 

RTC Module เวลาไม่รัน ค้างอยู่ค่าเดิม

ไม่รู้
ผมเป็นมือใหม่หัดเล่น แต่สงสัยว่าพออัพโค๊ดเเล้วทำไมเวลาที่ได้นั้นไม่รันเพิ่มเลยอ่ะครับ ค้างอยู่เวลาเดิมตั้งแต่เเรกไม่ไปไหนเลย แบบนี้เป็นเพราะ RTC ใช่มั้ยครับ ละมีวิธีการแก้มั้ย
QUOTE 
ความคิดเห็นที่ #1
เจ้าของร้าน

เวลาเดินทำงานปกติตามที่เขียนโปรแกรมอุปกรณ์ไม่มีปัญหา

อาการนี้สาเหตุมาจาก โค้ดมีคำสั่งตั้งเวลาอยู่ เอาบรรทัดตั้งเวลา ออกก็จะใช้ได้ครับ

QUOTE 
ความคิดเห็นที่ #2
ไม่รู้
แต่โค้ดที่ผมใช้เป็นโค๊ดจาก Example นะครับ


// CONNECTIONS:
// DS1302 CLK/SCLK --> 5
// DS1302 DAT/IO --> 4
// DS1302 RST/CE --> 2
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#include <ThreeWire.h>
#include <RtcDS1302.h>

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

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

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();

printDateTime(now);
Serial.println();

if (!now.IsValid())
{
// Common Causes:
// 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println("RTC lost confidence in the DateTime!");
}

delay(10000); // ten seconds
}

#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.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}

หรือต้องมีตัวโค๊ดตั้งเวลาด้วยหรอครับ
QUOTE 
ความคิดเห็นที่ #3
เจ้าของร้าน

ในตัวอย่าง มีคำสั่งตั้งเวลา

ทุกครั้งที่รีเซต ก็สัง่ให้ตั้งเวลาเดิม เวลาจึงเป็นค่าเดิมครับ

Rtc.SetDateTime(compiled);

แสดงความคิดเห็นที่ 1-3 จากทั้งหมด 3 ความคิดเห็น
ขาย ARDUINO
คุณภาพ อันดับ 1

ได้รับรางวัลร้านยอดเยี่ยม
ตั้งแต่ปี 2558
ขาย Arduino
วีดีโอสอน Arduino

สอน esp8266

สอน Arduino IoT
สอน Arduino แบบเร็ว

สอน NodeMCU

อุปกรณ์ Arduino

MEMBER ZONE

พูดคุย-สอบถาม