7
PC에서 Arduino로 Time을 동기화하려고합니다. Time 라이브러리를 사용하고 있지만 작동하지 않습니다.컴퓨터 시간을 USB를 통해 Arduino에 동기화 할 수 없습니다.
내 컴퓨터에서 arduino와 같은 시간을 유지하려면 어떻게해야합니까? 현재 Mac을 사용 중입니다.
그들의 문서화는 말한다 :
TZ_adjust=-8; echo T$(($(date +%s)+6060$TZ_adjust)) > /dev/tty.usbserial-A8008pym
내가 터미널
>export TZ_adjust=-8; echo T$(($(date +%s)+6060$TZ_adjust)) > /dev/tty.usbmodemfd131
에 시도 : 유닉스 시스템에서
, 당신은 쉘 명령과 함께 시간을 설정할 수 있습니다그리고 권한이 거부되었습니다.
내가 뭘 잘못하고 있니? arduino의 시간을 컴퓨터와 동기화하는 간단한 방법이 있습니까?
#include <Time.h> #define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits #define TIME_HEADER 'T' // Header tag for serial time sync message #define TIME_REQUEST 7 // ASCII bell character requests a time sync message void setup() { Serial.begin(9600); setSyncProvider(requestSync); //set function to call when sync required Serial.println("Waiting for sync message"); } void loop(){ if(Serial.available()) { processSyncMessage(); } if(timeStatus()!= timeNotSet) { digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh digitalClockDisplay(); } delay(1000); } void digitalClockDisplay(){ // digital clock display of the time Serial.print(hour()); printDigits(minute()); printDigits(second()); Serial.print(" "); Serial.print(day()); Serial.print(" "); Serial.print(month()); Serial.print(" "); Serial.print(year()); Serial.println(); } void printDigits(int digits){ // utility function for digital clock display: prints preceding colon and leading 0 Serial.print(":"); if(digits < 10) Serial.print('0'); Serial.print(digits); } void processSyncMessage() { // if time sync available from serial port, update time and return true while(Serial.available() >= TIME_MSG_LEN){ // time message consists of a header and ten ascii digits char c = Serial.read() ; Serial.print(c); if(c == TIME_HEADER) { time_t pctime = 0; for(int i=0; i < TIME_MSG_LEN -1; i++){ c = Serial.read(); if(c >= '0' && c <= '9'){ pctime = (10 * pctime) + (c - '0') ; // convert digits to a number } } setTime(pctime); // Sync Arduino clock to the time received on the serial port } } } time_t requestSync() { Serial.print(TIME_REQUEST,BYTE); return 0; // the time will be sent later in response to serial mesg }
"내가 얻을를"... 뭐? – sachleen
@sachleen 사용 권한이 거부되었습니다. 죄송합니다. –
sudo를 사용하여 명령을 시도해 볼 수 있습니까? –