# Voxl-IO questions (GPIO & i2c)

Source: https://forum.modalai.com/topic/749/voxl-io-questions-gpio-i2c
Category: VOXL SDK and Software (https://forum.modalai.com/category/47/voxl-sdk-and-software)
Posted: 2022-02-16 09:03:15 UTC by amitmol
Replies: 2 · Views: 836

## amitmol · 2022-02-16 09:03:15 UTC

I have a few questions about the voxl-io library, and I would love if you could help me:

	1.1. Missing ability to GPIO interrupt (or missing documentation?)
	1.2. Missing ability to control of Pull Up/Down (Is the hardware exist to do so?, or missing documentation?)
	1.3. Need clarification in the i2c api, can I write to a device without specifying a designated register?
		For example in the smbus linux library: (https://www.kernel.org/doc/html/latest/i2c/smbus-protocol.html)
			i2c_smbus_write_byte(...): Writes a single byte to a device
			i2c_smbus_write_byte_data(...): Writes a single byte to a designated register on the device

## Reply by modaltb (ModalAI staff) · 2022-02-21 13:48:35 UTC

Hi @amitmol ,

The VOXL is based on the snapdragon 820, built for smart phones, and has a bit less control than a microcontroller with configurability....

- Interrupt- not out of the box as far as I know
- pull up/down - this is a device tree modification likely, not something quick
- on this platform, we use voxl-io to send/receive the I2C commands to the sDSP, so it's what's exposed there presently only unless it's added later

## Reply by Chad Sweet (ModalAI staff) · 2022-03-07 16:40:59 UTC

We have example Python code in voxl-modem to control the B2B GPIO

```
## All GPIO pins need to be exported before they can be used
#
def gpio_export(num):
    subprocess.call("echo " + num + " > /sys/class/gpio/export",
                    stderr=FNULL, shell=True)

## Each GPIO has to have its direction set prior to use
# @param num  pin number
# @param direction 'in' or 'out'
#
def gpio_direction_map(num, direction):
    subprocess.call("echo " + direction + " > /sys/class/gpio/gpio" \
                    + num + "/direction",
                    stderr=FNULL, shell=True)

## Set a value to an 'out' gpio
#
def set_gpio(num, value):
    subprocess.call("echo " + value + " > /sys/class/gpio/gpio" + num + "/value",
                    stderr=FNULL, shell=True)

##  Reads a GPIO pin
#   @apram pin
#       pin number
#   @return
#       integer value [0,1]
def gpio_read_int(pin_int):
    gpio_file = '/sys/class/gpio/gpio' + str(pin_int) + '/value'
    value = subprocess.check_output(['cat', gpio_file]).strip()
    return int(value)
```
