LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 03-08-2013, 10:41 AM   #1
Registered: Nov 2004
Location: Tri-Cities, WA
Distribution: Gentoo, Ubuntu, Mint,Fedora
Posts: 62

Rep: Reputation: 16
arduino jdk and ttyACM0 not working? MINT

I lost my connection to /dev/ttyAMC0 after running a java app
- I've got Arduino 1.01 installed on Linux MInt 14. (I've also used Win 7, Mac OSX 10.5+, and Gentoo)
- My boards work.
- I also have Oracle JDK installed
cwc@dog26 ~/java $ java -version
java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode)

- Here are my groups
cwc@dog26 ~ $ groups
cwc adm dialout cdrom sudo dip plugdev lpadmin sambashare

Here is my tty
- cwc@dog26 ~ $ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Mar 7 19:01 /dev/ttyACM0

Here's what happened.
I ran some simple arduino code that collected input from A0 and I was able to get this to work.
And use the serial monitor to get output.
Then I compiled and ran a application and I lost /dev/ttyACM0 via Arduino


Now I must say I compiled and ran the program with out setting this line correctly fist:
private static final String PORT_NAMES[] = { "/dev/ttyACM0"};
Here's the Java I ran:

int lightPin = 0;  //define a pin for Photo resistor
int ledPin=11;     //define a pin for LED
int input = 0;
int ainput = 0;
int count = 0;

void setup()
    Serial.begin(9600);  //Begin serial communcation
    pinMode( ledPin, OUTPUT );

void loop()

    analogWrite(ledPin, analogRead(lightPin)/4);  //send the value to the ledPin. Depending on value of resistor 
      count ++;
     input = analogRead(lightPin); 
     ainput = ainput + input;
     Serial.print('        '); 
                                    divide by 4.
  // delay(1000); //short delay for faster response to light.
  if (input < 300) {
  // Serial.print(input);
 //   Serial.print('   ');
//   Serial.println(count);
      count ++;
import java.util.Enumeration;

public class SerialTest implements SerialPortEventListener {
	SerialPort serialPort;
        /** The port we're normally going to use. */
	private static final String PORT_NAMES[] = { "/dev/ttyACM0"};
	* A BufferedReader which will be fed by a InputStreamReader 
	* converting the bytes into characters 
	* making the displayed results codepage independent
	private BufferedReader input;
	/** The output stream to the port */
	private OutputStream output;
	/** Milliseconds to block while waiting for port open */
	private static final int TIME_OUT = 2000;
	/** Default bits per second for COM port. */
	private static final int DATA_RATE = 9600;

	public void initialize() {
		CommPortIdentifier portId = null;
		Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

		//First, Find an instance of serial port as set in PORT_NAMES.
		while (portEnum.hasMoreElements()) {
			CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
			for (String portName : PORT_NAMES) {
				if (currPortId.getName().equals(portName)) {
					portId = currPortId;
		if (portId == null) {
			System.out.println("Could not find COM port.");

		try {
			// open serial port, and use class name for the appName.
			serialPort = (SerialPort),

			// set port parameters

			// open the streams
			input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
			output = serialPort.getOutputStream();

			// add event listeners
		} catch (Exception e) {

	 * This should be called when you stop using the port.
	 * This will prevent port locking on platforms like Linux.
	public synchronized void close() {
		if (serialPort != null) {

	 * Handle an event on the serial port. Read the data and print it.
	public synchronized void serialEvent(SerialPortEvent oEvent) {
		if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
			try {
				String inputLine=input.readLine();
			} catch (Exception e) {
		// Ignore all the other eventTypes, but you should consider the other ones.

	public static void main(String[] args) throws Exception {
		SerialTest main = new SerialTest();
		Thread t=new Thread() {
			public void run() {
				//the following line will keep this app alive for 1000 seconds,
				//waiting for events to occur and responding to them (printing incoming messages to console).
				try {Thread.sleep(1000000);} catch (InterruptedException ie) {}
dog26 ~ # lspci
00:00.0 Host bridge: Intel Corporation Mobile 945GM/PM/GMS, 943/940GML and 945GT Express Memory Controller Hub (rev 03)
00:02.0 VGA compatible controller: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev 03)
00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/GME, 943/940GML Express Integrated Graphics Controller (rev 03)
00:1b.0 Audio device: Intel Corporation NM10/ICH7 Family High Definition Audio Controller (rev 01)
00:1c.0 PCI bridge: Intel Corporation NM10/ICH7 Family PCI Express Port 1 (rev 01)
00:1c.1 PCI bridge: Intel Corporation NM10/ICH7 Family PCI Express Port 2 (rev 01)
00:1c.3 PCI bridge: Intel Corporation NM10/ICH7 Family PCI Express Port 4 (rev 01)
00:1d.0 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #1 (rev 01)
00:1d.1 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #2 (rev 01)
00:1d.2 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #3 (rev 01)
00:1d.3 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #4 (rev 01)
00:1d.7 USB controller: Intel Corporation NM10/ICH7 Family USB2 EHCI Controller (rev 01)
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev e1)
00:1f.0 ISA bridge: Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge (rev 01)
00:1f.2 IDE interface: Intel Corporation 82801GBM/GHM (ICH7-M Family) SATA Controller [IDE mode] (rev 01)
02:06.0 CardBus bridge: Texas Instruments PCIxx12 Cardbus Controller
02:06.2 Mass storage controller: Texas Instruments 5-in-1 Multimedia Card Reader (SD/MMC/MS/MS PRO/xD)
02:06.3 SD Host controller: Texas Instruments PCIxx12 SDA Standard Compliant SD Host Controller
02:06.4 Communication controller: Texas Instruments PCIxx12 GemCore based SmartCard controller
08:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5753M Gigabit Ethernet PCI Express (rev 21)
10:00.0 Network controller: Intel Corporation PRO/Wireless 3945ABG [Golan] Network Connection (rev 02)

Last edited by cwc; 03-09-2013 at 06:42 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Arduino IDE not working brianL Slackware 3 03-02-2013 06:19 AM
[SOLVED] Arduino MEGA 2560 REV3, Arduino IDE working software versions jamesf Slackware 1 05-02-2012 01:56 AM
jdk not working crash_override_me Ubuntu 3 10-18-2005 01:35 PM
jdk 5.0 not working in Ubuntu crash_override_me Ubuntu 5 09-08-2005 01:13 PM
jdk 1.3.1_06 not working in mandrake 9.2 zho40 Linux - Software 4 12-15-2003 01:09 PM

All times are GMT -5. The time now is 07:56 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration