MattairTech MT-DB-U4 User manual

MT-DB-U4 User Guide
December 30, 2015 1 http://www.mattairtech.com/

MT-DB-U4 User G ide
Table of Contents
Table of Contents
Overview........................................................................................................................4
Introduction.......................................................................................................................................4
MT-DB-U4 Features..........................................................................................................................4
ATmega32U4 Features.....................................................................................................................5
MT-DB-U4 Hardware.....................................................................................................8
Board Revisions................................................................................................................................8
Pin Descriptions................................................................................................................................9
Boot Jumper / RESET button / LED................................................................................................10
ISP Header.....................................................................................................................................10
JTAG...............................................................................................................................................11
Mounting Holes...............................................................................................................................11
Power Configuration..................................................................................................12
Bus Powered - 5V...........................................................................................................................12
Externally Powered – 3.4V to 5.5V..................................................................................................12
Externally Powered – 3.0V to 3.6V..................................................................................................12
USB Shield......................................................................................................................................12
Arduino Compatibility (IDE 1.6.7)..............................................................................13
What's New.....................................................................................................................................13
Summary.........................................................................................................................................13
Special Notes..................................................................................................................................14
Pin Configurations...........................................................................................................................14
MT-DB-U6 (AT90USB64/AT90USB128).........................................................................................15
MT-DB-U4 (ATmega32U4)..............................................................................................................16
MT-DB-U1/MT-DB-U2 (AT90USB162/ATmega32U2).....................................................................16
Pin Capabilities...............................................................................................................................17
Using Arduino with MattairTech USB boards..................................................................................18
Serial Monitor..................................................................................................................................18
Updated Tone.cpp...........................................................................................................................18
Detailed Memory Usage Output After Compilation..........................................................................19
USB Technical Notes......................................................................................................................19
Installation.......................................................................................................................................20
Driver Installation............................................................................................................................20
Windows.........................................................................................................................................20
Linux...............................................................................................................................................21
OS X...............................................................................................................................................21
AVR Core Installation......................................................................................................................21
Uploading the First Sketch..............................................................................................................22
USB CDC Bootloader (Arduino compatible)....................................................................................22
Bootloader Firmware Installation Using the Arduino IDE.................................................................22
Using AVRDUDE Standalone.........................................................................................................23
December 30, 2015 2 http://www.mattairtech.com/

MT-DB-U4 User G ide
Possible Future Additions................................................................................................................23
ChangeLog.....................................................................................................................................23
License and credits.........................................................................................................................24
CDC Bootloader (Arduino/AVRDUDE)......................................................................25
CDC Serial Driver............................................................................................................................25
CDC Bootloader..............................................................................................................................25
DFU Bootloader (FLIP/dfu-programmer)..................................................................28
FLIP................................................................................................................................................29
dfu-programmer..............................................................................................................................31
Running Bitlash Demo...............................................................................................32
Schematic....................................................................................................................34
Fuse and Lock Settings.............................................................................................35
Troubleshooting / FAQ...............................................................................................35
Support Information...................................................................................................35
Legal.............................................................................................................................36
Appendix A: Precautions...........................................................................................37
Appendix B: Other MattairTech Products................................................................38
December 30, 2015 3 http://www.mattairtech.com/

MT-DB-U4 User G ide
Overview
Overview
Introduction
The MT-DB-U4 is a development board for the Atmel ATmega32U4 USB microcontroller. The
board has 40 pins in a dual inline configuration with 100 mil pin spacing and 700 mil row spacing
which allows for easy mounting on a breadboard. It includes a mini USB connector, status LED,
16MHz crystal, reset button, HWB boot jumper, and ISP header pads. A bootloader comes
preinstalled which allows programming of the chip over USB without an external programmer. An ISP
header is available which can be used with an external programmer. This header can be reconfigured
to allow the MT-DB-U4 itself to be used as an ISP programmer (hex file available on website), or to be
used as a SPI master or slave. The board can be powered via USB at 5V or it can be externally
powered (3V - 5.5V). All pins are routed to headers, including those used by on-board hardware. The
chip can be clocked externally, and the board is compatible with HV programming. The USB
connections are also routed to header pins, which allows for panel-mount USB connectors. The PCB
is high-quality with ENIG (gold-plated) finish, red soldermask, and white screenprinting showing the
pinout and Arduino pin numbering. There are two 3mm mounting holes (~5mm pad). It measures
approximately 2.1” x 0.9” (52mm x 23mm) and is 0.062” (1.6mm) thick.
MT-DB-U4 Features
●ATmega32U4 USB microcontroller
●32KB FLASH, 2.5KB SRAM, 1KB EEPROM
●12 10-bit ADC channels (1 used by LED which can be disconnected)
●Serial USART, SPI, and TWI (I2C) communications
●4 timers with 14 PWM channels (up to 7 simultaneous)
●Arduino compatible (now supports IDE 1.6.7 and boards manager)
●CDC (Arduino/AVRDUDE) or DFU (FLIP) bootloader preinstalled
●Bitlash preinstalled (Arduino command shell)
●ISP header (program chip using external programmer)
●16MHz crystal
●Green Status LED
●Reset button
●Bootloader jumper
●Mini USB connector
●Powered by USB or external power supply
●5V (USB) or 3V - 5.5V (external)
●All pins routed to headers (including those used by on-board hardware)
●Can be mounted on a breadboard
●USB pins routed to header pins (for panel-mount USB connector)
●Inductor on analog supply with separate ground pin
●High-quality PCB with gold-plated finish
●Two 3mm mounting holes (~5mm pad)
●Measures approx. 2.1” x 0.9” (52mm x 23mm) and 0.062” (1.6mm) thick.
December 30, 2015 4 http://www.mattairtech.com/

MT-DB-U4 User G ide
ATmega32U4 Features
●
● !
"#$%!&!&"& ' ()*!
"$+*,!-&.'&&
"/!(0-
"1-#23!-!#24
"0 -+(!-
●56&
"$+7(&(&8/&
"+9%7(&
"#7(&))0
".:)& (&;#<<<</&:#<<<<<))0
"6;+<(&%= :#<<(&+%=
"0- -'&
(&8(0-
3!..0-
&!---&--!18
"'!(
●>3,?)))&9##@A9#-B
"!(& -8&>3,
")*&0-68!!--
"/&))0/!&&'&!>3,
●1+9</!&-:-6!!-3& -
" -&!(1&!&-C+9<
"!--&&&!-#+8:	%8:&
")-< 3&&;!-2@8(&
"28)-&50!6&!'!-
&!&3&&
" C!8)-&&4!-+%28(&!88'
"/!(-$+8(&16-(
"!&-:&!!-&
" 1&-&&81!&&
"@4/!&-!&0-
"1!& :6&D!&
" (&&&--
●-/!&
"0-1-3;$+!-A24-
"083: !-& -
"3#283: !-& - -!
"0#<8-3: !?2@4B -
"/!8. &
"/!. &8&!+#2&
"*. &-0-8&!
+##&
"0!-! -!
"#+&#<86 ?!&6E &8,B
"813/
"&:
"(0+
"8.3-0-0&
"0- -
"!-.'!-
"0-3-!&
●-/!&
December 30, 2015 5 http://www.mattairtech.com/

