-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,60 @@ | ||
# arduino-nano-setup | ||
Arduino Nano V3.0 ATmega328 CH340G playground on Ubuntu 15.10 | ||
|
||
![Arduino Nano V3.0 ATmega328 CH340G](https://github.com/Pozo/arduino-nano-setup/blob/master/arduino-ano-v3.0-atmega328-ch340g.jpg "Arduino Nano V3.0 ATmega328 CH340G") | ||
|
||
#### Driver (already installed) | ||
|
||
lsmod | grep 'ch' | ||
modinfo ch341 | ||
http://lxr.free-electrons.com/source/drivers/usb/serial/ch341.c | ||
|
||
#### Arduino IDE | ||
|
||
Arduino IDE [here](http://arduino.cc/en/Main/Software). | ||
|
||
sudo ./arduino | ||
|
||
Arduino IDE settings : Tools/Board `Arduino Nano` Tools/Processor `ATmega328` Tools/Programmer `Arduino as ISP` | ||
|
||
#### Debug with Wireshark | ||
|
||
modprobe usbmon | ||
sudo wireshark | ||
|
||
#### Control with Java | ||
|
||
sudo apt-get install librxtx-java | ||
sudo usermod -a -G dialout $USER | ||
sudo adduser $USER dialout | ||
sudo reboot | ||
|
||
##### Run sample app #1 | ||
|
||
mvn exec:java | ||
mvn exec:java -Dport.id=/dev/ttyUSB0 | ||
|
||
##### Run sample app #2 | ||
|
||
mvn clean install | ||
java -jar target/arduino-0.0.1-SNAPSHOT.jar | ||
java -jar -Dport.id=/dev/ttyUSB0 target/arduino-0.0.1-SNAPSHOT.jar | ||
|
||
#### DTR causing a reset | ||
|
||
##### Description | ||
|
||
http://stackoverflow.com/a/35406863 | ||
http://stackoverflow.com/questions/3918032/bash-serial-i-o-and-arduino | ||
|
||
##### Terminal and Arduino IDE serial monitor dumps | ||
|
||
`echo "ON" > /dev/ttyUSB0` - [ubuntu.terminal.echo.pcapnp](https://github.com/Pozo/arduino-nano-setup/blob/master/ubuntu.terminal.echo.pcapnp "ubuntu.terminal.echo.pcapnp") | ||
|
||
|
||
`using Arduino IDE serial monitor` - [arduino.ide.serial.monitor.pcapng](https://github.com/Pozo/arduino-nano-setup/blob/master/arduino.ide.serial.monitor.pcapng "arduino.ide.serial.monitor.pcapng") | ||
|
||
stty -a < /dev/ttyUSB0 | ||
echo "ON" > /dev/ttyUSB0 wont work | ||
echo "OFF" > /dev/ttyUSB0 wont work | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
target | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
.recommenders | ||
|
||
# Eclipse Core | ||
.project | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# PyDev specific (Python IDE for Eclipse) | ||
*.pydevproject | ||
|
||
# CDT-specific (C/C++ Development Tooling) | ||
.cproject | ||
|
||
# JDT-specific (Eclipse Java Development Tools) | ||
.classpath | ||
|
||
# Java annotation processor (APT) | ||
.factorypath | ||
|
||
# PDT-specific (PHP Development Tools) | ||
.buildpath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# Tern plugin | ||
.tern-project | ||
|
||
# TeXlipse plugin | ||
.texlipse | ||
|
||
# STS (Spring Tool Suite) | ||
.springBeans | ||
|
||
# Code Recommenders | ||
.recommenders/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.github.pozo</groupId> | ||
<artifactId>arduino</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rxtx</groupId> | ||
<artifactId>rxtx</artifactId> | ||
<version>2.1.7</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.1.2</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<!-- use mvn versions:display-dependency-updates versions:display-plugin-updates --> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>versions-maven-plugin</artifactId> | ||
<version>1.3.1</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.12.2</version> | ||
<configuration> | ||
<includes> | ||
<include>**/*Test.java</include> | ||
</includes> | ||
<excludes> | ||
<exclude>**/*LiveTest.java</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<createDependencyReducedPom>true</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>com.github.pozo.MainFrame</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.4.0</version> | ||
<configuration> | ||
<mainClass>com.github.pozo.MainFrame</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
|
||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.github.pozo; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
|
||
import gnu.io.CommPortIdentifier; | ||
import gnu.io.NoSuchPortException; | ||
import gnu.io.PortInUseException; | ||
import gnu.io.SerialPort; | ||
import gnu.io.UnsupportedCommOperationException; | ||
|
||
public class Arduino { | ||
private static final String PROPERTY_PORT_ID = "port.id"; | ||
private static final String PORT_ID = "/dev/ttyUSB0"; | ||
/** 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; | ||
|
||
private static SerialPort serialPort; | ||
|
||
private static final String OFF_COMMAND = "OFF"; | ||
private static final String ON_COMMAND = "ON"; | ||
|
||
public static String open() { | ||
String result = ""; | ||
try { | ||
String portIdFromProperty = System.getProperty(PROPERTY_PORT_ID); | ||
String portId = (portIdFromProperty==null)? PORT_ID : portIdFromProperty; | ||
serialPort = (SerialPort) CommPortIdentifier.getPortIdentifier(portId).open(Arduino.class.getName(), TIME_OUT); | ||
// useless in this case https://github.com/processing/processing/blob/master/java/libraries/serial/src/processing/serial/Serial.java#L560 | ||
serialPort.setDTR(false); | ||
serialPort.setSerialPortParams(DATA_RATE, | ||
SerialPort.DATABITS_8, | ||
SerialPort.STOPBITS_1, | ||
SerialPort.PARITY_NONE); | ||
|
||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(serialPort.getInputStream())); | ||
|
||
result = bufferedReader.readLine(); | ||
} catch (PortInUseException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchPortException e) { | ||
e.printStackTrace(); | ||
} catch (UnsupportedCommOperationException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return result; | ||
} | ||
|
||
public static void close() { | ||
if (serialPort != null) { | ||
serialPort.removeEventListener(); | ||
serialPort.close(); | ||
} | ||
|
||
} | ||
|
||
public static String turnOnLED() throws IOException { | ||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(serialPort.getInputStream())); | ||
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(serialPort.getOutputStream())); | ||
|
||
bufferedWriter.write(ON_COMMAND); | ||
bufferedWriter.flush(); | ||
|
||
return bufferedReader.readLine(); | ||
|
||
} | ||
|
||
public static String turnOffLED() throws IOException { | ||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(serialPort.getInputStream())); | ||
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(serialPort.getOutputStream())); | ||
|
||
bufferedWriter.write(OFF_COMMAND); | ||
bufferedWriter.flush(); | ||
|
||
return bufferedReader.readLine(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.github.pozo; | ||
|
||
import java.awt.EventQueue; | ||
import java.awt.event.ActionEvent; | ||
import java.io.IOException; | ||
|
||
import javax.swing.AbstractAction; | ||
import javax.swing.Action; | ||
import javax.swing.Box; | ||
import javax.swing.JButton; | ||
import javax.swing.JFrame; | ||
|
||
public class MainFrame { | ||
private JFrame frame; | ||
private final Action turnOnLed = new AbstractAction("ON") { | ||
private static final long serialVersionUID = 335039065675847328L; | ||
|
||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
String response = Arduino.turnOnLED(); | ||
System.out.println(response); | ||
} catch (IOException e1) { | ||
e1.printStackTrace(); | ||
} | ||
} | ||
}; | ||
private final Action turnOffLed = new AbstractAction("OFF") { | ||
private static final long serialVersionUID = -6049179799308301774L; | ||
|
||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
String response = Arduino.turnOffLED(); | ||
System.out.println(response); | ||
} catch (IOException e1) { | ||
e1.printStackTrace(); | ||
} | ||
} | ||
}; | ||
|
||
public static void main(String[] args) { | ||
EventQueue.invokeLater(new Runnable() { | ||
public void run() { | ||
try { | ||
Arduino.open(); | ||
MainFrame window = new MainFrame(); | ||
window.frame.setVisible(true); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { | ||
|
||
public void run() { | ||
Arduino.close(); | ||
} | ||
})); | ||
} | ||
|
||
public MainFrame() { | ||
initialize(); | ||
} | ||
|
||
private void initialize() { | ||
frame = new JFrame(); | ||
Box bv = Box.createHorizontalBox(); | ||
|
||
frame.setBounds(100, 100, 450, 300); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.add(bv); | ||
JButton button = new JButton(turnOnLed); | ||
bv.add(button); | ||
|
||
JButton buttonOff = new JButton(turnOffLed); | ||
bv.add(buttonOff); | ||
} | ||
|
||
} |
Oops, something went wrong.