# Setting specific Arduino Pins to High/Low

**URL:** <https://discuss.pynq.io/t/setting-specific-arduino-pins-to-high-low/2435>\
**Category:** Support\
**Created:** [March 17, 2021, 2:49am UTC](https://discuss.pynq.io/t/setting-specific-arduino-pins-to-high-low/2435 "2021-03-17T02:49:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![e0325448](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@e0325448](https://discuss.pynq.io/u/e0325448)\
**Post date:** [March 17, 2021, 2:49am UTC](https://discuss.pynq.io/t/setting-specific-arduino-pins-to-high-low/2435/1 "2021-03-17T02:49:06Z")

</div>

Hi,

Does anybody have any example on how to set individual Arduino pins to High or Low? The examples that are offered in the ‘base’ folders all require a grove shield which I do not own at the moment.

Currently, I am trying to use a custom IP overlay, and output the output values of the custom IP to try to read it on an Oscilloscope, with the help of a DAC. If anyone has ideas, tips, or examples, it would be much appreciated.

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [March 23, 2021, 6:23pm UTC](https://discuss.pynq.io/t/setting-specific-arduino-pins-to-high-low/2435/2 "2021-03-23T18:23:24Z")

</div>

Hi,  
You can use the Arduino\_IO class for this.

See this notebook, or Markdown below.

[https://gist.github.com/cathalmccabe/cf4aefff2035963004ab1572de9c00cf](https://gist.github.com/cathalmccabe/cf4aefff2035963004ab1572de9c00cf)

## Import BaseOverlay and Arduino\_IO

```python
from pynq.overlays.base import BaseOverlay
from pynq.lib.arduino import Arduino_IO

base = BaseOverlay("base.bit")

```

## Get handles to Arduino pins

The Arduino pins are connected to a MicroBlaze microprocessor in the base overlay. `base.ARDUINO` is a handle for this processor and needs to be passed as a parameter to the Arduino\_IO class.  
Pins D0-D19 on the Ardunio interface can be selected by index (0-19), and the direction of the pin input or output is specified with ‘in’ or ‘out’.

```python
arduino_pin_d0 = Arduino_IO(base.ARDUINO, 0, 'out')
arduino_pin_d1 = Arduino_IO(base.ARDUINO, 1, 'in')

```

We can now call `.read()` or `.write()` for each pin

```python
arduino_pin_d0.write(1)

```

```python
arduino_pin_d1.read()

```

# Add a toggle button widget

```python
import ipywidgets as widgets
from IPython.display import display

```

Add button widget, and define function to turn pin “on”/“off” when button is clicked.

```python
# Start "off":
arduino_pin_d0.write(0)      

# Create the toggle button
toggleButton = widgets.ToggleButtons(
    options=['off', 'on']
)

# create function to be called on button change
def toggle_pin(button_value):
    if(button_value.new is "off"):
        arduino_pin_d0.write(0)
    else:
        arduino_pin_d0.write(1)

 
# Observe the button and call the toggle_pin function when it is clicked. 
# Pass the *value* of the button to the function (this will be "on" or "off")
toggleButton.observe(toggle_pin,'value')

# Display the button
display(toggleButton)

```
