Categories
Embedded

Debugging

I’ve been playing around with my simple sound toy and I hit a weird issue which I’m glad to say I finally solved….

The sound toy will play clips of Bob or Paul from the wonderful Gone Fishing programme. Yeah, yeah, I know it’s copyright but this is purely a personal project and is just a vehicle for learning.

Weirdness

Once I sorted the GPIO pin issue (see previous post) and finally got the Adafruit Rp20240 to play a WAV file, I thought I was home free. Fool I am!

My next task was one I’d been putting off, I was going to have to wade through all 7 (seven!) series of Gone Fishing and to select a set of clips I wanted to embed in this toy.

I wanted around 25+ clips; but after playing around with the sample rate (lower sample rate, smaller file size, squeeze more in the flash memory) I realised I could have more than that.

The issue was then one of workflow.

I started off by watching a few episodes and then noting a few phrases per episode that I liked. However, when you stop and think about it, this doesn’t work for two reasons:

  1. I’d have to go back and get the WAV sample(s)
  2. A few phrases per episode?! Including Christmas specials, there have been 49 episodes! So really I need less than one clip per episode.

I needed to re-think things!

My new plan was to watch the episodes on my laptop, and somehow record the sample I like straight away. Also, I would need to LOVE the clip – I was not short of footage or episodes to get through. And I certainly didn’t need more than 40-50 samples on the toy.

There are some nerdy ways of going about recording audio from a video you are playing on the on the computer but, to save the amount of thinking I had to do, I elected to go back to an app I’d used before, many moons ago: Audio Hijack.

With this tool, I could watch episodes on my laptop, and quickly record snippets.

Yeah the snippets may well need a bit of editing but what the heck?

I found that the mac desktop had a built in ‘trim’ facility to help me trim the clip down, which was great, but it created a problem.

The Problem

The problem was that if you use the ‘trim’ facility built into Mac Finder, it messes with the WAV header, which then mucks up the code.

Trust me, I am doing you a favour by not talking you through how I painstakingly found this out, but it did involving viewing the WAV files in hex!

In fairness, as happens a lot, with a bit of time to mull, I smelled the rough direction of the problem. The (ChatGPT) code (that has already caused me issues – see previous posts!) had hard coded offset values for the WAV file headers – errrr….yeah, that’s not very brittle is it?

Editor’s note: it was very brittle.

Long story short (again!) using the Mac Finder ‘trim’ messed up the headers and the offest.

Answer? Use Audio Hijack to capture my raw clips, and then use Audacity to trim the clips and to export.

Oh, and my other learning was that exporting to a sample rate of 11,025 Khz is a good compromise between quality and file sizes.

So, back to reviewing Gone Fishing!

p.s. I have also started the very early stages of looking into how to design 3D stuff for another project I’m working on.

Categories
Embedded

It’s alive!

So I had to wait a few days to get a variable voltage power supply (you can just see it on the left) but this was pretty easy to set up.

I dialed up 5v and 1amp and nothing happened. Uh oh I thought. Then when I increased the voltage a little, the little blue light on the device lit up.

I looked around and noticed an old speaker from a lovely old Sony mini-stereo I had. I had no idea if it still worked but I thought I would give it a try.

It immediately sprang into life (Garbage – I’m only happy when it rains) and it sounded bloody good!

Oh, I missed a step – connecting my iPhone to it via Bluetooth was typically straight forward. Only oddity was that it seemed to have two Bluetooth profiles:

  • Wuzhi Audio
  • Wuzhi Audio App

I think the App one is for an App which can control certain settings. I downloaded what I thought was the app but it looked pretty ropey so I gave up on it and got back to the task in hand.

I then decided to run out and grab a speaker from my car (partially to see if it’s bad compared to the Sony, people have been saying how bad these original Citroen speakers are) and then, when on the street, remembered by car was in the garage having an MOT. Doh!

Still, this is progress.