MT-DB-U4 User G ide
"&8!6
"4 80&
"'-&F0G( '? :)*0&B
")*!-!&
"*-&;6 5&!&8()*
8(
●:0'&
":08 0!-!&33-!&
"+28:0&
"@@3H/'#<*#<
"@@H/5'I*I
●0-&
"+9I%9%
●0--!
"!&?@<= J%= B
●*!/D!(
"4+9I!&
"#24@9%!&
December 30, 2015 6 http://www.mattairtech.com/

MT-DB-U4 User G ide
December 30, 2015 7 http://www.mattairtech.com/

MT-DB-U4 User G ide
MT-DB-U4 Hardware
MT-DB-U4 Hardware
Board Revisions
There are two board revisions, A and B. Boards shipped after November 22, 2 12
are revision B. Revision B adds two 3mm (~5mm pad) mounting holes, adds a solder
jumper to allow disconnection of the LED from pin D7, adds solder jumpers to allow
connection of the xtal traces to two main header pins, adds Arduino pin numbering to the
screen printing, and makes other various changes to improve the manufacturing process.
Revision A Revision B (current)
December 30, 2015 8 http://www.mattairtech.com/

MT-DB-U4 User G ide
Pin Descriptions
Pin Description
Gnd Digital ground
5V, Vbus 5V output from USB Vbus. Vbus pin is tied to 5V pin. These pins are
connected to the Vbus and UVcc pins of the microcontroller.
Vcc Voltage input pin. Use solder jumper J1 to connect this pin to 5V (default
setting) when using USB power. In this case, Vcc is an output. Leave J1
unconnected to supply power from an external source to the Vcc pin. This
pin is connected to the Vcc and AVcc pins on the microcontroller, as well
as the ISP header and reset pullup. See Power Configuration Section.
3.3V 3.3V output from the microcontrollers internal 3.3V regulator. This pin is
connected to Ucap on the microcontroller.
Avcc Voltage input to the analog section of the microcontroller. This pin is
connected to Vcc through a 10uH inductor and 100nF capacitor and
provides power to the microcontroller analog section (Avcc pin).
Aref Voltage input. This is the reference voltage used by the ADC in the
microcontroller. DO NOT connect if using an internal reference.
Agnd Analog ground
RST Connects to reset pin of microcontroller as well as the reset button. A 10K
pullup resistor and 100nF capacitor are connected to this pin.
E2 / B (Boot) This pin is connected to the HWB jumper. The jumper is connected to
ground through a 240 ohm resistor. The pin is sampled after all reset
sources, including power-up. If the pin is low (HWB jumper installed), then
the bootloader is run. If the pin is high (HWB jumper removed), then the
user application is run. This pin functions as a normal GPIO pin at all other
times. The 240 ohm resistor provides short-circuit protection in case the
pin is used as an output and the jumper is installed.
D7 / L (LED) The green status LED is connected to this pin. The LED is connected to
ground through a 240 ohm resistor. Drive the pin high to turn on the LED.
It can be disconnected by cutting the solder jumper trace (Rev B only).
xtal1 This pin is connected to the on-board 16MHz crystal. If using an external
clock, connect it to this pin, connect the solder jumper (Rev B only), and
configure the microcontroller fuses to use an external clock. This is also
useful for HV programming or recovery from incorrectly set fuses.
xtal2 This pin is connected to the on-board 16MHz crystal. This pin is useful
along with xtal1 to connect an external crystal. Board revision B has a
solder jumper to connect this to the external header pin.
E6, F0, F1, F4, F5, F6,
F7
These are generally used as analog pins. Analog ground plane runs under
these pins. Consult datasheet for functionality.
All other pins Consult datasheet for functionality.
December 30, 2015 9 http://www.mattairtech.com/

MT-DB-U4 User G ide
Boot Jumper / RESET button / LED
This section does not apply to the Atmel DFU bootloader option, in which case, the fuses will be left
at their factory default settings and the factory installed Atmel DFU bootloader will not be overwritten.
The boot jumper (labeled HWB) selects between the bootloader and user application. The pin is
sampled after reset or power-up. Note that the hardware HWB function of the ATmega32U4 is disabled
(HWBE fuse is disabled) and the bootloader startup code is always run after reset or power-up (BOOTRST
fuse is set). This startup code then samples the state of the HWB pin. If it is high, the user application runs.
Otherwise, the bootloader continues to run, waiting for programming instructions while pulsing the LED.
The LED remains on when jumping to the user application. The bootloader always runs at 8 MHz, which is
compatible with lower voltages. It remains at 8MHz when jumping to the user application. The user may
then set the cpu speed to 16MHz in software, if running at 5V.
It is not necessary to remove and replace the jumper when switching between the bootloader and
the user application. The jumper can be left on. After FLASH programming, the CDC bootloader will
automatically jump to the application. If using the DFU bootloader, then you can command FLIP or dfu-
programmer to jump to the application. Then, when running the application, the reset button can be
pressed to re-enter the bootloader. This is useful when writing and debugging firmware. When the firmware
is complete, the jumper can be removed so that future resets will always run the application.
ISP Header
The ISP header is configured by default to allow ISP programming using an external programmer.
That is, RESET is routed to pin 5. Pin 1 is marked on the board (it is the pin closest to the chip). The ISP
header can be reconfigured so that pin PB0 (SS) is connected to pin 5 rather than RESET. This can be
done by switching solder jumper J2, next to the ISP header, to the position opposite to the “ISP” label. This
allows the MT-DB-U4 to be used as an AVRISPmkII programmer itself, using Dean Camera's AVRISPmkII
software available at http://www.fourwalledcubicle.com/. A precompiled hex file will be made available at
http://www.mattairtech.com/ on the MT-DB-U2 product page. Note that when using the ISP header in this
way, Vcc and ground are output to the target board. Therefore, the target board should not be powered
itself. You should also verify that it is safe to power the target board through the ISP connector. Another
use for the ISP header configured with SS on pin 5 is to make use of SPI, either as a master or slave. SPI
can also be used on the normal DIL headers.
December 30, 2015 10 http://www.mattairtech.com/

MT-DB-U4 User G ide
JTAG
JTAG can be used for programming and debugging. While there is no JTAG header, all JTAG
signals are available on the DIL header pins. Four JTAG signals are shared with ADC pins (F4-F7).
JTAG is enabled while running the bootloader only. It is disabled when the user application is run to
allow access to the ADC pins. It can be re-enabled in software. When using the Atmel DFU bootloader
option, JTAG will always be enabled. It will then have to be disabled in software or by fuse setting to
enable access to the four ADC channels.
Mounting Holes
There are two grounded mounting holes. They have a hole diameter of 3mm and the pad is
4.8mm. Each one is located 6.2mm from the closest long edge of the board. The hole nearest the
USB connector is 11.4mm from the closest short edge. The hole furthest from the USB connector is
2.7mm from the closest short edge.
December 30, 2015 11 http://www.mattairtech.com/

MT-DB-U4 User G ide
Power Configuration
Power Configuration
Bus Powered - 5V
By default, the MT-DB-U4 is configured for 5V from the USB connector (Vbus). In this
configuration, solder jumper J1 is set to the 5V position. This shorts 5V (Vbus) to Vcc. Thus, the 5V
and Vcc pins are both outputs. The 3.3V pin is also an output from the AVR internal regulator, which
must be enabled. This pin can supply about 55mA.
Externally Powered – 3.4V to 5.5V
In this configuration, disconnect solder jumper J1 (not set to 5V or 3.3V). Then supply 3.4V to
5.5V to the Vcc pin, which is now an input. The 5V pin still outputs 5V when the USB cable is plugged
in. The 3.3V pin is also an output from the AVR internal regulator, which must be enabled. This pin
can supply about 55mA. Note that when using a voltage less than 4.5V, the AVR should be set to run
at 8MHz or less. This can be done in software using the prescaler (no need to change the crystal).
Externally Powered – 3.0V to 3.6V
In this configuration, change your code to disable the internal 3.3V regulator. Disconnect solder
jumper J1 (not set to 5V or 3.3V). Then supply 3.0V to 3.6V to both the Vcc pin and the 3.3V pin,
which are now both inputs. Alternatively, the solder jumper J1 can be set to the 3.3V position so that
only the Vcc pin need be connected. Note that unlike the AT90USBXX2 or ATmegaXXU2, the internal
3.3V regulator cannot be used to power Vcc because the regulator is disabled on reset or power-up.
Also note that if the bootloader is set to run (HWB jumper installed) the regulator will be enabled. The
regulator is then disabled before jumping to the user application. The regulator is never enabled if the
application is configured to run (HWB jumper not installed). Therefore, if the bootloader is to be used
in this configuration, only 3.3V should be connected to Vcc. The 5V pin still outputs 5V when the USB
cable is plugged in. In this configuration, the AVR should be set to run at 8MHz or less. This can be
done in software using the prescaler (no need to change the crystal).
USB Shield
Jumper J3 can be soldered to connect the USB shield to ground. The USB specification calls
for the USB shield to be connected to ground on the host side only. However, some prefer to have it
grounded on the device side as well, though a ground loop would be formed. An 0603 SMT
component may be soldered on the solder jumper pads as well.
December 30, 2015 12 http://www.mattairtech.com/

MT-DB-U4 User G ide
Arduino Compatibility (IDE 1.6.7)
Arduino Compatibility (IDE 1.6.7)
This is a fork of the Arduino AVR core from arduino/Arduino (hardware/arduino/avr/ directory) on
GitHub. This will be used to maintain Arduino support for AVR boards including the MattairTech MT-
DB-U1, MT-DB-U2, MT-DB-U4, and the MT-DB-U6 (see https://www.mattairtech.com/).
This core is intended to be installed using Boards Manager (see below). To update from a previous
version, click on MattairTech AVR Boards in Boards Manager, then click Update.
What's New
●Initial release of the 1.6.x compatible AVR core.
●Any combination of CDC, HID, or UART can be used (or no combination), by using the Tools-
>Communication menu.
●Note that switching between CDC and CDC+HID will require re-selecting the COM port.
●More detailed memory usage at end of compilation (see below).
●Merged in upstream updates.
Summary
Feature MT DB U6 MT DB U4 MT DB U2 MT DB U1
Microcontroller AT90USB64/AT90US
B128, 8-Bit AVR
ATmega32U4, 8-
Bit AVR
ATmega32U2, 8-
Bit AVR
AT90USB162, 8-
Bit AVR
Clock Speed 16 MHz 16 MHz 16 MHz 16 MHz
Flash Memory 128 KB
(AT90USB128) / 64
KB (AT90USB64)
32 KB 32 KB 16 KB
SRAM 8 KB (AT90USB128) /
4 KB (AT90USB64) 2.5 KB 1 KB 512 B
EEPROM 4 KB (AT90USB128) /
2 KB (AT90USB64) 1 KB 1 KB 512 B
Digital Pins 46* 26 21 21
Analog Input Pins 8 (10-bit) 11* (10-bit) No analog No analog
PWM Output Pins 7* 7 4 4
External
Interrupts 6* (8 PCINT)* 5 (8 PCINT)* 8 (13 PCINT)* 8 (13 PCINT)*
USB CDC and HID CDC and HID CDC and HID CDC and HID
UART (Serial) 1 1 1 1
SPI 1 1 1 1
I2C (TWI) 1 1 No I2C No I2C
Operating Voltage 5V/3.3V 5V/3.3V 5V/3.3V 5V/3.3V
December 30, 2015 13 http://www.mattairtech.com/

MT-DB-U4 User G ide
Feature MT DB U6 MT DB U4 MT DB U2 MT DB U1
DC Current per I/O
Pin 2 mA 2 mA 2 mA 2 mA
●Only INT pins are supported in this core (PCINT pins are not supported).
●MT-DB-U4: 1 additional analog pin is available by disconnecting the LED (solder jumper on rev B
and higher boards)
●MT-DB-U6-64/128: 2 additional digital, 2 additional PWM, or 2 additional INT pins available with
RTC crystal removed. Note however, that the RTC crystal holes are smaller and closer together
than the header pin holes.
Special Notes
●Tools->Communications menu
Currently, the Tools->Communications menu must be used to select the communications
configuration. This configuration must match the included libraries. For example, when including the
HID and Keyboard libraries, you must select an option that includes HID (ie: CDC_HID_UART).
This menu is currently needed to select the USB PID that matches the USB device configuration
(needed for Windows). This may become automatic in a future release.
●Include platform specific libraries
You may need to manually include platform specific libraries such as SPI.h, Wire.h, and HID.h.
●EXCEPTION_FOR_57600
The MattairTech ArduinoCore-avr uses a more accurate baud rate for 57600 than the stock
arduino. When using the USART to communicate with another Arduino, define
EXCEPTION_FOR_57600.
●New interrupt mapping
The MattairTech ArduinoCore-avr has changed interrupt pin mapping from the previous 1.0.5
release. The arduino pin number is now used with attachInterrupt() instead of the interrupt number.
See 'Pin Configurations' below.
Pin Configurations
To determine the Arduino pin number, start at the upper-left corner of the board opposite of the USB
connector. This is pin 0 (most boards have a 0 printed nearby). The numbering increases in a counter-
clockwise direction around the board. Many pins have multiple configurations available. For example,
arduino pin 29 (AVR pin D0) on the MT-DB-U6 can be a PWM output (analogWrite), an external interrupt
input, digital I/O, or the SCL pin of I2C.
December 30, 2015 14 http://www.mattairtech.com/

MT-DB-U4 User G ide
MT DB U6 (AT90USB64/AT90USB128)
================== MattairTech MT-DB-U6 (AT90USB64/AT90USB128) ==========================
INT/Other P M Analog Digital Digital P M INT/Other Comm
=========================================================================================
---------------------
LED 0 | E0/L O O RST |
1 | E1 H B E2/B| 37 JUMPER
2 | C0 D7 | 36
3 | C1 O O D6 | 35
4 | C2 O O D5 | 34 XCK
5 | C3 O O D4 | 33
6 (TC3C) 6 | C4 O O * D3 | 32 32 (INT3) TX
7 (TC3B) 7 | C5 PORT A D2 | 31 31 (INT2) RX
8 (TC3A) 8 | C6 D1 | 30 30 (TC2B) 30 (INT1) SDA
9 | C7 D0 | 29 29 (TC0B) 29 (INT0) SCL
| |
JTAG TDI 10 (ADC7) 10 | F7 E3 | 28
JTAG TDO 11 (ADC6) 11 | F6 P R S E7 | 27 27 (INT7)
JTAG TMS 12 (ADC5) 12 | F5 O B7 | 26 26 (TC1C)
JTAG TCK 13 (ADC4) 13 | F4 - + O B6 | 25 25 (TC1B)
14 (ADC3) 14 | F3 O O B5 | 24 24 (TC1A)
15 (ADC2) 15 | F2 P R IN B4 | 23 23 (TC2A)
16 (ADC1) 16 | F1 B3 | 22 MISO
17 (ADC0) 17 | F0 * O O B2 | 21 MOSI
18 (INT6) 18 | E6 O O B1 | 20 SCLK
| Aref O O B0 | 19 SS
| Vbus ISP 3.3V|
| D- _____ Vcc |
| D+ | | 5V |
| Gnd | USB | Gnd |
---------------------
* Pins 38-45 are on the PORT A header. Pins 46 and 47 are the RTC crystal pins E4 and E5
in use by the RTC by default). With RTC crystal removed, there are 2 additional digital
pins 46 and 47), 2 additional PWM pins TIMER2A on pin 23 and TIMER2B on pin 30), and 2
additional INT pins INT4 on pin 46 and INT5 on pin 47). All pins can be used with
analogRead ). 8 of these pins are actual analog inputs, the rest connect to the internal
reference pin 47) or ground.
December 30, 2015 15 http://www.mattairtech.com/

