2016年6月28日 星期二

mbed client using Raspberry Pi with IT-Pi Shield



介紹如何利用yotta 工具進行編譯 linux mbed client

what is yotta ? 

  • mbed OS applications as yotta executables 
  • yotta - to build the mbed example programs
  • yotta is a module management system for C++ and C designed to make it easier to build better software by re-using code.
  • yotta uses the CMake build system, and targets describe how the compiler should be run by providing a CMake
  • yotta is written in python, and distributed using pip, the python package manager
  • 利用yotta 可以到yotta 公開的 module registry (http://yotta.mbed.com/)下載 module (即library)來使用. 另外, yotta 目標希望可以用同一份原始碼來編譯出不同平台上的code
     (yotta target <target_name>)  

yottta 工具安裝

成功安裝完必要的dependency後 , 接著進行安裝 yotta

1.) Installing Package Dependencies

sudo apt-get install python-setuptools cmake build-essential ninja-build python-dev 
sudo apt-get install libffi-dev 
sudo apt-get install libssl-dev
sudo easy_install pip

2) Installing yotta

sudo pip install yotta     //wait and pray......


問題排除 

如果按照上面步驟,安裝yotta, 套件找不到情況, 建立virtualenv , 解決python 相依套件的問題

Installing in a Virtualenv


Virtualenv is a way of separating different python programs installed on the same system from each other. If you have a complex python environment on your system it’s recommended that you install yotta inside a virtualenv. 

  1. Ensure you have virtualenv itself installed. It can be installed with:
    pip install virtualenv
    
    Check that your installation is succesful by running virtualenv --version.
  2. Create a directory to use for the yotta virtualenv:
    mkdir yotta-venv
    virtualenv ./yotta-venv
    
  3. activate the new virtualenv:
    source ./yotta-venv/bin/activate
    
  4. install yotta in the virtualenv:
    pip install yotta
    
  5. (optional) add the binary directory of your virtualenv to your PATH: (if you omit this step, you will need to run yotta as../path/to/yotta-venv/bin/yotta instead of simply yotta.
    export PATH="/path/to/yotta-venv/bin:$PATH"
    
Now yotta should work as normal. You will need to activate the virtualenv any time you want to run yotta commands (you can deactivate it afterwards, by simply running deactivate).

Yotta 成功安裝畫面

 編譯 mbed client linux Source 

 made sure you have installed yotta and all necessary toolchains.

  1. In the command prompt, go to mbed-client-linux-example.
  2. Set up the application with correct Certificate and Domain:
    B. Go to My devices -> Security credentials.
    C. Click GET MY DEVICE SECURITY CREDENTIALS. You will get the needed certificate information as well as the endpoint name and domain.
    D. Copy the security credentials to source/security.h.
  3. In the command prompt, type yotta target arm-linux-native to set up the target device., 這裡會產生出資料匣 build/arm-linux-native
  4. In the command prompt, type yotta build. The executable file will be created in the folder build/arm-linux-native/source/.

    (yotta build -d: 可加入debug 訊息輸出)
編譯code 時會去pubic repository 下載module , 故要求驗證身份

5. In the folder mbed-client-linux-example/build/arm-linux-native/source/, run the executable from the command line, type ./mbed-client-linux-example.

         6. 若要將整個project 清空: 執行 yotta clean


The build process (what is ninja?)



---------------------
參考文件

2016年6月18日 星期六

關於L293D馬達驅動模板


L293D馬達驅動板


The shield contains two L293D motor drivers and one 74HC595 shift register. The shift register expands 3 pins of the Arduino to 8 pins to control the direction for the motor drivers. The output enable of the L293D is directly connected to PWM outputs of the Arduino.

The Motor Shield is able to drive 2 servo motors, and has 8 half-bridge outputs for 2 stepper motors or 4 full H-bridge motor outputs or 8 half-bridge drivers, or a combination.

模組板規格

  • 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution dedicated timer - no jitter!
  • 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal shutdown protection, internal kickback protection diodes. Can run motors on 4.5VDC to 25VDC.
  • Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5% resolution)
  • Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil or interleaved stepping.
  • Pull down resistors keep motors disabled during power-up
  • Big terminal block connectors to easily hook up wires (18-26AWG) and power
  • Arduino reset button brought up top
  • 2-pin terminal block and jumper to connect external power, for separate logic/motor supplies
  • Tested compatible with Arduino Mega 1280 & 2560, Diecimila, Duemilanove, and UNO
  • Download the easy-to-use Arduino software library, check out the examples and you're ready to go!




http://www.kidmakers.org/-for-the-galileo/
Motor shield Motor電源與Arduino Vin 關係

