Sunday, 21 March 2021

The ESP32 Analog (Analogue!) Clock

As promised, here's the new stupid analogue clock. 

It consists of two 270 degree analogue meters, thoughtfully calibrated 0-70V and 0-300A, kindly donated by Andy from North Hill Audio in Malvern, and an ESP32 with it's nice in-built RTC, wifi etc etc...

The idea is almost identical to the previously stupid analogue clock, found here. This time, we will use the ESP32's built in wifi to connect to the internet, and pick up the time from an NTP server, and set the ESP32's inbuilt RTC. There's an example in the ESP32's arduino library to do this, and utilises the standard time.h library to maintain the clock. I'll set a random time to refresh the RTC randomly between 12 and 24 hours, I don't want to keep bothering the NTP server. I can then output hours and minutes using PWM to drive the meter movements. 

First off we're going to need to do something about the scaling on our meter movements, as I can't easily drive 0-70 volts, nor 0-300 amps! 

Examining the meters shows the 0-300A meter is actually a 75mV full scale deflection meter (FSD), designed to be used with an external shunt of 0.025 ohms (or does it ... read on), this is good, as we can easily drive that.

The 0-70 volt meter reads directly. Disassembling it shows it has a "multiplier" resistor (actually 3 resistors in series, one adjustable) with the earthy end of the movement. 

Shorting out the multiplier gives us a meter with about 200mV FSD, perfect. The meters are dated 1972.
Both meters pull a fair amount of current ... 

A schematic is conjured up. There's not much too it.

As ESP32 has no native support for analogWrite, but we can use the ledc function. I don't care it's not driving an LED, and neither should you 😉. Each output pin, feeds the base of BC547 NPN transistor which is driving the meter. There's a 1K pot in the emitter to allow FSD for the meters to be set accurately. The venerable 7805 regulator supplies our +5V to the ESP32 and meters. 

There's an output on IO18 for a PM indicator LED, and an output on IO15, which I'm going to use to drive a relay, to give the clock a ticking sound ...

The script has some differences to the original ATMEGA328P script, as there's no 409Hz interrupt timing required, as the RTC is doing that job for us, and the code to receive the 433MHz timing signal has now gone, as that's now taken over by NTP. There's a section to extract the individual hours, minutes and seconds from the RTC, and load them into separate variables that we can manipulate. There's also no "smooth" function, as both hours and minutes are smooth, and there's no 400Hz interrupt timer to give us 1/409th of a second to drive a "smooth" seconds meter, and there isn't one anyway! The clock is also permanently set to 12 hour mode, with a PM indicator on pin XX. I've retained the fabulous "IsBST" routine. It just works. If you're outside of the UK, you'll need to modify the code to suit your timezone.

The software can be found on my github page at

The electronics is mounted up on perf board.

So that's the electronics and software sorted. 

I ordered a wooden craft box from eBay to mount it all in.

A couple of stains and finishing oil are tried out on the inside... 

.. and while they dry, I use libre cad to make a cutting plan for the front. 

The template is printed out , and taped to the box.

The two holes are cut out for the meters

The box given many coats of finishing oil to bring out the grain, and give it some shine.

I had to get a bit creative when  mounting the meters, as I didn't have the original mounting hardware..

I added some redundant 19" rack handles as a stand. I'm pleased with the results.

There, and goodnight, it's 250 amps past 51 volts!

I notice there's a kickstarter, where you can now buy something very similar. 

Pyers read this last night, and has pointed out the value of the shunt is wrong. I simply glanced at the back of the 300A meter, and mis-read it... I had wrongly assumed 0.025ohms was the value of the shunt... But 75mV across 0.025 ohms only gives us 3A... not 300.
Reading the label correctly, it simply states "Use with external shunt" , and the 0.025ohms is "lead resistance". The shunt should be 0.00025 ohms for a full scale deflection of 300A. 

Thursday, 25 February 2021

Moving on up from ATMEGA328 & Arduino. The ESP32 "Mexican wave" light chaser.

I've recently been looking at other microcontroller options for some upcoming projects. Arduino and the ATMEGA328 have been wonderful devices, but it's getting on a bit now. 

