Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Raspberry PI 2 play AUDIO

burger
2015-12-03
2021-08-05
  • burger - 2015-12-03

    Hello,

    I want to play AUDIO files with my RPI2. What do I have to do in Codesys? My idea is to play AUDIO files when some digital bit is ON.

    regards

     
  • jvondrus - 2015-12-03

    Hello:

    Enable commands at /etc/CODESYScontrol.... (do not remember right name), add to settings:

    [SysProcess]
    Command=AllowAll
    

    OR more safety:

    [SysProcess]
    Command.0=aplay
    Command.1=mplayer
    ...
    

    In Codesys program add variable:

    VAR
       cmdResult   :    RTS_IEC_result;               // Command Result
    END_VAR
    

    And use command for play the sound (for aplay command):

    SysProcess***ExecuteCommand('aplay /theway/tomusic/sound.wav', ADR(cmdResult));    // Delete that "***", I have to add it because forum filtering it
    

    Remember, that program will stop at command until the sound is played. Its better to make 2nd Task for sound playing with using some buffer or mark at GLOBAL VARIABLE.

    IF soundState THEN SysProcess***ExecuteCommand('aplay /theway/tomusic/sound.wav', ADR(cmdResult)); soundState:= FALSE; END_IF     // Delete that "***", I have to add it because forum filtering it
    

    Maybe you have to add library:
    SysTypes Interfaces
    SysProcess

     
  • burger - 2015-12-04

    Thank you! This worked fine.

     
  • loloka09 - 2016-03-13

    jvondrus hat geschrieben:
    Maybe you have to add library:
    SysTypes Interfaces
    SysProcess

    Hallo jvondrus,

    How can I add this library?
    Thanks, your help!

    regards

     
  • eschwellinger

    eschwellinger - 2016-03-13

    Hi,
    see screenshot just type in what you know from the library - name of an FB or name of the Lib

    BR
    Edwin

    IMG: AddSysTypes2.jpg

    IMG: addLibrary.jpg

     
  • mike197678 - 2016-11-15

    Hello,

    I am currently testing a video file with:

    Video_1: STRING: = 'sudo omxplayer -o both /home/pi/media/test.mp4';

    The file is also played via the "omxplayer".
    Works perfect,
    But how can I finish playing that prematurely?

    In the terminal I press "q"

    is that possible?

    Thank you very much
    mfg mike

     
  • hiright - 2017-03-20

    Edit: I got it working. Now that I have an account I can see the screenshot mentioned above. Just an addition, I had to click on the "display advanced libraries" in the Add Library window.

    I am interested in getting this code to work on my Raspberry Pi 3 using CODESYS V3.5 SP10 P2 +. I have SysTypes Interfaces (3.5.2.0) and SysProcess (3.5.7.0) installed. I'm very new to CODESYS and Raspberry Pi.

    In declaring the variable cmdResult, there is an error "Identifier 'RTS_EIC_result' not defined". I also tried

    cmdResult   : POINTER TO RTS_IEC_result;
    

    but I get the same error.

    Also, regarding the SysProcessExecuteCommand (minus the ) I have the same "Identifier not defined" error. Is there an "Import" that I'm missing?

    jvondrus hat geschrieben:
    Hello:

     
  • agustinomg - 2018-10-30

    I also have the same error RTS_IEC_RESULT Module not found, does anyone knows how to solve this problem.

    Thank you best regards

     
  • Nira - 2019-03-21

    is there someone who can explain me how to play an audio file in Codesys through LD.
    I have added a file (.WAV) with Filezilla, or it is also possible to add a audio file in Codesys by right-clicking on application and add file.

    IMG: add.JPG

    IMG: Sysprocess.JPG

    IMG: Library Manager.JPG

    IMG: Filezilla.JPG

    IMG: Codeys.JPG

     
  • Nira - 2019-03-27

    Thank you dor your replay, very helpfull.
    Let me start from the beginning.
    I open a new project > standard project > PLC PRG in LD > Add library's SysProcess and SysTypes 2 Interfaces.
    Add POU > Funktion block > in open in ST > Then add the code like in the screenshot

    Make a prg like in the screenshot.

    Add the file in the device like in the screenshot.

    Buils the program with no fault.

    If i put the software in simulation and build te program i get a fault like in the screenshot.

    IMG: fault.JPG

    IMG: no fault.JPG

    IMG: add sound file.JPG

    IMG: prg.JPG

    IMG: ST.JPG

    IMG: Pou.JPG

     
  • toatan-th - 2020-08-27

    Someone can give sample project for Raspi play audio.
    Thank you

     
    • Morberis

      Morberis - 2020-08-27

      @eschwellinger linked to one I believe, here's the link.

       

      Last edit: Morberis 2020-08-27
  • toatan-th - 2021-08-05

    how to change sound file

     
  • toatan-th - 2021-08-05
     

    Last edit: toatan-th 2021-08-05

Log in to post a comment.