def main(): pyb = Pyboard('/dev/ttyACM0') pyb.enter_raw_repl() now = datetime.utcnow() print('Setting UTC time') pyb.exec_raw("" "import sys\n" "rtc = pyb.RTC()\n" "rtc.init()\n" "t_py = ({0},{1},{2},{3},{4},{5},{6},{7})\n" "t = '({0}, {1}, {2}, {4}, {5}, {6})'\n" "rtc.datetime(t_py)\n" "print('UTC Time now is:')\n" "print(rtc.datetime())\n" "try:\n" " with open('datetime.correction', 'a+') as f:\n" " f.write('Initialized UTC RTC with:' + t + '\\n')\n" " f.flush()\n" " f.close()\n" " print('Done writing to file')\n" "except Exception as exc:\n" " sys.print_exception(exc)\n" "print('PyBoard execution finished.')\n" "".format(now.year, now.month, now.day, now.date().weekday() + 1, now.hour, now.minute, now.second + 1, 0), data_consumer=write_to_console ) pyb.exit_raw_repl() print('Done!')
def main(): with open(FILENAME, 'w+') as f: pass pyb = Pyboard('/dev/ttyACM0') pyb.enter_raw_repl() t0 = datetime.today() calibration_tracker.setT0(t0) print('Syncing RTC and PC clock') pyb.exec_raw("rtc = pyb.RTC()\n" "t = ({0},{1},{2},{3},{4},{5},{6},{7})\n" "rtc.datetime(t)\n" "".format(t0.year, t0.month, t0.day, t0.date().weekday() + 1, t0.hour, t0.minute, t0.second + 1, 0), data_consumer=write_to_console) while True: now = datetime.today() pyb.exec_raw("rtc_time = pyb.RTC().datetime()\n" "t_expected = ({0},{1},{2},{3},{4},{5},{6},{7})\n" "print(str(rtc_time) + ':' + str(t_expected))".format( now.year, now.month, now.day, now.date().weekday() + 1, now.hour, now.minute, now.second + 1, 0), data_consumer=write_to_buffer) time.sleep(SLEEP_PERIOD) pyb.exit_raw_repl() print('Done!')
def launch_pyb_script(): pyb = Pyboard('/dev/ttyACM0', wait=30) pyb.enter_raw_repl() print('Before exec') with open('endless-accel-loop.py', 'rb') as f: pyfile = f.read() pyb.exec_raw( pyfile, data_consumer=data_consumer_console_printer) print('After exec') pyb.exit_raw_repl() print('Exited raw REPL')
def main(): pyb = Pyboard('/dev/ttyACM0') pyb.enter_raw_repl() now = datetime.utcnow() print('Writing RTC correction checkpoint') pyb.exec_raw( "rtc_time = pyb.RTC().datetime()\n" "rtc_time_str = '({{0}}, {{1}}, {{2}}, {{3}}, {{4}}, {{5}})'.format(rtc_time[0], rtc_time[1], rtc_time[2], rtc_time[4], rtc_time[5], rtc_time[6])\n" "t_real = ({0},{1},{2},{3},{4},{5})\n" "with open('datetime.correction', 'a+') as f:\n" " f.write('Current UTC RTC is:' + rtc_time_str + '\\n')\n" " print('Current UTC RTC on Pyboard is:' + rtc_time_str)\n" " f.write('Real UTC time is:' + str(t_real) + '\\n')\n" " print('Real UTC time is:' + str(t_real))\n" " f.flush()\n" " f.close()\n" "".format(now.year, now.month, now.day, now.hour, now.minute, now.second + 1), data_consumer=write_to_console) pyb.exit_raw_repl() print('Done!')