How to control the Amp2 from HifiBerry ?

yann2021
2023-06-21
2023-07-04
  • yann2021 - 2023-06-21

    Hello,

    To have a good sound quality I would like to use the Amp2 from HifiBerry:
    https://www.hifiberry.com/shop/boards/hifiberry-amp2/
    Is it possible to control it from Codesys? If yes how?

    Many thanks in advance for your replies.
    Yann

     

    Last edit: yann2021 2023-06-21
  • eschwellinger

    eschwellinger - 2023-06-21

    I do it for example on a Wago Touchpanel 600 that way:
    (Play sound)

    IF xTest OR PLC_PRG.xAlarm THEN 
        //SysProcess.SysProcessExecuteCommand('aplay /var/opt/codesys/alarm1.wav', ADR(Result)); 
        SysProcess.SysProcessExecuteCommand('aplay /var/opt/codesys/PlcLogic/Application/alarm1.wav', ADR(Result)); 
        xTest := FALSE; 
    END_IF 
    
     
  • yann2021 - 2023-06-23

    Hello,

    Many thanks for your answer. What exactly "ADR(Result)" do? How should I declare it?

    Yann

     
    • hermsen

      hermsen - 2023-06-27

      You define a Result in your PLC code, to monitor wether the SysProcess.SysProcessExecuteCommand returns a succes or fail.

       
  • yann2021 - 2023-06-27

    Hello,
    Many thanks, it's working but now how can I adjust the volume ?

     
  • eschwellinger

    eschwellinger - 2023-06-27

    google for 'amixer' cmd under linux

     
  • yann2021 - 2023-06-27

    Hello,
    Of course with:
    "amixer cset numid=3 50%"
    I can change the volume. This is working only if the sound is played in the command line on the Raspi (via Putty) with the command:
    "aplay /home/pi/mb/post.wav"
    But when the command is done via Codesys with:
    "SysProcessExecuteCommand('aplay /home/pi/mb/post.wav', ADR(cmdResult));"
    the volume set before seems ignored and the sound is played at the maximum volume...
    What can I do...?

    Thx
    Yann

     
  • eschwellinger

    eschwellinger - 2023-06-27

    if you call the amixer command via CODESYS?

     
    • yann2021 - 2023-06-28

      Hello,
      I tryed this:

      SysProcessExecuteCommand('amixer cset numid=3 20%', ADR(cmdResult2));           
      SysProcessExecuteCommand('aplay /home/pi/mb/post.wav', ADR(cmdResult));
      

      But it's not working... the sound is played but the volume is still at maximum...

       
  • yann2021 - 2023-07-04

    Hello,
    Any other hints...?

     

Log in to post a comment.