MT-DB-U4 User G ide
MT DB U4 (ATmega32U4)
========================= MattairTech MT-DB-U4 (ATmega32U4) =============================
INT/Other P M Analog Digital Digital Analog P M INT/other Comm
=========================================================================================
-------------------
0 (ADC11) 0 | B4 RST |
1 (TC1A) 1 (ADC12) 1 | B5 D7/L| 25 25 (ADC10) 25 (TC4D) LED
2 (TC1B) 2 (ADC13) 2 | B6 D6 | 24 24 (ADC9)
3 (TC3A) 3 | C6 D5 | 23 23 (REF)
4 (TC4A) 4 | C7 D4 | 22 22 (ADC8)
JUMPER 5 | E2/B D3 | 21 21 (INT3) TX
| Agnd D2 | 20 20 (INT2) RX
6 (ADC7) 6 | F7 D1 | 19 19 (INT1) SDA
7 (ADC6) 7 | F6 D0 | 18 18 (TC0B) 18 (INT0) SCL
8 (ADC5) 8 | F5 xtal1|
9 (ADC4) 9 | F4 xtal2|
10 (ADC1) 10 | F1 B7 | 17 17 (TC1C)
11 (ADC0) 11 | F0 B3 | 16 MISO
12 (INT6) 12 (TEMP) 12 | E6 B2 | 15 MOSI
| Aref B1 | 14 SCLK
| Avcc B0 | 13 SS
| Vbus 3.3V|
| D- _____ Vcc |
| D+ | | 5V |
| Gnd | USB | Gnd |
-------------------
* Because of the unusual layout of the ATmega32U4, all pins can be used with analogRead ).
12 of these pins are actual analog inputs 1 used by LED), the rest connect to the internal
reference, internal temperature sensor, or ground.
MT DB U1/MT DB U2 (AT90USB162/ATmega32U2)
=============== MattairTech MT-DB-U1/MT-DB-U2 (AT90USB162/ATmega32U2) ===================
Comm Interrupt P M Digital Digital Interrupt P M Comm/other
=========================================================================================
-------------------
SPI SS 0 | B0 RST |
SPI SCLK 1 | B1 D7 | 20 20 (INT7) JUMPER
SPI MOSI 2 | B2 D6 | 19 19 (INT6)
SPI MISO 3 | B3 D5 | 18
4 | B4 D4 | 17 17 (INT5)
5 | B5 D3 | 16 16 (INT3) USART1 TX
6 | B6 D2 | 15 15 (INT2) USART1 RX
7 (TC1C) 7 | B7 D1 | 14 14 (INT1)
8 (INT4) 8 | C7 D0 | 13 13 (INT0) 13 (TC0B) LED
9 (TC1A) 9 | C6 C2 | 12
10 (TC1B) 10 | C5 X1 |
11 | C4 X2 |
| Vbus 3.3V|
| D- _____ Vcc |
| D+ | | 5V |
| Gnd | USB | Gnd |
-------------------
December 30, 2015 16 http://www.mattairtech.com/