關於 74HC595 Shift Register


  74HC595 為一個位移暫存器: 8bit serial in, parallel out。主要可以透過控制 SER、RCLK, SRCLK 3個輸入接腳控制8個輸出(QA~QH), 這如同是一個3-to-8的Decoder。
  74HC595 位移暫存器可以作為I/O Expansion, 用3根GPIO獲得到8個輸出


  • Vcc
    Up to 6V (needs to be the same voltage as your microcontroller) – Usually 3.3 / 5v
  • QA to QH
    Shift Register Outputs.==> Register 輸出pin
  • SER.
    (Serial) Input for the next pin that gets shifted in.==> Register 輸入pin
  • SRCLK
    (Serial Clock) pulled high, 時 SER pin 狀態會丟入Register
  • RCLK
    (Register Clock) Needs to be pulled high to set the output to the new shift register values,  pulled high, 時 Register 內部8bit值會輸出到QA~QH. This must be pulled high directly after SRCLK has gone LOW again.
  • /SRCLR
    (Serial Clear) Will empty the whole Shift Register if pulled LOW, must be pulled High to enable.清除8bit register內容
  • /OE
    (Output Enable) This pin enables the output when tied to GND, & disabled when HIGH.=>控制輸出與否
  • OH' (pin 9) : You know how the last register just dumps its value when it is shifted over? 每次Shift Out 的值 (即bit 9的內容)

2016年6月16日 星期四

USB over IP (1)



The USB/IP Project aims to develop a general USB device sharing system over IP network. To share USB devices between computers with their full functionality, USB/IP encapsulates USB I/O requests into IP packets and transmits them between computers.


技術架構


  1. Server : 伺服端為USB Host Controller,實際和USB Device連接並分享 USB , 如分享USB 隨身碟、USB Webcam。對於VHCI Driver而言,Stub driver 即如同一個 usb device的driver,Stub Driver 還必須進行IP <-->USB 的封包處理
  2. Client : 客戶端用以連接伺服端並且進行遠端掛載/卸載 (attach/detach) USB。VHCI (Virtual Host Controller Interface)  Driver 為虛擬USB Host),讓SB device 好像直接插入到Host controller 中 (但此為虛擬的HCI)。Client端將IP封包 (其payload為USB 封包),送入VHCI,使系統以為真有USB插入。 


usbip-design


Linux  kernel 3.17.x 後內建支援 USB over IP的功能

[USB/IP Support ]
This enables pushing USB packets over IP to allow remote machines direct access to USB devices. It provides the USB/IP core that is required by both drivers.  

Linux 
root@server1:~# sudo modprobe usbip-host




root@server1:~# usbipd -D

you should see that the usbip daemon is listening on TCP port 3240



root@server1:~# sudo apt-get install usbip

root@raspberrypi:~# usbip list -l

 - busid 1-1.1 (0424:ec00)
   Standard Microsystems Corp. : unknown product (0424:ec00)

 - busid 1-1.4 (0781:5567)
   SanDisk Corp. : Cruzer Blade (0781:5567)

root@raspberrypi:~# usbip bind --busid=1-1.4

usbip: info: bind device on busid 1-1.4: complete


root@raspberrypi:~# lsusb

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0781:5567 SanDisk Corp. Cruzer Blade


資源參考
http://usbip.sourceforge.net/
http://askubuntu.com/questions/612355/share-usb-drive-over-network





2016年6月7日 星期二

E24電阻值



由於阻值數量龐大,廠商不可能製作每一種規格電阻值,所以 EIA 制定了一些標準阻值。


電阻的標稱阻值分為E6、E12、E24、E48、E96、E192六大系列,分別適用於允許偏差為±20%、±10%、±5%、±2%、±1%和±0.5%的電阻器.其中其中以E12與E24最常見。,E48、E96、E192系列為高精密電阻數系。


E6系列電阻標稱阻值,對應允許偏差為±20%,查看E6系列電阻規格表.
E12系列電阻標稱阻值,對應允許偏差為±10%,查看E12系列電阻規格表.
E24系列電阻標稱阻值,對應允許偏差為±5%,查看E24系列電阻規格表.
E48系列電阻標稱阻值,對應允許偏差為±2%,查看E48系列電阻規格表.
E96系列電阻標稱阻值,對應允許偏差為±1%,查看E96系列電阻規格表


E12系列:1.0、1.5、 2.2、2.7、3.3、3.9、4.7、5.6、8.2
E24系列:1.0、1.1、1.2、1.3、1.5、1.6、1.8、2.0、2.2、2.4、2.7、3.0、3.3、3.6、3.9、4.3、4.7、5.1、5.6、6.2、6.8、7.5、8.2、9.1


數值1.0、2.2、3.3、4.7 ,它表示電阻值必須從這個系列中號碼選取,具體值可以放大或縮小10的整數倍.比如有效數字2.2,放大可以得到220歐姆的電阻標稱值,縮小可以得到22毫歐的標稱值。