Arduino controlled Dual Mono AK4490 DAC (Part 2)

Following up on Part 1, it’s time to talk about the “brains of the operation”. Bare with me, this is going to be a rather long read.Hardware selection

The DAC needed to be controlled by a microcontroller so I looked into my options. I wanted something that would:

  • Be easy to program, so the Arduino IDE was a must.
  • Be able to drive a TFT.
  • Have enough storage capacity to store enough code & fonts for the TFT.
  • Be readily available.
  • Be relatively low cost, since it would have no influence on the dac’s SQ.
  • Be easy to build / integrate into a new design, even by a novice.

After some consideration, I decided to use an STM32F103 ready-made module. It would plug in to a “mainboard” of my design, along with the chosen TFT. It would be fast enough, have enough flash & ram, be easy to integrate and develop for and it would cost next to nothing.

Next up was the TFT. I’d seen on Ebay an interesting one that was relatively big, high resolution and inexpensive. It was this one:

It can be found on Ebay by searching for “3.5 tft uno 320 x 480”. Expect to pay 6-8€ inc. shipping.

After some searching I found a suitable library that (after some slight tinkering) would allow my tiny STM32 to drive it properly. (Note: do not download the library from this link. I will provide a customized version of the library together with my code).

I found a ready-made library for configuring the Si570 and modified it to run on my STM32, using one of its hardware I2C ports. I will also include this library in my code. To complete the recipe I also found working rotary encoder and IR receiver libraries.

The code

Next up was the prototyping work. I adapted my TFT HiFiDuino Pro code to run on the STM32 & TFT combo, with support for AK4490 dual mono operation. The end result had this feature list:

  • Support for either Dual Mono or single chip setups.
  • Support for the Amanero Combo384 USB to I2S module (must be set up as slave with MCLK/2 and F0,1,2,3 enabled).
  • Control with one rotary encoder with push-to-select functionality.
  • IR Remote support.
  • Support for software volume control, from -99dB to 0dB
  • Display incoming signal sampling rate and type, determined by “reading” the relevant I/O pins of the USB to I2S board.
  • Display and control of the AK4490’s digital filter.
  • Selection of the proper MCLK frequency according to incoming SR and type and programming of the Si570 accordingly.
  • Control of “DSD Direct” function of the AK4490s.
  • Control of the DSD Filter’s Frequency (50KHz or 150KHz).
  • Control of the Sound Mode of the AK4490.
  • Choice of either inverted or normal analog output for the AK4490s.
  • Choice of two sets of MCLK frequencies, either 22/24MHz or 45/49MHz.
  • Remote power on/off functionality (or always on – configurable in the code).

Software Requirements:

In the download I am including the modified versions of the libraries (as mentioned above) as well as the necessary font files. Be sure to extract the contents of “Libraries (place in Libraries folder)” to your Arduino IDE’s “libraries” folder.

Download it here: aKduino v2 (62594 downloads )

Here is the revision history:

v1.72 24/12/2017:

  • Minor changes to make compatible with current stm32duino core (changed HardWire.h to Wire.h and other minor stuff).
  • First public release as part of completed dual mono DAC project.

v1.66 10/10/2017:

  • Minor volume bugfix.
  • SuperSlow filter still problematic.
  • Enabled DAC synchronization feature (experimental..).

v1.64 30/09/2017:

  • Bugfixes.

v1.60 20/09/2017:

  • Added support of rotary encoder and IR remote control.
  • 3.5″ TFT support.

v1.50 07/01/2017:

  • Added support of rotary encoder for volume control.
  • Bugfixes related to DSD.

v1.41 06/01/2017:

  • Added support for dual mono mode.

v1.36 03/01/2017:

  • Added very basic TFT support.

v1.35 20/12/2016:

  • Code cleanup for first public release.

v1.33 19/12/2016:

  • Added full control of sound parameters through serial port.

v1.27 18/12/2016:

  • First functional version.
  • Automatic switching between PCM and DSD by monitoring DSDPIN.

The “motherboard”

After I was certain that everything related to the software was working the way it should, I designed a “motherboard” that would take care of the following:

  • Accept the STM32F106 board.
  • Accept the 3.5″ TFT.
  • Accommodate an 24LC256 EEPROM chip, used to store the DAC’s configurable settings.
  • Accommodate two sets of I2C signal isolators and I/O expanders.
  • Include headers for the encoder, IR receiver, power relay, non-isolated and isolated I2C communication, unused uC pins, etc.

This is what I ended up with:

Basic Hardware Requirements:

  • STM32F106 module (a.k.a. “blue pill”, search Ebay for “stm32f106c8t6 board”)
  • 3.5″ TFT with resolution of 320 x 480 (Search Ebay for “3.5 tft uno 320 x 480”)
  • 24LC256 EEPROM chip
  • I2C Isolator ICs, I/O expanders, passive components, etc (see BoM)
  • Rotary Encoder
  • IR Receiver
  • Compatible IR remote control (Apple Remote or other – in any case you must edit the code and input the proper IR codes for your remote, see below)
[table “” not found /]

How do I make it work?


You have to supply the board with 5VDC at ~300mA through header DC_5V.
[table “” not found /]

Basic connectivity

Serial port:
[table “” not found /]

Rotary encoder:
[table “” not found /]

IR control:
[table “” not found /]

If you will be controlling a power on/off relay, you can use the POWER_RELAY header:
[table “” not found /]

Expansion header:
[table “” not found /]

I2C header (non-isolated):
[table “” not found /]

Isolated I2C ports

The board has provisions for two separately isolated I2C ports, complete with I/O expanders on their isolated sides. The idea is to connect the DAC board to one of the isolated ports (I2C_ISOL1 & MCP_ISOL1) and your USB-to-I2S board to the other isolated port (usually MCP_ISOL2)
[table “” not found /]

[table “” not found /]
[table “” not found /]
[table “” not found /]

That’s it for Part 2. Stay tuned for Part 3: The output stage.

Winter 2017-2018 teaser :-)

So many projects, so little time.. Here’s a teaser on what’s to come:

PGA2311-based preamp, with multiple inputs board, controlled by a custom Arduino, with an OLED screen.

Salas DCG3 preamp, powered by custom Salas Shunt Reg 1.2R.

MPD TFT display for Rasberry Pi, controlled by an STM32.

Ian’s Multichannel FIFO.’s DigiOne RPi HAT.

Dual Mono AK4490 DAC with on-board Si570 programmable oscillator and reclocking, Single ended Class A discreet output stage, Arduino controlled with STM32 controller and 3.5″ TFT screen.

Arduino controlled AK4118 based s/pdif receiver, with AK4137 SRC.

Update: TFT HiFiDuino v2.13

I did a little work on the TFT HiFiDuino code, incorporating most of the enhancements I made to the ArDAM1021 code.







These are the enhancements:

  • Option of displaying white text & graphics on black background as well as the “original” look.
  • New encoder code (it requires a new library).

Plus a few minor bugfixes here and there.

The new version of the code is here (v2.13): TFT_HiFiDuino_v2.xx (12302 downloads ) (Note: As always, the code on this page may not be the current one, i.e. there may be a newer version available. The latest version is always up at the project’s official page.)

I will also update the code’s official page with the new version of the code.

Soekris dam1021 Arduino Control Code

A few days ago Soren announced that the release of the new firmware for the dam1021 was close.

In light of that announcement I have decided to release the Arduino code that I had written a few months back, even though it is not quite finished.

2015-07-31 18.15.44_res

I am doing this to help fellow Arduino & dam1021 enthusiasts in their quest of remote-controlled color TFT bliss.

So, for now, no real documentation – this is no polished piece of software, but it works (for the most part).

Since it is based on the TFT HiFiDuino code, you can get started by reading its documentation. It should not be hard to get started with this. The code itself also contains useful comments.

I should remind you that the dam1021 at the moment only “talks” real RS-232, meaning that a circuit that converts the TTL level serial port of the Arduino to a real RS-232 port is necessary.
However, we were promised that with the firmware upgrade the second, isolated TTL serial port would be enabled, so here’s hoping..

Also, I have come across a strange problem with the serial communication with the dac. In the beginning all is well but after a while the dam no longer responds to the commands that are sent by the Arduino. However, it (the dam) is still sending data back to the Arduino – when the sampling rate changes, the new SR is displayed properly on the TFT.

I have verified that the Arduino is indeed sending the commands to the dam:



I hope the problem gets sorted out in the new firmware release.

Anyway, here is the code: ArDAM1021 Code (75873 downloads )  The project also has its own page:

Let me know what you think. I promise to put more work into it in the next few weeks..

Arduino and SPI TFT LCDs

I love TFTs because one can make with them professional looking project displays without necessarily breaking the bank.

