忘備録-Sparkfun.com MP3 Player Shieldを使う時のチュートリアル指定ファイルが存在しない

  • Sparkfun.com MP3 Player ShieldをUNOで使う時にインストールするライブラリのピン(SSを10→9)に変更しないといけない。
  • https://www.sparkfun.com/tutorials/295
    2_1.png
     が存在しないのですが、Arduino/libraries/SdFat/SdFatConfig.hの一番下
    2_2.png
     にありました。ここのCSを10→9に変えると動きました。

Eclipseを使ってJavaでシリアル通信

  • 動作環境:Windows7 64bit
  • 手順
 .轡螢▲訥命を行いたいEclipseのpackage下に追加ライブラリ用のフォルダを作る(名前は何でもいいけど写真ではlib)
1.png
 追加用のライブラリをインストール

  このフォルダを解凍した中の、

   rxtxParallel.dll

   rxtxSerial.dll

   RXTXcomm.jar

  をコピーして、,離侫ルダ内にペースト

  • もしもパソコン自体にインストールしたい場合は、Program Files内のJavaファイルのライブラリに入れる(やってないので動くかは不明)
 EclipseでLibrary  Pathを追加する
  • Eclipseを起動
  • まず、新しく作ったフォルダが入っているPackage名を右クリックして、Refreshを選択。(または、Package名を選択後、F5を押す。)    これで、新フォルダがPackageに仲間入り。  
  • ProjectタブのPropertiesをクリックする。Propertiesの左にJava Build Pathがあるのでクリック。
  • Librariesタブをクリック。Add Jars...をクリックして、,悩遒辰織侫ルダ内のRXTXcomm.jarを選択。
    2.png
  • これで設定は完了。あとはプログラムを書くのみ。
 ぅ廛蹈哀薀犧鄒
  • CommLight.java(メインがあるファイル)
     //port check
     //JDK check
     import java.io.*;
     public class CommLight{
    	static File sharedText;
    	
    	public static void main(String[] args){
           
           SerialComm serialcomm = new SerialComm();
           serialcomm.open();
           int i = 10;
           while(i>0){
           	serialcomm.write((byte)0x34);
           	try{
               	Thread.sleep(500);
               }catch(Exception e){
               	
               }
               serialcomm.write((byte)0x20);
               try{
               	Thread.sleep(500);
               }catch(Exception e){
               	
               }
               serialcomm.write((byte)0x78);
               try{
               	Thread.sleep(500);
               }catch(Exception e){
               	
               }
               i--;
           }
    		System.out.println("Hello, World");
    	}
    }
  • SerialComm.java
     import gnu.io.*;
     import java.io.*;
     import java.util.*;
     public class SerialComm implements SerialPortEventListener{
    	private SerialPort port;
     //	private static BufferedReader reader;
    	private InputStream in;
    	private OutputStream out;
    	SerialComm(){
    		super();
    	}
    	public void open(){
    		try {
    			// Serial port initialize
    			CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM6");
    			port = (SerialPort)portId.open("USB Serial Port", 2000);
    			port.setSerialPortParams(
    					9600,					 // í êMë¨ìx[bps]
    					SerialPort.DATABITS_8,   // ÉfÅ[É^ÉrÉbÉgêî
    					SerialPort.STOPBITS_1,   // ÉXÉgÉbÉvÉrÉbÉg
    					SerialPort.PARITY_NONE   // ÉpÉäÉeÉB
    					);
    			port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    			try{
    				port.addEventListener(this);
    				port.notifyOnDataAvailable(true);
    				
    				in = port.getInputStream();
    				out = port.getOutputStream();
    			}catch(TooManyListenersException ex){
    				System.out.println("Error1: "+ex);
    			}
    		} catch (Exception e) {
    			System.out.println("Error2: " + e);
    			System.exit(1);
    		}
    	}
    	public void close(){
    		try{
    			in.close();
    			out.close();
    			port.close();
    		}catch(Exception e){
    			System.out.println("close: "+e);
    		}
    	}
    	public void read(){
    		try{
    			byte[] buffer;
    			int temp = in.available();
    			if(temp>0){
    				System.out.println("temp: "+temp);
    				buffer = new byte[temp];
    				temp = in.read(buffer);
    				int num = 0;
    				while(num<temp){
    					System.out.println("b "+num+": "+Integer.toHexString((byte)buffer[num]));
    					num++;
    				}
    			}
    			in.close();
    		}catch(Exception e){
    			System.out.println("error4: "+e);
    		}
    	}
    	public static String toHex(byte[] digest) {
    		StringBuilder sb = new StringBuilder();
    		for (byte b : digest) {
    			sb.append(String.format("%1$02X", b));
    		}
    		return sb.toString();
    	}
    	public void write(byte data){
    		try{
    			out.write((byte)data);   
    			out.flush();
    			//ÉXÉgÉäÅ[ÉÄÇ&#8710;COMÉ|Å[ÉgÇ&#63743;ï¬Ç∂ÇÈèàóù
    		}catch(Exception e){
    			System.out.println("port exception: "+e);
    		}
    	}
    	public void run() {
    		try {
    			InputStreamReader isr = new InputStreamReader(System.in);
    			BufferedReader br = new BufferedReader(isr);
    			OutputStream out = port.getOutputStream();
    			boolean flagQuit = false;
    			while (!flagQuit) {
    				String input = br.readLine();
    				if (input.length() > 0) {
    					if (input.equals(":quit"))
    						break;
    					input += "\r";
    					out.write(input.getBytes("US-ASCII"));
    				}
    			}
    			port.close();
    		} catch (Exception e) {
    			System.out.println("Error3: " + e);
    		}
    	}
    	public void serialEvent(SerialPortEvent event) {
    		if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
    			read();
    		}
    	}
     }
 ゴ粟