MT-DB-U4 User G ide
Pin Capabilities
●Digital: All pins can be used for general purpose I/O
●Supports INPUT, OUTPUT, and INPUT_PULLUP.
●Each pin can source or sink a maximum of 20 mA.
●Internal pull-up resistors of 20-50 Kohms (disconnected by default).
●Use the pinMode(), digitalWrite(), and digitalRead() functions.
●Analog Inputs: 8 pins (MT-DB-U6) or 11 pins (MT-DB-U4) can be configured as ADC
analog inputs.
●These are available using the analogRead() function.
●All pins can be used for GPIO and some pins can be used for other digital functions (ie.
pwm or serial).
●Each pin provides 10 bits of resolution (1024 values).
●Each pin measures from ground to 5.0 volts.
●The upper end of the measurement range can be changed using the AREF pin and the
analogReference() function.
●PWM: 7 pins (MT-DB-U6, MT-DB-U4) or 4 pins (MT-DB-U2, MT-DB-U1) can be configured
as PWM outputs.
●Available using the analogWrite() function.
●Each pin provides 8 bits of resolution (256 values) by default.
●External Interrupts: Up to 8 pins can be configured with external interrupts.
●6 pins (MT-DB-U6), 5 pins (MT-DB-U4), or 8 pins (MT-DB-U2, MT-DB-U1).
●Available using the attachInterrupt() function.
●Serial: 1 pair of pins can be configured for TTL serial I/O.
●MT-DB-U6: Serial1: pin 31 (RX) and pin 32 (TX).
●MT-DB-U4: Serial1: pin 20 (RX) and pin 21 (TX).
●MT-DB-U2, MT-DB-U1: Serial1: pin 15 (RX) and pin 16 (TX).
●SPI: 3 or 4 pins can be configured for SPI I/O (SPI).
●MT-DB-U6: Pin 21 (MOSI), pin 20 (SCK), pin 22 (MISO), and optionally pin 19 (SS, not
currently used).
●MT-DB-U4: Pin 15 (MOSI), pin 14 (SCK), pin 16 (MISO), and optionally pin 13 (SS, not
currently used).
●MT-DB-U2, MT-DB-U1: Pin 2 (MOSI), pin 1 (SCK), pin 3 (MISO), and optionally pin 0
(SS, not currently used).
●SPI communication using the SPI library.
●TWI (I2C): 2 pins can be configured for TWI I/O (Wire).
●MT-DB-U6: Pin 30 (SDA) and pin 29 (SCL).
●MT-DB-U4: Pin 19 (SDA) and pin 18 (SCL).
●MT-DB-U2, MT-DB-U1: TWI not present
●TWI communication using the Wire library.
●LED: One pin can be configured to light the onboard LED (LED_BUILTIN).
●Pin 0 (MT-DB-U6), pin 25 (MT-DB-U4), or pin 13 (MT-DB-U2, MT-DB-U1).
●Bring the pin HIGH to turn the LED on.
●AREF: One pin can be configured as an AREF analog input.
December 30, 2015 17 http://www.mattairtech.com/

