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.

Categories
Uncategorized

How I lost a stone in 77 days….

In Dec 0f 2020 (yes, that year) I hit 15 stone for the first time in my life.

And I knew that was coming.

2020 had been a bit of a slob fest for me. The grim full stop on a miserable couple of years as my marriage ended. I won’t talk about that here as we all have our sad stories to tell – I mention it purely to add context as to where I was.

The Reckoning

Since separating from my ex (finally divorced last Dec) I’d fallen into bad habits. Bad habits such as little or no exercise, too much pub time, poor quality food – the usual.

I knew that, at some point, change was coming; but I also knew that I had to choose that point. So, in that sense, I was happy to go with the flow for a while and let it work itself through my system.

15 Stone

The reckoning point for me hit in December. The divorce had finally come through, and, whilst it didn’t change anything (we’d been separated for years), it felt decisive in other ways. Like a crossroads, and an opportunity for renewal.

I also hit 15 stone. The heaviest I’d ever been.

All my concerns about the booze, the lack of exercise, the diet etc all came running home. I focussed on how I wanted to be in 2021, and what steps I needed to take.

Tech addition #1

On the 28th of Dec, my new scales arrived. I wanted one that didn’t cost the earth and came with a phone app so that I could track progress.

Setting it up was a sinch but I was saddened to see my weight had hit 15st. I decided to weigh every Tuesday, thinking that daily would just be a distraction – you needed a week to see bigger picture changes (and then I was more focused on the overall change per month).

Still, 15st was my starting point. My personal body fat ground zero.

Tech addition #2

I also wanted a basic step counter; the Xiaomi Mi Smart Band 4 was cheap and perfect for this.

Setting a daily goal for 10k steps, I was now on my way to dealing with the 15stone situation in front of me.

Let me know talk a bit more specifically about the approach I took, and the reasons why….

Booze

Booze (like it can do) crept in too much in 2020. So rolling into 2021 a much stricter regime was put in place; with only a small amount of drink on Friday and Sat.

Also, this meant no Guinness or bottles of ale (meh!). Which is a shame, as I love those. But they are basically like a hamburger in a bottle, a calorific hand grenade – and you can’t just keep chugging those & expect no consequences.

I found a great 0% beer from Morrisions which, whilst still containing calories, was completely booze-free – so that helped me in the week where I’d conditioned myself to a beer at the end of the day. It actually tastes nice, I can’t tell the difference between that a non-0% lager.

In terms of a dry Jan, or dry 2021, I did consider it but, at the same time, I didn’t want to set myself unrealistic goals in what was already going to be a difficult, transitional year.

Going back to very moderate drinking on the weekend, would be a good plus. My intention though, is to revisit my thoughts on booze as I go.

Exercise

The Xiaomi smart band was fantastic. The daily 10k step goal gave me (a very task orientated person) an easy way to take action.

Starting from late December I’ve done the 10k every day (apart from, annoyingly, one day when I just dipped under and didn’t notice in time!).

Walking was the obvious/simple way to knock off the steps but, with that needing up to 3 walks a day, another method was required..

Bon to Run

I’ve run before. I can’t say I love it, personally I prefer swimming in the morning but that’s just not an option at the moment. So running presented the easy, straight-out-the-front-door option.

I’d not run for a while so I knew it would be uncomfortable getting back into it. On top of that, I was now 15st which made a bad situation only worse. A double whammy.

My approach to running was this: ignore how fast etc, just do what you can, the fact that I was running meant that I could knock a good chunk of my 10k steps goal in one hit.

I got used to running a daily 5K. No times. No apps (aside from music). Just get out the door and run.

It was certainly hard at first. Laying in bed, not feeling particularly positive, the last thing you want to do is to shift your arse out of bed and pound the streets. However, I focussed on the goal. And I focussed on how I felt when I returned from the run: proud of myself and full of positivity. Aside from the steps, this was a much better way to start the day mentally.

Also, and perhaps I’m an oddball here, I don’t mind running in the rain, in fact, I think it’s quite fun. So on those days where it pees it down, running was always an option if walking was not.

Food

In terms of diet, I’ve never been too bad. And, thinking about it now, I don’t think I’ve ever really struggled with my weigh etc.

In 2020 I probably had too many takeaways, so that had to be knocked on the head. But, aside from that, I was fairly sensible.

I avoid too much sugar, and processed foods as really it’s sugar (not fat) that’s the cause of weight gain. I think I stopped buying fruit juice as, even though it’s nice, it’s a huge blast of sugar, and not great for the teeth.

