2016年7月29日 星期五

4 port relay module






當input 為 0V ....   相對應的led 會亮起來...  然後    com 和 NO 會連起來


當input 為 5V ....   相對應的led 會暗起來...  然後    com 和 NC 會連起來

因為input 的default 為 3.3V 高電為......

widora opkg install

1.   python


     $ opkg install python


2016年7月28日 星期四

widora ethernet setting

Ref : https://wiki.openwrt.org/doc/uci/network


config 'interface' 'example'
        option 'proto'   'dhcp'
        option 'ifname'  'eth0'
        option 'defaultroute' '1'

mt7688 duo i2c study



首先要先了解7688duo 的架構





















in arduino  ->   Serial1

in   mpu    -> /dev/ttyS0


=======================================================
in arduino side
=======================================================


void setup() {
Serial.begin(115200); // open serial connection to USB Serial port (connected to your computer)
Serial1.begin(57600); // open internal serial connection to MT7688AN
// in MT7688AN, this maps to device
pinMode(13, OUTPUT);
}
void loop() {
int c = Serial1.read(); // read from MT7688AN
if (c != -1) {
switch(c) {
case '0': // turn off D13 when receiving "0"
digitalWrite(13, 0);
break;
case '1': // turn off D13 when receiving "1"
digitalWrite(13, 1);
break;
}
}
}


=======================================================
 7688 side
=======================================================


import serial
import time
s = None
def setup():
    global s
   # open serial COM port to /dev/ttyS0, which maps to UART0(D0/D1)
   # the baudrate is set to 57600 and should be the same as the one
   # specified in the Arduino sketch uploaded to ATmega32U4.
   s = serial.Serial("/dev/ttyS0", 57600)
def loop():
  # send "1" to the Arduino sketch on ATmega32U4.
  # the sketch will turn on the LED attached to D13 on the board
  s.write("1")
  time.sleep(1)
  # send "0" to the sketch to turn off the LED
  s.write("0")
  time.sleep(1)
if __name__ == '__main__':
   setup()
   while True:
        loop()


mt7688duo 開始篇

Ref : http://makerpro.cc/2016/02/setting-linkit-smart-7688-openwrt/


設定7688網路模式

首先第一步當然就是送電囉,照著7688 developer’s guide(連結),我們在供電的地方接上MicroUSB送電。

第一步.在供電的地方接上MicroUSB送電



7688預設會執行網路分享器的功能,所以我們在筆電可以搜尋到7688的無線網路訊號,(這邊使用Windows系統,Mac請自行類比囉),而WiFi訊號(所謂的SSID)最後面所看到的六碼,代表這一片7688的硬體位置,所以理論上如果有多顆7688,在沒有被修改的情況下,應該是不會搞混才是。


7688預設會執行網路分享器的功能,所以我們在筆電可以搜尋到7688的無線網路訊號,(這邊使用Windows系統,Mac請自行類比囉),而WiFi訊號(所謂的SSID)最後面所看到的六碼,代表這一片7688的硬體位置,所以理論上如果有多顆7688,在沒有被修改的情況下,應該是不會搞混才是。

在筆電可以搜尋到7688的無線網路訊號


當我們連線上7688的無線網路訊號之後呢,我們就到瀏覽器中打入「mylinkit.local」,這時候會看到下圖的畫面,並且要求我們設定一組密碼(須設定六碼),這是因為全新的7688還沒有定義任何密碼,使用者可以自行決定,這邊要特別注意,這組密碼不是剛剛分享無線網路的密碼!這組密碼是我們要登入其中的OpenWRT的時候要用到的,所以要記好!


設定好帳密後...


但是目前7688自己是AP(分享器,Access Point),怎麼辦呢?不要緊張!我們只要把7688設定成跟一般電腦一樣,去接外部的無線網路就好囉,馬上在橘黃色的部分選擇「Network」,就會看到以下畫面,也就是7688目前屬於AP mode,而且可以設定7688網路分享的密碼,既然我們要接到外部的無線網路,我們就要把設定改成「Station mode」,也就是7688跟其他裝置一樣都只是一個station而已。



















接著我們就在搜尋WiFi列表中,選取我們要連接上的無線網路,並在下方打入正確的密碼。



第三個,可以直接搜尋「IP Scanner」這類型的服務,就可以搜尋到同一個無線網路中,其他人的IP位置囉。


使用SSH的特殊連線

看到我們的裝置名稱「mylinkit」,而且查到IP之後,我們就開啟大家愛用的PuTTY(連結),使用一個叫做SSH的特殊連線方式(看看鳥哥怎麼說),打入IP位置就可以連線了。



================================================================
按住wifi button  5秒.... 就可以從  station mode 回到  AP MODE....

按住wifi button 超過 20秒.... 就會回到factory reset

================================================================

This chapter describes how to program the peripheral sensors on the LinkIt Smart 7688 board. This does not apply to Link It Smart 7688 Duo since they have different pin breakout.
From the hardware aspect, MediaTek MT7688AN SOC on the LinkIt Smart 7688 board handles all the Wi-Fi communication, USB device control, SD card access and sensor connection.
Related software stacks are provided for developers to access the sensors attached to the MT7688AN.
+
UPM is the repository for sensor drivers written in libmraa and it provides API bindings for Python, Node.js and C languages. So it’s convenient for developers to use UPM to access peripheral sensors and modules with the programming language that they preferred.
LinkIt Smart 7688 has built-in UPM support.The detailed support list of sensors in UPM can be found in the UPM project page.



In this section, we will show how to use the mt7688_pinmux command to switch the pin mux for changing the function of a pin.

Name

mt7688_pinmux -- switch the pin mux of MT7688

Synopsis

mt7688_pinmux get
mt7688_pinmux set <group> <function>

Description

In the system console of LinkIt Smart 7688, type the mt7688_pinmux get command to query the current pin mux states:












Taking the ephy group (mapping to the EPHY_LED0_N pin) as an example, we can see the Group ephy is able to provide ephyand gpio functions. And currently it is in the ephy function due to the surrounded [ and ].
If we want to change the function of a group, we can use the mt7688_pinmux command with the set parameter. The following example changes the function of the Group ephy from ephy to gpio:
root@mylinkit:/# mt7688_pinmux set ephy gpio
set pinmux ephy -> gpio
And we can also use the get parameter to verify the current pin mux states:
root@mylinkit:/# mt7688_pinmux get
Group i2c - [i2c] gpio
Group uart0 - [uart] gpio
Group uart1 - [uart] gpio
Group uart2 - [uart] gpio pwm
Group pwm0 - [pwm] gpio
Group pwm1 - [pwm] gpio
Group refclk - refclk [gpio]
Group spi_s - spi_s [gpio]
Group spi_cs1 - [spi_cs1] gpio refclk
Group i2s - i2s [gpio] pcm
Group ephy - ephy [gpio]
Group wled - [wled] gpio
We can see the function of the Group ephy has been changed from ephy to gpio.

有用[]  包起來代表是現在的mode.....

======================================================================

Basic Concepts of MRAA

Libmraa is a C/C++ library to interface with the peripheral on LinkIt Smart 7688. Libmraa is pre-installed in the system image of LinkIt Smart 7688 and supports C++, Python and Node.js bindings.

Installing MRAA

Libmraa is already installed in the system image of LinkIt Smart 7688, so you don't need to install it again. For a list of libmraa APIs, please see here for more information.

Basic Concepts

The majority of hardware modules such as GPIO, UART, SPI, and PWM are represented as objects created by mraa's factory function. These modules are initialized on certain pins that are identified by pin numbers. The pin numbers in the libmraa on LinkIt Smart 7688 are identical to the GPIO number in the data sheet and in the Linux GPIO subsystem.
The following Python example creates GPIO object on GPIO 2:
import mraa
pin = mraa.Gpio(2)    # Initialize GPIO2 (P10 on LinkIt Smart 7688 board)
This maps to P10 of LinkIt Smart 7688 and it’s the IS2_WS pin in data sheet, as shown in table below.
GPIO NumberDatasheetSilk print on LinkIt Smart 7688
2I2S_WSP10
Refer to the Pin-out diagram of LinkIt Smart 7688 to see the mapping between the silk print on the board and the GPIO number. This GPIO number also applies to Linux: /sys/class/gpio/2 which maps to exactly the same P10 pin on the LinkIt Smart 7688 board.

=============================================================================

Using MRAA in Python

This section introduces major modules of Python libmraa to give you ideas about how to work with GPIOs and the other interfaces that are available on LinkIt Smart 7688.

Installing MRAA

