RAK12002 With RAK11200 WisBlock Core Guide
Prerequisite
- Assemble the RAK12002 with a WisBlock Base and WisBlock Core by following the RAK12002 Installation Guide.
- Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Software Configuration and Example
- Select the RAK11200 WisBlock Core.
Figure 1: Selecting RAK11200 as WisBlock Core- Next, copy the following sample code into your Arduino IDE.
Click to view the code
/**
@file RAK12002_RTC_DateTime_RV-3028-C7.ino
@author rakwireless.com
@brief Set and read RTC time.
@version 0.1
@date 2021-04-30
@copyright Copyright (c) 2021
**/
#include "Melopero_RV3028.h" //Click here to get the library: http://librarymanager/All#Melopero_RV3028
Melopero_RV3028 rtc;
/**
* @brief Arduino setup function
* @note Called once after power on or reset
*
*/
void setup()
{
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
rtc.initDevice(); // First initialize and create the rtc device
rtc.writeToRegister(0x35,0x00);
rtc.writeToRegister(0x37,0xB4); //Direct Switching Mode (DSM): when VDD < VBACKUP, switchover occurs from VDD to VBACKUP
rtc.set24HourMode(); // Set the device to use the 24hour format (default) instead of the 12 hour format
// Set the date and time
// year, month, weekday, date, hour, minute, second
// Note: time is always set in 24h format
// Note: month value ranges from 1 (Jan) to 12 (Dec)
// Note: date value ranges from 1 to 31
rtc.setTime(2021, 4, 6, 30, 0, 0, 0);
}
/**
* @brief Arduino loop function
* @note Output date and time every second
*
*/
void loop()
{
Serial.printf("%d:%d:%d %d/%d/%d \n",rtc.getHour(),rtc.getMinute(),rtc.getSecond(),rtc.getYear(),rtc.getMonth(),rtc.getDate());
delay(1000);
}
NOTE
If you experience any error in compiling the example sketch, check the updated code for the RAK11200 WisBlock Core Module that can be found on the RAK12002 WisBlock Example Code Repository
- Click the link to locate the library.
Figure 1: Locating the required library in the Library Manager- Install the required library.
Figure 1: Installing the Library- Select the correct port and upload your code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading codeNOTE
RAK11200 requires the BOOT0 pin to be configured properly before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.
- When you successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the RAK12002 date/time logs. You will be able to see the Time and Date in the Serial Monitor.
Figure 1: RAK12002 date/time logs- You can set the time and date in the code.
Figure 1: Code for setting the time and date in RAK12002
Figure 1: Time and Date format