Introduction: Arduino Gainclone 2.0

After running my Arduino controlled Gainclone amp for the last 8 years, the LCD died and I decided that it was time for a revamp. This instructable is based on the original and is designed to be an 'upgrade' from that. Please see it here - https://www.instructables.com/Arduino-Powered-Gainclone-amplifier/

This could also be used just as a sound processor/Input switcher board to attach to a commercial AMP but is designed to add some smarts to a generic home made 2 channel amplifier.

This time around:

  • New graphic based OLED screen
  • Upgrading to STM32F103 (AKA Bluepill)
  • Internal RTC (But with no battery, you could add...)
  • Ditching the Radio Module (because I never used it, and it wasn't implemented well)
  • Fixed rotary encoder (It worked but not the best)
  • Ability to set the time from controls
  • Professionally fabbed board

The STM32F103 is like an Arduino (Nano/Uno etc) on steroids. Although it is magnitudes more powerful than the old Atmega32, the reason I have used it for this upgrade is that it has much more programming space that is needed for storing the fonts for the LCD. The code runs at about 160% of the available space in an Atmega32 chip but only takes 40% of the STM32F103CBT6 or 85% of the STM32F103C8T6 at 55840 bytes.


***** This project contains components of dealing with domestic mains voltage and requires knowledge of how to work with it safely. Please ensure your skills match your goals and stay safe. The Author has produced this information with care but takes no responsibility for your actions.*****

This also requires some finer soldering skills so please consider this before taking on the project.

Supplies

STM32F103CXT6 based board and Programmer* AliExpress ~$12 *verify pinout matches board, F4X1 boards DONT*

3.12" 256x64 dot OLED Display AliExpress ~$30

Rotary Encoder AliExpress $2 - I recommend these over just the bare encoder as it has pullups on the signal pins

5v Regulator AliExpress (~$1 each but packs of 5)

Header pins AliExpress

TDA7439 IC AliExpress 10 for $5!

Screw Headers AliExpress

Solid State Relay AliExpress (i.e SSR-10DA) for switching mains power to AMP *Ensure it will work with 3v control signal

IR Remote and Receiver AliExpress ($3) Rx Jaycar $4.50 (Jaycar sell a remote but not ideal buttons)


Other General Electronic parts that you should be able to find anywhere:

4 X 100nf Polyester/MKT

8 X 0.47uf Polyester/MKT

2 X 5.6nf Polyester/MKT

2 X 18nf Polyester/MKT

2 X 22nf Polyester/MKT

2 X 2.2uf Tantalum

1 X 10uf Polarized

220uf Polarized - Optional smoothing cap for 5v rail if you have issues

1 X BD681 Darlington Transistor for fan if you want it.

2 X 4.7k 1/4w resistor

1 X 10k 1/4w resistor

2 X 2.7k 1/w resistor

2 X 5.6k 1/4w resistor

Bi Colour Common Anode (Positive) LED for power indicator. Or 2 different colour LEDS of your choice + current limiting resistor to suit either 3.3 or 5v.

Female headers for the STM32 to be able to make it removable from the board

16 way Ribbon cable (rainbow makes it easier)

These generic parts were available to me from my local Jaycar store (AU/NZ)


The board pictured was manufactured by JLCPCB. For me that's about $30 for 5 boards (Shipped Express).

If you want to make the board yourself, I have also provided a single sided version which should be easy to fabricate with your preferred method but please note the TDA7439 chip is NOT normal 2.54mm pin spacing and is very unforgiving if you drill holes out of alignment.

Approximate cost of all components is about AUD$100 including the 5 PCB from JLCPCB.


Gerber File Download

Step 1: Assemble the Main Board Components

Start with installing the resistors, and the TDA7439 IC, then move on to the capacitors and headers, then the regulator and transistor. The component labelling on the board should be pretty self explanatory.

There additional provision for a capacitor between the regulator and STM32 board if needed - If LED 'shimmers' perhaps you need to add.

Step 2: Connect IR, Rotary and Power Button

Spread, strip and tin all wires on one end of the ribbon cable and solder it to the 16 way header.

Determine the overall length you need for your install and split off the first 7 wires - These are for the power button, rotary encoder and IR.

Connections to the encoder:

vcc -> 3v3

Gnd - Gnd

SW -> BUT

CLK - > A*

DT -> B*

*If your actions on the rotary encoder are backwards, swap A/B wires.

IR Receiver:

VS - 3v3

GND -> Gnd

OUT -> IR

Power Button:

1 -> Gnd

2 -> PWR


Step 3: Connect OLED Display

The next 7 wires in the ribbon cable will go to the LCD screen - I used 5v for the OLED screen because the 3.3v regulator on the STM32 board will not be able to supply enough current for it. 3.3v signaling still works fine when powered with 5v.

The OLED screen needs to be put into SPI mode, to do this, we need to move the 0Ohm resistor from R6 to R5. Or, remove R6 and just make a solder bridge on the R5 spot like I did.

OLED Connections:

1 -> Gnd

2 - > 5v

4 - > SCK

5 - > MOSI

14 -> DC

15 -> RST

16 -> CS

Step 4: Connect Power Status LED

The last 2 wires are the ground wires for the power status LEDs. You can use 3.3 or 5v from the Encoder or OLED display respectively but you will need to place a current limiting resistor from the power source. For bright LEDs, this will be about 600Ohms, more for standard LEDs.

Step 5: Program the STM32

The steps involved for installing Arduino and configuring the environment are a bit beyond the scope of this project but in simple terms - Install the Arduino Software from https://www.arduino.cc and then install the STM32 environment (Link - See 'Getting Started' section) and don't forget the STM32Cube Programmer app (Free but account creation required)

I used version 1.8.16 of the Arduino platform

You will also need the following libraries:

My TDA7439 Library (Manual install)

The STM32RTC Library (Manual install)

The U8g2 Display library (Manage Libraries in Arduino)

The IRremote Library (Manage Libraries in Arduino)

Connect the corresponding wires between the STM32 board and the ST-Link Programmer (3.3v!), compile the code and let it upload to the board.

Once the board is programmed, you can install it onto the PCB.

If you are not using the 'KEYES' remote, you will need to determine the commands for your remote. There is an option in the code to debug the IR commands to add back into the code for use with your own remote.

Look for the line '#define debugIR' (Line 23) and set it to 1 instead of 0. This will then display IR codes received on the screen so you can 'learn' your remote. It looks horrid on the display but you will see the commands well enough to be able to note them down.

Update the code with your commands, set debugIR back to 0 and reprogram.

*** If programming later with the STM32 board installed, be sure NOT to connect the 3.3v line and the main power input at the same time, this is likely to cause damage to the STM32 board. I just connect Gnd, SCK and DIO, relying on the external power to the main PCB for power.

Project Files Download

Step 6: Testing

With everything wired and programmed up, you should be able to power up the board and the time should display dimly (00:00) and the power off led should come on.

Press the power button and the Display should brighten with the words 'Arduino Powered Gainclone' for a two seconds and revert back to the time. The power on led should now also light up.

From here you can use the rotary encoder to adjust volume and menus are available by pressing the rotary and scrolling through.

The same features are available from the IR remote (# for power, OK for Menu and left/right for change)

If it all looks good, I suggest from here you can connect a test input signal and connect an amplifier to the output to ensure everything is working ok such as volume and equalizer changes.

Step 7: Install in Amp

From there, you will need to at least connect the power input and SSR output.

*Once again, make sure your SSR will work at 3v logic, i had a 4v one initially but it was not able to turn on fully, causing a weird hum in the transformers and eventually tripping my resettable fuse.

Connect a suitable fan to the corresponding terminals if you are using one.

Step 8: Wrapping Up

Now that you have it all tested and working, consider how this will be used in your DIY amp. You can install the SSR and fan if desired/needed.


Set the time using the menu option. It defaults to hours first 'ok' then minutes 'ok' - it does not flash or indicate which is selected like an old style clock. I looked at implementing this but unless I migrated to the full U8G2 (graphics) library, it was not overly easy and limited reward.

If there is no RTC battery, this will be needed if the device is fully powered down. You can add an RTC battery to keep the time when powered off if you like via VBAT/GND pins.

Microcontroller Contest

Participated in the
Microcontroller Contest