Next step. Test with a speaker from the car. Hopefully that doesn’t sound bad (will test it back to back with the Sony speaker). If it does sound a bit ropey I can always invest in some new ones for the car.

Next test after that is to test the set up with the power supply from the car. I need to double check how I plug in to the custom ribbon on the Citroen audio.

The other big step will be getting the audio cage which this will sit in and the 3D printed fascia will attach to. The more I think of it, the knob will be in the middle.

Categories
Embedded

Car Audio Project [2]

When researching the amp to power the car’s (probable) 30w speakers I kept coming across amps with bluetooth built in and then it hit me:

I was over engineering things, I didn’t need ESP32 involved at all!

What I needed was something more basic like this:

This is the Dolla Tek 2x50w TPA3116 Bluetooth 5.0 mini amp.

This simplifies things somewhat.

I should be able to connect this directly to the car’s audio red power wire* (ignition), though I may need a fuse.

(*There is also a constant yellow wire from the battery but this then gets complex as you don’t want to accidentally drain the battery. I can live with the constraint for now that this only works when the car is started, if that becomes a pain, I’ll revisit options).

There is one volume knob which doubles as an on/off switch. That fits well with the minimal design I had in mind.

I doubt that I can change the name of the Bluetooth device but that’s fine, doesn’t bother me. It would be fun if you could but it’s no show stopper.

Aside: when I had a Bluetooth speaker (powered by it’s own internal battery) in the car, it would occassionaly, whilst driving, have bad interference for a few seconds before audio resumed. I never got to the bottom of this (well, I didn’t look very hard!). This is just something for me to remember, if there IS similar interference when I run this new amp, then at least I know it’s not the device itself, there is some other environmental/geographic factor at play. Anyway, that’s a ‘tomorrow problem’.

Whilst this simplifies things (and it is a shame not to use the ESP32 but there is no need, that’ll be used in a future project) it does leave a really interesting bit that I’m keen to learn about: I’ll still need to house/mount the amp et al and, better still, will need to 3D print a dashboard fascia. That’ll be interesting designing that, keeping it simple, giving space to just that one knob etc (perhaps even change the knob):

Is the knob central? Or does it look more intriguing being (say) bottom left? My gut feel is that exact centre feels weird.

I’m not going to buy a 3D printer yet, I’ll use an online service.

I’m not an audiophile and the car’s speakers are pretty crappy so just having semi decent streaming will be great (and before you say “if that’s the case, just use the phone’s loudspeaker“, nah, that’s crappy, have tried that, can’t live with that).

Steps

Ok, let’s revisit the steps:

  1. Buy the amp
  2. Perform a basic lab test to check it works
    (ideally with a similar speaker to what’s in the car)
  3. Get the bits I need to connect to the car’s custom audio ribbon.
  4. Create a test connecting device to the ribbon (and perhaps with a fuse as well, as ChatGPT is telling me)
  5. Drive around a bit with it playing (see if I get that occasional interference). If I hit a problem, will need to research.
  6. Consider how to mount (e.g. gut old stereo to keep cage & then mount a 3D printed fascia to the front)
  7. Design the fascia, get printed etc (rinse and repeat if mistakes/iterations)
  8. Mount & enjoy (to so speak)

Categories
Embedded

Car Audio Project

The next project I’m mulling is where I’m looking to replace the cassette/radio stereo in my aging Citroen Berlingo with something a bit more fancy.

I don’t own audio cassettes any more and I’m not a massive radio fan but I do like streaming from my phone. Hence I’ve been driving around with a bluetooth speaker in the car. As the battery died on the speaker for the second time, I hit on an idea:

What would it entail to remove the existing stereo, and replace it with a bluetooth device that allowed me to play my iPhone into the car speakers?

The big obvious win here is that I immediately avoid the need to charge a bluetooth battery.

ChatGPT

As usual, I spent quite a bit of time chatting to ChatGPT about the project, using AI to feel my way through the project, seeing what issues I was likely to have, and then finding a way around them.

