Hello everybody,
I'm trying to connect my monome grid to Bela with this puredata patch that works in my computer but not in the Bela Libpd (it says connecting to port 16219 but doesn't really work, neither print anything)

alt text

Thanks in advance for any help

[EDIT: deleted the previous comment]

@txarliema
Is the monome connected directly to Bela? Is it a USB device? Does it show up when you run lsusb?

Some work has been done to get the Monome to work on Bela (though not with Pd): https://forum.bela.io/d/240-monome-grid-bela, and it seems that you need some extra software besides Pd. The last post there makes a reference to the need for serialoscd to be running for the Monome to work? Do you have something like that (or some dedicated software?) running on the host that you don't have on Bela? Judging from the name of the program (serialoscd), I'd assume the Monome should show up as a serial interface on Bela? Does It? try: ls /dev/tty* with and without the Monome connected.

    giuliomoro
    Many thanks Giuliomoro for your help.

    Yes, the monome is a USB serialosc device, is connected directly to the Bela and it shows up when I run ls /dev as ttyUSB0 ... and it even reacts when I run screen /dev/ttyUSB0 connected to the Bela.

    Among the several discussions I checked out I was using the script from padenote bela-setup-monome.sh in the discussion you also mentioned https://forum.bela.io/d/240-monome-grid-bela to install libmonome and serialosc in the Bela, and to run serialoscd on the bela boot ... so, I thought it was properly installed and running, but it seems like actually it wasn't.

    After reading your reply I decided to install myself libmonome and serialosc following the instructions from here https://monome.org/docs/linux/ ... quite successful since I received this answers from the terminal when I'm running root@bela:~/serialosc/build/bin# ./serialoscd

    serialosc [m1000328]: connected, server running on port 17395
    serialosc [m1000328]: disconnected, exiting (when I disconnect the monome from the Bela)

    If I run serialoscd from a C++program in the Bela IDE I receive the same answer (connecting and disconnecting the monome from the Bela... attached a screenshot of the C++program with the answers of the console)

    So ... I asume that the Bela definitely recognise the monome

    But (silly enough) I still don't know if I have to run serialoscd in order to make the monome connection active or serialoscd is just a program to monitor if the monome is connected.

    And, if I should run serialoscd, I don't know how to do it ... or how to combine the C++ program to run serialoscd and my puredata patch. Sorry but I only know puredata and I have no idea about C++, and not an expert using terminal (https://github.com/BelaPlatform/Bela/wiki/Puredata-and-C-- and examples/08-PureData/customRender/ becomes quite difficult for me to follow)

    I also tried to change in my puredata patch the ports to [listen 17395( - [netreceive-u -b] and/or [connect localhost 17395( - [netsend -u -b] ... and didn't work neither

    So I keep [listen 12289( - [netreceive -u -b] and [connect localhost 16219( - [netsend -u -b] which are the ports that works at the computer (still not at the Bela)

    Thanks again for your help

    alt text

      txarliema so, I thought it was properly installed and running, but it seems like actually it wasn't.

      That's expected: we wouldn't necessarily install on our image everything that is reported to be working with Bela.

      txarliema But (silly enough) I still don't know if I have to run serialoscd in order to make the monome connection active or serialoscd is just a program to monitor if the monome is connected.

      I know nothing about it, but I would guess that serialoscd is a bridge between OSC and the monome: my guess is that it receives OSC messages from the user application and passes them over to the monome over serial, and also receives serial from the monome and passes it on as OSC to the user application. So, I guess it has to stay open throughout for the program to work!

      txarliema or how to combine the C++ program to run serialoscd and my puredata patch.

      that C++ program is really just doing the equivalent of starting serialoscd. You can replace it by starting serialoscd manually in a separate terminal (or in the console at the bottom of the IDE). These lines in padenot's script set serialoscd as a systemd service that will run automatically every time you start the board.

      txarliema I also tried to change in my puredata patch the ports to [listen 17395( - [netreceive-u -b] and/or [connect localhost 17395( - [netsend -u -b] ... and didn't work neither

      Judging from your log, serialoscd seems to use 17395 by default, so that is what you should have in Pd. But again, for this to work you need serialoscd to be running at the same time, either manually starting it in a separate terminal (or in the IDE), or by setting it up as a systemd process.

      This is my understanding, judging from the information you provided and padenot's post, but without knowing anything about the specific program / hardware.

        giuliomoro
        Thanks a lot again Giuliomoro

        giuliomoro txarliema so, I thought it was properly installed and running, but it seems like actually it wasn't.

        That's expected: we wouldn't necessarily install on our image everything that is reported to be working with Bela.

        I meant that I was expecting to have them installed and running on boot only after running the padenot script bela-setup-monome.sh ... which didn't work for me. I didn't mean that I was expecting to have it "by default" in the Bela image. Sorry for the misunderstanding

        Good news!!! I'm almost there!!!!

        I accessed to the serialosc configuration ~/.config/serialosc/<your_monome_id>.conf. and found both port numbers for the netsend (8000) and the netreceive (17395). Then, and after running serialoscd, the puredata patch runs and comunicate perfectly between bela and monome through those correct ports.

        What I need to figure out now is how to run serialoscd on boot, since I want to use the bela as standalone
        The script from padenot still doesn't work for me and I don't know how to make a systemd myself

        I tried to add at the beginning of the render.ccp program of 08-PureData/customRender/ those lines:
        #include <Bela.h>
        #include <cstdlib>
        int main() {
        std::system("/root/serialosc/build/bin/serialoscd");
        return 0;
        }

        to combine my PureData patch with my previos simple C++ program that runs serialoscd ... but still doesn't work. It runs serialoscd propertly from the C++ render.ccp (located on Sources) but it looks like it never runs my PureData patch _main.pd (which I located with a substitution of the one that was originally on Resources)

        Any clue about how to combine C++ and PureData to run serialoscd, please?

          In every Bela program, there is a default main() function that takes care of parsing the command-line options and initializing and starting the audio engine. The user normally does not need to see this, however they can override if they so wish (for instance in order to parse custom command-line options).

          txarliema I tried to add at the beginning of the render.ccp program of 08-PureData/customRender/ those lines:
          #include <Bela.h>
          #include <cstdlib>
          int main() {
          std::system("/root/serialosc/build/bin/serialoscd");
          return 0;
          }

          this effectively replaces the default main() function in the Bela code, so that the only thing that gets executed is this function of yours (as it contains no calls to the Bela_...() functions).

          systemd on the board manages which programs run at startup. For instance, it manages when and how to start the networking between the board and your computer, and it manages the Bela program that runs at startup. In order to enable a program to run at startup, you need to create a bespoke systemd "unit". This is achieved by placing a file in /lib/systemd/system with the appropriate name and content, and then enabling it (either by calling systemctl enable or by creating a symlink to it into /etc/systemd/....

          As mentioned earlier, padenot's script does exactly this.

          giuliomoro These lines in padenot's script set serialoscd as a systemd service that will run automatically every time you start the board.

          The lines I linked to above are copy/pasted below for your convenience:

          cat << EOF > serialoscd.service
          [Unit]
          Description=simple
          [Service]
          Type=forking
          ExecStart=serialoscd
          PIDFile=/var/run/serialoscd.pid
          RemainAfterExit=no
          Restart=on-failure
          RestartSec=5s
          [Install]
          WantedBy=multi-user.target
          EOF
          
          chmod 777 serialoscd.service
          mv serialoscd.service /lib/systemd/system/serialoscd.service
          ln -s /lib/systemd/system/serialoscd.service /etc/systemd/system/multi-user.target.wants/serialoscd.service

          this is the equivalent of:
          - creating a file serialoscd.service with this content:

          [Unit]
          Description=simple
          [Service]
          Type=forking
          ExecStart=serialoscd
          PIDFile=/var/run/serialoscd.pid
          RemainAfterExit=no
          Restart=on-failure
          RestartSec=5s
          [Install]
          WantedBy=multi-user.target

          making it executable and moving it to /lib/systemd/system/, and then calling systemctl enable serialoscd. Run the above lines once, and reboot: you should find out that serialoscd has already been started. To check its log, run: journalctl -fu serialoscd.

            giuliomoro
            Thanks Giuliomoro. Amazing help!!!

            I've got it working very good now with a C++ program combined with my puredata patch from BOOT.

            The systemd from Padenot I didn't try it yet, and I'm going to leave it for later, since now I prefer to develope the option of PD + C++ programs.

            For the record, here the modifications I did of the default main()

            I added the lines

            98 		 system("/root/serialosc/build/bin/serialoscd");
            99		 system("oscsend localhost 10567");

            of course the path of the serialoscd might be different in other users
            and the port number must be the same that the one used on pd patch

            Here I paste the whole render.ccp source (after adding those lines)

            /*
             * default_main.cpp
             *
             *  Created on: Oct 24, 2014
             *      Author: parallels
             */
            #include <unistd.h>
            #include <iostream>
            #include <cstdlib>
            #include <libgen.h>
            #include <signal.h>
            #include <getopt.h>
            #include "../include/Bela.h"
            
            using namespace std;
            
            // Handle Ctrl-C by requesting that the audio rendering stop
            void interrupt_handler(int var)
            {
            	gShouldStop = true;
            }
            
            // Print usage information
            void usage(const char * processName)
            {
            	cerr << "Usage: " << processName << " [options]" << endl;
            
            	Bela_usage();
            
            	cerr << "   --help [-h]:                        Print this menu\n";
            }
            
            int main(int argc, char *argv[])
            {
            	BelaInitSettings* settings = Bela_InitSettings_alloc();	// Standard audio settings
            
            	struct option customOptions[] =
            	{
            		{"help", 0, NULL, 'h'},
            		{NULL, 0, NULL, 0}
            	};
            
            	// Set default settings
            	Bela_defaultSettings(settings);
            	settings->setup = setup;
            	settings->render = render;
            	settings->cleanup = cleanup;
            
            	while (1) {
            		int c = Bela_getopt_long(argc, argv, "h", customOptions, settings);
            		if (c < 0)
            		{
            			break;
            		}
            		int ret = -1;
            		switch (c) {
            			case 'h':
            				usage(basename(argv[0]));
            				ret = 0;
            				break;
            			default:
            				usage(basename(argv[0]));
            				ret = 1;
            				break;
            		}
            		if(ret >= 0)
            		{
            			Bela_InitSettings_free(settings);
            			return ret;
            		}
            	}
            
            	// Initialise the PRU audio device
            	if(Bela_initAudio(settings, 0) != 0) {
            		Bela_InitSettings_free(settings);
            		fprintf(stderr,"Error: unable to initialise audio\n");
            		return 1;
            	}
            	Bela_InitSettings_free(settings);
            
            	// Start the audio device running
            	if(Bela_startAudio()) {
            		fprintf(stderr,"Error: unable to start real-time audio\n"); 
            		// Stop the audio device
            		Bela_stopAudio();
            		// Clean up any resources allocated for audio
            		Bela_cleanupAudio();
            		return 1;
            	}
            
            	// Set up interrupt handler to catch Control-C and SIGTERM
            	signal(SIGINT, interrupt_handler);
            	signal(SIGTERM, interrupt_handler);
            
            	// Run until told to stop
            	while(!gShouldStop) {
            		usleep(100000);
            		 system("/root/serialosc/build/bin/serialoscd");
            		 system("oscsend localhost 10567");
            	}
            
            	// Stop the audio device
            	Bela_stopAudio();
            
            	// Clean up any resources allocated for audio
            	Bela_cleanupAudio();
            
            	// All done!
            	return 0;
            }

              When you paste code, please remember to enclose it in triple backticks (```). I edited your message above.

              txarliema whole render.ccp

              that's main.cpp

              txarliema
              98 system("/root/serialosc/build/bin/serialoscd");
              99 system("oscsend localhost 10567");

              I don't think this is a great approach. You should really use a systemd service, as mentioned above, in the long run. Unless oscsend returns immediately, that would block the program, and prevent it from exiting gracefully. Not a big deal, but not clean either. But if this works for your prototyping ...