MT-DB-U4 User G ide
●The upper end of the analog measurement range can be changed using the
analogReference() function.
●Reset: Bring this line LOW to reset the microcontroller.
Using Arduino with MattairTech USB boards
Because of the similarities with the Arduino Leonardo, please read
http://arduino.cc/en/Guide/ArduinoLeonardo first.
Within the Arduino IDE Tools menu, select the appropriate MattairTech board, Frequency/Voltage,
Processor, Communications setting, and COM port. There are 2 Frequency/Voltage configurations for
each board, 16MHz(5V) and 8MHz(3.3V). You may select 8MHz even if using 5V. When operating at
3.3V, you should select 8MHz. Operating at 16MHz at 3.3V is out of spec, but should work fine at
room temperatures. Be sure to select the Communications setting that matches your sketch (by
default, this is CDC_ONLY). This is important.
Note that some example sketches indicate the use of pins using the naming convention D2, D3, etc.
These are Arduino digital pins, not to be confused with port D pins. Most MattairTech USB AVR
boards are printed with both port pin names as well as sequential numbers indicating the Arduino pin
number. You may use the 'A' or 'D' prefixes, but they are simply aliased to the arduino pin number (ie:
A2 = D2 = 2).
There are several libraries included with Arduino. Some of these need simple changes to work with
MattairTech boards. Usually, only pin mappings need to be changed.
Serial Monitor
To print to the Serial Monitor over USB, use 'Serial'. Serial points to SerialUSB (Serial1 is a UART).
Unlike most Arduino boards (ie. Uno), USB AVR based boards do not automatically reset when the
serial monitor is opened. To see what your sketch outputs to the serial monitor from the beginning, the
sketch must wait for the SerialUSB port to open first. Add the following to setup():
while !Serial) ;
Remember that if the sketch needs to run without SerialUSB connected, another approach must be
used. You can also reset the board manually with the Reset button if you wish to restart your sketch.
However, pressing the Reset button will reset the AVR chip, which in turn will reset USB
communication. This interruption means that if the serial monitor is open, it will be necessary to close
and re-open it to restart communication.
Updated Tone.cpp
Tone.cpp now supports multiple simultaneous tone generation (one tone per timer). The MT-DB-U6
currently supports up to 4 simultaneous tones using timers 3, 1, 2, and 0 if not using the RTC,
otherwise, timers 3, 1, and 0 are used for 3 tones. The MT-DB-U4 currently supports up to 3
simultaneous tones using timers 3, 1, and 0. A future release may support a fourth tone from timer 4.
December 30, 2015 18 http://www.mattairtech.com/

