/ README.rst
README.rst
1 Introduction 2 ============ 3 4 .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ntp/badge/?version=latest 5 :target: https://circuitpython.readthedocs.io/projects/ntp/en/latest/ 6 :alt: Documentation Status 7 8 .. image:: https://img.shields.io/discord/327254708534116352.svg 9 :target: https://discord.gg/nBQh6qu 10 :alt: Discord 11 12 .. image:: https://github.com/adafruit/Adafruit_CircuitPython_NTP/workflows/Build%20CI/badge.svg 13 :target: https://github.com/adafruit/Adafruit_CircuitPython_NTP/actions/ 14 :alt: Build Status 15 16 Network Time Protocol (NTP) helper for CircuitPython. 17 18 19 Dependencies 20 ============= 21 This driver depends on: 22 23 * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ 24 25 Please ensure all dependencies are available on the CircuitPython filesystem. 26 This is easily achieved by downloading 27 `the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_. 28 29 Installing from PyPI 30 ===================== 31 On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 32 PyPI <https://pypi.org/project/adafruit-circuitpython-ntp/>`_. To install for current user: 33 34 .. code-block:: shell 35 36 pip3 install adafruit-circuitpython-ntp 37 38 To install system-wide (this may be required in some cases): 39 40 .. code-block:: shell 41 42 sudo pip3 install adafruit-circuitpython-ntp 43 44 To install in a virtual environment in your current project: 45 46 .. code-block:: shell 47 48 mkdir project-name && cd project-name 49 python3 -m venv .env 50 source .env/bin/activate 51 pip3 install adafruit-circuitpython-ntp 52 53 Usage Example 54 ============= 55 56 .. code-block:: python 57 58 import time 59 import board 60 import busio 61 from digitalio import DigitalInOut 62 from adafruit_esp32spi import adafruit_esp32spi 63 from adafruit_ntp import NTP 64 65 # If you are using a board with pre-defined ESP32 Pins: 66 esp32_cs = DigitalInOut(board.ESP_CS) 67 esp32_ready = DigitalInOut(board.ESP_BUSY) 68 esp32_reset = DigitalInOut(board.ESP_RESET) 69 70 # If you have an externally connected ESP32: 71 # esp32_cs = DigitalInOut(board.D9) 72 # esp32_ready = DigitalInOut(board.D10) 73 # esp32_reset = DigitalInOut(board.D5) 74 75 spi = busio.SPI(board.SCK, board.MOSI, board.MISO) 76 esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) 77 78 print("Connecting to AP...") 79 while not esp.is_connected: 80 try: 81 esp.connect_AP(b"WIFI_SSID", b"WIFI_PASS") 82 except RuntimeError as e: 83 print("could not connect to AP, retrying: ", e) 84 continue 85 86 # Initialize the NTP object 87 ntp = NTP(esp) 88 89 # Fetch and set the microcontroller's current UTC time 90 ntp.set_time() 91 92 # Get the current time in seconds since Jan 1, 1970 93 current_time = time.time() 94 print("Seconds since Jan 1, 1970: {} seconds".format(current_time)) 95 96 97 Contributing 98 ============ 99 100 Contributions are welcome! Please read our `Code of Conduct 101 <https://github.com/adafruit/Adafruit_CircuitPython_NTP/blob/master/CODE_OF_CONDUCT.md>`_ 102 before contributing to help this project stay welcoming. 103 104 Documentation 105 ============= 106 107 For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.