Serial port communication support

Have there ever been any plans for JUCE to support serial port communications? (Obviously including via USB like what Arduino does.)

Until that time, you could use the JUCE Serial Port Library hosted here: I use it specifically to talk to Arduino’s.


Thanks, I’ll take a look at that!

I successfully used the asio (asynchronous I/O) library for that. Asio is part of boost but also available as lightweight header-only standalone version

1 Like


Do you have an example as how you use this? I’m new to Juce and trying to understand how to implement this.

Any direction would be great.


I just updated an older project of mine to work with the latest JUCE, and put it on github. I’ve also moved the serial port library to github as well… It’s an ‘example’ of how to use the library, but I can’t comment on the code quality… lol…

1 Like

Thank you.

In your cSerialPortListMonitor.cpp, line 39 you are referencing SerialPort::getSerialPortPaths()… however I can not see anywhere in the cSerialPortListMonitor.h file, importing “juce_serialport.h”?

How do you have access to the serialPort?

I have added the juce_serialport folder to the JUCE modules folder, thinking it would be included with “…/JuceLibraryCode/JuceHeader.h”

I have added the header and cpp file to Projucer, then launched it and included “juce_serialport.h” inside my file - states could not be found.

Or have I got it all wrong when adding / including external libraries?

If it’s a JUCE module the header should be included in JuceHeader.h and the source files will automatically be getting compiled for you, no need to add anything other than the the juce module to the Projucer.

Perhaps you didn’t add the module to your .jucer project?

What @anthony-nicholls and @richie said! :slight_smile:

Ok. Strange. I added the juce_serialport folder from your website, and placed it inside the Juce modules folder. Then added it inside of Projucer via ‘Add a module from a specified folder…’ and this is the resulting error:

However, when I added the juce_serialport folder to my desktop and re-add the module, it works.

Is this a known issue? Or should I never add any modules to the Juce module folder?

That’s it. I noticed that it does not work by adding any module to the JUCE module folder.
Instead you can simply create a folder for “user modules” which is linked into “Global Paths”.

I can’t comment on the underlying juce module mechanism, and whether or not 3rd party modules can be added to the JUCE modules folder, but it isn’t an issue specific to the serial port module. I put all of my 3rd party modules in a separate folder.

Did this solve your linking issue?

No it does not. I keep having the same linking error whether I add the module from the user module folder (global path) or from a separate folder. I just tried to write another simple project adding only the module and few lines to integrate serial port communications and it happens the same errors for all the functions I’m using.

I declare the related members in the header file as


class MainComponent : public Component

// Serial Ports 
StringPairArray portList;
SerialPortConfig SPConfig {9600, 8, SerialPortConfig::SERIALPORT_PARITY_NONE, SerialPortConfig::STOPBITS_1, SerialPortConfig::FLOWCONTROL_NONE};
SerialPort* pSP;
SerialPortInputStream * pInputStream;



and as follows in the constructor :


portList = SerialPort::getSerialPortPaths();
if (portList.size())
int numberOfPorts = portList.size();

    for (int i=0; i<numberOfPorts; ++i) {       // find the expected port to use
        String name = portList.getAllValues()[i];

        if (name == "/dev/tty.usbmodem143401")
            pSP = new SerialPort(portList.getAllValues()[1],SerialPortConfig(9600, 8, SerialPortConfig::SERIALPORT_PARITY_NONE, SerialPortConfig::STOPBITS_1, SerialPortConfig::FLOWCONTROL_NONE)); // create the serial port 
           pInputStream = new SerialPortInputStream(pSP);          // create stream for reading


The whole code compiles well. But still linker error

Hi Chris,

Dear Chris,

Hope you doing good. i’m trying to integrate this module into a juce project.
Following error happen. Can you help to check?

JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn’t find class “com.artiphon.juce_serial.UsbSerialHelper” on path: DexPathList[[zip file “/data/app/com.juce.audioplaybackdemo-MUG7xSP70eHXPcmEBK7J5A==/base.apk”],nativeLibraryDirectories=[/data/app/com.juce.audioplaybackdemo-MUG7xSP70eHXPcmEBK7J5A==/lib/arm64, /data/app/com.juce.audioplaybackdemo-MUG7xSP70eHXPcmEBK7J5A==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]


Hello everyone, Hi @cpr2323,

I often use this library for serial communication and it works great, however on Windows I keep getting memory leaks when closing the app, when Serial port is connected and used.

Does anyone have a simple code example with the lib ? Maybe @cpr2323, I read you have sent sample code.

Here’s what VS Code tells me about memory leaks when closing the app :

Detected memory leaks!
Dumping objects →
{150166} normal block at 0x000001F31B82E3B0, 96 bytes long.
Data: < <7: 8 > 80 3C 37 3A F7 7F 00 00 38 07 00 00 00 00 00 00
{150161} normal block at 0x000001F31B7B5460, 35 bytes long.
Data: < > 00 00 00 00 CD CD CD CD 0C 00 00 00 00 00 00 00
Object dump complete.

It seems weird to me that the class name is not explicit, and not even the same each time, and never coherent.

Maybe I’m doing something wrong and I would like to compare.

Thank you very much for your help.


I’m happy to take a look. I’ll double check my example code, and if you have a small example that exhibits this behavior, I can try that too. I fixed a bug recently (in Feb or March) so it would be good to know if your issue arose before,or after, that change

Sorry I missed your msg. Did you ever get this resolved? I didn’t do the Android implementation, but I check to see what is needed.

I’ve tried including the juce_serialport_master folder into modules by going projucer->modules->add a module from specific folder-> juce_serialport_master but it says this is not a valid module folder. Is this module still working? I need it like a diabetic needs insulin. My life depends on it.

Does JUCE not have a built in module for this?