MT-DB-U4 User G ide
The MT-DB-U2 and MT-DB-U1 support 2 simultaneous tones using timers 1 and 0. Note that timer 0
has a lower accuracy for tone generation because it is 8-bit (timers 3 and 1 are 16-bit). Note also that
use of timer 0 temporarily disables the use of delay(), which will return to normal operation once the
tone stops playing. Thus, timer 0 is set with the lowest priority. For example, if generating DTMF tones
on the MT-DB-U4, timers 3 and 1 will be used. However, the MT-DB-U2 and MT-DB-U1 will both use
timer 0 for the second tone. If timer 0 is used, delay() should not be called while timer 0 is generating a
tone. Instead, use _delay_ms(), which is included with avr-libc.
The DTMF_Demo sketch demonstrates usage of Tone.cpp for DTMF generation.
Detailed Memory Usage Output After Compilation
In this release, two programs are run at the end of compilation to provide more detailed memory
usage. This is enabled only when verbose messages for compilation is enabled in the IDE
Preferences. Just above the normal flash usage message, is the output from the size utility. Above the
size utility output is the output from the nm utility. The values on the left are in bytes. The letters stand
for: T(t)=.text, D(d)=.data, B(b)=.bss, and everything else (ie: W) resides in flash (in most cases).
USB Technical Notes
●Note that USB CDC is required for auto-reset into the bootloader to work (otherwise,
manually press reset with jumper installed).
ATmegaxxU4: 832 bytes DPRAM, 1 (control, 64 byte max) + 1 (two banks, 256 byte max) + 5 (two
banks, 64 byte max) endpoints AT90USBxxx6/7: 832 bytes DPRAM, 1 (control, 64 byte max) + 1 (two
banks, 256 byte max) + 5 (two banks, 64 byte max) endpoints
// These are used by the core
#define USB_CONTROL_EP_SIZE 16
#define USB_CONTROL_EP_BANKS 1
#define USB_DEFAULT_EP_SIZE 64
#define USB_DEFAULT_EP_BANKS 2
#define USB_CDC_NOTIFICATION_EP_SIZE 16
#define USB_CDC_NOTIFICATION_EP_BANKS 1
#define USB_CDC_DATA_EP_SIZE 64
#define USB_CDC_DATA_EP_BANKS 2
// These can optionally be used by PluggableUSB libraries
#define USB_HID_EP_SIZE 16
#define USB_HID_EP_BANKS 1
#define USB_MIDI_EP_SIZE 64
#define USB_MIDI_EP_BANKS 2
#define USB_MSD_EP_SIZE 64
#define USB_MSD_EP_BANKS 2
AT90USBxx2: 176 bytes DPRAM, 8 - 64 byte endpoints, 1 (control) + 2 (one bank) + 2 (two banks)
endpoints ATmegaxxU2: 176 bytes DPRAM, 8 - 64 byte endpoints, 1 (control) + 2 (one bank) + 2 (two
banks) endpoints
// These are used by the core
December 30, 2015 19 http://www.mattairtech.com/

