Giter Site home page Giter Site logo

daniel-thompson / usb-relay Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 5.0 249 KB

Power control system with USB interface, built using off-the-shelf microcontroller and relay boards

License: GNU General Public License v3.0

Makefile 46.96% Shell 4.68% C 48.36%
pdu stm32f103 stm32f4-discovery

usb-relay's Introduction

usb-relay - USB relay control module

usb-relay is a quick 'n dirty relay controller based on two very cheap off-the-shelf boards.

Assembled usb-relay device

Quickstart for STM32F103 boards

  • Install the Arm Embedded Toolchain (or similar arm-none-eabi- compiler), openocd and dfu-util.
  • Clone this repo: git clone https://github.com/daniel-thompson/usb-relay.git
  • Fetch the libraries: cd usb-relay; git submodule update --init --recursive
  • Build the firmware: make
  • Use JTAG/SWD programmer to install the booloader. Either make -C src/bootloader flash for STLink v2 or make -C src/bootloader BMP_PORT=/dev/ttyACM0 flash for a Black Magic Probe.
  • Use the bootloader to install the main application using the microcontroller board's own USB socket: make -C src/stm32f1-relay flash

Hardware setup

The firmware can be easily ported but has been most heavily tested on STM32F103C8T6 based breakout boards. Connections required are:

  • USB to host computer
  • 5v and GND to relay board
  • GPIOB 12-15 -> relay 1-4
  • GPIOA 8-10 -> relay 5-7
  • GPIOB 6 -> relay 8

All the GPIO connections are on one side of the controller board (and the first seven are sequentially allocated).

Alternative boards

  • Carbon by Seeed and 96Boards.
  • STM32F4-Discovery (undocumented)
  • Most STM32F103 breakout boards have jumpers enabling them to permanently assert USB hotplug. If your board does not do this then you will likely have to configure a GPIO pin to assert hotplug. usb-relay does not contain code for this. Adding it is an exercise for the reader!

Usage

The firmware registers itself as a CDC-ACM device and, under Linux, will be presented as ttyACMx where x is typically 0 on "simple" machines although will be larger if there is any USB communication or modem device installed (for example an unused 3G modem).

Type help to get a list of available commands. On STM32F1 platforms the commands available are:

  • echo - test command that echos back its input
  • id - reports a unique device serial number (the same number is also reported as the USB serial number)
  • help - shows a list of commands
  • led - manipulate the LED on the board (for testing, takes the same arguments as the relay command)
  • reboot - reboot into DFU mode to allows a firmware upgrade (firmware upgrade mode can also be triggered by resetting the board whilst leaving it plugged into the host)
  • relay1 to relay8 - can be used to turn the relay on or off as well as toggling its state or sending a 1 second pulse
  • version - reports firmware version and build date
  • uptime - show time since power on

udev rules

The firmware uses the STM32 unique device ID to provide every physical instance with a unique serial number. This allows udev rules to be introduced to ensure stable device enumeration regardless of any changes to the USB topology.

SUBSYSTEM=="tty", ATTRS{manufacturer}=="redfelineninja.org.uk", ATTRS{serial}=="045101780587252555FFC660", SYMLINK+="ttyrelayC660"
SUBSYSTEM=="tty", ATTRS{manufacturer}=="redfelineninja.org.uk", ATTRS{serial}=="7301C2152B72E52DE2744F3B", SYMLINK+="ttyrelay4F3B"

The serial number can picked up from the kernel log (dmesg) or using udevadm: udevadm info --attribute-walk /dev/ttyACM0 | grep serial .

udevadm can also be used to re-apply the rule if any changes are made to the symlink: sudo udevadm trigger /dev/ttyACM0

Example hardware

usb-relay should readily port to most STM32-based microcontroller boards. However the following example hardware is easily (and cheaply) availabe and will work out-of-the-box.

STM32F103C8T6 microcontroller development board from vcc-gnd.com. Normally very easy to source on eBay.

STM32F103C8T6 microcontroller development

Eight channel relay board from specialist supplier (or eBay)

Eight channel relay board

usb-relay's People

Contributors

daniel-thompson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.