I am particularly fond of the SPI interface because it uses a minimum number of I/O pins. This means that since even a minimal Arduino (one based on an ATmega328) can drive a low-cost TFT with I/O left for other tasks, the cost may be kept down. Nowadays, it is realistic to implement a basic Arduino with a 2.2″ TFT for less than 10€. An ATmega328 with an Arduino bootloader goes for 1,50€ on Ebay, a 2.2″ SPI TFT goes for about 3,50€, so “vintage” character LCDs are definitely on their way out.

So, let’s get down to business. What does one need in order to get one of these displays to work?
Obviously, you need the TFT display itself. I don’t care where you buy it from – you may get it from Adafruit or SparkFun or iTead or any one of the “big name” shops or you may get it from Ebay (a.k.a. “China”). In my experience, it doesn’t really matter as long as you know what you are purchasing. For example, on Ebay when you search for 2.4″ SPI TFT LCD you will come across this:


and this:


They are essentially the same TFTs, but the first one is ~1€ cheaper than the second one. The difference is the PCB that is included. Do not underestimate this PCB. If you go for the plain TFT you will have to solder it to a suitable PCB like this one:

2014-11-25 00.42.57_resize

Sure, it is no herculean task, but the TFT + adapter will most likely cost more than a TFT pre-mounted on a PCB.

Rolling your own PCB is indeed an option, but IMHO it is not worth it, not unless you are planning to go into mass production. For 1 or 2 pieces just do yourself a favor and shell out the extra €. You won’t regret it.

But let’s backtrack just a bit. How does one select a TFT? Surely, one would think that size and resolution are the most important factors. I say sure, as long as you have the software part covered. In order to actually show stuff on a TFT you need an appropriate library. You should not take for granted that such a library indeed exists for that gorgeous hi-res IPS TFT that you found for 10€ on Ebay. Many sellers on Ebay just write the word “arduino” on the TFT’s description without giving it much serious thought. Plus you should expect zero (0) support from most Ebay sellers. Most of them can’t and won’t help you if you run into trouble with your code.

So, you should always do a little research. Google is your friend. A good start is Karlsen Henning’s UTFT library. Being billed as a Universal TFT Library it does indeed support a large number of TFT controllers. If your display’s controller is included in UTFT’s compatibility list, you are somewhat covered. I say somewhat because UTFT is not always the best choice since it has a pretty heavy footprint. It will consume the better part of an ATmega328’s flash memory capacity. Fortunately, there are other libraries out there. I will go into more detail later on.

So, you got a TFT and are faced with the task of hooking it up to the Arduino. Relax, it’s simple. You only need to connect 4 or 5 wires, plus power and GND. Let’s start with the basics.

1) Power (Vcc). Most displays need 3.3V to function. This is a requirement of the TFT panel itself as well as of the driver IC that is always part of the assembly (it is an embedded part – you can not really see it). But as you probably know, most Arduinos run on 5V. Display manufacturers that make products for Arduino of course know that and usually include an on-board regulator that takes 5V as input and gives the necessary 3.3V. In most cases there is a selector on the PCB (jumper, solder bridge, or something) that lets you configure the board for 5 or 3.3 volt operation. Look out for that.

2) LED power. This pin controls the backlight of the TFT panel. It consists of a number of LEDs, depending on the size of the LCD panel. Bigger panel means more LEDs and thus more power consumption. It is usually connected to GND or to 5V/3.3V. Some times a current limiting resistor is also necessary. Other times the resistor is built-in and so is a mosfet that allows you to adjust the LED backlight’s brightness by connecting it to a pin that supports PWM (some of the more expensive TFTs support this). In any case, read the manual. You may come across a Chinese TFT that you had to have but then noticed that it has sparse if any documentation. If this happens, play it safe by connecting the LED pin to GND through a resistor (a few hundred ohms is usually a good starting point). If it lights, it means that the polarity is OK. If it does not, try applying 5 or 3.3V to it (through the resistor). If it lights but is too dim, use a smaller resistor. Usually each LED draws about 10-15mA, so if you know how many LEDs your TFT uses you can estimate its power draw and thus select a proper resistor.

3) Signalling. This is the nice part about using SPI: you only need 4 or 5 wires.
CLK (or SCLK / SCK): This is the clock input pin.
MOSI (or SDI / SDA): This is the Master Out Slave In pin. The actual raw data that is sent to the TFT passes through this wire.
CS (or TFT_CS or LCD-CS): This is the chip select pin.
D/C (or A0 or RS): This is the Data or Command selector pin.

We also have the Reset pin. Some times you can get away with connecting it to the Arduino’s reset pin, but it is better to connect it to a normal pin in order to have better control over it.

A special note here: Signalling is usually done at 3.3V unless the TFT’s manufacturer has implemented some kind of level shifting on board the PCB. This level shifting may be done by an IC (best case), or a bunch of transistors and resistors (fair enough..) or just 1.2K resistors (a bit of a kludge, but it usually works). It is important to be careful not to send 5V into a TFT that only supports 3.3V logic because in that case you will most likely damage the TFT.

At this point you need to take a break from the hardware and consider the software, since your choice of library will dictate the particulars of the next step, which is the connection of the signal wires to the Arduino.

Your main choices are two: the UTFT library and the Adafruit GFX library.

Each library has its strengths and weaknesses.


  • Very nice text support, especially with the add-on UTFT_DLB. Any TrueType font can be converted into a UTFT font of any size with minimum effort.
  • It is indeed universal. You only need to change one parameter in your code to support a different TFT. One library to rule them all, etc.


  • Memory consumption. Nice fonts come at a price. No big deal if you have a MEGA or DUE, but makes things pretty cramped in an ATmega328.

Adafruit GFX

  • Relatively small footprint.


  • Ugly (blocky) fonts if you scale them to a non-native size. This is being fixed by 3rd party code that now supports a small number of proportional fonts but is nowhere near as versatile as UTFT’s code.

You really should become familiar with both of them since different projects will steer you towards one or the other.

Depending on your choice of library, you may need to use the hardware SPI pins for CLK and MOSI or you may be free to use any pins you like. It really just depends on the library.

Each of the libraries uses a slightly different notation for the signal pins. I will try to sum things up in this table:

[table “” not found /]

You may notice that most libraries say that you can just connect the TFT Reset pin to the Arduino Reset Pin. If you do that, you should put 0 as the reset pin.

Good luck!

TFT HiFiDuino v2.01 + video

As is usually the case, a few bugs crept into the v2 release. So, here is v2.01: TFT_HiFiDuino_v2.xx (12302 downloads ) (Note: As always, the code on this page may not be the current one, i.e. there may be a newer version available. The latest version is always up at the project’s official page.)

Also, here is a video of the code in action:

TFT HiFiDuino v2!

It’s official: Version 2 of the TFT HiFiDuino controller is complete!

There is a number of changes, thus the new version:

  • New minimal display mode as default. Goes into full display when changes are to be made to parameters.
  • Full graphics support in the minimal display.
  • New proportional fonts (TrueType).
  • New IR code. Now supports a much larger range of remote manufacturers.
  • Support of MCP23008 IC to control misc devices.
  • New option to set 0db as default (power-on) volume for connection to a preamp.

The code is (and will remain) compatible with my current shield. (Hint: shield v2 is also coming up!)

New requirements:

Plus the good old UTFT library.

I am including the necessary fonts and bitmaps in the ZIP. The fonts should go into your UTFT & UTFT_DLB directories, usually found in the Windows user’s Documents folders (for example, here: c:\Users\<user name>\Documents\Arduino\libraries\UTFT_DLB\).

The bitmaps should go into your sketch’s folder.

I have included in several places in the code SerialUSB output for debugging purposes. It is commented out in this release for performance purposes. However, it is very easy to re-enable for either debugging or viewing of the IR codes sent to the Arduino. You may use these IR codes to customize the code to support your remote by changing the relevant #define statements in the Remote control definitions section.

Due to code size and performance requirements I’m afraid that from v2 onwards TFT HiFiDuino will only be compatible with the Arduino Due. Sorry, it’s the price to pay for nice graphics. Thankfully, it’s a pretty low price. 😛

You may download it here: TFT_HiFiDuino_v2.xx (12302 downloads ) (Note: As always, the code on this page may not be the current one, i.e. there may be a newer version available. The latest version is always up at the project’s official page.)

I will soon update the code’s official page to v2.


Laying out a display is hard work, Part 2

A couple of weeks back I wrote that I was working on the next version of the TFT HiFiDuino code and that I was struggling with its new aesthetic.

I was considering something resembling this: 2014-12-14 21.50.50_resize

But, I did warn you that the final version would probably look nothing like this. I was right.

Two weeks have passed since then and I am very close to a v2 release. The aesthetics are 99% complete and I am just ironing out a few bugs.

This is the final look: IMG_8570_crop_res IMG_8567_crop_res

Stay tuned.. v2 will be out before the end of 2014!