Arduino on FreeBSD

The Arduino IDE sucks and there's no need for it in a UNIX environment. Also the FreeBSD port of it is almost unusable. Luckily, you can write, compile, deploy and also monitor Arduino programs using just basic command line utilities. This article has now also been published on the FreeBSD Wiki.


Required ports:


Now that you have all the software installed add the following line to your /boot/loader.conf in case you want the Arduino kernel module to load automatically on boot. If you want to manually load the module whenever you need it, skip this step:


Load the kernel module:

	# kldload uarduno

Check your ~/.arduino/preferences.txt and see if the following lines exist (source):


Add your user to the dialer group:

	# pw group mod dialer -m $USER

Connecting the board

Standard Arduino boards connect as /dev/cuaU0 and/or /dev/ttyU0 on FreeBSD. In case these serial ports don't show up in /dev, you might need to press your board's reset button. After you've plugged your board into a USB port, you should get the following output from dmesg. Although the output may vary, the important thing is that your board is connected and detected.

	ugen1.5: <Arduino ( product 0x0043> at usbus1
	uarduno0: <Arduino ( product 0x0043, class 2/0, rev 1.10/0.01, addr 5> on usbus1

If dmesg returned information about your board, you should also see cuaU0 and/or ttyU0 in /dev. In case your board is still not detected - considering it's not a fake one, try using a different USB cable or reset it again and make sure you've followed the setup steps correctly.

The Makefile

As I said above, the only thing you're going to need in order to get started is just a Makefile that'll be used to compile and upload your Arduino programs. Make a new directory for your Arduino project and then make a Makefile with the following lines:

	ARDUINO_DIR= 	/usr/local/arduino
	ARDUINO_MK_DIR= /usr/local/arduino-bsd-mk
	ARDUINO_LIBS=	/usr/local/arduino/libraries
	ARDUINO_PORT= 	/dev/cuaU0
	ARDUINO_BOARD= 	your_board_name
	TARGET=		your_program_name

	include /usr/local/arduino-bsd-mk/

In this case my board is an Arduino Uno, but if you have a different one, edit the ARDUINO_BOARD variable. You can see which board types are available in /usr/local/arduino/hardware/arduino/boards.txt. If you want to install new libraries copy them over to /usr/local/arduino/libraries.

Building and uploading a program

So now the only thing you have to do is to actually write some Arduino code. After you're done writing your code and you're ready to compile and upload, run the following command:

	# make clean && make upload clean

If all went well you should see the board executing your new code, if it doesn't, try to see what errors the Makefile produced.


The Arduino IDE provides a serial monitor feature, but FreeBSD has a builtin monitoring utility which can be accessed directly from the terminal. Run this whenever you want to monitor your board and exit with ~!:

	$ cu -l /dev/cuaU0

Using board types other than the Uno

As it's mentioned above, we're using the uarduno kernel module. Even though the module's description is "FreeBSD Kernel Driver for the Arduino Uno USB interface", you can, in fact, use different board types other than the Uno. According to uarduno's website, you can modify /usr/ports/comms/uarduno/files/ids.txt to include a more board types; the two fields are Vendor ID and Product ID. Read the comments inside the file for more information.

	{ 0x2341, 0x0001 },  // Arduino UNO, vendor 2341H, product 0001H
	{ 0x2341, 0x0042 },  // Arduino MEGA (rev 3), vendor 2341H, product 0042H
	{ 0x2341, 0x0043 },  // Arduino UNO (rev 3), vendor 2341H, product 0043H
	{ 0x2341, 0x0010 },  // Arduino MEGA 2560 R3, vendor 2341H, product 0010H 
	{ 0x2341, 0x8037 },  // Arduino Micro

When you're done, clean and re-build the port.

Known issues and their fixes

Even though you might have plugged your board to your machine, you might notice that there is no device appearing in /dev. Although there is no definite answer as to why this is happening, make sure that the USB cable is connected properly; on some boards - certainly mine - you have to hear a click sound.

When trying to use a new library, you might notice that your code doesn't compile. Considering the library isn't broken, a common issue is that you haven't stored the library in the correct path. As already mentioned, libraries are stored in /usr/local/arduino/libraries, so you have to move it there.