USB IO Expander

by RobBest in Circuits > Microcontrollers

118 Views, 1 Favorites, 0 Comments

USB IO Expander

USB_IO_Expander_Powerpoint.png

I created this device so that I could control I/O pins, communicate via IIC or SPI and do other things without the need to program a Micro Controller.

By simply typing some commands using ASCII characters via a terminal emulator program on your computer you can do that using this USB I/O Expander.

The main features are:

  • Reading and writing eight I/O pins
  • IIC interface for controlling IIC devices
  • SPI interface for controlling SPI devices
  • Digital to Analog Conversion (DAC) with 2 selectable analog outputs
  • Analog to Digital Conversion (ADC) with 4 selectable analog inputs
  • Two channel Pulse Width Modulation (PWM) signal generator

The device consists of a PIC16F1455 Microcontroller programmed with the JAL programming language.

For a detailed overview of all commands see the attached manual.

Supplies

You need to have the following components for this project:

  • A breadboard
  • 1 * PIC microcontroller 16F1455
  • 1 * Electrolytic capacitor 10 uF/16V
  • Capacitors: 1 * 100 nF, 1 * 470 nF
  • Resistors: 2 * 22 Ohm, 1 * 10k
  • 1 * USB connector
  • Optional: An 8-pin connector
  • Optional: A reset button

See the basic schematic diagram in the next section on how to connect the components.

Building the Electronics

schematic_diagram.png

See the schematic diagram. The heart is formed by a PIC16F1455 Microcontroller and that is all you need (of course it should be programmed with the USB I/O Expander software). The device is powered by the USB connection.

You can build the circuit on a breadboard or the printed circuit board using the 8-pin connector to connect the device to the outside world. I used a breadboard for this project.

The Software

The software is written for a PIC16F1455 using the JAL programming language. The software uses 7241 bytes of ROM and 398 bytes of RAM.

The main program performs the following tasks:

  • Parsing the commands
  • Activating the relevant functions
  • Send the response and answer

All other functions are divided over various include files to make maintenance easier.

Next to that the software uses the following JAL libraries:

  • IIC library
  • SPI library
  • ADC library
  • DAC library
  • PWM library

The PIC controller runs on an internal clock of 48 MHz. The hexfile for programming the PIC16F1455 is attached.

If you are interested in using the PIC microcontroller with JAL – a Pascal like programming language – visit the JAL website.

Tools

terminal_emulator_example.png

As mentioned earlier no special tools or libraries are needed to control the USB I/O Expander from your PC. A terminal emulator program is sufficient. The screenshot shows a typical procedure where the contents of an – empty – EEPROM is read, programmed and read again using an IIC interface.

The steps shown are:

  1. Ping the device. This is optional, just checking if the device is alive.
  2. Initialize the IIC interface at 400 kHz.
  3. Reset the register – word - address of the EEPROM to 0 before reading.
  4. Read 10 bytes from the EEPROM (starting at word address 0). EEPROM is empty (0xFF).
  5. Write 10 bytes of data starting at word address 0.
  6. Reset the register – word - address of the EEPROM to 0 before reading.
  7. Read 10 bytes from the EEPROM (starting at word address 0)

If you want to automate your actions, a Python library was created that handles the commands, the response and the answers. Next to that several Python scripts are available that were used to test the device.

All source files, documentation, Python scripts, including the various schematic diagrams that were used for the demonstration can be found on GitHub.

Demo

USB IO Expander Instructables

The video shows all functionality of the USB I/O expander. It starts with the schematic diagram followed by a short demo using the various Python scripts.

Have fun building your own project and looking forward to your reactions.