Libmraa and its Python bindings are already installed in the system image of LinkIt Smart 7688, so you don't need to install it again.
To use libmraa in Python, you need to import it. In the below example, libmraa is imported and the output is the build version of the mraa:
import mraa
print (mraa.getVersion())
For a list of libmraa APIs, please see here for more information.

GPIO and Interupts

To control GPIO pins, initialize the pin as GPIO pin and set its mode. The simplest operation mode is OUTPUT - set the pin to HIGHor LOW to enable and disable external switches or to form signal patterns.
import mraa
pin = mraa.Gpio(2)    # Initialize GPIO2 (P10 on LinkIt Smart 7688 board)
pin.dir(mraa.DIR_OUT) # set as OUTPUT pin
Then, call pin.write(0) to set the pin state to LOW or call pin.write(1) to set the pin state to HIGH. To make the Wi-Fi LED blink periodically, set pin 44 (WLED_N) to GPIO mode and execute the following code:
import mraa
import time

# Refer to the pinout digram for the GPIO number to silk print mapping
# in this example the number 44 maps to Wi-Fi LED.
pin = mraa.Gpio(44)
pin.dir(mraa.DIR_OUT)

while True:
    pin.write(1)
    time.sleep(1)
    pin.write(0)
    time.sleep(1)
There’s another GPIO mode which is INPUT. It takes the digital signal input from the pin and interprets it into 1 and 0. This example will continuously print out the value received from P10 on the board. You can short 3V3 and P10 to observe the change in values.
import mraa
import time

# Refer to the pinout digram for the GPIO number to silk print mapping
# in this example the number 2 maps to P10 on LinkIt Smart 7688 board
pin = mraa.Gpio(2)
pin.dir(mraa.DIR_IN)

while True:
    print "P10 state:", pin.read()
    time.sleep(0.3)
Finally, an interrupt service routine can be installed to the pin and invoked when the values of the input pin P10 (GPIO2) has changed. Call isr API with the trigger type you want to register and the function to be called. Note that the function runs in a different thread.
import mraa
import time

def callback(userdata):
    print "interrupt triggered with userdata=", userdata

pin = mraa.Gpio(2)
pin.dir(mraa.DIR_IN)
pin.isr(mraa.EDGE_BOTH, callback, None)

while(True):
    time.sleep(1)
    # simply wait for interrupt

PWM

Use PWM module to generate a pulse width modulated signal pattern. This is useful to control actuator peripherals such as servo motors. To use PWM, initialize it on a certain pin such as GPIO. Note that only GPIO18GPIO19GPIO20GPIO21 supports PWM on LinkIt Smart 7688. To control the PWM pattern, several parameters are required, including:

Period

This defines the carrier frequency of the modulation. It’s controlled by period, period_ms and period_us APIs.

Duty Cycle or Pulse Width

These two parameters are related to each other and usually you only need to set one of them. Duty cycle is controlled by write API with a value range between 0.0 to 1.0, where 0.0 is 0% of duty cycle and 1.0 is 100% of duty cycle. Pulse width also defines the pattern in a different unit: the "uptime" of the signal in time units. This is defined by pulsewidth, pulsewidth_ms, and pulsewidth_us APIs.
The following example generates a 500Hz PWM signal with 25% duty cycle on pin P26.
import mraa

pin = mraa.Pwm(18)  # initialize on GPIO18 (pin P26)
pin.period_ms(2)    # set PWM frequency to 500Hz (2ms period)
pin.enable(True)    # enable PWM output
pin.write(0.25)     # set duty cycle to 25%

I2C

I2C (Inter-Integrated Circuit) is a widely used protocol among peripherals. It consists of 2 signal pins - usually named SDA and SCL. LinkIt Smart 7688 comes with 1 set of I2C on GPIO4(P21) and GPIO5(P20) as SCL and SDA respectively. The way I2Cs are initialized is slightly different from GPIO modules - instead of using pins, I2Cs are initialized according to its device index. Since there is only 1 set of I2C master device on LinkIt Smart 7688, you can simply pass 0 - and it is always on pin GPIO4 andGPIO5.
import mraa
i2c = mraa.I2c(0)
I2C is capable of connecting multiple slave devices to a single I2C master. Each slave device is identified by a 7-bit address. The following example scans for a Seeed Studio 3-Axis Digital Accelerometer attached to LinkIt Smart 7688 by reading the device ID from its registers.
import mraa

i2c = mraa.I2c(0)
# Grove - 3-Axis Digital Accelerometer(+-16g)
# is a ADXL345 configured to I2C address 0x53.
i2c.address(0x53)
# The device ID should be 
if 0xE5 == i2c.readReg(0x00):
    print "Grove - 3-Axis Digital Accelerometer found on I2C Bus"
else:
    print "Grove - 3-Axis Digital Accelerometer not found"
For more details on I2C API, please see here. To drive an I2C device, you need to operate multiple I2C sequences. LinkIt Smart 7688 also comes with libUPM pre-installed, which is a set of driver repository built upon libmraa. Please see here for a driver example of Seeed Studio 3-Axis Digital Accelerometer.

write(I2c selfuint8_t const * data) → mraa::Result[source]
data: uint8_t const *
Write length bytes to the bus, the first byte in the array is the command/register to write
data: Buffer to send on the bus, first byte is i2c command
length: Size of buffer to send
Result of operation
writeByte(I2c selfuint8_t data) → mraa::Result[source]
data: uint8_t
Write a byte on the bus
data: The byte to send on the bus
Result of operation
writeReg(I2c selfuint8_t reguint8_t data) → mraa::Result[source]
reg: uint8_t data: uint8_t
Write a byte to an i2c register
reg: Register to write to
data: Value to write to register
Result of operation
writeWordReg(I2c selfuint8_t reguint16_t data) → mraa::Result[source]
reg: uint8_t data: uint16_t
Write a word to an i2c register
reg: Register to write to
data: Value to write to register
Result of operation

SPI

SPI (Serial Peripheral Interface) can also be used to control peripheral devices. On LinkIt Smart 7688 it consists of 4 pins:SPI_MOSI(P22)SPI_MISO(P23)SPI_CLK(P24), and SPI_CS1(P25).
It’s important to note that the SPI device is also used for communicating with the internal flash storage on the board. Therefore, developers should access the SPI functionality through SPI modules only and avoid treating these SPI pins as general GPIO. Otherwise, the flash storage may work incorrectly.
The SPI module in libmraa is initialized by device index, instead of pin number:
import mraa
spi = mraa.Spi(0)
The SPI protocol allows flexible configurations on signal patterns. Depending on your peripheral, you may need to configure the pattern with APIs like bitPerWord and mode. Please see here for API details.

=====================================================================

Using UPM in Python

UPM is an open source sensor and peripheral driver repository based on libmraa APIs. Among the popular sensor drivers such as I2C accelerometers and many others are available from this repository.
LinkIt Smart 7688 system image is pre-installed with UPM and you can start programming on existing sensors immediately – but if the default implementation is not available, you can use opkg package manager to update the UPM library.
UPM comes with bindings in C++, Python and Node.js. Let’s get started with an example where you’ll learn how to use UPM and Python to receive values from an I2C accelerometer – a Grove 3-Axis Digital Accelerometer (±16g).
  1. Connect the accelerometer to your board. If you have the breakout board, you can attach it to the I2C grove interface. If not, you can also connect the pins from the accelerometer to the corresponding pins GND3V3SDA(P20) and SCL(P21) on LinkIt Smart 7688 board.
  2. Import pyupm_adxl345 module from the UPM repository in your program, you’ll do this in the next step. This module is used because the Grove 3-Axis Digital Accelerometer (±16g) uses the ADXL345 chipset.
  3. Create a Python script adxl.py with following content:
    import pyupm_adxl345 as adxl
    import time
    device = adxl.Adxl345(0)
    while True:
        device.update()
        a = device.getAcceleration()
        print "(x,y,z)=%5.1f, %5.1f, %5.1f" % (a[0], a[1], a[2])
        time.sleep(0.3)
    
  4. Execute the Python script in system console by typing the following command:
    python adxl.py
    
You should see the acceleration value printed repeatedly. Try moving the sensor around to see changes in the values – now you can use the sensor to detect accelerations. For a list of other available Python modules in UPM repository, check here. The UPM repository also comes with a handful of examples for your reference.




有mpu 9150....
==============================================================================

Using USB Webcam

By connecting a USB webcam to the USB host port on LinkIt Smart 7688, users can easily setup the video streaming service according to the following steps.

Supported cameras

LinkIt Smart 7688 has installed Linux UVC (USB Video Class) drivers to provide USB webcam suppport. Webcams follow the UVC standard can be supported on LinkIt Smart 7688. The real capabilities and supported resolution depend on the current UVC driver implementation.