I've played with the very powerful Teensy range of controllers a little bit, and they're great, just, well, a bit pricey .... The audio functions they perform are, however, wonderful. Probably great "bang for the buck" ... I just really don't need that much bang!

A while ago, I visited the USA, and one guy there gave me a "Blue Pill" , a fast, 32 bit microcontroller, with plenty of IO. Sadly not much in the way of RAM, and support for libraries seems a bit lacking. It is, however, stupid cheap.

I seen & read a bit on the ESP32. Looks good, and is cheaply priced. I've bought a couple. The one thing that (sort of) lets it down is the absence of a simple analogWrite function to control it's myriad of PWM outputs. It does have 2 proper DAC's though. Thankfully there's a function called ledc, which is largely similar, but operates at a higher (5KHz) PWM frequency than Arduino uno (nano etc) 490Hz, which makes filtration a bit easier. It's got wifi, bluetooth, a magnetic hall sensor (why??), and a built in RTC, and probably much more!

A while back I built the Arduino analogue clock , and always intended  to incorporate two large 270 degree meters. I never got round to it. My intention is to modify the code to use the in-built RTC, synchronised by NTP via Wifi, and use that to drive the meters. Seems easy enough, and will be a good project to cut my teeth on. 

In the meantime, I've been playing with ledc to make a mexican-wave style LED chaser, to get the hang of things a bit. It's based on adding more channels to the example supplied in the Arduino IDE for ESP32.

Hang some LED's off the pins as listed in the code, with appropriate current limiting resistors (220Ohm), and enjoy.

  LEDC Software Mexican wave

// use first 8 channels of 16 channels
#define LEDC_CHANNEL_0     0
#define LEDC_CHANNEL_1     1
#define LEDC_CHANNEL_2     2
#define LEDC_CHANNEL_3     3
#define LEDC_CHANNEL_4     4
#define LEDC_CHANNEL_5     5
#define LEDC_CHANNEL_6     6
#define LEDC_CHANNEL_7     7

// use 13 bit precission for LEDC timer
#define LEDC_TIMER_13_BIT  13

// use 5000 Hz as a LEDC base frequency
#define LEDC_BASE_FREQ     5000

// fade LED PIN (replace with LED_BUILTIN constant for built-in LED)
#define LED_PIN_0      23
#define LED_PIN_1      22
#define LED_PIN_2      21
#define LED_PIN_3      19
#define LED_PIN_4      18
#define LED_PIN_5      17
#define LED_PIN_6      16
#define LED_PIN_7      15

int brightness [] = {0, 32, 64, 96, 128, 160, 192, 244, 255}; // how bright the LED is

int fadeAmount[] = {1,1,1,1,1,1,1,1}; // how many points to fade the LED by

// Arduino like analogWrite
// value has to be between 0 and valueMax
void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
  // calculate duty, 8191 from 2 ^ 13 - 1
  uint32_t duty = (8191 / valueMax) * min(value, valueMax);

  // write duty to LEDC
  ledcWrite(channel, duty);

