Saturday, February 11, 2023

Adding MQTT to the Arylic DIY Amp with an ESP32

 

Arylic Up2Stream DIY Amp v4

The Arylic Up2Stream DIY Amp is a feature rich, great sounding amplifier that can be used to add all sorts of "smart" features to an old pair of speakers you have sitting in a closet or the attic.  By default, access to many of these features require that you install a mobile app and use a cloud server. But of course, as always, we want to focus on completely local control.  This article will cover using both local options via some of the features of the amp itself, but more importantly substantially expanding these options by using a connected ESP32 to provide MQTT access to nearly every option.


First, Arylic did not provide the amp, nor any other form of compensation for this article.  The amp was provided by a generous subscriber of my YouTube channel and I purchased all the remaining components myself.  So, all opinions I offer here are completely my own and based on my honest experiences.

General Overview


I actually have two separate YouTube videos on this amp.  The first is more of an overview of the features and potential interfaces to be used.  For full details on the amp and it features and some basic speaker testing, please see this video as I'm only going to hit a few highlights here.  The primary purpose of this particular article is on how to extend local control and not really a review of the amp itself.

Click to enlarge

The amp has a multitude of audio input options, including Bluetooth, WiFi, line-in via microUSB, USBDAC, optical, full size USB-A for a thumb drive or external USB device, DLNA and some streaming services (but don't look for Amazon or YouTube or Sirius... these aren't currently supported.. but you can stream over Bluetooth or USB line-in for these services).  The amp supports speakers from 4Ω to 8Ω speakers at up to 50W per channel.

But it's the other interfaces of the board that are of interest for this article... specifically the RX/TX pins, ADC_KEY, GPIO1 and GPIO2 and a few more that we are going to take advantage of to extend the local capabilities.

Why?


That might be the first question you asked!  And while it is a legitimate one, I'll try to answer at least the "why" for me.  The first step in the instructions for the amp says to go download and install an app on your phone.  This app is going to need access to local files, GPS and more (at least on Android).  But if you dig a little bit, you can find that it has both an HTTP API and a UART interface, where nearly every feature can be accessed locally. So, my goal was to build and configure the amp without ever installing the mobile app (I still have not installed it!).

And of course, we want the amp to be integrated into Home Assistant so we can use the media features there, and in our automations.  Now, to be fair, since this amp acts as a DLNA media renderer, as soon as it joins your network* Home Assistant will detect it and you can integrate it as a media player... both without the app and without any of the steps I'm taking in this article.  But a lot of the amp features still aren't available within Home Assistant's media player integration.  We're going to resolve that by creating an MQTT-to-UART interface via an ESP32 connected to (and powered by) the amp.

*The one thing this app and build cannot do is the initial onboarding of the amp onto your wifi network.  But this can still be done without installing the mobile app via a browser and some simply HTTP commands.  I summarize how to do this towards the end of this article and in the Github wiki.  However, if you are always going to have the amp connected to your network via Ethernet cable, then wifi onboarding is entirely optional. 

Caveats and Other Notes


One final section before we get into the wiring and details.  The code I have written and am providing in my Github repo is specifically for the following hardware/firmware versions:

Hardware:  Arylic Up2Stream 2.0 - Board version v4
Firmware: 36-30cb0ae0-6  (from UART as version-git commit build-api)

Other versions, newer or older, have not been tested and may or may not work with certain MQTT/UART commands.  In fact, the latest documentation I could find for UART was v5, and my v6 version has additional commands and others were different.  Unfortunately, I won't be able to test and make changes for earlier or later versions.  However, my code is freely available via Github, so if you can find the API changes, updating the code to change the UART calls should be pretty trivial.  For these reasons, I won't be accepting any change or feature requests for the code I am freely providing.  Consider it as a starting point for your own future versions if necessary.

Next, pretty much everything I am going to cover is optional... you can add as many features as you want, and omit those you don't want or need.  The only real requirements are as follows:

A power supply.  The board does not come with a power supply.  The specs call for 12-24V, but if you want full power out of the board, you will need 24V and I recommend at least 5A or more.

The ESP32 is needed for MQTT, the OLED display and to use your own IR remote.  If you don't want MQTT, a display or a remote, you can omit the ESP32 altogether.  Note that you can also extend the onboard IR receiver if you are using an Arylic remote or other compatible programmable remote, you can do so without the ESP32.  Both methods of remote control will be covered below.

All the other items (volume knob, push buttons, external LED, extended IR) are fed directly from ports on the amp.  You can add or omit these individually and they can be done with or without the ESP32/MQTT.

