2024-11-25

I²S

I²S is, err, fun.

What is I²S

Well, first off, it is grammatically like I²C which is an acronym with two Is in it which people then treat an acronym like a mathematical equation and so make it I²C. I²C is IIC. I²S is the same annoying logic, it is in fact IIS, which is Inter-Integrated Circuit Sound, which wikipedia says is pronounced "eye-squared-ess"[citation needed]), and yes, I know nobody that says squared! It is eye-two-ess in my book.

But what is it exactly?

Well, it is a standard (and I use the term loosely) for audio over digital signalling.

What this means in practice is digital microphones and digital speaker driver chips. And to be honest I am amazed. This is clever tech, and pretty much a result of mobile phones.

The options

One challenge is that there are many options. It seems, at least, you may need.

  • MCLK which seems to be a master clock at a higher frequency. Now, whilst the code and hardware I use in ESP32 understands this, it seems it is usually not needed.
  • A WS or LR clock (I assume WS is "Which Side", and LR is "Left/Right").
  • A BLCK - a bit clock.
  • A data line for the clocked data in or out.

This is not too bad, especially if MCLK is not needed.

Basically the WS clock is slower, and the BCLK is faster and it allows for each side to have a number of bits of data to be clocked. Simple enough.

PDM mode

The first thing that threw me is that there are I2S microphones that use PDM. I really don't quite grasp the logic here, sorry. PDM looks simple enough (mono) as it looks like you have on/off period that relate to the level of audio. But I am uncertain how that works as clocked left and right.

The PDM microphone I tried allows up to 4.8MHz clocking which is way over audio, so clearly means clocking more and sampling that to decode the PDM.

Seriously I don't (yet) understand, but it works, and the ESP32 can handle it and get 16 bits per sample for each side at various rates.

Standard mode

This makes more sense - you have a BCLK that, say, clocks 32 bits and then every 32 bits the WS clock toggles. So the LR clock is the sample rate, and one side clocked on BCLK when WS is low, and the other when WS is high. Clocked MSB first, signed.

What is actually cunning here is how many bits per sample. A microphone could supply 8, 16, 24, 32, whatever bits, MSB first, on the change of WS and clocked each BCLK. Then stop, and that would be noise for any extra bits. So if you clocked something that only does 24 bits at 32 BCLK per WS cycle, you get 32 bit data where top 24 bits is meaningful.

Philips mode?

There is, of course, a catch! There is a Philips mode, which means the data clocked on BCLK is one clock later than the change of WS clock. But standard mode has no such delay! Oddly, it seems Philips mode is more standard.

Stereo or mono

The underlying format is always Stereo (well, ish), but the hardware on the ESP32 is not daft. I can say I only want left or right channel mono from the stream. Output is always stereo, and there is an option to say mono which I assume (hope) sends same data on each side.

TDM mode

There is, it seems, another mode, where WS is a short pulse at start of frame, and BCLK allows lots of channels, well 8 channels I think, to be clocked. Is this a hark back to 8 track tape?

Hardware

The ESP32 handles all these modes, yay!.

For stereo input you wire two microphones on the same bus, one set as left and one as right.

For stereo output the same, a speaker driver wired as left, or right. It can also be wired as left+right even.

What is amazing is the chips that now exist.

Microphone

TDK do tiny microphones, a PDM one, and a 24 bit per sample I2S one. They are unbelievably good.

Speaker

This was even more impressive - Maxim do a really tiny speaker driver, and it is 1.3mm square BGA that does it all - a cap on power maybe, but it takes BCLK, LRCLK, DATA, and drives a 4 ohm speaker, and that is it! Use two and you have stereo.

Why is this so good?

The simple answer is the hardware in chips like the ESP32 mean that audio in, or out, is a DMA behind the scenes process allowing blocks of data to be sent or received reliably by the hardware.

Before this you would need a good quality ADC sampled at a consistent high speed rate. You would need a good quality DAC updated at a consistent high speed rate. This was hard work. A chip for each was complicated.