After quite a bit of discussion, this is what I’ve arrived at:

This time we shall use an ESP32 WROOM to power the project.

Why not the Pi or the RP2040 (like in my sound toy project)? Well, the reason is the ESP32 has built in Bluetooth and excellent support for Bluetooth audio streaming. This time I didn’t need the rechargeable battery facility on the Adafruit Feather as the car would provide the power.

The general approach will be this:

I’ll remove and discard the old stereo (though I may salvage anything I need, such as the case if that helps). And I’ll replace it with my ESP32 device that will connect to my phone and stream audio via Bluetooth.

The ESP32 will connect to the existing Citroen audio cables (I found a great Youtube video on what cables I could expect to see etc).

I’ll need something to step down the car’s 12v power to the 5V needed by the ESP32.

I’ll need a fairly powerful amp to power the non-trivial car speakers, so this will be another board (e.g. TPA3116). Now because this amp will typically need more power than the 5v the board needs, this will be wired into the car’s power. I’m going to need to research a bit more to check what wattage the car’s speakers need and then find the right board. Some boards seem to come with a volume control but I think I’d prefer to just let that be controlled via the phone (though this may change come testing).

When mounted, I think we’ll aim to have just one button (though there may be a volume, as above). I like the really minimal approach here.

The button will be controlled by the ESP32 and will, basically, turn it on and off.

A longer press (10 seconds?) will put the device into discoverable mode so that phones can connect to it.

I’ll probably have two LEDs. One red one to show if the device is on. One blue one to show if a device is connected. When in pairing mode, the LEDs can flash. I don’t see the need to label the LEDs on the fascia.

The device will remember stored Bluetooth profiles and it’ll connect to the last one by default. I don’t think this is a problem, e.g. if myself and the wife get in the car (both of whose phones are already paired to the stereo) then the easy option is to put one phone in airplane mode (or disconnect from the stereo), allowing the other to take over (so yeah, the stereio will need to notice a bluetooth connection has disconnected, and then round-robin on the list of connected, paired devices).

I thought about adding a display to the device but I don’t think this is needed (ie to show artist/track info). Again, the more minimal view appeals to me.

I will 3D print the front of the case; that’ll be a good opportunity to learn that. The type of printer I need I think will be quite affordable (and useful on other projects) or I can use an online printing service to start.

If I decide later to have a display on the device, or a volume control, I can print a new case.

Oh, and because the device has Wifi I should be able to connect to it via my laptop and update the code that way. I’ll test that early as, if not, then I may need to include a USB-C slot on the fascia (though that raises other issues, we’ll cross that bridge when we come to it).

First Steps

So, after lots of thinking and navel gazing, the first phase will be this:

Set up the ESP32, connect it to a basic, small amp/speaker (for testing purposes only), pair it to my iPhone 15, and play music.

After that, we can think about how we build a basic unit that can be tested in the car. Which will mean dealing with the car’s voltage, and using an amp more suited to the car’s speakers.

After that hurdle has been crossed, we can get to grips with designing a case, 3D printing it, and mounting it to the car.

Easy.

(ahem!)

Categories
Embedded

Back to embedded!

I used to play with electronics as a teenager but then life got in the way and with marriage, kids, running a business etc.

Life at my web design / support agency is no longer as hectic as it used tobe so that gives me a bit more time to think about about I want to learn and get fired up about.

One thing I’ve found is that I’ve been yearning to do more physical things; perhaps as a side-effect of working in the ephemeral digital realm for so long. I’ve been taking on some carpentry projects (very hands on, very rewarding) but back in the tech world, I’ve started playing again with electronics.

Cheap as chips!

In the image below you see my holding a variety of Adafruit Feather running RP2040 chip made by Raspberry Pi.

I find it amazing that you can buy this amount of tech for so little. The breadth of engineering that goes into this little board – it’s amazing.

