# Music Player with NFC using Raspberry Pi and .NET



## W1zzard (Feb 21, 2022)

Started work on a new side project: a portable music player for my daughter. Select song by placing a NFC token on the player, similar to Toniebox or Phoniebox

Will code a proper .NET application though, with web services, instead of a mix of Python + Shell scripts like some other solutions







Made good progress this weekend. Playback and switching between Internet Radio stations with NFC tags already works.

Red PCB on the left is the NFC reader, above it, green PCB is a Hifiberry Miniamp. The big PCB on the right side is a Raspberry Pi 4B

Incoming tomorrow is a USB battery pack, and an electronic MOSFET relay, so I can properly power off the whole thing on shutdown


----------



## silentbogo (Feb 21, 2022)

Did you have to beat down a few scalpers for that 4B, W1zz?   

Cool project. Do you run Windows IoT? I tried it once - wasn't my bag of beans ))))


----------



## W1zzard (Feb 21, 2022)

silentbogo said:


> Did you have to beat down a few scalpers for that 4B, W1zz?


I simply bought it online in a shop here in Germany for 50 Euros. Not a lot of stock around though it seems.



silentbogo said:


> Do you run Windows IoT?


Nah, Linux all the way. Will strip down the boot process though to save on boot time. Little girls can be impatient


----------



## Solaris17 (Feb 22, 2022)

Please review this on the blue table.


----------



## Shrek (Feb 22, 2022)

Might not be the right place to ask, but what is the progress with Windows 11 ARM on the Raspberry Pi?


----------



## W1zzard (Feb 23, 2022)

Progress update:





USB battery pack (20000 mAh) can power this for 30 hours. I tested with less than half-full and it ran over 10 hours
Got me some little speakers, which sound worse than I expected t.t, ordered bigger ones
Added a rotary encoder for volume control. The existing libraries are surprisingly bad and either require polling, miss pulses or generate fake pulses from noise/bouncing. Ended up writing my own interrupt-driven library using a state-machine

Next: look into power on/off capability using MOSFETs


----------



## W1zzard (Jul 1, 2022)

First super ghetto prototype. Works really well

- Switched from Raspberry Pi 4 to Pi Zero 2W for the lower power consumption/longer battery life
- Web interface using .NET core working great. Upload MP3 working perfectly.
- Added shairport-sync so the player appears as AirPlay audio device on the network. Everything played back is automatically recorded and can be saved into replayable tracks
- Found some bugs in the .NET IOT button debounce code, issue opened on Github so they can add my fix

Next:
- Build a prototype wooden case to get a feel for what's usable in dimensions, then look into 3D printing a case
- Add Atmel Microcontroller for power management (Raspberry cannot power off on its own)
- Look into how to improve durability of print on these cards
- Find a knob for the rotary dial
- Look into buildroot to build a custom linux that boots as quickly as possible


----------



## Selaya (Jul 1, 2022)

now thats something them ghetto modders would approve of


----------



## W1zzard (Sep 12, 2022)

Much less ghetto prototype, to get a feel for dimensions and component placement, etc, so I can 3D print the case later






Went through several component revisions


Switched to Pi Zero 2W for its lower power consumption
Turns out a power bank is unusable for this kind of project, because the power bank will just turn off when power draw is low (Raspberry off, MCU on)
Now using a 4-battery 18650 Li-ion "Battery Shield", which can permanently supply power
Built a custom Linux distro using Buildroot to reduce boot time, now around 12 seconds (still super long with an impatient kid, but better than 30 secs). Loading and starting a .NET app takes surprisingly long, like 3 seconds
Added an Atmel AVR 8-bit microcontroller for power management (Raspberry cannot power down on its own). Raspberry pulls a GPIO pin high on shutdown that the AVR watches for and then cuts the power
For power management I tried a bunch of MOSFET modules, but they all suck because they are low-side switching, finally found a module using IRF5305S, which does high-side switching, so I have a common ground and my buttons can be used to power on the machine
Raspberry is super annoying with its voltage requirements.. as soon as you have a little bit of resistance, voltage can drop below 5 V, at which point the Raspberry will crash or run into other issues. Solution: use a MT3608 voltage booster, set it to 5.7 V output via trimpot and all voltage problems solved, it will just boost whatever input voltage you have to the target voltage
Wanna make awesome cable connections? Buy a "Dupont" crimping set on Amazon and make your own cables


----------



## Shrek (Sep 12, 2022)

Why two different speakers?


----------



## GreiverBlade (Sep 13, 2022)

Shrek said:


> Why two different speakers?


bass and mid/high... eh?

usually multi driver speaker units have a big woofer and a tweeter, better sound replication 

same kind as my FH1s... 13.6mm dynamic for the bass and balanced armature for the mids and high (all that in one ear, double that if i use both ears ... and yes i do use them both, most of the time. )


