{"id":16008298,"url":"https://github.com/jimbobbennett/pybadgewifi","last_synced_at":"2026-04-30T10:31:45.302Z","repository":{"id":81417257,"uuid":"242431863","full_name":"jimbobbennett/PyBadgeWiFi","owner":"jimbobbennett","description":"How to get a PyBadge connecting to WiFi","archived":false,"fork":false,"pushed_at":"2020-02-23T01:50:16.000Z","size":132,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T10:44:24.662Z","etag":null,"topics":["adafruit","circuitpython","pybadge","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimbobbennett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-23T00:22:55.000Z","updated_at":"2020-12-14T17:28:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"115cc443-46df-4420-b007-48a39ca58e6c","html_url":"https://github.com/jimbobbennett/PyBadgeWiFi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbobbennett%2FPyBadgeWiFi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbobbennett%2FPyBadgeWiFi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbobbennett%2FPyBadgeWiFi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbobbennett%2FPyBadgeWiFi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimbobbennett","download_url":"https://codeload.github.com/jimbobbennett/PyBadgeWiFi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247277414,"owners_count":20912523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adafruit","circuitpython","pybadge","python"],"created_at":"2024-10-08T12:41:17.836Z","updated_at":"2026-04-30T10:31:40.279Z","avatar_url":"https://github.com/jimbobbennett.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyBadge Wi-Fi\n\nThis repo contains instructions on how to get an [Adafruit PyBadge](https://www.adafruit.com/product/4200) connecting to Wi-Fi using an [Adafruit Airlift FeatherWing](https://www.adafruit.com/product/4264).\n\n\u003e The code here can also be used to connect a PyPortal to Wi-Fi using the built in ESP32 chip\n\n## Hardware\n\n* An [Adafruit PyBadge](https://www.adafruit.com/product/4200) - this is a Circuit Python device that has a display and controllers similar to a game console. Out of the box it doesn't have Wi-Fi connectivity, but it does have a FeatherWing socket on the back to plug in add-on boards.\n\n* An [Adafruit Airlift FeatherWing](https://www.adafruit.com/product/4264) - this is an ESP32 based Wi-Fi add-on board for Adafruit devices. It comes with headers, and when soldered on can plug into the FeatherWing socket on the back of the PyBadge.\n\n### Assembling the hardware\n\n1. Solder the headers to the Airlift FeatherWing\n\n![The feather wing with headers soldered on](./Images/SolderedFeatherwing.jpeg)\n\n1. Plug the FeatherWing into the socket on the back of the PyBadge\n\n![The feather wing connected to the PyBadge](./Images/PyBadgeAndFeatherwing.jpeg)\n\n1. Connect the PyBadge to your computer via the USB socket\n\n## Software\n\nThe software to connect to the Wi-Fi needs some Adafruit Circuit Python libraries, as well as some custom code. You can find the code in the [Code](./Code) folder.\n\n### Install the Adafruit libraries\n\n1. Head to the [Circuit Python Releases on the Adafruit GitHub repo](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases)\n\n1. Download the latest version of the libraries for the version of Circuit Python you are using\n\n1. Unzip the downloaded file if necessary\n\n1. Locate the PyBadge on your computer. It should be mounted as a drive called `CIRCUITPYTHON`\n\n1. Inside the PyBadge folder, open the `lib` folder\n\n1. Copy the following files/folders from the downloaded Circuit Python libraries to the `lib` folder on the PyBadge\n\n    | Name                    | Type   |\n    | ----------------------- | ------ |\n    | `adafruit_bus_device`   | Folder |\n    | `adafruit_esp32spi`     | Folder |\n    | `adafruit_requests.mpy` | File   |\n\n### Define a secrets file with Wi-Fi details\n\nRather than encode Wi-Fi connection details in code, it is better to put them in a separate file that can be hidden from source code control, either by adding it to your `gitignore`, or by hiding changes using [this technique](https://www.jimbobbennett.io/hiding-api-keys-from-git/).\n\n1. Create a file called `secrets.py` in the root of the `CIRCUITPYTHON` folder.\n\n1. Add the following to this file\n\n   ```python\n    secrets = {\n        'ssid' : '\u003cSSID of your Wi-Fi\u003e',   # Keep the two '' quotes around the name\n        'password' : '\u003cPassword\u003e',         # Keep the two '' quotes around password\n        }\n   ```\n\n   Set `\u003cSSID of your Wi-Fi\u003e` to be the SSID of your Wi-Fi\n\n   Set `\u003cPassword\u003e` to be the password for your Wi-Fi\n\n### Connect to the Wi-Fi\n\n1. Create a new file in the root of the `CIRCUITPYTHON` folder called `connection.py`\n\n1. Add the following code to this file. You can find this file in the [Code](./Code) folder if you just want to copy it to your PyBadge\n\n    ```python\n    import board, busio\n    from secrets import secrets\n    from digitalio import DigitalInOut\n    import adafruit_requests as requests\n    import adafruit_esp32spi.adafruit_esp32spi_socket as socket\n    from adafruit_esp32spi import adafruit_esp32spi\n\n    class Connection:\n        def __connect(self, spi, cs, ready, reset, log):\n            esp = adafruit_esp32spi.ESP_SPIcontrol(spi, cs, ready, reset)\n\n            requests.set_socket(socket, esp)\n\n            if log:\n                print(\"Connecting to AP...\")\n\n            while not esp.is_connected:\n                try:\n                    esp.connect_AP(secrets['ssid'], secrets['password'])\n                except RuntimeError as e:\n                    if log:\n                        print(\"could not connect to AP, retrying: \",e)\n                    continue\n\n            if log:\n                print(\"Connected to\", str(esp.ssid, 'utf-8'), \"\\tRSSI:\", esp.rssi)\n                print(\"My IP address is\", esp.pretty_ip(esp.ip_address))\n\n        # Connect a PyPortal\n        def connect_pyportal(self, spi, log = False):\n            esp32_cs = DigitalInOut(board.ESP_CS)\n            esp32_ready = DigitalInOut(board.ESP_BUSY)\n            esp32_reset = DigitalInOut(board.ESP_RESET)\n\n            self.__connect(spi, esp32_cs, esp32_ready, esp32_reset, log)\n\n        # Connect a PyBadge\n        def connect_pybadge(self, spi, log = False):\n            esp32_cs = DigitalInOut(board.D13)\n            esp32_ready = DigitalInOut(board.D11)\n            esp32_reset = DigitalInOut(board.D12)\n\n            self.__connect(spi, esp32_cs, esp32_ready, esp32_reset, log)\n    ```\n\n1. Add the following code to the `code.py` file in the `CIRCUITPYTHON` folder. This file should already be there as part of the default install, but if it is not there, create it. This file is run when the PyBadge boots up.\n\n    ```python\n    import board\n    import busio\n    import adafruit_requests as requests\n    from connection import Connection\n\n    spi = busio.SPI(board.SCK, board.MOSI, board.MISO)\n\n    conn = Connection()\n    conn.connect_pybadge(spi, True)\n\n    TEXT_URL = \"http://wifitest.adafruit.com/testwifi/index.html\"\n\n    print(\"Fetching text from\", TEXT_URL)\n    r = requests.get(TEXT_URL)\n    print('-'*40)\n    print(r.text)\n    print('-'*40)\n    r.close()\n\n    print(\"Done!\")\n    ```\n\n    This code uses the `Connection` module to connect to Wi-Fi, then downloads some test to show that it is working.\n\n1. Save the file. The PyBadge will reboot and connect to the Wi-Fi. You will see the connection on the PyBadge screen and in your terminal if you are connected [to the serial output](https://learn.adafruit.com/welcome-to-circuitpython/kattni-connecting-to-the-serial-console).\n\n    ```\n    Press any key to enter the REPL. Use CTRL-D to reload.soft reboot\n\n    Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.\n    code.py output:\n    Connecting to AP...\n    Connected to \u003cSSID\u003e         RSSI: -52\n    My IP address is 192.168.197.188\n    Fetching text from http://wifitest.adafruit.com/testwifi/index.html\n    ----------------------------------------\n    This is a test of Adafruit WiFi!\n    If you can read this, its working :)\n\n    ----------------------------------------\n    Done!\n    ```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimbobbennett%2Fpybadgewifi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimbobbennett%2Fpybadgewifi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimbobbennett%2Fpybadgewifi/lists"}