2016年1月22日 星期五

Raspberry Pi: Windows 10 IoT Memo

since: 2016/01/22
update: 2016/01/22

reference:
1. Windows IoT - Downloads
2. Windows IoT - Setup your Raspberry Pi 2
3. Windows IoT - Use SSH to connect to a Windows IoT Core device


A. 說明:
     1. 需要 Windows 10 才可以安裝

     2. 已在 Windows 上安裝過以下軟體:
         Windows 10 IoT Core
         Windows 10 IoT Core Dashboard

-----------------------------------------------------------------------------------------------

B. 可使用 ssh 登入
    > Windows 上安裝 putty

-----------------------------------------------------------------------------------------------

C. ID / pass:
    administrator / xxxx

Raspberry Pi: Setup For LED Pixel Art

since: 2016/01/22
update: 2016/01/22

reference:
1. Raspberry Pi and IOIO Board | PIXEL: LED ART
2. PIXEL Console App | PIXEL: LED ART
3. Overview | Web Enabled PIXEL on Raspberry Pi | Adafruit Learning System
4. Raspberry Pi and PIXEL | PIXEL: LED ART
5. RPiBlog: Installing Oracle JDK 8 on Raspberry Pi


A. Download the udev rules file.

    1. 到 Downloads · ytai/ioio Wiki , 下載 Linux 版的檔案: 50-ioio.rules (另存新檔)
       其內容為:
ACTION=="add", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="0008", SYMLINK+="IOIO%n", MODE="666"
ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="0008", ENV{ID_MM_DEVICE_IGNORE}="1"


    2.  將 50-ioio.rules 上傳到 pi 裡:
         $ scp 50-ioio.rules pi@192.168.1.24:/home/pi

    3. copy it to your rules directory (one time step)
       $ sudo cp 50-ioio.rules /etc/udev/rules.d

    4. restart udev
       $ sudo restart udev
       (or $ sudo /etc/init.d/udev restart)

-----------------------------------------------------------------------------------------------

B. Check IOIO recognized status
    1. Plug your IOIO into a free USB port on the Raspberry Pi

    2. check if it’s recognized using this command
        $ ls /dev/IOIO*
           /dev/IOIO0

-----------------------------------------------------------------------------------------------

C. Install Java on your Pi
    1. for pi 1:
        $ sudo apt-get install openjdk-7-jre

    2. for pi 2:
       $ sudo apt-get install openjdk-8-jre

    3. 備註:
        切換使用不同版本的 java 方式: (如果有安裝不同的版本)
        $ sudo update-alternatives --config java

-----------------------------------------------------------------------------------------------

D. 安裝 avahi-daemon
    $ sudo apt-get install avahi-daemon

-----------------------------------------------------------------------------------------------

E. Check PIXEL recognized status
    1.Move the toggle switch on the side of PIXEL from the “Bluetooth” position to the “PC” position

    2. Plug PIXEL into a free USB port on your Raspberry Pi using the included USB A-A cable.

    3. Then check if it’s recognized using this command:
        $ ls /dev/ttyACM0*
           /dev/ttyACM0

-----------------------------------------------------------------------------------------------

F. 下載 PIXEL Console App
        http://ledpixelart.com/console/
    1. 在此使用 PIXEL: Console V2.0 版本
    2. 上傳到 pi 裡:
        $ scp pixelc_2_0.jar pi@192.168.1.24:/home/pi

-----------------------------------------------------------------------------------------------

G. 測試:
     先將
pixelc_2_0.jar  更名成: pixelc.jar
     1. $ java -jar -Dioio.SerialPorts=/dev/IOIO0 pixelc.jar --gif=black.gif
     2. $ java -jar -Dioio.SerialPorts=/dev/IOIO0 pixelc.jar --gif=black.gif --write
     3. $ java -jar -Dioio.SerialPorts=/dev/IOIO0 pixelc.jar -–zip=95050
     4. $ java -jar -Dioio.SerialPorts=/dev/ttyACM0 pixelc.jar --gif=black.gif
     5. $ java -jar pixelc.jar --gif=fire.gif
     6. $ java -jar pixelc.jar -–zip=95050 