And as with all electronics projects, use caution and assure power is disconnected from all devices when wiring and making connections.  NoteThe voltage pins on the amp (e.g. 3.3V and 5V) remain energized any time the amp is plugged into power, either via the power supply or an external USB port, such as a PC.  Be sure to unplug all power sources and do not assume that everything is powered down when the amp is in standby mode and the LED is off.

OK... let's get into it... starting with all the parts I used in my build.  Mix and match for your own build.  To see the video version of this build, please see this YouTube video.

Parts List


As mentioned immediately above, you may mix and match parts depending on what you do or don't want to add to your amp.  This list is the parts I used for my build as described here and shown in the related YouTube video.

QTY

Item or Part

Notes

1

Arylic Up2Stream Amp v4

Required (obviously!)

1

24V 6A DC Power Supply

Required – not included with amp

1

ESP32 Mini

Other ESP32 may work, but not tested

1

Common Anode RGB LED

To extend onboard LED indicator

1-11

Normally Open Push Buttons

For local button control

1

Rotary Encoder Module

For local volume control (can substitute buttons.

1

JST Connector Kit 2.0 mm

Need to connect amp header to other components

1

OLED 128x64 SSD1306 Display

Local display

1

Pk. Various Resistors

Need for both buttons and LED

1

100 nF Ceramic Capacitor

Needed for buttons

1

IR Remote Receiver TL1838

For extending/adding your own remote

1

IR Remote

If adding your own – just an example

1

Dupont Jumper Kit

For power from amp to ESP32

1

ElectroCookie Solderable Proto board

For final soldered version

1+

Breadboards/Dupont jumpers

For bench testing/design

1

5V fan

For cooling, amp can get a bit warm

1

1000 µF Electrolytic Capacitor

 

 

 

 

 

 

 

1

Pair speakers 4Ω – 8Ω

 

 

Miscellaneous wires and jumpers

 

1

Enclosure

Design your own: wood, 3D printed, etc.

 

 

 

 

 

 

Some of these links may be Amazon affiliate links.  Use of these links will not affect your pricing, but this blog may earn a small commission if you make a purchase.  Use of these Amazon links is one the best ways to show your support for the blog... at absolutely no cost to you!

Connections and Options


From here on out, I'll cover each of the individual component connections and options.  Again, unless otherwise noted, each of these are independent and can be installed or omitted without impacting the others.  But as a reference, here are a couple overall wiring diagrams if you want to connect every option I list.  Each of these connections will be broken down in more detail below.

Click to enlarge


Local Push Buttons - Click to enlarge

Rotary Encoder/Volume Wiring (optional ESP32 switch)


A note on ground connections: Everything being connected to the amp needs a ground connection.  These should all be tied to a common ground.  If using the ESP32 and ElectroCookie board, the easiest way to do this is to bring a ground connection from the 5V/GND connection on the amp to a ground rail on the ElectroCookie board and feed all other necessary ground connections from that rail.  If not using the ESP32/ElectroCookie, then tie all your ground connections together via wire nut, solder, Wago, etc.

Sharing 3.3V and 5V connections:  Everything that will optionally be connected to the amp is going to need either 3.3V or 5V power.  While there are a couple of options for 3.3V, there is only one 5V connection readily available on the amp.  If you are going to be using an ElectroCookie board, then the best option is to create a 5V power rail on one side and a 3.3V rail on the other side:

Click to enlarge

By creating a 5V and 3.3V power rail with a common ground on both sides, you can now power any components requiring 3.3V from one side of this board and anything requiring 5V on the from the other side (including the ESP32 if you are using one).  The ground, which is common and can be created by running a ground from the amp to both sides, or by running a single ground and joining the two sides with the small jumper at the bottom of the board (you don't have to do both... one or the other will suffice), so you can get any common ground connections needed from either side of the board.  Even if you don't plan on using the ESP32 and ElectroCookie board, you may want to create some sort of 5V and 3.3V power rails with a common ground using terminal blocks, Wagos or some other method if you are planning on implementing more than one or two of the following features.


Creating connectors for the amp pin headers

Most of the connections on the amp are JST-style connections with 2.0 mm pin spacing.  This means that the pins are too close together to use normal Dupont jumpers.  And Arylic doesn't currently sell any cables made for their amps, so the best bet is to make your own.  While you can buy premade cables with a set number of pins and wire color, I'd recommend picking up a pretty cheap kit that allows you to make your own cables, with the number of pins and wire colors you prefer.


The kit like I show above (and link to in the parts list) allows you to create anything from a 2 to 10 pin connector, which is more than we will need for the amp project.  And the leads simply click into the JST connector... no soldering or crimping needed!



This also allowed me to cut the male end off of a standard Dupont jumper and solder to the pre-tinned ends of the leads, meaning I could test and prototype on a standard breadboard.  When ready to make the final soldered version, I'd just cut the Dupont jumper back off and wire the JST connector leads straight to the ElectroCookie board.

While all the headers on the amp are 2.0 mm spacing, there is one exception... the 5V and GND power that I will be connecting to the ESP32 for it's power uses standard 2.54 mm pin spacing.  So normal Dupont connectors can be used on that connection for testing.


Adding a Local Volume Knob

This might be one of the most common additions, depending where you place your finished amp, so I'll cover that first.  It is also one of the easiest to accomplish and will work all by itself, without any of the other modifications.

Encoder Pins - click to enlarge

You'll need to create or purchase a 4-pin JST connector with 2.0 mm pin spacing (see the section immediately above on creating connectors for the amp).  And if you are going to be testing on a breadboard, you'll want to add Dupont connectors, again as described above.  If building your own, you can use any colors you like, but just note which colors are connected to which pin... particularly the 3.3V and ground pins.  Reversing these would be a bad thing!

Rotary Encoder Wiring - click to enlarge


Connect GPIO2 from the amp to the data (DT) pin on the encoder.  GPIO1 connects to clock (CLK), ground to ground (GND) and 3.3V to V+.  Note that your encoder may say it is designed for 5V, but mine works just fine with 3.3V.

The switch pin (SW), if your encoder has one, isn't used in this step for volume control, but we will make use of this later with the ESP32 to control what is shown on the OLED display.  The SW is basically a switch that you activate by pushing in or clicking the volume knob.

That's all you need for volume control of the amp!  If you have setup the amp and speakers connected, you should be able to power on the amp and immediately control the volume.  If the knob appears to work backward (e.g. volume goes down instead of up when rotating the knob clockwise, just reverse the DT and CLK pins.

Pin Header "18"

Everything else that we are going to connect and use are all fed off of a single 13 pin header.  And this creates a bit of a challenge and you'll need to make some decisions about which features you want to implement.


The issue is that there are a total of 13 pins.  I could not find a 2.0 mm JST connector that had 13 pins in a single row... and my kit only had connectors for a maximum of 10 pins.  But not a huge issue.  You can use more than one JST connector, but because of the size of the JST connectors, using more than one means that at least one pin has to be skipped for the two side-by-side connectors to fit.

There are already a few pins that won't be used.  First is the LED_WHITE.  This is meant for RGBW, and since the LED I will be using (and the one built into the amp) is just RGB, we don't need the white pin.  And the rightmost 2 pins, the IIC pins, are reserved for the LCD display that Arylic sells.  I could not get these pins to work with my own OLED display, but I'm going to be driving that from the ESP32 anyway, as it gives me more flexibility.  I also decided not to use the RESET pin.  I don't want to take the risk of inadvertently resetting the amp by pushing or bumping the wrong button!  If I really need or want to reset the amp, I can do that via MQTT (or the HTTP API).


By skipping the RESET pin, it now allows me to create two connectors... a four-pin for 3V3 through TX, and a six-pin for LED_GREEN through IR.


You can adjust the pins and headers for your particular need.  If there is a pin within a header that you don't need or want, you can just skip adding the wire to the header (like I did for LED_WHITE above).  For example, if you want the RESET pin, you could create a six-pin header for 3V3 through LED_GREEN, skip LED_WHITE and then create a 4-pin header for LED_BLUE through IR.  You get the idea!

Adding Local Pushbuttons

For this section, we will be adding local pushbuttons to the amp to control certain features.  You can add up to 11 different buttons.  The documentation shows the button options as:


Note that the function of the button is designated just by selecting the value of the connected resistor.  For my example, I'll be showing the mode (source select), play/pause, volume up, volume down... and a 12th undocumented option I discovered accidently... a standby/power button.  Now, if you are implementing the rotary knob for volume control, you probably don't also need volume push buttons.  So you can make them something else by just changing the resistor value... or simply omit them.

Here are the header pins needed for this addition:


You will also need different value resistors based on which buttons you want to implement and a 100nF / 0.1uF ceramic capacitor.

Click to enlarge

Here is a photo of my buttons connected on a breadboard.  I decided to show it here because it is a bit easier to see and describe than after the buttons are soldered and placed in an enclosure for the final version.

For whatever buttons you select, one leg of the normally-open button should be connected to a common ground.  I talked about common grounds above, but somewhere in your project, you should tie all the grounds that you need together... this can be on a power rail of the breadboard/ElectroCookie, tied together via wire nut, etc.

The other leg of the button connects through the appropriate resistor to a common line (shown as the + rail of the breadboard in the photo) that connects to the wire from the amp's ADC_KEY pin.  Add a 100nF across the ground and common (+) line.

Now, if you look at the "official" diagram, it shows a 3.3V line with a 10K resistor:


But as I discovered, the ADC_KEY is already at 3.3V and has an internal 10KΩ pull-up resistor, so you don't need to add these. The only connections between the amp and your buttons are the ADC_KEY and a common ground.

Now, a note about that "hidden" 12th feature.  Note in the above image that the white button shows a 10.2kΩ resistor, but that isn't shown in the official diagram as an option.  Originally, I meant to use this as a 'mute' button, which requires a 12kΩ resistor.  It just so happens that I didn't have a 12kΩ resistor on hand, so I thought I'd try a 10kΩ and 2.2kΩ resistor in series, thinking that might be close enough.  But I inadvertently used a 220Ω resistor with the 10kΩ and to my surprise, this button functioned to put the amp into standby/power down mode... and pressing again would 'wake' the amp.  I liked this feature so much I decided to keep it, and would eventually use it to also power down the OLED display when the amp goes into standby mode (well, technically I just blank the display via a Home Assistant automation... power really isn't cut).  I don't know if other resistor values would work, as I didn't test them.  But since I will be using the rotary encoder for my volume control, I don't need the volume buttons.  I'll likely replace one as a mute button when I get a 12kΩ resistor and probably just remove the other one.

Remember that when the amp is in standby mode, the 3.3V and 5V pins on the board remain ON. Unplug from power supply and any externally powered USB sources (such as a PC) when working with any of the pins.

If you plan on placing your buttons at a significant distance from the amp, note that voltage drop over a longer wire run could require different resistor values since the buttons work by sending different voltages to the analog ADC pin.

Adding buttons can be done with, or without any of the other additions listed.  You can just add buttons and nothing else if that's what you prefer.

Extending the LED

Another set of pins on the "18" header allows you to extend the LED out to your own common anode RGB LED.  The LED indicates the current active mode or source for the amp, such as blue for Bluetooth, green for line-in, red for USB, white for wifi, etc.  If you are either going to mount your amplifier out of sight or maybe place it in an enclosure and still want the LED indicator light, then this section is for you!

The following pins are used to extend the LED:


You will need a common anode RGB LED and three 1kΩ resistors.  The wiring of this is pretty straightforward.

Click to enlarge


If you haven't used common anode LEDs before, there will be one long leg.  That where the 3.3V gets connected.  The shorter leg on one side is the red pin, and the shorter legs on the other side are the green and blue pins. A 1kΩ resistor is added to the RGB lines. That's all there is to this addition.  The external LED will now match the amp's onboard LED.  If the external LED shows a different color, assure you haven't mixed up the R, G and B pins!

You may extend the LED without any of the other modifications, or it can be in addition to any of the others.

Extending the IR Remote

For this, you will need to be using the 'official' Arylic remote, which can be found on their web site, or a programmable remote that has been programmed with the expected codes.  The links at the end of this article will have a link to the Arylic site where the remote can be found, along with their documentation on the remote codes.  If you wish to use your own IR remote instead of the one from Arylic, then see the alternate IR remote method that requires an ESP32 in the section that follows.


To extend the IR, we will use the IR pin on the header, along with 3.3V and a ground.  If you are already using the 3.3V for another source, such as the external LED, you can either split that off and feed both the LED and IR receiver or you can use the 5V connection right next door.


Since the IR receiver has an operating voltage of 2.7V - 5.5V, you can power it by either source.  Just note that the 5V header uses 2.54 mm spacing, so you can use normal Dupont cables for this connection.  But if you are going to be adding the ESP32, we'll need these pins to power the ESP32.  See the above section about creating power rails for connecting multiple components.  Just suffice it to say that you can use either a 3.3V or 5V connection for the IR receiver.

Click to enlarge

Just be sure to observe the proper pin wiring on the IR receiver.  "S" indicates the signal or data out line and the (-) represents the ground.  The voltage connection (whether 3.3V or 5V) connects to the center pin.

This addition can be done with or without any of the other components.  However, if you plan on adding the IR receiver for your own remote use to the ESP32 (as described below), you probably do not want to extend the built-in IR receiver as the two different receivers will not be compatible with the same remote.

This completes the extensions and add-ons that I did with just the amp itself.

Extending the Amp even more with an ESP32


To extend the amp's features even further, an ESP32 can be added.  This can give us the ability to control nearly all of the amp's features and options via a Home Assistant (or other MQTT-enabled platform... like NodeRed).  We can also add a small OLED display to give us local feedback about the various state of the amp.

Up until this point in the article, everything could be done without the ESP32.  But for the remainder of the enhancements, the ESP32 is required.

Installing the firmware on the ESP32

Before connecting the ESP32 to the amp, I recommend that you first install the firmware. The very first install requires connecting the ESP32 to a USB port on your computer.  After the first install, any future firmware updates can be completed wirelessly over the air.  The Github wiki has full details on installing the firmware and completing the initial configuration, so I'm not going to cover that here.  In addition, any future upgrades or new features will be detailed in the Github repo, so always check there for the latest changes and updates.

Connecting the ESP32 to the amp

We will need to use two pins on the amp and two pins on the ESP32 to establish communication.  Then we will also power the ESP32 from the 5V pin and ground available on the amp.


Note that all the connections made to the ESP32 (for this, the OLED display and your own IR receiver if you are adding one) will always use the inner row of pins on either side.  These are highlighted in white and represent the original Wemos D1 Mini (ESP8266) pins.  When we get to mounting everything on an ElectroCookie board, the ESP32 will be mounted on a header and the actual wire connections will be to the ElectroCookie.  More on that to follow, but the above just shows the direct connections if not using any sort of board.  Just be sure not to use any outer row pins and not to make any inadvertent connections between the inner and outer rows.  Also note that the above image shows the bottom of the ESP32.  Be sure not to 'flip' the connections to the wrong side when looking at the ESP32 from the top.

The RX and TX connections above is what allows the ESP32 to send commands, and receive data back, from the amp using a serial/UART connection.  This connection is use for both MQTT and for the OLED display.

Adding an OLED Display

You can optionally add a small OLED display to show certain status values of the amp.  This includes things like the currently selected source, volume, treble, bass, connectivity (e.g Internet, wifi)... and for some sources, the current title, artist, album and track number of the song that is playing.  Basically, any data returned by the amp can be displayed.


The firmware is designed for use with a 128 x 64 SSD1306 display.  The use of other displays may be possible, but you may have to modify the firmware libraries and calls to use other displays.  Sorry... but please don't request modification for other displays.  I will be unable to fulfill those requests. The source code is available via Github, so if you want to use a different display, you will need to copy the firmware and make those changes yourself.

There is no direct connection between the display and the amp.  The connection made here is between the display and the ESP32.

Click to enlarge

Note that the working voltage for the OLED display is 3.3V - 5V, so you can also optionally power it from a common 5V line as well as the 3.3V pin from the ESP32.

By default, after connecting the display, it will show the currently selected source (e.g. Bluetooth, Line-In, Optical, etc.) as the default "home screen".  Any changes such as volume, bass, or anything else reported back by the amp as a change will be displayed for approximately 5 seconds before the display defaults back to the home screen.  If you want to be able to change the default home screen, see the next section!  

Using the Rotary Knob Switch with the OLED Display

Remember WAY back earlier in the article when I showed adding that rotary encoder for controlling the volume on the amp?  And recall that there was an unused pin (SW) that could be used as a switch?  Well, we are now going to use that pin/switch to change what is shown as the default screen on the display.


All that needs to be done here is to wire that unused SW pin from the rotary encoder to GPIO19 on the ESP32.  The other pins from the rotary encoder should already be wired to the amp.

Once this connection is made, you can click the knob to change what is shown as the "home screen".  Current options are Source, Volume, Title, Track, Mute and Blank (select the last one if you want the display to be blank except when changes occur and are displayed.  Again, check the Github repo for latest information if these screens or the order changes.


Alternate IR Remote - use any remote

If you wish to use your own remote (and nearly any IR remote can be used), then instead of extending the onboard IR receiver via the pin on the amp, the IR receiver can be connected to a GPIO pin on the ESP32 (I used GPIO18).  The ESP32 will than accept the IR codes you specify from your remote and translate those to UART commands to control the amp.  An example of wiring the IR receiver in this manner is shown in the diagram below.  The Github repo with the code for the ESP32 also describes how to define the codes from your remote and assign those to commands for the amp.

Installing everything on an ElectroCookie Board


So now is the challenging task of trying to take all the working components that are on breadboards: 


and to try to reduce everything down to just the amp and a single ElectroCookie breadboard:


At this point, it's a just a bit of 'MacGyvering' to see what is the best way to fit all the parts together and to optimize wiring lengths.  My goal, if I can make it all fit, is to try to get the amp and this breadboard in an enclosure that is approximately 8" x 5" x 2".  Now, the buttons, rotary/volume knob, LED and display don't have to fit on the ElectroCookie since they will be mounted in the faceplate of the enclosure.  So, this is the "plan" I've come up with:

Click to enlarge


I will be placing pin headers on the ElectroCookie for mounting the ESP32. Since I'll be using the 'inner row' (D1 Mini equivalent) pins on the ESP32, this will give me one row of holes on each side for making connections to the GPIO pins.

The actual wiring for all the individual parts are described above... and of course your version may well be different depending upon which features you opt to implement and those that you choose to omit.  The only things added here are a small 5V fan (actually made for the Raspberry Pi) and a 1000µF capacitor.  The fan will be mounted over the heat sink, as I did find that the amp can get warm when playing at higher volume for extended periods. It will be powered by the 5V rail on the ElecroCookie (which in turn is powered by the amp).  The capacitor is just added to even out the power on the 5V side.

Creating or building an enclosure


The materials and size of the enclosure will be entirely dependent upon the components you opt to implement (or omit), whether you want a wood plastic or metal enclosure, have access to a 3D printer, etc. I'll just show what I decided to build as a source of ideas for creating your own.

I opted to build my base, sides and top out of wood and stain to coordinate with my desk where the amp would live.  Mostly I decided this because I already had the wood and stain and didn't have to buy any materials!  I would design and 3D print the front panel.  But if you have better woodworking skills than me, you could make the front panel out of wood (or even metal).


If first determined the size that I was going to need to comfortably hold the amp and the ElectroCookie board side-by-sideI then sanded, stained and polyurethaned the wood.  I opted not to stand the inside of the base and top... mostly because I'm lazy, but they won't show when finished anyway.


I wanted to line up the back edge of the amp with the back edge of the enclosure, because all the inputs, including main power, are located here and I wanted easy access.  In addition, I wanted the speaker wire set screws to protrude out the back so that speakers could be connected/disconnected without removing the top panel.  The USB port on the ESP32 will also be accessible if needed (but with OTA updates, this probably won't be used).

Click to enlarge

I then installed the offsets for the boards.  This not only keeps the board secure, but will allow me to route wiring underneath as well as over the top of the boards.  I opted to use metal offsets, as I knew I would be removing and reinstalling the boards repeatedly during the wiring stage and I did not want to wear out plastic offsets.


The sides were glued on and secured with a couple of finish nails.  I also designed and 3D printed the front faceplate. That's all the construction needed before mounting and wiring everything together.


I opted to make all my soldered connections on the ElectroCookie board first.  Note the socket for the ESP32 on the left side.  The sockets allow the ESP32 to be easily removed if necessary and also allows access to one row of through-holes on the board for making connections to the ESP32 pins (since the ESP32 mini is wider than a D1 Mini, these through-holes would not be available if the ESP32 was soldered directly to the board).  Also note the small PCB sticking up at the top right corner.  This is the PCB for the IR receiver.  The existing design was not conducive to mounting on the front panel.


So, I simply desoldered the actual receiver, added some extension wire and just mounted the PCB to the ElectroCookie board and made my connections there.  Yeah... I could have ordered a different IR receiver, but I already had about a dozen of these, so I wanted to use what I had on hand.


Click to enlarge

Here is everything installed, connected and powered on for the first time.  While all the connections to the ElectroCookie board are soldered, I opted to make all the connections from the board to other components using custom made Dupont, spade or JST connectors.  I did this should I need to replace or repair and particular external component.  And it's a good thing I did!  Initial testing showed I made a mistake in how I wired up the LED indicator.. and I was getting the wrong color for some sources.  But since I used connectors instead of soldering everything, I simply disconnected everything, unscrewed the ElectroCookie board and lifted it out of the enclosure.  I corrected my wiring mistake (wrong resistor used), then simply replaced the ElectroCookie board and reconnected everything.  


Here is the final assembled (and fully working) version.  I still need to add some labels for the buttons, but from left to right:

  • OLED display that shows any changes made (e.g. volume, source, balance, tone, etc.).  The default display mode can also be selected (or blanked) by clicking the volume rotary knob on the right.
  • Four buttons... source selection, mute, pause/play and standby.
  • LED indicator (over the standby button) shows whether the amp is active (lit) or in standby mode (unlit) and the color also indicates the active source.
  • Rotary volume knob - clicking also changes the default OLED display
  • IR receiver - I'm just using a cheap remote I actually purchased for LED projects, but it currently can control source, volume, treble, base, balance and put the amp in standby mode.  More options are possible, I just haven't added the codes for them.
The small grill on the top is for the fan that is mounted directly over the heat sink.  I'm not thrilled with how this looks, and I would have preferred a smooth top with no openings, but as I mentioned, the amp can get a little warm and I didn't want it to overhead inside of the enclosure.


For now, I've just left the back side open.  This is both to help with airflow and to allow access to all the ports.  I may eventually 3D print a frame to at least cover up  the unfinished edges of the wood, but since this faces the back side of my desk, it really isn't noticeable.  I also need to find something better to do with the wifi and bluetooth antennae.  

But for now, I'm happy with it and have multiple sources of music that can now be played at my desk, with control via the local buttons/knob on the amp, via the remote control or through Home Assistant/MQTT.

Initial WiFi onboarding


As mentioned at the beginning of this article, the one thing you cannot do with this build is onboard the amp to your wifi (this only applies to the amp, not the ESP32).  Now, the easy way is to download the app onto your phone and use it to join the amp to your wifi.  But as I also mentioned, my goal was to complete this entire project without installing yet another device-specific app on my phone.  Not to fear... the amp can be onboarded to your wifi with just a web browser and a few simple commands.  If you only plan on using the amp with a wired Ethernet connection, then wifi onboarding is entirely optional.

I cover the step-by-step process of doing this in my first amp overview video, but I'll summarize the steps and commands here (this information is also repeated in the Github repo).

Preliminary Steps

First, you will need to temporarily connect the amp to your network with an Ethernet cable (we can't send commands to it if isn't on the network!).  Once that is done, you will need to use your router or other utility to get the IP address that is assigned to the amp.

Next, the HTTP command to onboard to your wifi requires that your wifi name (SSID) and password be entered in hex.  Don't worry, there are a lot of online resources to help with this.  I used this one and it worked fine, but you can search for 'text to hex converter' and find another one if you wish:


Simply enter your wifi SSID into the input text box and click convert.  Then copy the output to Notepad or other text editor.  Repeat this process for your wifi password and copy that to your temporary document as well.  Both the SSID and password are case-sensitive!  Be sure you have included any capitalization for your SSID and password, otherwise the process will not work because the hex values will be incorrect.

At this point, you should have three pieces of information.  The amp's Ethernet-connected IP address, and hex values for both your wifi SSID and password:


Connecting to WiFi:

Now open up a web browser and enter the following command (all on one line, no spaces):

http://amp_ip_address/httpapi.asp?command=wlanConnectApEx:ssid=hex_ssid:ch=num_ch:auth=text_auth:encry=text_encry:pwd=hex_pwd:chext=num_ext

You will need to replace the text highlighted in red with your specific network details, as follows:

amp_ip_address: The current ethernet IP address (192.168.1.208 in the example).

hex_ssid: The hexed value of your wifi SSID

num_ch: The channel number to use for your wifi (1-12). Only supports 2.4 GHz.

text_auth: Connection authorization type (OPEN or WPA2PSK)

text_encry: Encryption used (AES or NONE)

hex_pwd: The hexed value of the wifi password

num_ext: 0 or 1

Now, if you do not know the values for channel, authentication, encryption and/or chext, it's not a problem!  Just enter the following command into your browser:

http://amp_ip_address/httpapi.asp?command=wlanGetApListEx

It will return a list of all wireless networks visible to the amp:

Click to enlarge

Simply locate the hexed SSID value that matches yours and it will tell you what the values are for channel, auth, encry and extch for that particular wifi network!  So, using the values from above, a complete command for joining the example wifi network would look like this (again, entered as one long command with no spaces):

http://192.168.1.208/httpapi.asp?command=wlanConnectApEx:ssid=4d795769666953534944:ch=1:auth=WPA2PSK:encry=AES:pwd=53656372657450617373776f7264:chext=0

If the command is accepted, then an 'OK' will be returned to the browser.  But this only means the command was accepted, but not that the amp necessarily successfully joined your wifi.  But there's another command for that!

Checking wifi connection status

Of course, you can check your router and see if a new device connected, but if it isn't there or you can't find it, that's not very helpful.  But you can issue this command in your browser and the amp will return its wifi connection status:

http://amp_ip_address/httpapi.asp?command=wlanGetConnectState

This command will return one of four values:
  • PROCESS: The amp is still in the process of connecting.  Wait a few minutes and try refreshing the page
  • FAILPAIR: Either the SSID or password was incorrect.  Be sure you are using the hexed values and have included proper capiltalization.
  • FAIL: The connection failed for some other reason.  Check your command carefully and assure you haven't made any typos, included any spaces or entered a wrong value.
  • OK:  The wifi connection was successful.
Once you receive an "OK", then the amp has joined your wifi.  You can disconnect your Ethernet cable if desired at this point.  You should also use your router or other utility to get the wireless IP address of the amp, as it will be different than the wired ethernet IP address.  The IP address isn't used directly by the amp or this build, but you can use it to bring up the local web application provided by the amp if desired.  I won't be covering the local web app in this article, but it is pretty self-explanatory and info can be found online if you want to know more.

Home Assistant and using MQTT


As mentioned at the start of this article, as soon as the amp is successfully connected to your network (via either Ethernet or wifi), Home Assistant will automatically discover the amp as an DLNA Media Renderer device:


And once you add it via the configure button, and optionally give it a more meaningful name, Home Assistant will create a new media player.  With that, you can do all the other normal stuff or automations that you'd do with any other media player.  This includes using it as a text-to-voice device, so that you can have Home Assistant make notifications or other announcements via the amp:


In addition, depending on the source of the audio, a number of useful attributes are also automatically reported and available for your use:

Data reported when using DLNA

All this was just by adding the amp to your network... no mobile app and none of the steps I just covered!  But while the normal Home Assistant media player gives you control over basic features, like volume, play, pause, etc., it doesn't provide the ability to adjust a lot of the other properties of the amp (like treble, bass, pregain, voice prompts, source changing, etc.).  That's where MQTT is going to come to the rescue!

Using the ESP32 as a "translator", we can use MQTT to send commands directly to the amp.. and get additional data back from the amp that will be sent to MQTT.  This would allow you to not only create custom dashboards for the amp, but to use any of the commands or data attributes in automations.

And while this focuses on Home Assistant, the system should be compatible with any other system that can send and receive MQTT data, such as NodeRed.

While the setup and configuration of an MQTT broker is beyond the scope of this article, Home Assistant has an MQTT add-on integration or your can set up your own broker and you can find plenty of good information online on using MQTT.

And while the full (and most current) information on the MQTT topics available will always be available in the Github repo, this is a simplified list of topics that allow you to control or return data from the amp at the time of this article:


With these MQTT commands, Home Assistant dashboards and automations can be created utilizing nearly all the features of the amp.

Sample Home Assistant Dashboard - click to enlarge


Future considerations


One feature of the amp that I haven't touched on, either here or in the YouTube videos, is the ability to sync multiple amp devices together to create a whole-home audio system.  Not only are there additional commands that can be used with synced systems, it might be possible to create speaker groups in Home Assistant to send the same music source to more than one amp/speaker set simultaneously.  I haven't included any of this yet, simply because I currently do not have the ability to test it.  That may change in the future, and if so, I will attempt to update both this blog but you will also be able to find that information in the Github repository.

I would like to sincerely thank Rich Lessard (aka EX_BELSERVICEMAN) not only for providing the amp, but for his contributions to this article.  

Links


Arylic remote control - Official Arylic Site
Arylic remote codes - official link broken at the time of writing
YouTube video 1 - Initial overview and wifi onboarding
YouTube video 2 - The build covered in this article
Github Repository - ESP32 code
Text to Hex Online Converter - for initial wifi onboarding




2 comments:

  1. thanks for such an awesome and highly detailed article. after watching your video about 7 times, im glad i finally found these diagrams! any insight on how the "phono" pins work? would love to add a turntable!

    ReplyDelete
    Replies
    1. You are welcome. I love what I've been able to do with the amp and it gets used daily. I have an update on it that adds SiriusXM streaming. But regarding the phono pins, I'll have to go back and check the official documentation, but I believe they are currently listed as "for future use". They were previously labeled as mic inputs (I think) in previous versions. So it is possible that support for turntables may be in the plans, but I'm not sure that they are usable right now with the current firmware, but let me know if you find out differently.

      Delete

To help eliminate spam and to keep all conversations civil, submitted comments are moderated. Therefore your post may not show up immediately. Please be patient as most reviews are completed within a few hours.