Arduino + openFrameworks + Firmata ok on OS X but not Ubuntu

Hello all,

I’m using the Arduino Uno SMD version in an openFrameworks project (oF version 0062) using Firmata (the standard Uno version that comes with the latest Arduino IDE). Everything works great on my development platform (OS X 10.6) but when I move to Ubuntu 10.10 I’m having problems. Since Arduino is running Firmata, I’m assuming I don’t even have to get the Arduino IDE running on Ubuntu. So when I plug in the Arduino, I can see that it’s running on /dev/ttyACM0. I switched my openFrameworks code to connect on this port, and though it is not listed among the enumerated devices, it reports that the Arduino is set up correctly. Also, I can run the oF Firmata example, though it seg faulted once or twice.

The circuit is simple, I’ve just got a bunch of momentary switches (joysticks) wired directly from the digital inputs to ground. I set the pins to be inputs, and I turn on the internal pullup resistors so that each pin reads ‘1’ when the switch is disconnected, and ‘0’ when it is connected. So, with all my joysticks disconnected, all pins return ‘1’.

However, in linux the digital inputs are not all returning ‘1’ like they are supposed to. Pins 2 and 3 return 1, but the rest are returning 0. Also, sometimes my program seg faults for no apparent reason. I assume this is related to the seg faults I experienced with the openFrameworks Firmata example.

I don’t really know where to start debugging this… any ideas?


I went ahead and installed the Arduino IDE so I could run my initial test sketch, and that worked just fine (all inputs reporting ‘1’), so I think it has something to do with either Firmata or openFrameworks on linux.

Further debugging shows that the Arduino is working as expected - I ran a quick test in Processing using their Firmata library on both OS X and Linux and it works great.

So it’s down to a bug somewhere in openFrameworks, either in ofArduino or ofSerial.

At first I didn’t think any of the pins were working in Linux but as it stands pins 2 and 3 are working correctly; all other pins are returning ‘0’.

mm, usually in linux the serial port is something like /dev/ttyUSB0. haven’t seen anything like /dev/ttyACM0 before. but perhaps it has changed lately?

anyway, will take a look later

Thanks arturo, I’d really appreciate it. FYI the new Arduino UNO’s don’t use the FTDI USB to Serial chips anymore, which I think is why they show up at ttyACM0 instead of ttyUSB0.

Can you test with just using an ofSerial instance and sending a single character from the Arduino? ofArduino just uses an ofSerial instance to facilitate comm between the OF app and the Arduino, so if the problem isn’t in ofSerial it should be easy to track down.

Good idea. Here’s the code, it works correctly on both platforms (shows a stream of console output; seven or eight lines of ‘byte = -2’ followed by a line of ‘process this byte: A’).

Arduino code:

void setup()  
  // start serial port at 9600 bps:  
void loop()  
    Serial.print('A', BYTE);   // send a capital A  

openFrameworks code:

I just copied the ‘update’ code from ofArduino.cpp, with the one correction I saw on github to check for byte >= 0 instead of != -1, since OF_SERIAL_NO_DATA is -2.

void testApp::setup(){	   
	serial.setup("/dev/tty.usbmodem1d11",9600); // mac osx  
	//serial.setup("/dev/ttyACM0", 9600);	    // linux  
void testApp::update(){  
	int dataRead=0;  
	// try to empty the _port buffer  
	while (dataRead<512) {  
		int byte = serial.readByte();  
		// process data....  
		if (byte>=0) {  
			std::cout << "process this byte: " << (char)byte << std::endl;  
		// _port buffer is empty  
			std::cout << "byte = " << byte << std::endl;  
void testApp::draw(){  

I don’t see anything that looks problematic in the ofArduino code, but it seems like if you’re in a pinch you could just set up a simple communication protocol to send button press info with something like “D1” to indicate a button press on digital pin 1. I’ve had some trouble getting the Uno to communicate with my linux laptop that’s unrelated to OF, so it’s nice to see that you got yours working.

I’ve also had trouble with Arduino. I loaded firmata onto the UNO SMD edition, loaded the OF 0062 firmata example, and only some of the functions seem to work. clicking on the screen will light up one LED, but the one that is connected to the PWM pin does not do anything. It also shows -1 for the analog input at all times, no matter what I have connected to it. I’ve also seen a few intermittent seg faults for seemingly no reason.

I’ll probably end up doing a simple serial protocol as joshuanobel suggested, as I really only need to sense a few switches.

If I find anything out about the firmata woes, I’ll report back though.

Works w/ firmata_test running in background.

Can confirm issues w/ analog input on Linux (Ubuntu 9.10) + Arduino UNO.
Wrote simple test app for sending digital input + reading an analog value.

Windows 7: Works fine.
Ubuntu 9.10: I also get -1 when I try to read the analog values. Sending digital values work. Notice segmentation fault sometimes.

*But* the code seems to work if I have firmata_test running in the background. (downloaded from

getAnalog(int pin) returns -1 if there is no analog history.
getAnalogHistory(int pin) returns 2 (_analogHistoryLength = 2 in constructor) with firmata_test, and 0 without firmata_test running in background.