-----------------------------------------------------------------------------------------------

H. 其他:
     套件更新:
     $ sudo apt-get update
     $ sudo apt-get upgrade
     $ sudo apt-get dist-upgrade
     $ sudo rpi-update

     others:
     $ sudo apt-cache search openjdk
     $ sudo apt-get install openjdk-7-jdk
     $ sudo update-alternatives --config javac

2016年1月16日 星期六

Processing: An error occurred during startup

since: 2016/01/16
update: 2016/01/16


A. 錯誤:
     Processing 2.21 無法開啟

-----------------------------------------------------------------------------------------------

B. 解決方式:
    1. 可先開啟 Processing 3, 查看最下方偏好設定檔的位置.
        或看 C. 備註3.

    2. 刪除整個 "偏好設定檔目錄", 在此例為: /Users/Lanli/Library/Processing

    3. 重新開啟 Processing 2

-----------------------------------------------------------------------------------------------
  
C. 備註:
     1. WindowsMac 皆適用

     2. "偏好設定檔目錄" 預設為隱藏
          Windows: 目錄設定顯示所有隱藏檔
          Mac: Finder > 前往 > 前往檔案夾 ...

     3. Windows 與 Mac 預設的 "偏好設定檔目錄" 位置:
         Windows: C:\Users\Lanli\AppData\Roaming\Processing
         Mac: /Users/Lanli/Library/Processing

2016年1月15日 星期五

openFrameworks: Reading From And Writing To Files With ofBuffer Class

since: 2016/01/15
update: 2016/01/15
reference:

A. in header file:
    ....
    /* config file */

    bool debug; // debug mode: to show more message or not
    float checkTime_second;
   
    /* record datetime to file */
    ofBuffer readBuffer;
    ofBuffer checkTimeBuffer;
    string nowDateString;


-----------------------------------------------------------------------------------------------

