Two way serial communication with raspberry Pi (radio project)

I wonder if the bootloader is eating your data.

Immediately after the serial port is opened, the Arduino spends about 1500ms in the bootloader waiting to see if you are about to upload a new sketch.

During this time, any serial output sent from the PC side is interpreted by the bootloader, not your program. Mostly, it is ignored. Just like what you are seeing.

The unix 'echo' command opens the port and writes to it right away. This works fine on the serial monitor, but because of the bootloader problem it won't work on arduino.

If this reasoning is sound, you need a little program to open the serial port and wait a couple seconds before sending the playlist length, rather than using 'echo'.

-br

Edit: Another way, besides waiting a fixed time, is to wait for a character string from the arduino to signal 'ready'. Bitlash, for example, sends '\n> ' as a prompt when it's ready. You can see this at work in the bloader.js program, which uploads files to Arduino over the serial port: