• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Music Player with NFC using Raspberry Pi and .NET

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
28,741 (3.75/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
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

eoOAluA.png


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
 
Last edited:
Did you have to beat down a few scalpers for that 4B, W1zz? :D

Cool project. Do you run Windows IoT? I tried it once - wasn't my bag of beans ))))
 
Did you have to beat down a few scalpers for that 4B, W1zz? :D
I simply bought it online in a shop here in Germany for 50 Euros. Not a lot of stock around though it seems.

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 :)
 
Please review this on the blue table.
 
Might not be the right place to ask, but what is the progress with Windows 11 ARM on the Raspberry Pi?
 
Progress update:
vlzrhbio74.jpg


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
 
e40N96u.png


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
 
14D5VYG.jpeg


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

CKjpNxI.jpeg


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
 
Last edited:
Why two different speakers?
 
Why two different speakers?
bass and mid/high... eh?

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

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. )
 
Großer Vater!
 
Got some upgrades I see.... :D
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...
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).


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".

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.

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.... :banghead:
 
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.
 
Last edited:
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

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

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.

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"

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

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