B. in c++ file:
     1. Read File:
   
    ....

    // read config file
    readBuffer = ofBufferFromFile("config.txt");
    //cout << readBuffer.getText(); // let's see what it says
    vector<string> lines = ofSplitString(readBuffer, "\n");
   
    for( int i = 0; i < lines.size(); i++){
        //cout << lines[i] << endl;
       
        if(i == 1) {
            debug = ofToBool(lines[i]);
            if(debug) {
                ofLog(OF_LOG_NOTICE, ">>>>> debug true");
            }
            else {
                ofLog(OF_LOG_NOTICE, ">>>>> debug false");
            }
        }
        else if(i == 4) {
            checkTime_second = ofToFloat(lines[i]);
            ofLogNotice(">>>>>>>>> checkTime_second") << checkTime_second;
        }

   

     2. Write File:
         ....

         // inner some loop
         if(ofGetElapsedTimef() >= checkTime_second) {
             ofResetElapsedTimeCounter();
               
             nowDateString = ofGetTimestampString("%Y%m%d%H%M%S");
             checkTimeBuffer.set(nowDateString.c_str(), nowDateString.size());
             if(ofBufferToFile("dateTime.txt", checkTimeBuffer)) {
                 ofLogNotice(">>>>>>>>> update checking dateTime") << nowDateString;
             }
         }


AppleScript: Repeat Checking App Status

since: 2016/01/15
update: 2016/01/15


A. 新增 AppleScript:
    1. 開啟 Automator:

   
     2. Automator > 檔案 > 新增 > 應用程式 > 選擇:
    
     3. 工具程式 > 執行 AppleScript > 拖拉到右方

    4. 預設程式碼:
on run {input, parameters}
   
    (* Your script goes here *)
   
    return input
end run


-----------------------------------------------------------------------------------------------

B. 修改 AppleScript:
on run {input, parameters}
   
    #
    # start: variables defined
    #
   
    # script repeat delay time (second)

    set repeatDelayTime to 180
   
    # dateTimeFile Path
    # /Lanli/RD/project/openFrameworks/of_v0.9.0/apps/myApps/myFirstApp/bin/data/

    set dateTimeFilePath to (("Lanli:RD:project:openFrameworks:of_v0.9.0:apps:myApps:myFirstApp:bin:data:") as text)
   
    # dateTimeFile Name
    set dateTimeFileName to "dateTime.txt"
   
    # completed dateTimeFile
    set dateTimeFile to dateTimeFilePath & dateTimeFileName
   
    # allow time difference to sysDateTime & appUpdateTime (second)

    set allowedSecondDiff to 120


    # allowed min free memory (MB)
    set allowedMinFreeMemory to 0
   
    # my app name
    set myAppName to "myFirstApp"

    # reboot system or not
    set reboot to false   

    #
    # end: variables defined
    #

   
    ##########################################################
   
    #
    # start script repeat
    #

    repeat
       
        # delay 180 second  
        # delay 180 
  
        delay repeatDelayTime
       
        # start: repeat task
       

##########################################################       
        # 
        # check 01:  app update status
        #
        # Read lines from file.

        set fileLines to paragraphs of (read file dateTimeFile as «class utf8»)
       
        # Loop over lines read and copy each to the clipboard.
        repeat with perLine in fileLines
            set the clipboard to perLine
            #display alert (the clipboard)
            set appUpdateTime to (the clipboard) as integer
            exit repeat # we just need read one line here
        end repeat
       
        # get sysDateTime
        set sysDateTime to nowTimeFormat() as integer
       
        # check time diff
        if (appUpdateTime + allowedSecondDiff) ≥ sysDateTime then
            # display dialog "you pass" with title "check app update status" buttons {"OK"} default button 1
        else
            # display dialog "reboot" with title "check app update status" buttons {"OK"} default button 1
            set reboot to true
        end if
       
       
        #
        # check 02:  system memory free
        #
       
        # query memory free (MB)

        set vmStats to (text 12 thru -2 of (do shell script "vm_stat | grep 'Pages free'")) * 4096 / 1024 / 1024
        # show free Memory
        #display dialog vmStats with title "Memory Free (MB)" buttons {"OK"} default button 1

       
        # if vmStats <= 0 MB
        if vmStatsallowedMinFreeMemory then
            set reboot to true
        end if
       
        # for test
        #set reboot to false

       
        #
        # reboot system or not
        #

        if reboot is true then
            #display dialog "reboot" with title "reboot system or not" buttons {"OK"} default button 1
           
            #step 1: kill your app 
            tell application "System Events"
                set ProcessList to name of every process
               
                if myAppName is in ProcessList then
                    set ThePID to unix id of process myAppName
                    do shell script "kill -KILL " & ThePID
                end if
            end tell
           
            #step 2: reboot system
            tell application "Finder"
                restart
            end tell
           
        else
            #display dialog "pass" with title "reboot system or not" buttons {"OK"} default button 1
        end if
       
       
        # end: repeat task
       

##########################################################       
        # exit script repeat: for only once execute
        #exit repeat
       
        #   
        # end script repeat
        #  
     
    end repeat
   
    return input
end run



# nowTimeFormat
on nowTimeFormat()
   
    set theDate to current date
    set y to text -4 thru -1 of ("0000" & (year of theDate))
    set m to text -2 thru -1 of ("00" & ((month of theDate) as integer))
    set d to text -2 thru -1 of ("00" & (day of theDate))
    set hh to text -2 thru -1 of ("00" & (hours of theDate))
    set mm to text -2 thru -1 of ("00" & (minutes of theDate))
    set ss to text -2 thru -1 of ("00" & (seconds of theDate))
   
    # 2016-01-15-10-56-46
    #return y & "-" & m & "-" & d & "-" & hh & "-" & mm & "-" & ss
    # 20160115105646

    return y & m & d & hh & mm & ss
   
end nowTimeFormat