Skip to content

Atmel AVR Firmware for controlling relay board over USB

License

Notifications You must be signed in to change notification settings

thmahe/usbrelay-firmware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Status GitHub Issues GitHub Pull Requests License


Atmel AVR Firmware for controlling relay board with V-USB (https://www.obdev.at/vusb/)
Compatible with www.dcttech.com relay boards

Table of Contents

Features

  • Compatible with darrylb123/usbrelay host software
    • Read/Write relay state
    • Change serial number
  • Hardware schematics

Getting Started

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.

Prerequisites

Install dependencies required to build, deploy & test usbrelay-firmware.

$ sudo apt-get install avr-libc avr-gcc avrdude usbrelay

Build firmware

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

Deployment

Before deploying your firmware ensure to configure your flashing tool properly.

# Default configuration in Makefile
PROGRAMMER 	= avrisp
PROGRAMMER_PORT = /dev/ttyUSB0
PROGRAMMER_BAUD = 19200

Flash fuses

# 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.

Flash firmware

Finally flash your firmware by running:

$ make flash
...
avrdude: safemode: Fuses OK (E:FF, H:CA, L:DF)
avrdude done.  Thank you.

Interact with your board

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

How to customize it ?

AVR related customization

From Makefile under Editable options section you can customize below variables:

DEVICE ... Targetted MCU (default: atmega8)
F_CPU .... MCU frequency in Hz (defautl: 16000000)

USB Configuration

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

Relay related customization

Number of relay:

Simply modify below line in src/usbconfig.h

#define RELAY_COUNT     4

Relay mapping

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.

Hits