It’s been a baptism of fire getting back into this tech, even someone who has dabbled in it many years ago, and who comes from a programming background, there is a lot to learn.

A quick list of what I’ve recently learned:

  • Some of the different boards out there (Pi, Adafruit, ESP32)
  • A reminder of how to use a veroboard
  • How to solder (love my new cordless soldering iron!)
  • Python programming

…and that was the purpose really, to start to find out what I need to know, and to take basic steps forward. To use a project as a learning vehicle.

A project

Like with carpentry, it’s wonderful to have the tools, but you need a project to start thinking about things, and to focus on. Otherwise you are just staring at a blank piece of paper blinded by the almost limitless possibilities in front of you.

My first project is a sound toy. The goal it this:

To have a palm sized, rechargeable device, that plays various, stored digital sounds.

Sounds simple but it’s a good case to help learn.

For starters, I started off buying the Raspberry Pi Pico for this project, but it quickly became apparent that even though this was a fairly small Raspberry PI, it was probably too big for my needs. And it was too powerful – not that it being a waste was the killer issue there, it’s just that being powerful meant power hungry and, remember, this was meant to be a battery powered device.

So I’ve put that to one side for now (it will certainly be be used in a future project) and after some research I came across the Adafruit Feather Prop-maker.

This device has a few important advantages over the Pi Pico for this project:

  • It has a built in amp
    I’ll need this to power the speaker, with the Pico, I would need an external amp breakout board (such as the MAX98357A). Having the amp onboard makes my life easier
  • Lower power consumption (as less complexity on the board e.g. this does not have WIFI or Bluetooth, not needed)
  • Built in support for battery packs (again, you’d need another board if it did not)

So, armed with my better fit board, I started again.

ChatGPT is great!

At this point, I should give a nod to ChatGPT. This has been my companion as I’ve been chatting through the project. Explaining what I’ve been trying to do, and bouncing ideas off it. It certainly helped me, for example, find an alternative when I realised the power consumption of the Pi Pico made that tech a non-starter.

AI has been very, very helpful here.

Very helpful as well with talking through how to set up the boards, getting started with an IDE, whether to use CirtuitPython or MicroPython etc. All things that would have been harder (but not impossible) to do with plain, vanilla Google searches.

What I also like abotu ChatGPT is now you can have ‘Projects‘ so I can have an area for all my Raspberry Pi/Embedded stuff. And it remembers what I’m trying to achieve with a project. It’s like having a patient friend with you.

ChatGPT sucks!

However, it’s not all plain sailing. As soon as you get into niche areas like, for example, that for. this project I’m using the Adafruit Feather Prop-Maker, it can forget that it has an amp built in etc.

But the biggest issue were the code examples.

They didn’t work.

Now this is not really a criticism as I didn’t really expect them to fully work. I understood that we had a lot of moving parts here, and this was complex stuff. Having starting point code (even if not working) is a great help.

But the problem was, when things don’t work it’s a binary thing: there was no sound coming out of the speaker. So you have to be able to troubleshoot. Luckily years working in IT has equipped me with those skills.

After a few hours troubleshooting I was getting nowhere and a little downhearted.

Then I started making a few breakthroughs..

I saw (well, heard!) the light..…

Researching the actual tech specs I started noticing issues with the code; where ChatGPT had made assumptions (perhaps based on other RP2040 boards).

I realised that if it was missing steps out, and getting important details wrong, I needed to be be more vigilant with what I was accepting from it.

After a night of troubleshooting (with little to show for it), I woke up with a fresh idea to check the code for pin configuration against the official tech specs. I quickly spotted the mistake* and then, with a huge smile on my face, I finally heard noise come out of the speaker and, a few moments later, my voice (from a quickly cobbled together WAV sample).

(*Actually, I THINK the ChatGPT example code had the wrong port configuration but the right numbers in code comments! Weird!)

So, sorry, I’ve rambled enough now, in a follow up post I’ll chat about my next steps with this project.