MT-DB-U4 User G ide
#define USB_CONTROL_EP_SIZE 16
#define USB_CONTROL_EP_BANKS 1
#define USB_DEFAULT_EP_SIZE 32
#define USB_DEFAULT_EP_BANKS 2
#define USB_CDC_NOTIFICATION_EP_SIZE 16
#define USB_CDC_NOTIFICATION_EP_BANKS 1
#define USB_CDC_DATA_EP_SIZE 32
#define USB_CDC_DATA_EP_BANKS 2
// These can optionally be used by PluggableUSB libraries
#define USB_HID_EP_SIZE 16
#define USB_HID_EP_BANKS 1
#define USB_MIDI_EP_SIZE 32
#define USB_MIDI_EP_BANKS 2
#define USB_MSD_EP_SIZE 32
#define USB_MSD_EP_BANKS 2
Installation
Driver Installation
Windows
Prior to core version 1.6.9-mt1, sketches compiled with both CDC and HID USB code by default, thus
requiring a CDC driver for the bootloader and a CDC-HID driver for sketches. Now that PluggableUSB
is supported, sketches compile with only CDC code by default. Thus, only one driver is needed. Since
HID and MIDI are currently supported (and MSD potentially in the future), driver installation will be
required for each different combination of USB devices. There are currently four USB composite
device combinations that include CDC as well as a CDC only device. Each supported combination has
a unique USB VID:PID pair, and these are listed in the .inf file. Once the first device is installed (the
CDC only device), future installations might be automatic, otherwise, you may direct the installer to the
same .inf file. The drivers are signed and support both 32 and 64 bit versions of Windows XP(SP3),
Vista, 7, 8, and 10.
1. If you do not already have the CDC bootloader installed, see below.
2. Download https://www.mattairtech.com/software/MattairTech_CDC_Driver_Signed.zip and
unzip into any folder.
3. Plug in the board with the jumper installed. The LED should light.
4. Windows will detect the board. Point the installer to the folder from above to install the
bootloader driver.
5. If you don't intend on using Arduino, you can skip the rest of this list. See Using AVRDUDE
Standalone below.
6. If you do not already have the test firmware installed, see Using AVRDUDE Standalone below.
7. Press the reset button to run the test firmware (blink sketch).
8. Windows will detect the board. Point the installer to the above folder to install the sketch driver
(if needed).
December 30, 2015 20 http://www.mattairtech.com/
Table of contents
Other MattairTech Motherboard manuals