void setup() {
  // Setup timer and attach timer to a led pin
  ledcAttachPin(LED_PIN_0, LEDC_CHANNEL_0);
  ledcAttachPin(LED_PIN_1, LEDC_CHANNEL_1);
  ledcAttachPin(LED_PIN_2, LEDC_CHANNEL_2);
  ledcAttachPin(LED_PIN_3, LEDC_CHANNEL_3);
  ledcAttachPin(LED_PIN_4, LEDC_CHANNEL_4);
  ledcAttachPin(LED_PIN_5, LEDC_CHANNEL_5);
  ledcAttachPin(LED_PIN_6, LEDC_CHANNEL_6);
  ledcAttachPin(LED_PIN_7, LEDC_CHANNEL_7);

void loop() {

  for (int i = 0; i <= 7; i++) {
    ledcAnalogWrite(i, brightness[i]); // set the brightness of each led in the array
    brightness[i] = brightness[i] + fadeAmount[i]; // increase the brightness of each led
    if (brightness[i] <= 0 || brightness[i] >= 255) { // until it gets to 255, then reverse the direction of fade, until it gets to 0, and reverse again
      fadeAmount[i] = -fadeAmount [i];
    delay (1);

Tuesday, 26 January 2021

What is this?? The Amazon 2TB External SSD.

"You buy cheap, you buy twice"

An SSD was required for a Raspberry Pi project.  One was ordered from Amazon, 2TB. It was stupid cheap. 

It turns up...

It's plugged into the Pi, ready to clone the OS onto it... nope, not having it. Nothing detected... weird.

It's plugged in to a Windows PC... bing... a 2TB drive... there's a file on it, it's a word document. mustsee.doc. It's written in't fluent Yorkshire... 

What foolery is this??

Rat duly smelt. 

Let's investigate... 

Running Hard Disk Sentinel gives us some info... It's apparently a "Samsung HM201HI" ... except for a quick Google shows no such thing exists. Or is it 2 Samsung HM201HI's? It's also got some duff sectors on it. 

OK, let's run H2testw on it and see if it's really as big as it makes out... 

We may be here some time... 
As it turns out, we didn't have to wait as log as we thought... 
It had fallen over after 320 GB... 

So I sprung it apart ...
... and (no surprise) , it's a 320GB mechanical drive. 
It is, of course, a scam... 

Saturday, 23 January 2021

Arduino Audio Compressor.

As part of an upcoming project, I need to compress some audio a bit. 

Now there's plenty of analogue compressor schematics on the web, but a lot require obsolete FETs or odd ball lamps, shining on an LDR (the optical compressor). I fancied a different approach.

Here's the plan, audio comes in to the "top" of a digital pot (also known as an R-DAC), the pot is controlled by the arduino. The wiper of the pot is connected to out audio output. That way, we can use the arduino to effectively wind our pot up and down to control the level of the audio. 

The wiper of the pot also feeds a rectifier, and the resultant level sampled by one of the Arduino's analogue ports, and that value is processed to provide the control signal to the pot.

A schematic is scratched out...

Audio comes in on J1, C3 is a DC blocking cap as the audio is biassed to half of the 5v supply by R1 & R2. The audio then feed the top of our digital pot, U2, on pin 5. Pin 7 of our pot is the bottom of our pot, and is connected to GND. Audio emerges from the wiper of out pot on pin 6, there's another coupling cap, C9, and the audio is then biassed to half our 12V rail by R14 & R16. It feeds a buffer amp, U1B and is output via R15 & C11, and is referenced to gnd by R17.The audio also feed U1A, which has a gain of about 14, and boosts the audio up to a sensible 10 volts pk-pk or so. This is coupled via C8 to our rectifier (D1 and a small filter cap of 10nF. This then drives the ADC of the arduino on pin A0. I haven't really shown the power supply, but it's just a single 12V supply, the 5V being derived from the arduino's on board regulator.

The software, can be found on my github page, as usual

There are some variables to play with, being Target, Avg, Attack and Decay. Play around with the values and get a feel for it.

One other thing I played with, was feeding U1A from the incoming audio, rather than the devices own output. It was possible to get the software to lose control and end up with no audio coming out, but it could be tamed.. I think this type is called a "feed forward" compressor, and again, worth some experimentation. 

Here it is lashed on a bit of breadboard. It performed surprisingly well, and quiet too.

Thursday, 21 January 2021

Linn Keltik repairs

As well as sending me a lingo (see here), John sent down a Klout amplifier... It had the same issues as this one, only was completely dead. A re-cap fixed it. 

It was also fitted with the Keltik Bass extension module. This is simply a low pass filter to allow the amplifier to drive a woofer as part of an active cross-over system. 

It's really nicely made, and was given a re-cap to ensure reliable service.

The Keltik module is mounted on a single metal spacer which bolts up to one of the four transistor heat spreader cap screws. Remove the spacer before attempting to remove the cap screw, or the whole thing locks up. The other end is supported in a groove on the speaker terminal output insulator.

There's a single connector to remove on the board.

We'll need to remove that screening can, which is simply desoldered. 

Same the other side...

.. to gain access to those hidden electrolytics.

Look at all those precision poly caps... nice!

You'll need 2 off 220uF 16V , 8 off 22uF 50V, 2 off 2.2uF 50V and 1 off 10uF 63V . 

They needed replacement, some were physically leaking, and smelt horrible during desoldering! 

Another saved from landfill! 

Saturday, 16 January 2021

Linn Lingo repair - won't change speed.

John from the cold north rang...

"Got a Lingo here, it's been serviced by someone here, but it's now stuck in 33 RPM. Care to take a look?"

Yeah - why not?

It's the first version of the lingo.

Off with the lid, and I can see some work's already been done. It's been recapped. The workmanship is good... or is it?

The original repairer was obviously proud of his work, as there's a signed sticker inside the unit. I've blurred this out to prevent embarrassment. 

Now the lingo is similar to other power supplies of this era from linn, they suffer with capacitor failure. Now you could upgrade your supply to the latest and greatest (don't forget kids, Linn ownership is all about upgrades, right?), or get it repaired. This has all new capacitors, of quality brand, so it should be good. It was only done in August last year (it's now January). Apparently 45 RPM hasn't worked since they had it back... 

So it's just stuck in 33. Pushing and holding the switch just causes the Red led to go from bright to dim repeatedly, and never get to 45. Great ... it's usually either U7 or U8, best to change both to avoid issues. It's a 74LS74. The best way to get them out is to cut off the legs, and remove each leg separately to avoid damaging the (as usual) fragile double-sided print. I get two new IC's and socket them. Powering back up, and switch to 45 , it briefly lights the green 45 RPM light, before dropping back to the original fault. Damn. 

Thankfully having socketed the IC's, I can remove them without damaging them, and test them in the sometimes useful DiagnoSYS IC tester (thanks Norm).

One is duff... double damn... was it a duff one out of the packet? I replace it, and promptly blow another. Triple damn. What's going on?

There's a bit of feedback from the motor drive amplifier on the lingo, so it knows when to turn the voltage down to the motor. This feeds U4, a 74LS221. It's removed , and a socket fitted. A new chip changes the fault slightly. Sadly the DiagnoSYS tester can't do 74LS221's..  Checking U7 again shows it hasn't failed again, so that's something. Out with the scope. There should be a ~5 second timing constant. Checking around, I find it. It's on pin 6 of U4... and is formed by C7 (220uF) and and R33 (56K) (those of you who have just got the calculator out, will inform me that that's 12 seconds, and yes, you're right, but it triggers the IC as it moves over the trigger threshold, of around half of the supply). The cap is obviously brand new, but is removed anyway and tested. It tests fine. But it's only 22uF. C7 and C9 have been reversed!! (now you know why I blurred the label!).

It's reassembled again, and this time works fine! 

"The person that never made a mistake, never made anything" 


Saturday, 2 January 2021

Heathkit Stereo control unit USC-1

Happy New Year! 

Having sorted the MA-12's, time to move onto to the USC-1 preamp...

It's designed to be mounted into the front of a cabinet of some description. 

They keen-eyed amongst you may notice the absence of mains transformer. The power supply is derived from the MA12 amplifier via a multi-pin lead. 

It's a reasonable layout, but the chassis edges are sharp. There's two PCBs, each containing Two EF86's and an ECC83. The EF86's produce two diferent levels of gain, one setting for TAPE1/2, GRAM and MIC, and the second stage conntecting the inputs from RADIO and AUX. There's no real RIAA equalisation on the GRAM but a little bit of loading. The second EF86 feeds a tone stack, which is then amplified by one half of the ECC83, followed by the other. There's also a low pass filter implemented here. It's full of horrible Hunts... 

The base is removed to gain access to the solder side.

... and a good while spent changing all those nasty caps out...

I chose not to re-stuff the can on this occasion, as there's a nice bit of tag strip that forms the power supply filter, so they could just be mounted there ...

At some stage in the past, the volume control has been replaced, for one without a switch. It's also been wired up backwards. It's now wired up correctly, so as not to deafen the unsuspecting user.

How's it sound? I thought there would be more "blow" due to the EF86's cascaded, but it's reasonably quiet. Obviously the TAPE setting is nothing more than a head amplifier, so not suitable for a line level output from a modern deck.  Pity about the RIAA, or lack thereof...*  Tone controls are actually very nice, and don't offer too much cut or boost. 

The switch-gear is lovely, and has stood the test of time really well. 

*upon reading the manual, it transpires the input stage was designed for a Decca FFSS cartridge, the manual does give some suggestions about use with other carts.