Skip to content

HifiBerry or alternative DAC for Dynamic_RDS #23

@TomasRa1

Description

@TomasRa1

On https://www.aliexpress.com/item/1005005393398013.html is possible to buy very cheap but with relatively good audio quality DAC for Rpi with IC PCM5102A.
HifiBerryPCM5102A_DAC It works nicely as good quality audio driver for FM transmitter as I tested.
For Rpi connection it needs these Rpi GPIOs: +5V/pin2, GND/pin6, BCK/pin12, LCK/pin35, Din/pin40
You can see on picture mutual connection and also 4 PCB jumpers, which must be soldered as on this picture:
PCM5102_jumpers
For to use this or similar Rpi HifiBerry DAC or also for to use Rpi built-in PCM DAC we need reconnect Dynamic_RDS PWM output from pin32 (GPIO12) PWM0 to any other free pin, because built-in Rpi audio or external HifiBerry DAC needs this pin PWM0.
For more detailed informations regarding Rpi implementation of this HifiBerry DAC module, please visit eg. https://blog.himbeer.me/2018/12/27/how-to-connect-a-pcm5102-i2s-dac-to-your-raspberry-pi/.
I decided to use RPi pin11 (GPIO17) for PWM output.

It needs to modify "Dynamic_RDS_Engine.py".

  1. Delete (or comment by "#") all regarding PWM0.
  2. Added on the beginning of file to the end of IMPORT loads (from line 17):
~~~~~~
import smbus
import subprocess
import unicodedata
from time import sleep
from datetime import date, datetime, timedelta
from urllib.request import urlopen
from urllib.parse import quote
import RPi.GPIO as GPIO     # RPi GPIO for transmitter output power set
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)    # Set GPIO17/pin11 as PWM2 OUTPUT
pwm_2 = GPIO.PWM(17, 18000) # PWM2 set to GPIO17/pin11,PWMf=18kHz
pwm_2.start(0)              # PWM2 duty cycle=0 (0V on pin11)

@atexit.register
def cleanup():
  try:
    logging.debug('Cleaning up fifo')
    os.unlink(fifo_path)
  except:
    pass
  logging.info('Exiting')

# ===============
# Basic I2C Class
~~~~~~
  1. Add under "class QN80xx(Transmitter):/def update(self):/# TX gain changes and input impedance" and above "def shutdown(self):"(from line 271):
    # TX output power update
    pwm_2.ChangeDutyCycle(int(config['DynRDSQN8066AmpPower']))
    logging.info('PWM2 duty cycle updated to {}%'.format(config['DynRDSQN8066AmpPower']))
    self.activePWM = True
  1. Modify # With everything stopped, disable PWM (from line 279):
     # With everything stopped, disable PWM
    if self.activePWM:
      logging.debug('Stopping PWM2')
      pwm_2.ChangeDutyCycle(0)
      logging.debug('PWM2 duty cycle = 0')
      GPIO.cleanup()
      logging.debug('GPIO cleanup')
      self.activePWM = False

MODIFY Dynamic_RDS.php:

  1. Delete or comment by "//" PWM0 detection on lines 97-99
  2. Modify line 100 to: PrintSettingGroup("DynRDSPowerSettings", "", "", 1, "Dynamic_RDS", "DynRDSFastUpdate");
  3. Modify end of file lines 116-124:
> <h2>PWM and audio hardware setup</h2>
> <div class="container-fluid settingsTable settingsGroupTable">
> For output power control of 
> Transmitter board: <li>Connect Transmitter board PWM input pin -> to RPi pin11 (GPIO17)</li> <li>Use ferrite bead around cable 
> between RPi and Transmitter board.</li> For HiFiBerry DAC: <li>Add line to /boot/config.txt:</li> <li>dtoverlay=hifiberry-dac</li> 
> <li>HiFiBerry/RPi connection: +5V/pin2, GND/pin6, BCK/pin12, LCK/pin35, Din/pin40</li> </div> </div>                                         
> <div class="container-fluid settingsTable settingsGroupTable">
> </div>
> </div>

MODIFY settings.json from line 115 (to 140):

>         "DynRDSQN8066ChipPower": {
>             "name": "DynRDSQN8066ChipPower",
>             "description": "Chip Power (92-122)",
>             "tip": "Adjust the power output from the transmitter chip",
>             "restart": 0,
>             "reboot": 0,
>             "type": "number",
>             "min": 92,
>             "max": 122,
>             "step": 1,
>             "suffix": "dB&mu;V <i class='fas fa-fw fa-bolt fa-nbsp ui-level-1'></i>",
>             "default": 120
> 	},
>         "DynRDSQN8066AmpPower": {
>             "name": "DynRDSQN8066AmpPower",
>             "description": "Amp Power (0-100)",
>             "tip": "Adjust the power output for the amplifier after the transmitter chip.",
>             "suffix": "% <i class='fas fa-fw fa-bolt fa-nbsp ui-level-1'></i>",
>             "restart": 0,
>             "reboot": 0,
>             "type": "number",
>             "min": 0,
>             "max": 100,
>             "step": 1,
>             "default": 0
> 	},

I am not so proffesional as Mr. Nick Anderson. I think that my code for Dynamic_RDS_Engine.py needs tunning, because I am only amateur. Eg. I was also not sucessful with attempt to not send PWM value repeatedly when not changed. But I tested this my solution in longer transmitter's operation sucessfuly.
I also think that when we will sucessful with improve i2c I/O errors during communication by replace SMBUS with "SOFTWARE I2C" than we can change all values setting on Plugin FPP web page to change for immediately update without need any restart (as I already realized above on PWM and chip power set).
I hope that Nick will be understanding :-)

Metadata

Metadata

Assignees

Labels

FPP changeA change or fix was needed in FPPdocumentationImprovements or additions to documentationenhancementNew feature or requesthardwareRelates to physical hardwarepending verificationFix is done. Waiting to confirm.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions