using muxers on the digital inputs would allow to increase the number of digital inputs at the expense of lowering their sampling rate. Using muxers generally requires loads of wires and using a bespoke pcb would be ideal. This would also cause troubles if you were to use rotary encoders, in which case you would need some shift registers.
Additionally, if you were to use some of the digital IOs to drive the muxer, you would then lose some of the available IOs.
If you need more than 16 digital inputs, an option could be to use the Bela multiplexer capelet, which has a 8x multiplexer connected to the analog inputs. This uses a custom PRU code to drive the multiplexer logic.

2 months later
2 months later

giuliomoro I'm curious about the net receive replacement for libpd...
Did you get it to work?

Apologies for the delay. What stopped me so far is that I wanted to find a unified solution for libpd and heavy, which would not use [netsend] and [netreceive], but instead something like:

[r bela_netreceive]
|   
|  [r bela_netereceive_port]
| / 
|/
[print]
[r bela_netsend]
|   
|  [r bela_netsend_destination]
| / 
|/
[print]

I plan to do this by the end of the week.

In order to capture the keys from an usb-kbd and send yo Pd, I tried this and I think it work:

render.cpp

 #include <fcntl.h>
 #include <linux/input.h>
 
 // Task for read the qwerty kbd
 AuxiliaryTask gInputTask;
 
 void read_kbd();
 
 // global variables to receive keys from the auxiliary thread
 bool newKeyEvent = false;
 int keyValue = 0;
 int keyType = 0;

in setup()

   // start qwerty kbd capture thread
 	if((gInputTask = Bela_createAuxiliaryTask(&read_kbd, 50, "bela-read-input")) == 0)
 		return false;

in render()

         if (newKeyEvent)
         {
         	if(keyType == 0)
              	libpd_float("keyup", (int)keyValue);
         	if(keyType == 1)
              	libpd_float("key", (int)keyValue);
		newKeyEvent = false;
	}
	Bela_scheduleAuxiliaryTask(gInputTask);

and

void read_kbd(){

	// Variables keyboard control
	struct input_event ev;
	ssize_t n;
	const char *dev = "/dev/input/event0";
	int fd;

	   // qwerty keyboard capture
 	fd = open(dev, O_RDONLY);
	if (fd == -1) {
		fprintf(stderr, "Cannot open %s:.\n", dev);
		return;
	}

	bool shouldStop = false;
	int n;
    
	while (!shouldStop && !gShouldStop)
	{
		n = read(fd, &ev, sizeof(ev));
		if (n == (ssize_t)-1) {
			shouldStop = true;
		} else if (n != sizeof(ev)) {
			shouldStop = true;
		} else
		{
			if (ev.type == EV_KEY && ev.value == 0 && ev.value <= 2)
			{
				keyType = 0; // key released
				keyValue = (int)ev.code;
				newKeyEvent = true;
			}
			if (ev.type == EV_KEY && ev.value == 1 && ev.value <= 2)
			{
				keyType = 1; // key pressed
				keyValue = (int)ev.code;
				newKeyEvent = true;
			}
			// I'm filtering key repetitions
		}
	}
 }

    alexBarrachina Thanks for sharing your solution.

    NOTE: I reformatted your post, you should use triple backtick (```) to enclose lines of code.

    8 days later
    giuliomoro changed the title to [Solved] USB vs Analogue in/outs .
    giuliomoro changed the title to USB vs Analogue in/outs .
    5 years later

    @tkay

    To copy that file you could:

    • copy the core/default_libpd_render.cpp file into your project. Assuming you have a project called PROJECT_NAME, you can do this by pasting this in the console at the bottom of the IDE:
      cp /root/Bela/core/default_libpd_render.cpp /root/Bela/projects/PROJECT_NAME/render.cpp
      and hit enter.
    • then you can edit the newly created render.cpp file using the IDE editor following the instructions above.
    • last, the Pd patch in the same project will need receivers such as [receive keyup] and `[receive key]
    giuliomoro changed the title to USB keyboard vs Analogue in/outs key matrix .
    a year later

    see this example ready for use: https://github.com/giuliomoro/bela-pd-keyboard. Note that only some keys are mapped to Pd all numbers and lowercase letters are mapped, and also these:

            COMMA , \
            DOT . \
            SLASH / \
            SPACE " " \
            ENTER "\\\\n" \
            SEMICOLON ";" \
            APOSTROPHE "\\\\'" \
            KPASTERISK "*" \

    If you see keys that do not work, you need to add them to this list in generate-parse.sh and run the script before rebuilding your project.

    Nice! Thanks so much. One thing though, I was planning on using a number keypad, not a full keyboard and it seems only the asterisk works. How exactly do I add these keys to the working parse? I saw generate parse file, but didnt quite know how to add these. Where can i see the Input event codes?

    OK I updated the files in the repo to include the numpads and some more keys. If a code is not recognised it will now be printed to the console. You can then go to /usr/include/linux/input-event-codes.h (e.g.: https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/input-event-codes.h , but better on the board itself) and figure out what's the name of the KEY_ macro corresponding to that event. You can then (probably) add that with some care to the pairs array in generate-parse.h.

    Anyhow, for now the numpad should work. Try it out.

    6 days later

    If this works with Pepper too, it's exactly what I was looking for!