<jupyter_start><jupyter_text>Using CircuitPython with JupyterThis project is a fork of [Adafruit's Jupyter kernel](https://learn.adafruit.com/circuitpython-with-jupyter-notebooks/) with a few enhancements (like reconnecting to the CP VM if the connection is lost). Until these changes have been incorportated in Adafruit's distribution use the instructions below instead of those on Adafruit's website.  InstallationRequires Python 3, then run the following commands from the command line:```pip3 install cp_kernel```Then run start [jupyter lab](https://jupyterlab.readthedocs.io) with ```jupyter lab```A browser window opens with the Jupyer Lab GUI. The console windows displays verbose information that you can ignore except when you experience problems.  CircuitPython NotebookChoose `File->New->Notebook` from the menu and select the `CircuitPython` kernel. Make sure a microcontroller board is connected to the computer via USB. The kernel finds the board automatically; check the console output in case of problems.Use the notebook as usual, except that now code in cells is uploaded to the board for evaluation with CircuitPython. Few differences:* No output is printed except that from explicit `print` statements* The results from evaluation are displayed all at once, not incrementally during code execution* Magic commands do not work, except those described below**Occasionally you may get syntax error messages for code that is clearly correct.** This is likely due to the microcontroller not being able to keep up with the code upload and occurs in particular with large cells. The solution is to add a delay between each line of code as it is being sent to the controller. Executing the cell below will set this delay to 0.1 seconds.<jupyter_code>%upload_delay 0.1<jupyter_output><empty_output><jupyter_text>Execute Python code as usual:<jupyter_code>for i in range(3):
    print(i)<jupyter_output>0
1
2<jupyter_text>Error messages are marked in the notebook output by coloring:<jupyter_code>for i in range(5):
    print(i)
    if i>3:
        raise IndexError("error demo")
    
print("never gets here")<jupyter_output>0
1
2
3
4<jupyter_text>Longer calculations output results as they become available:<jupyter_code>from time import sleep

for i in range(5):
    print(i)
    sleep(1)<jupyter_output>0
1
2
3
4<jupyter_text>Working with GPIOThe code below blinks an led (change `D7` to match your hardware). If you run this once, all works as expected, but if you execute the cell a second time you get an error:```Traceback (most recent call last):  File "", line 7, in ValueError: D7 in use```To fix it, you can either deinit the led (and other resources your code is using) before running the cell, or, simpler, perform a soft reset `%softreset` as shown below:<jupyter_code>%softreset

from board import D7
from time import sleep
import digitalio

led = digitalio.DigitalInOut(D7)
led.direction = digitalio.Direction.OUTPUT

led.switch_to_output(value=False, drive_mode=digitalio.DriveMode.PUSH_PULL)

for i in range(10):
    led.value = not led.value
    sleep(0.3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0651685393258427, 'fraction_numerical': 0.01059390048154093, 'mean_word_length': 5.269617706237424, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '654920', 'license': 'MIT', 'n_tokens_mistral': 900, 'n_tokens_neox': 859, 'n_words': 404, 'path': 'doc/.ipynb_checkpoints/circuitpython_kernel-checkpoint.ipynb', 'repo_name': 'bboser/eventio', 'size': '3115'}