———-追記(2019/06/27)———-
「Real Time Clock Module ( DS1307 + AT24C32 ) + Arduino UNO + Arduino IDE 1.8.8」に新しい記事
———-追記ここまで———-
久しぶりの Arduino ネタは DS1307 と AT24C32 を載せた
RTCモジュール(Real Time Clock Module LIR2032付き送料込み$1.51)
を Arduino UNO に接続して時刻をシリアルモニタに表示させる覚書き。
Arduino は新しいセンサーやモジュールのテスト用ボードという位置づけなので、スケッチを探してきて、確かに動作することを確認するまでが Arduino の仕事だ。
配線は以下の通り
VCC –> 5V
GND –> GND
SDA –> ANALOG IN A4
SCL –> ANALOG IN A5
こちらから頂いてきたTime.zipというファイルを解凍してその中の
Time¥Time
をライブラリ登録する(追記1)。
Time¥Time¥Examples¥TimeSerial¥TimeSerial.pde
をArduino IDEに読み込んで、Arduino UNOに書き込む。
この際、以下のようなエラーが出るので、
Serial.print(TIME_REQUEST,BYTE);
のうちの「,BYTE」を削除して「print」を「write」に変更し、
Serial.write(TIME_REQUEST);
とする。
2011/11/30 Arduino-1.0リリース時の変更点
BYTEキーワードは廃止。
1バイトのデータをそのまま送信する際はSerial.write()を使用する。
実行すると、シリアルモニタに
Waiting for sunc message
と表示されるので、
例えば「T1408483320」と入力すると、以下のように時刻が表示され始める。
1408483320 は、例として 2014/8/19 21:22 をUNIX Time というものに直した値で、これに「T」をつけて入力するとその時刻からカウントが始まる。
私の場合は、Libreoffice Calc で以下のようにして求めた。
A1 = “2014/8/19 21:22”
B1 = (A1-DATEVALUE(“1970/1/1 00:00:00”))*86400
「UNIX Time」で検索すれば変換サイトも見つけることが出来る。
追記(2015/03/01)
久しぶりにやってみたらエラーが出まくった。
ちなみにIDEのバージョンは1.6.0になっている。
良く見るとみんな同じエラーだ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
ビルドオプションが変更されました。全体をリビルドしています。 In file included from D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:10:0: D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:18:18: error: variable 'monthStr1' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr1[] PROGMEM = "January"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:19:18: error: variable 'monthStr2' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr2[] PROGMEM = "February"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:20:18: error: variable 'monthStr3' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr3[] PROGMEM = "March"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:21:18: error: variable 'monthStr4' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr4[] PROGMEM = "April"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:22:18: error: variable 'monthStr5' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr5[] PROGMEM = "May"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:23:18: error: variable 'monthStr6' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr6[] PROGMEM = "June"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:24:18: error: variable 'monthStr7' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr7[] PROGMEM = "July"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:25:18: error: variable 'monthStr8' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr8[] PROGMEM = "August"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:26:18: error: variable 'monthStr9' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr9[] PROGMEM = "September"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:27:19: error: variable 'monthStr10' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr10[] PROGMEM = "October"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:28:19: error: variable 'monthStr11' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr11[] PROGMEM = "November"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:29:19: error: variable 'monthStr12' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthStr12[] PROGMEM = "December"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:31:22: error: variable 'monthNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))' PGM_P monthNames_P[] PROGMEM = ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:37:26: error: variable 'monthShortNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:39:16: error: variable 'dayStr0' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr0[] PROGMEM = "Err"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:40:16: error: variable 'dayStr1' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr1[] PROGMEM = "Sunday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:41:16: error: variable 'dayStr2' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr2[] PROGMEM = "Monday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:42:16: error: variable 'dayStr3' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr3[] PROGMEM = "Tuesday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:43:16: error: variable 'dayStr4' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr4[] PROGMEM = "Wednesday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:44:16: error: variable 'dayStr5' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr5[] PROGMEM = "Thursday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:45:16: error: variable 'dayStr6' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr6[] PROGMEM = "Friday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:46:16: error: variable 'dayStr7' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayStr7[] PROGMEM = "Saturday"; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:48:20: error: variable 'dayNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))' PGM_P dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7}; ^ D:\Data\Electronics\Arduino\_sketch\libraries\Time\DateStrings.cpp:49:24: error: variable 'dayShortNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))' char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; ^ コンパイル時にエラーが発生しました。 |
とりあえず「error: variable ‘hogehoge’ must be const」と言ってるので、constにしてみる。
直すのはスケッチフォルダの中の
¥libraries¥Time¥DateStrings.cpp
で、エラーの出ている行に片っ端からconstを追加する。
面倒だから直したあとのDateStrings.cppを以下に全部載せる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
/* DateStrings.cpp * Definitions for date strings for use with the Time library * * No memory is consumed in the sketch if your code does not call any of the string methods * You can change the text of the strings, make sure the short strings are each exactly 3 characters * the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in Time.h * */ #include <avr/pgmspace.h> #include "Time.h" // the short strings for each day or month must be exactly dt_SHORT_STR_LEN #define dt_SHORT_STR_LEN 3 // the length of short strings static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null const char monthStr1[] PROGMEM = "January"; const char monthStr2[] PROGMEM = "February"; const char monthStr3[] PROGMEM = "March"; const char monthStr4[] PROGMEM = "April"; const char monthStr5[] PROGMEM = "May"; const char monthStr6[] PROGMEM = "June"; const char monthStr7[] PROGMEM = "July"; const char monthStr8[] PROGMEM = "August"; const char monthStr9[] PROGMEM = "September"; const char monthStr10[] PROGMEM = "October"; const char monthStr11[] PROGMEM = "November"; const char monthStr12[] PROGMEM = "December"; const char * const monthNames_P[] PROGMEM = { "",monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6, monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12 }; const char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec"; const char dayStr0[] PROGMEM = "Err"; const char dayStr1[] PROGMEM = "Sunday"; const char dayStr2[] PROGMEM = "Monday"; const char dayStr3[] PROGMEM = "Tuesday"; const char dayStr4[] PROGMEM = "Wednesday"; const char dayStr5[] PROGMEM = "Thursday"; const char dayStr6[] PROGMEM = "Friday"; const char dayStr7[] PROGMEM = "Saturday"; const char * const dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7}; const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; /* functions to return date strings */ char* monthStr(uint8_t month) { strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month]))); return buffer; } char* monthShortStr(uint8_t month) { for (int i=0; i < dt_SHORT_STR_LEN; i++) buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)])); buffer[dt_SHORT_STR_LEN] = 0; return buffer; } char* dayStr(uint8_t day) { strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day]))); return buffer; } char* dayShortStr(uint8_t day) { uint8_t index = day*dt_SHORT_STR_LEN; for (int i=0; i < dt_SHORT_STR_LEN; i++) buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i])); buffer[dt_SHORT_STR_LEN] = 0; return buffer; } |
今度は問題なく完了した。
PICでも動かしてみた。
「Real Time Clock Module ( DS1307 + AT24C32 ) + PIC18F2550 + SC1602B」
「Real Time Clock Module ( DS1307 + AT24C32 ) + PIC18F2550 プリント基板作成」
追記1(2019/06/27)
リンク先でファイルに行きつけなかった。
ライブラリマネージャからインストールできると思う。戻る