Atmel AVR Firmware for controlling relay board with V-USB (https://www.obdev.at/vusb/)
Compatible with www.dcttech.com relay boards
- Compatible with darrylb123/usbrelay host software
- Read/Write relay state
- Change serial number
- Hardware schematics
These instructions will get you a copy of the project ready to be deployed on your hardware.
See deployment for notes on how to flash the firmware.
Install dependencies required to build, deploy & test usbrelay-firmware.
$ sudo apt-get install avr-libc avr-gcc avrdude usbrelay
To build usbrelay-firmware simply follow steps below
$ git clone git@github.com:thmahe/usbrelay-firmware.git
$ cd usbrelay
# Fetch v-usb submodule
$ git submodule init
$ git submodule update
# Build firmware
$ make firmware
With as expected output:
avr-gcc ...
...
avr-objcopy -j .text -j .data -O ihex build/firmware.elf build/firmware.hex
avr-size build/firmware.hex
text data bss dec hex filename
0 2444 0 2444 98c build/firmware.hex
Built firmware can be found at location build/firmware.hex
Before deploying your firmware ensure to configure your flashing tool properly.
# Default configuration in Makefile
PROGRAMMER = avrisp
PROGRAMMER_PORT = /dev/ttyUSB0
PROGRAMMER_BAUD = 19200
# Default configuration for fuses in Makefile:
# FUSE_L = 0xdf
# FUSE_H = 0xca
$ make fuse
...
avrdude: safemode: Fuses OK (E:FF, H:CA, L:DF)
avrdude done. Thank you.
Finally flash your firmware by running:
$ make flash
...
avrdude: safemode: Fuses OK (E:FF, H:CA, L:DF)
avrdude done. Thank you.
Your device should be available with usbrelay
under default serial number UNSET
.
$ usbrelay
Device Found
type: 16c0 05df
path: /dev/hidraw1
serial_number: UNSET
Manufacturer: thmahe.dev
Product: USBRelay4
Release: 100
Interface: 0
Number of Relays = 4
UNSET_1=0
UNSET_2=0
UNSET_3=0
UNSET_4=0
From Makefile
under Editable options section you can customize below variables:
DEVICE ... Targetted MCU (default: atmega8)
F_CPU .... MCU frequency in Hz (defautl: 16000000)
Change USB ports mapping from src/usbconfig.h
Default mapping:
#define USB_CFG_IOPORTNAME B
#define USB_CFG_DMINUS_BIT 0
#define USB_CFG_DPLUS_BIT 1
Simply modify below line in src/usbconfig.h
#define RELAY_COUNT 4
Depending on your board design you might need to change relay mapping configuration set in src/main.c
Default mapping:
uint8_t *OUPTUT_REG[RELAY_COUNT] = {&DDRC, &DDRC, &DDRC, &DDRC};
uint8_t *RELAY_PORT[RELAY_COUNT] = {&PORTC, &PORTC, &PORTC, &PORTC};
int RELAY_BIT[RELAY_COUNT] = {0, 1, 2, 3};
Given mapping above, relay 1 is controlled using PC0 pin.