{"id":1839,"date":"2012-07-30T15:58:35","date_gmt":"2012-07-30T06:58:35","guid":{"rendered":"http:\/\/mkusunoki.net\/?p=1839"},"modified":"2013-12-06T22:00:30","modified_gmt":"2013-12-06T13:00:30","slug":"aquestalk-pico-atp3011f1-pu-%e3%81%ab%e6%99%82%e9%96%93%e3%82%92%e3%81%97%e3%82%83%e3%81%b9%e3%81%a3%e3%81%a6%e3%82%82%e3%82%89%e3%81%a3%e3%81%9f%e3%80%82","status":"publish","type":"post","link":"https:\/\/mkusunoki.net\/?p=1839","title":{"rendered":"AquesTalk pico ATP3011F1-PU \u306b\u6642\u9593\u3092\u3057\u3083\u3079\u3063\u3066\u3082\u3089\u3063\u305f\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/mkusunoki.net\/?attachment_id=1840\" rel=\"attachment wp-att-1840\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"960\" src=\"http:\/\/mkusunoki.net\/wp\/wp-content\/uploads\/2012\/07\/DSCF0478.jpg\" alt=\"\" class=\"alignnone size-full wp-image-1840\" srcset=\"https:\/\/mkusunoki.net\/wp\/wp-content\/uploads\/2012\/07\/DSCF0478.jpg 1280w, https:\/\/mkusunoki.net\/wp\/wp-content\/uploads\/2012\/07\/DSCF0478-320x240.jpg 320w, https:\/\/mkusunoki.net\/wp\/wp-content\/uploads\/2012\/07\/DSCF0478-1024x768.jpg 1024w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>\n\u4eca\u56de\u306f\u3001Arduino UNO \u306b EtherNet \u30b7\u30fc\u30eb\u30c9\u3092\u8f09\u305b\u307e\u3057\u3066\u3001\u30b5\u30f3\u30d7\u30eb\u30b9\u30b1\u30c3\u30c1\u306e UDP NTP \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u63a1\u53d6\u3057\u305f\u6642\u523b\u304b\u3089\u3001\u7121\u9650\u30eb\u30fc\u30d7\u3067\u6642\u9593\u3092\u3057\u3083\u3079\u3063\u3066\u3082\u3089\u3046\u90e8\u5206\u306e\u4f5c\u6210\u3092\u884c\u306a\u3044\u307e\u3057\u305f\u3002\u4ee5\u4e0b\u306b\u52d5\u4f5c\u3055\u305b\u3066\u307f\u305f\u4f8b\u3068\u30bd\u30fc\u30b9\u3092\u8cbc\u308a\u4ed8\u3051\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<p>\nAquesTalk pico \u306e\u30b3\u30de\u30f3\u30c9\u306b\u306f\u6570\u5b57\u8aad\u307f\u4e0a\u3052\u30b3\u30de\u30f3\u30c9\u3068\u3044\u3046\u306e\u304c\u3042\u3063\u3066 &lt;NUMK VAL=\u6570\u5b57&gt; \u3068\u3044\u3046\u30b3\u30de\u30f3\u30c9\u3067\u4f55\u5341\u3068\u3044\u3046\u3057\u3083\u3079\u308a\u3082\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u3042\u308b\u7a0b\u5ea6\u624b\u629c\u304d\u51fa\u6765\u305d\u3046\u3067\u3059\u3002\u52d5\u753b\u306f\u30d4\u30f3\u30dc\u30b1\u3066\u307e\u3059\u304c\u3001Q3HD\u306e\u7126\u70b9\u8ddd\u96e2\u3068\u30b3\u30f3\u30d1\u30af\u30c8\u4e09\u811a\u306e\u9ad8\u3055\u306e\u554f\u984c\u3067\u3059\u306e\u3067\u4ed5\u65b9\u3042\u308a\u307e\u305b\u3093\u3002\n<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/mxjHcYlRnL8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div>\n<p>#include <stdio.h><br \/>\n#include <Wire.h><br \/>\n#include <SPI.h><br \/>\n#include <Ethernet.h><br \/>\n#include <EthernetUdp.h><\/p>\n<p>byte mac[] = {<br \/>\n  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };<br \/>\nunsigned int localPort = 8888;<br \/>\nIPAddress timeServer(192, 43, 244, 18); \/\/ time.nist.gov NTP server<br \/>\nconst int NTP_PACKET_SIZE= 48;<br \/>\nbyte packetBuffer[ NTP_PACKET_SIZE];<br \/>\nEthernetUDP Udp;<br \/>\n#define I2CPICO 0x2E<\/p>\n<p>void setup() {<br \/>\n  Wire.begin();<br \/>\n  if (Ethernet.begin(mac) == 0) {<br \/>\n    Serial.println(&#8220;Failed to configure Ethernet using DHCP&#8221;);<br \/>\n    \/\/ no point in carrying on, so do nothing forevermore:<br \/>\n    for(;;)<br \/>\n      ;<br \/>\n  }<br \/>\n  Udp.begin(localPort);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n  char tt[128];<\/p>\n<p>  sendNTPpacket(timeServer);<br \/>\n  delay(1000);<br \/>\n  if ( Udp.parsePacket() ) {<br \/>\n    Udp.read(packetBuffer,NTP_PACKET_SIZE);  \/\/ read the packet into the buffer<br \/>\n    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);<br \/>\n    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);<br \/>\n    \/\/ combine the four bytes (two words) into a long integer<br \/>\n    \/\/ this is NTP time (seconds since Jan 1 1900):<br \/>\n    unsigned long secsSince1900 = highWord << 16 | lowWord;  \n    const unsigned long seventyYears = 2208988800UL;     \n    unsigned long epoch = secsSince1900 - seventyYears;  \n\n    int hh = ((epoch % 86400L) \/ 3600) + 9;\n    switch(hh) {\n      case 24: hh = 0; break;\n      case 25: hh = 1; break;\n      case 26: hh = 2; break;\n      case 27: hh = 3; break;\n      case 28: hh = 4; break;\n      case 29: hh = 5; break;\n      case 30: hh = 6; break;\n      case 31: hh = 7; break;\n      case 32: hh = 8; break;\n    }\n    int mm = (epoch % 3600) \/ 60;\n    int ss = epoch % 60;\n    sprintf(tt,\"i'mano\/ji'kokuwa  <NUMK VAL=%i>ji <NUMK VAL=%i>fun <NUMK VAL=%i>byo&#8217;-de_su. \\r&#8221;,hh,mm,ss);<br \/>\n    AquesTalkPico_Send(tt);<br \/>\n  }<br \/>\n  delay(15000);<br \/>\n}<\/p>\n<p>void AquesTalkPico_Ready() {<\/p>\n<p>  while(1) {<br \/>\n    Wire.requestFrom(I2CPICO, 1);  \/\/ request 1 byte<br \/>\n    if(Wire.available() > 0) {<br \/>\n      if(Wire.read() == &#8216;>&#8217;) break;<br \/>\n    }<br \/>\n    delay(50); \/\/ delay 50ms<br \/>\n  }<br \/>\n}<\/p>\n<p>void AquesTalkPico_Send(char *msg) {<br \/>\n  unsigned char i;<br \/>\n  char *smsg;<\/p>\n<p>  smsg = msg;<br \/>\n  AquesTalkPico_Ready();<br \/>\n  while(*smsg != 0) {<br \/>\n    Wire.beginTransmission(I2CPICO);<br \/>\n    for(i = 0; i < 32; i++) {\n      Wire.write(*smsg++);\n      if(*smsg == 0) {\n        break;\n      }\n    }\n    Wire.endTransmission();\n  }\n}\n\nunsigned long sendNTPpacket(IPAddress&#038; address)\n{\n  memset(packetBuffer, 0, NTP_PACKET_SIZE); \n  packetBuffer[0] = 0b11100011;   \/\/ LI, Version, Mode\n  packetBuffer[1] = 0;     \/\/ Stratum, or type of clock\n  packetBuffer[2] = 6;     \/\/ Polling Interval\n  packetBuffer[3] = 0xEC;  \/\/ Peer Clock Precision\n  packetBuffer[12]  = 49; \n  packetBuffer[13]  = 0x4E;\n  packetBuffer[14]  = 49;\n  packetBuffer[15]  = 52;\n\n  Udp.beginPacket(address, 123); \/\/NTP requests are to port 123\n  Udp.write(packetBuffer,NTP_PACKET_SIZE);\n  Udp.endPacket(); \n}\n[\/code]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306f\u3001Arduino UNO \u306b EtherNet \u30b7\u30fc\u30eb\u30c9\u3092\u8f09\u305b\u307e\u3057\u3066\u3001\u30b5\u30f3\u30d7\u30eb\u30b9\u30b1\u30c3\u30c1\u306e UDP NTP \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u63a1\u53d6\u3057\u305f\u6642\u523b\u304b\u3089\u3001\u7121\u9650\u30eb\u30fc\u30d7\u3067\u6642\u9593\u3092\u3057\u3083\u3079\u3063\u3066\u3082\u3089\u3046\u90e8\u5206\u306e\u4f5c\u6210\u3092\u884c\u306a\u3044\u307e\u3057\u305f\u3002\u4ee5\u4e0b\u306b\u52d5\u4f5c\u3055\u305b &hellip; <a href=\"https:\/\/mkusunoki.net\/?p=1839\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;AquesTalk pico ATP3011F1-PU \u306b\u6642\u9593\u3092\u3057\u3083\u3079\u3063\u3066\u3082\u3089\u3063\u305f\u3002&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[118],"class_list":["post-1839","post","type-post","status-publish","format-standard","hentry","category-kousaku","tag-aquestalk-pico"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mkusunoki.net\/index.php?rest_route=\/wp\/v2\/posts\/1839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mkusunoki.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mkusunoki.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mkusunoki.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mkusunoki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1839"}],"version-history":[{"count":0,"href":"https:\/\/mkusunoki.net\/index.php?rest_route=\/wp\/v2\/posts\/1839\/revisions"}],"wp:attachment":[{"href":"https:\/\/mkusunoki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mkusunoki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mkusunoki.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}