DancingQuanta / pyusbiss

Python API for USB-ISS Multifunction USB Communications Module
MIT License
2 stars 3 forks source link

Add GPIO support #5

Open gwdehaan opened 6 years ago

gwdehaan commented 6 years ago

on IO : When I look at the RPI.GPIO and https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/FT232H.py (and pyftfi) the instance is a spichannel or a pin. Up until now the instance in my implementation has been the USBISS module itself :

t=GPIO('COM3', 'input', 'output', 'input', 'adc')
# default GPIO function for pin 1..4
t.SetPinOn(2) # set Led connected to pin 2

RPI / pyftdi / FT232H.py

#init
led = gpio.GPIO(17)
led.setDirection(1)
led.setValue(1)

Would you agree to the following :

t=GPIO('COM3')
led = t.IO.pin(2) #
led.setDirection(OUTPUT)
led.setValue(HIGH)  

We can discuss the exact names for the methods. SPI / I2C / Serial are modes that have a single instance and fixed HW pins associated, whereas GPIO is configurable per pin as input, output or ADC.

DancingQuanta commented 6 years ago

It is nice to be as close as possible to other libraries. So I agree with your idea.

Do you understand the connection between the software of these libraries and the hardware they work with? That will come in useful when trying to control individual pins, especially because a word have to be sent to USB-ISS to change a pin's state.

DancingQuanta commented 6 years ago

Do please add any gpio related USB-ISS command bytes to 'usbiss.py' similar with SPI command bytes. This will make sure that the usbiss.py can be used as standalone class. This will allow a developer to write their class on top.

DancingQuanta commented 6 years ago

How are you getting on?

gwdehaan commented 5 years ago

GPIO

Usage

from usbiss import usbiss
from usbiss import gpio

Port = 'COM3'

usbissdev = usbiss.USBISS(Port)
Io4 = gpio.GPIO(usbissdev)

io4.setup_pins({1:gpio.OUT, 2:gpio.OUT, 3:gpio.IN, 4: gpio.IN}, {1:gpio.LOW, 2:gpio.LOW})
io4.output(1, gpio.HIGH)

Methods

method Description
setup(pin, mode) Setup the pin to mode pin - pin between 1 and 4 mode - IN, OUT, ADC
setup_pins(pins, values) Setup multiple pins and optionaly set their value pins - dictionary to setup multiple pins at once values - dictionary to setup pinvalues Example : setup_pins({1:gpio.OUT, 2:gpio.OUT, 3:gpio.IN, 4: gpio.IN}, {1:gpio.LOW, 2:gpio.HIGH})
output(pin, level) set the specified pin to level, HIGH or LOW pin - pin between 1 and 4
output_pins(pins) Set the value of multiple pins pins - dictionary of pin number to pin value Example : {1:gpio.LOW, 2:gpio.HIGH})
input(pin) Read the value of pin. Returns HIGH or LOW pin - pin between 1 and 4
input_pins(pins) Read the values of multiple pins. Returns a list of values pins - list of pins to read
adc(pin, vcc) Read de analog value on the specified pin. Returns the voltage pin - pin between 1 and 4 vcc - the voltage that the usbiss is operating on 3,3 or 5 Volt. (jumper selectable)

Tests

Test Description
test_gpio.py Testing basic functionality by performing some loopback tests. Hardware setup is described in the test script

Extra

con_mode Description
FULL All 4 pins are available for GPIO (default)
I2C Pins 1 and 2 are usable for GPIO
SERIAL Pins 3 and 4 are usable for GPIO

References

www.robot-electronics.co.uk/htm/usb_iss_io_tech https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/FT232H.py