----------



## nomdeplume (Sep 13, 2022)

Großer Vater!


----------



## silentbogo (Sep 13, 2022)

Got some upgrades I see....  
Pi4s are still as rare as unicorn's ass here, but I had a chance to play with one just a few weeks ago. Super-fast, super-cool, but unfortunately not mine...


W1zzard said:


> Added an Atmel AVR 8-bit microcontroller for power management (Raspberry cannot power down on its own). Raspberry pulls a GPIO pin high on shutdown that the AVR watches for and then cuts the power


It's finicky, but it can. There are some premade solutions for that, but ultimately it all boils down to the following: on the Pi you need to attach a power button to GPIO3(GLOBAL_EN), then you disable "WAKE_ON_GPIO" and enable "POWER_OFF_ON_HALT", add "GPIO_SHUTDOWN" as well(or just write a script that triggers on GPIO, if you need to do something specific prior to powering off). That's pretty much an equivalent of your conventional power button.
I don't remember if power LED is staying on or not with this thing, but it can be disabled in that same script(temporarily) or in config(permanently, since it's in the box anyways).




W1zzard said:


> Turns out a power bank is unusable for this kind of project, because the power bank will just turn off when power draw is low (Raspberry off, MCU on)


Not a conventional power bank, but there are some that do have continuous output regardless of power draw. Though, I'm not even sure if Pi4's outrageous standby power can be considered "low".



W1zzard said:


> Raspberry is super annoying with its voltage requirements.. as soon as you have a little bit of resistance, voltage can drop below 5 V, at which point the Raspberry will crash or run into other issues.


If I were you, I'd check that wiring for issues. PMIC cuts off at 4.6V, which is a long way from 5V input. Kinda the issue that plagues cheap chinese powerbanks, which put out more power than designed for.



W1zzard said:


> Wanna make awesome cable connections? Buy a "Dupont" crimping set on Amazon and make your own cables


Or use your existing mini-fit crimper. I just had to adjust gears for proper release point - now it's all nice and clean.
Though, I'd really want to find a set of attachments for crimping short contacts, cause these get mangled on any gear settings with my current setup.
Had to use dupont connectors throughout my entire 3D Printer wiring, which was and still is a nightmare, and still isn't finished....


----------



## Ferrum Master (Sep 13, 2022)

W1zzard said:


> I simply bought it online in a shop here in Germany for 50 Euros. Not a lot of stock around though it seems.



I am jelly... here those come around 100-150€ 

Also I ordered Raspberry Pi Zero 2 W on Farnell, I don't hope it to see it this year.

One fair warning about 5.7V.

The TVS surpressor diode there is SMBJ5.0A-TR so breakdown at 6.4V... with trimp pot you may trigger it.

Another fair warning the PMIC there is extremely fragile and if you fry it you cannot replace it as it needs to be configured as it is a programmable PMU, code for that isn't known IMHO. 

Just put thicker wires as there is low voltage. Another trick is add a capacitator at the TYPE-C wire connector, strip it and solder a cap at the end of it, it will mitigate fluctuations and then you may omit the Vreg.


----------



## W1zzard (Sep 13, 2022)

Shrek said:


> Why two different speakers?


Bought two different ones to get a feel for the quality difference. The bigger one is MUCH better and will use 2x in final



silentbogo said:


> It's finicky, but it can. There are some premade solutions for that, but ultimately it all boils down to the following: on the Pi you need to attach a power button to GPIO3(GLOBAL_EN), then you disable "WAKE_ON_GPIO" and enable "POWER_OFF_ON_HALT", add "GPIO_SHUTDOWN" as well(or just write a script that triggers on GPIO, if you need to do something specific prior to powering off). That's pretty much an equivalent of your conventional power button.


Yeah, I built that myself. dtoverlay=gpio-shutdown in config.txt is what you want, don't use a shutdown script. The unit has no power off button, it will automatically shut down itself after x minutes of not playing music. You can power it back on by pressing a button



silentbogo said:


> but there are some that do have continuous output


Not in the EU, at least not as "power bank". There's something from TalentCell, which has a physical switch, but that can't be switched off through software.



silentbogo said:


> Though, I'm not even sure if Pi4's outrageous standby power can be considered "low".


Pi has no standby. You mean its off state that really isn't off? That's high enough to not shutoff the power bank, but too high for a battery-powered device. Battery will be empty in a day or two. What I meant was "when the Pi is really off and the MCU is on, the power draw is so low that the power bank will turn itself off"



silentbogo said:


> PMIC cuts off at 4.6V, which is a long way from 5V input.


I mean the low voltage warning (0x00050005) and things get unstable long before 4.6 V is reached



Ferrum Master said:


> PMIC


PAM2306 on Pi Zero 2W, up to 6.5 V absolute max, 5.5 V recommended, I think I'll be fine


----------