Step-by-step

In this section, we use mjpg-streamer as the streaming application and it's already installed in the system firmware by default. For the webcam, Logitech C310 is used in this example.

Step 1: plug the webcam into the USB host port on LinkIt Smart 7688

Step 2: type the following command in the system console

Open the system console of LinkIt Smart 7688 and type the command:
# mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480 -f 25" -o "output_http.so -p 8080 -w /www/webcam" &

Step 3: connect the PC to the same local network as LinkIt Smart 7688

  • If LinkIt Smart 7688 is in AP mode, connect the PC to LinkIt Smart 7688 AP directly.
  • If LinkIt Smart 7688 is in Station mode, connect the PC to the same AP that LinkIt Smart 7688 connects to.

Step 4: open a brower and check the video

In the browser, connect to http://mylinkit.local:8080 and the streaming video from the webcam will be shown as below: 

===============================================================================

Audio Playback and Recording

LinkIt Smart 7688 has an I2S interface for audio playback and recording. This is not availalbe to LinkIt Smart 7688 Duo. You'll need an audio DAC to convert I2S to analog sound data.
A simple option is to get a LinkIt Smart 7688 breakout from Seeed Studio, and use it for audio playback and record.
Note: the recording function is only supported with firmware v0.9.3 and above. Also the LinkIt Smart 7688 breakout v2 from Seeed Studio is required. For the v1 breakout board, there are HW reworks needed to enable the recording function.

Basic setup

  • First, install LinkIt Smart 7688 to the breakout, as shown below: 
  • Plug an earphone (with Mic if it's for recording) to the audio jack.
  • Power up the board.
  • Connect it with a USB drive which contains the audio files.

Audio Playback

MP3 playback

To play a MP3 file, use madplay:
# madplay "path_to_your_mp3_file"

WAV playback

To play a WAV file, use aplay as below:
# aplay -M "path_to_your_wav_file"
For details about aplay, please refer to the aplay manual page.

Audio recording

WAV recording

Note: for a high bit-rate WAV recording (like 16bit/44.1k format as the below example), please record the file to a destination withhigh I/O speed (e.g. USB drive, SD card, or RAM) instead of the on-board flash. Due to the low writing speed of the on-board flash, users will experience sound jittering and buffer overrun if the recorded file is written to the on-board flash.
To record an audio file, use arecord as below:
+

# arecord -f cd -t wav -M /Media/USB-A1/my_recording.wav
For details about arecord, please refer to the arecord manual page.

===========================================================================

Hardware limitations

I2C

Two I2C operation modes are not supported:
  • Clock stretching
  • Repeated start

SPI

  • The max size of the I/O buffer of SPI is 16 bytes. If a data transmission larger than 16 bytes is issued, there will be an error reported.
  • Full-duplex mode is not supported. Only half-duplex mode is supported.

I2S

  • Mono (1 channel) is not supported.
  • The supported sampling rates and data width are up to 192kHz / 24-bit.

Known issues

Wi-Fi driver

  • AP mode is with better performance than Station mode.
  • LinkIt Smart 7688 cannot be in both AP and Station mode at the same time (i.e. not available as a wireless repeater).
  • Monitor mode is not supported.
  • In Station mode, WPA-enterprise and WPA2-enterprise encryption protocols are not supported. WEP is not supported by default in OpenWrt due to its insecurity and it can be cracked in seconds.

USB

  • USB 2.0 devices will be detected as USB 1.1 devices. [Solved in firmware v0.9.3 and above]

I2S

  • WAV recording with WM8960 is not supported yet. [Solved in firmware v0.9.3 and above]

SPI

  • [v0.9.3] the .frequency() API in MRAA is not functional. Please use the spi-config command to adjust the SPI working frequency. The following command sets the SPI working frequency to 7MHz:
    # spi-config -d /dev/spidev32766.1 -s 7000000
    
  • [v0.9.3] 16-bit data type is not functional. It can only work with 8-bit data type.
  • For LinkIt Smart 7688, the MSB of a data transmission might be error. LinkIt Smart 7688 Duo does no have this issue. [Solved in firmware v0.9.3 and above]

UPM sensor support

  • For the UPM compatibility of Seeed GROVE sensors on LinkIt Smart 7688, please refer to the related post on LinkIt Smart 7688 technical forum.