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

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.