There was no calory counting or cooking certain food or food groups etc. I just carried on as normal (e.g. tacos with kids, spag bol, chilli-con-carne etc). I’m not knocking calorie counting etc, whatever works for you. I’m just saying that I never went hungry.

I’ve never had much of a sweet tooth so I don’t buy loads of choc etc; what I do buy is for the kids. And I would certainly have some of it. So this was not a choc/sweet free zone, it’s just that I don’t like them much.

Thinking about it, I think the reason I didn’t consider getting stricter with the diet is that I felt that the easy gains were all booze-related. In my mind, I’d packed on the pounds in 2020 from alcohol – and if I could do the basics right, perhaps it would come off as quickly as it went on.

Sleep & Mental Health

A bugger about too much booze all the time is that it robs you of quality, rejuvenating sleep. You wake up from a crappy night’s sleep, and the day begins again – with you already behind the curve. This holds you back in the day and ends up being a self-fulfiling prophecy for having more booze in the evening.

The mind and body need sleep. It sounds obvious but they do. And you can’t constantly undercharge the body with too little sleep and expect there to be no consequences.

I got into the habit of getting in to bed around 9 (yeah, you read that right) reading a book for about an hour, and then drifting off. The exercise that I’d done in the day will have helped weigh me down here, making me ready for sleep.

Best foot forward

Another thing with mental health & starting the morning on a positive note. I found in 2020 I was leaving the kitchen in a bit of state in the evening and waking up to the it in the morning; confronting the mess was very much a ‘urrgh!” moment – and how is that conducive to starting the best with your best foot forward?

So, I got into the habit (and fair does to all of you who’ve been doing this for years!) of ending the day with a proper, quick mini-clean up of the kitchen and the front room.

This then means that when I wake in the morning, and make my first cuppa, I’m greeted by a spick and span kitchen not, to use one of my mum’s phrases, a ‘shit hole‘.

Small wins like that (such as making your bed first thing) can add up to big mental health wins.

So, those were the basics for my method going forward…

2021

My weekly regime was pretty much:

  • 10K steps a day (achieved my running or walking)
  • Running most days
  • No booze in week (and very moderate on Fri / Sat)
  • Being sensible with food

As off today 20th of March, my weight graph is:

I’ve gone down from the first reading on 28th of Dec (15 stone, 27.5% body fat) to March (16th 13st 8, 23.6% body fat).

I’m obviously very happy that the steps I put in place have worked, not just for the weight loss, but also for the feel-good factor, the mental health pay off. And the fact that I can wear t-shirts again!

….but where do I go from here?

Next Steps

I’ve never been a on/off diet person so I don’t see any ballooning back here with weight and piling it back on. And I have no intention of slipping back into bad habits (though, with the pubs reopening soon, and summer coming, temptation is certainly on the horizon!).

Now that I’ve established a routine, I’m looking at what I do next. That will be a combination of:

  • Pushing the running more. Go faster. Go for PB times with my 5K and weekend 10K. Strava is great for encouragement from other runners for that.
  • I do like my red wine on the weekend. My mate Stu Robson mentioned the small bottles which are great, and fit into my approach.
  • I’ve bought a juicer! I love fresh fruit etc and this is a nice way to get a big hit. Carrot and ginger is great. Like I said before though, you do need to be careful with the sugar here; fruit is full of fructose after all.
  • When things open up, I’ll be swimming again. There is a great gym close with a decent 25m pool. Have been a member before and will join again for swimming and classes. That’ll probably mean I swim one day, and run the next.
  • Swiming again: I’ve done a bit of open water swimming and love it! The exercise and the buzz when you get out. Whilst I have a wet suit, I’m not venturing out there until it’s a little warmer (kudos to you who brave the chilly water already!).

The End (not)

The way that I see it, I’m now entering phase 2. I’ve established a basic rhythm here, made some initial wins, the key now is to carry on and build on that.

I think the final thing I’d say is this: what I’ve laid out here is what works for me, if other methods work for you, that’s fine. If you are reading this and thinking ‘what a wanker! I could never lose that weight!” then I’m sorry – that’s not the point here – I’m more trying to say this: when I was ready, I knew the approach I needed to take. But you have to be ready.

Feel free to get in touch if you have any questions.

Love

Joel

Categories
Uncategorized

Robert Shaw

My friend Mark sent me a link to an excellent documentary on Robert Shaw earlier, and I have to say, it’s fantastic….

Categories
Uncategorized

Ecamm Live & Canon 550D (Rebel T2i)

I’ve been using my old trusty Canon 550D (aka Rebel T2i) to successfully stream via Ecamm Live for a while, though I have struggled with a few peculiarities. So, I’ve spent a little time this morning trying to get to the bottom of it….