Now the microphone is one chip, and the speaker driver is one very tiny chip. And that is it!

2024-11-17

Fencing

Bit of fun...

We usually put up some Christmas lights on the house - some fairy lights on the metal fencing at the front, but a pain as means a cable out of a window. They are usually just normal fairy lights.

But with my new found expertise in WS2812 style LED strips, and my controllers, I decided to do better.

11m of wooden fence at the front of the house on the road. So let's do this properly. The key point is I have outside power at the end of the fence for the hot tub. So I was able to install, under cover, a 20A 5V power supply.

I then got 4 strings of fairy light style water proof 5V WS2812 LEDs.

I drilled nearly 200 holes, carefully measuring each to be level and evenly spaced. That is surprisingly hard work, LOL. James followed me poking LEDs through the holes. We were both expecting to fall off the damn wall, and James's main concern is I would fall off whilst he was not videoing!

But it is not quite so simple. Just in case you don't know, there are two common issues with LED strips.

Current limit

One issue is max current draw can be too much for power supply. To test you can either work it out, or, simply set all LEDs full white. 200 LEDs is too much for a typical small 5V USB charger plug. Hence the 20A 5V supply.

I actually also did 663 (11m) RGBW LEDs on nice 45 degree extruded trunking with diffusers for the hot tub as well, from same supply. Now that used a lot of current - just one 5m strip is too much for a USB 5V charger when white.

Voltage drop

This is slightly harder to solve. Along the strip the current draw means voltage drops as you go along. Different LEDs need different voltages. First you lose some blue making it yellow, and then some green, making red/pink. And even before that, when white still, you lose some brightness.

So with this 50 LED strip - one strip works. Two strips work but losing brightness at end. Three strips means going distinctly yellow at the end. I wanted four strips!

The solution

The solution is power feed in - the strips even have extra tails for power as well as the three wires for power and data. You feed in extra power at each strip end, so for my 4 strips I feed in at 5 points.

But how do you feed in power? In some cases you could simply power your longer strip at both ends and not have enough drop to the middle to notice. But I don't have power at the other end.

But actually it is possible to feed in even with just power from one end. The reason is the resistance of the wires, these are classic Chinesium™thin wire. If you actually have some thick good quality copper wire you can run and extra power lead the whole length and feed in at each strip end. This is what is in the WAGO boxes in the image.

Merry New year!

P.S. my son sells the controllers and stuff, https://hiwtsi.uk/

Update: Measuring resistance on the 50 LED strip power lines showed 1Ω but the leads were 0.1Ω, so 0.9Ω. A similar length of copper wire registered 0.4Ω, so 0.3Ω, so ⅓ of the resistance.

James did a video :-)

2024-11-11

Playing cards

One of the fun diversions I have had in my time was making playing cards. I did a whole chapter in my biography on this.

My playing card design site https://www.me.uk/cards allows you to make a wide variety of cards. It is a fun little system I set up long ago.

However it has come up lately for a few reasons.

For a start I made some cards for the pub, on Amazon. Please buy some.

But also some error reports I had - some edge cases made bad cards. And making the cards for the pub meant I wanted custom card backs which it did not allow.

So I have updated. New features...

  • Fixed a bug making some size cards mess up court cards.
  • Upload custom artwork (PDF) for backs.
  • Upload custom artwork (PDF) for jokers.
  • Maze and arrows backs are more random, each deck is different (obvious all cards the same back in each deck - but every deck we make is unique).
  • Tidied the options to be clearer.
  • Added an option for a second set of aces to be included.

The last point was one I pondered. We make some unique decks, with an "11", or a "0" or "1" card, which is unusual. But actually what may sell better is a deck with a second set of aces, to have, well, "up your sleeve". So why not.

I have added custom ace of spades now too.

Deliveries from China

I have PCBs made in China (well Hong Kong). This is all my many small PCB projects (not FireBrick). I would rather use UK suppliers but I am...