-   Linux - Hardware (
-   -   arduino jdk and ttyACM0 not working? MINT (

cwc 03-08-2013 09:41 AM

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)

All times are GMT -5. The time now is 09:48 PM.