<jupyter_start><jupyter_text>![Callysto.ca Banner](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-top.jpg?raw=true)  Body ElectricityIn this experiment we are going to investigate the body's electrical signals while exercising and at rest using a [micro:bit](https://www.microbit.org) to collect data, similar to [electrocardiography](https://en.wikipedia.org/wiki/Electrocardiography). This is adapted from from [“Body Electrical & Waves“](https://docs.google.com/document/d/1KofuOt0v1lmQhQyJux1XWDVoCDeslcjDFysjStFmo1w) by [<NAME>](https://sites.google.com/view/utahcodingproject).If you don't have access to a micro:bit, you can skip the **Procedure** section and use the example data provided for your **Observations and Analysis**. Materials* micro:bit running the [latest firmware](https://microbit.org/get-started/user-guide/firmware)* USB cable* two wires (preferably with alligator clips)* tape (preferably skin tape or painter's tape)![micro:bit with wires](./images/microbit-with-wires.jpg) Procedure Setup1. Connect the micro:bit to your computer or Chromebook using the USB cable.2. Connect the wires to the micro:bit, one to **GND** and the other to **0**.3. Launch [Microsoft MakeCode with the ECG code](https://makecode.microbit.org/_DXa5vgUJpYzc).![MakeCode ECG](./images/makecode-ecg.jpg)4. Click the **↗Edit** button at the top right to open the code editor. If you prefer to program it in Python, the code should be:```pythonEKG = 0def on_forever():    global ECG    ECG = pins.analog_read_pin(AnalogPin.P0)    serial.write_value("ECG", ECG)basic.forever(on_forever)```5. Near the bottom left, click the **`...`** button and select **Pair device**, then follow the directions to pair your micro:bit.6. Once your micro:bit is paired, click the **`...`** button again and select **Download to micro:bit** to send the code to your micro:bit.![MakeCode pair](./images/makecode-pair.jpg) Collecting Data7. Click the **Show console Device** button.![MakeCode show console](./images/makecode-show-console.jpg)8. Tape the ends of the wire to the underside of your forearm, about 15 cm apart. Make sure that the exposed metal is touching your skin, you may need to hold them in place if the tape doesn't maintain contact between the metal and your skin.9. Sit still for about 5 seconds, then run in place for about 10 seconds, then sit still for another 5 seconds.10. Click the pause button at the top right.![MakeCode pause and download](./images/makecode-pause-download.jpg)11. Click the download button to download your data as a `csv` file. For more information on this check out the [documentation](https://makecode.microbit.org/device/data-analysis/viewing). You should now have a data file downloaded that is called something like `microbit-data-12-2021-21-32-29-0700.csv`. Uploading Data12. [Click this link](https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fcallysto%2Fcurriculum-notebooks&branch=master&subPath=Science/BodyElectricity&depth=1) to open the folder that this notebook is in. Sign in with your Google or Microsoft account if you haven't already.13. Click the `Upload` button at the top right to upload the `csv` file you downloaded in step 11, then click the blue `Upload` button.![Jupyter upload buttons](./images/jupyter-upload-buttons.jpg)14. [Click this link](https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fcallysto%2Fcurriculum-notebooks&branch=master&subPath=Science/BodyElectricity/body-electricity.ipynb&depth=1) to open this notebook on the Callysto Hub, and continue there. Observations and AnalysisClick on the code cell below. If you uploaded a `csv` file, change the first line to the name of your file.Click the `►Run` button to load and display the data.<jupyter_code>csv_filename = 'microbit-data-12-2020-14-30-15-0700.csv'

import pandas as pd
data = pd.read_csv(csv_filename, sep='\t', header=1)
data.columns=['time (s)', 'ECG']
data<jupyter_output><empty_output><jupyter_text>Visualizing DataNow that the data file is loaded, `►Run` the following code cell to visualize the voltage readings over time.<jupyter_code>import plotly.express as px
px.line(data, x='time (s)', y='ECG', title='ECG Voltage over Time')<jupyter_output><empty_output><jupyter_text>On the chart above you can zoom in on particular regions, and hover your mouse over the line to see the values. Selecting DataFind the time that you started your first resting period, and the time that you finished your second resting period. In our example data, these are 4.5 seconds and 28 seconds. In the code cell below change these to the time values for your data, then `►Run` the cell to display only the data between those times.<jupyter_code>start_time = 4.5
stop_time = 28

selected_data = data[data['time (s)'].between(start_time, stop_time)]
px.line(selected_data, x='time (s)', y='ECG', title='ECG Voltage over Time')<jupyter_output><empty_output><jupyter_text>LabellingEdit the **x** and **y** values for the annotations in the following code cell to display labels for when you were resting and exercising, then `►Run` the cell.<jupyter_code>px.line(selected_data, x='time (s)', y='ECG', title='ECG Voltage over Time'
        ).add_annotation(x=7, y=88, text='resting'
        ).add_annotation(x=12, y=110, text='exercising'
        ).add_annotation(x=23, y=96, text='resting')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11074440777411075, 'fraction_numerical': 0.018518518518518517, 'mean_word_length': 5.432783018867925, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 10, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '451766', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1648, 'n_words': 598, 'path': 'Science/BodyElectricity/body-electricity.ipynb', 'repo_name': 'callysto/curriculum-notebooks', 'size': '5458'}