顯示具有 小雪的幼幼班~Linkit Smart 7688 Duo 標籤的文章。 顯示所有文章
顯示具有 小雪的幼幼班~Linkit Smart 7688 Duo 標籤的文章。 顯示所有文章

2017年1月14日 星期六

LinkIt Smart 7688 Duo + Grove - IMU 10DOF 測試

****注意 Arduino IDE 使用1.6.7***** 



Grove - IMU 10DOF是採用 MPU-9250 三軸陀螺儀+三軸加速度+三軸磁場 加上 BMP180 氣壓感測器所組合而成。

規格 :
供電電源:3V-5V
通信方式:標準I2C
陀螺儀範圍:±250 500 1000 2000 °/s
加速度範圍:± 2 ±4 ±8 ±16g   
磁場範圍:  ±4800uT 
氣壓表範圍 300〜1100hPa


Library下載位置 :
https://github.com/Seeed-Studio/IMU_10DOF

這程式是用 IMU_10DOF Library 附的範例改寫。



#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <TouchScreen.h>

#include "I2Cdev.h"
#include "MPU9250.h"
#include "BMP180.h"

#define TFT_RST   5       //LCM  接腳
#define TFT_DC    6
#define TFT_CS    7
#define TFT_MOSI  8
#define TFT_MISO  9
#define TFT_CLK   10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);


MPU9250 accelgyro;
I2Cdev   I2C_M;

uint8_t buffer_m[6];

int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t   mx, my, mz;

float heading;
float tiltheading;

float Axyz[3];
float Gxyz[3];
float Mxyz[3];

volatile float mx_sample[3];
volatile float my_sample[3];
volatile float mz_sample[3];

static float mx_centre = 0;
static float my_centre = 0;
static float mz_centre = 0;

volatile int mx_max = 0;
volatile int my_max = 0;
volatile int mz_max = 0;

volatile int mx_min = 0;
volatile int my_min = 0;
volatile int mz_min = 0;

float temperature;
float pressure;
float atm;
float altitude;
BMP180 Barometer;

void setup()
{
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();
    
    tft.begin();
    tft.fillScreen(ILI9341_BLACK);
    tft.setRotation(3);

    // initialize device
   // Serial.println("Initializing I2C devices...");
    accelgyro.initialize();
    Barometer.init();
    
    tft.setCursor(0,20);
    tft.print("Acceleration(g) of X,Y,Z:"); 
    
    tft.setCursor(0,40);
    tft.print("Gyro(degress/s) of X,Y,Z:");

    tft.setCursor(0,60);
    tft.print("Compass Value of X,Y,Z:");
    
    tft.setCursor(0,80);
    tft.print("Heading:");

    tft.setCursor(0,100);
    tft.print(" Tilt Heading:");

    tft.setCursor(0,120);
    tft.print("Temperature: ");
    
    tft.setCursor(0,140);
    tft.print("Pressure: ");
    
    tft.setCursor(0,160);
    tft.print("Ralated Atmosphere: ");
    
    tft.setCursor(0,180);
    tft.print("Altitude: ");
    
}

void loop()
{

    getAccel_Data();
    getGyro_Data();
    getCompassDate_calibrated(); // compass data has been calibrated here
    getHeading();               //before we use this function we should run 'getCompassDate_calibrated()' frist, so that we can get calibrated data ,then we can get correct angle .
    getTiltHeading();
    
    tft.fillRect(0,30,120,10,0);
    tft.setCursor(0,30);
    tft.print(Axyz[0]);
    tft.print(" , ");
    tft.print(Axyz[1]);
    tft.print(" , ");
    tft.print(Axyz[2]);

   
    tft.fillRect(0,50,120,10,0);
    tft.setCursor(0,50);
    tft.print(Gxyz[0]);
    tft.print(",");
    tft.print(Gxyz[1]);
    tft.print(",");
    tft.print(Gxyz[2]);

    
    tft.fillRect(0,70,120,10,0);
    tft.setCursor(0,70);
    tft.print(Mxyz[0]);
    tft.print(",");
    tft.print(Mxyz[1]);
    tft.print(",");
    tft.print(Mxyz[2]);

    
    tft.fillRect(0,90,120,10,0);
    tft.setCursor(0,90);
    tft.print(heading);

    
    tft.fillRect(0,110,120,10,0);
    tft.setCursor(0,110);
    tft.println(tiltheading);

    temperature = Barometer.bmp180GetTemperature(Barometer.bmp180ReadUT()); //Get the temperature, bmp180ReadUT MUST be called first
    pressure = Barometer.bmp180GetPressure(Barometer.bmp180ReadUP());//Get the temperature
    altitude = Barometer.calcAltitude(pressure); //Uncompensated caculation - in Meters
    atm = pressure / 101325;

    
    tft.fillRect(0,130,120,10,0);
    tft.setCursor(0,130);
    tft.print(temperature, 2); //display 2 decimal places
    tft.print(" deg C");


    tft.fillRect(0,150,120,10,0);
    tft.setCursor(0,150);
    tft.print(pressure, 0); //whole number only.
    tft.print(" Pa");

    
    tft.fillRect(0,170,120,10,0);
    tft.setCursor(0,170);
    tft.print(atm, 4); //display 4 decimal places

    
    tft.fillRect(0,190,120,10,0);
    tft.setCursor(0,190);
    tft.print(altitude, 2); //display 2 decimal places
    tft.print(" m");
    
    delay(1000);

}


void getHeading(void)
{
    heading = 180 * atan2(Mxyz[1], Mxyz[0]) / PI;
    if (heading < 0) heading += 360;
}

void getTiltHeading(void)
{
    float pitch = asin(-Axyz[0]);
    float roll = asin(Axyz[1] / cos(pitch));

    float xh = Mxyz[0] * cos(pitch) + Mxyz[2] * sin(pitch);
    float yh = Mxyz[0] * sin(roll) * sin(pitch) + Mxyz[1] * cos(roll) - Mxyz[2] * sin(roll) * cos(pitch);
    float zh = -Mxyz[0] * cos(roll) * sin(pitch) + Mxyz[1] * sin(roll) + Mxyz[2] * cos(roll) * cos(pitch);
    tiltheading = 180 * atan2(yh, xh) / PI;
    if (yh < 0)    tiltheading += 360;
}



void Mxyz_init_calibrated ()
{

    
    while (!Serial.find("ready"));
   
    get_calibration_Data ();

}


void get_calibration_Data ()
{
    for (int i = 0; i < sample_num_mdate; i++)
    {
        get_one_sample_date_mxyz();
   
        if (mx_sample[2] >= mx_sample[1])mx_sample[1] = mx_sample[2];
        if (my_sample[2] >= my_sample[1])my_sample[1] = my_sample[2]; //find max value
        if (mz_sample[2] >= mz_sample[1])mz_sample[1] = mz_sample[2];

        if (mx_sample[2] <= mx_sample[0])mx_sample[0] = mx_sample[2];
        if (my_sample[2] <= my_sample[0])my_sample[0] = my_sample[2]; //find min value
        if (mz_sample[2] <= mz_sample[0])mz_sample[0] = mz_sample[2];

    }

    mx_max = mx_sample[1];
    my_max = my_sample[1];
    mz_max = mz_sample[1];

    mx_min = mx_sample[0];
    my_min = my_sample[0];
    mz_min = mz_sample[0];

    mx_centre = (mx_max + mx_min) / 2;
    my_centre = (my_max + my_min) / 2;
    mz_centre = (mz_max + mz_min) / 2;

}

void get_one_sample_date_mxyz()
{
    getCompass_Data();
    mx_sample[2] = Mxyz[0];
    my_sample[2] = Mxyz[1];
    mz_sample[2] = Mxyz[2];
}

void getAccel_Data(void)
{
    accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
    Axyz[0] = (double) ax / 16384;
    Axyz[1] = (double) ay / 16384;
    Axyz[2] = (double) az / 16384;
}

void getGyro_Data(void)
{
    accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
    Gxyz[0] = (double) gx * 250 / 32768;
    Gxyz[1] = (double) gy * 250 / 32768;
    Gxyz[2] = (double) gz * 250 / 32768;
}

void getCompass_Data(void)
{
    I2C_M.writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); //enable the magnetometer
    delay(10);
    I2C_M.readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer_m);

    mx = ((int16_t)(buffer_m[1]) << 8) | buffer_m[0] ;
    my = ((int16_t)(buffer_m[3]) << 8) | buffer_m[2] ;
    mz = ((int16_t)(buffer_m[5]) << 8) | buffer_m[4] ;

    Mxyz[0] = (double) mx * 1200 / 4096;
    Mxyz[1] = (double) my * 1200 / 4096;
    Mxyz[2] = (double) mz * 1200 / 4096;
}

void getCompassDate_calibrated ()
{
    getCompass_Data();
    Mxyz[0] = Mxyz[0] - mx_centre;
    Mxyz[1] = Mxyz[1] - my_centre;
    Mxyz[2] = Mxyz[2] - mz_centre;
}

上傳完成後就會顯示 IMU_10DOF個軸向的值。



2016年12月30日 星期五

LinkIt Smart 7688 Duo + SeeedStudio Grove-LCD RGB Backlight 測試

****注意 Arduino IDE 使用1.6.7***** 

SeeedStudio  的 Grove-LCD  RGB Backlight 是一個16字 兩行 的文字型LCM,用I2C當資料傳輸介面比起一般常見的並排型LCM接饺少很多Grove-LCD  RGB Backlight 另一個特點是背光顏色理論上是全彩的缺點是電源需用5VLinkIt Smart 7688 Duo 的Grove接口只有3.3V要接再一起就要有點技巧

Grove-LCD  RGB Backlight 包裝內容一樣是一條線跟一個LCM主體


Grove 線材的一端紅色剪下然後和上杜邦針腳

  把Grove線完整的那端插在LCM上,有剪線的那端插在LinkIt Smart 7688 Duo 的底座I2C Grove接口把焊有針腳的紅色線插在Arduino相容插座的5V接口

到這裡下載libraries https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight

解壓縮後放在Arduino的libraries下

\arduino-1.6.7-windows\arduino-1.6.7\libraries

開啟ARDUINO 輸入以下程式然後上傳

//

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;


void setup() 
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
}

void loop() 
{
   // Print a message to the LCD.
    lcd.setRGB(255, 255,255);
    lcd.print("Hello, world!");
    delay(1000);
    lcd.clear();
    
    lcd.setRGB(255, 0, 0);
    lcd.print("Backlight is red");
    delay(1000);
    lcd.clear();
    
    lcd.setRGB(0,255, 0);
    lcd.print("Backlight is green");
    delay(1000);
    lcd.clear();
    
    lcd.setRGB(0,0, 255);
    lcd.print("Backlight is blue");
    delay(1000);
    lcd.clear();
}


//

LCM就會用白色背光顯示Hello, world!



用綠色背光顯示Backlight is green


用藍色背光顯示Backlight is bule


用紅色背光顯示Backlight is red


2016年5月20日 星期五

Grove - Touch Sensor 測試-使用 LinkIt Smart 7688 Duo

Grove - Touch Sensor 測試-使用 LinkIt Smart 7688 Duo

       這是一個簡單的觸摸感測器模組可以用它來替代傳統的按鈕。使用TTP223-B的觸摸感測器IC電路它可以檢測電容的變化就是一個電子化的開關,取代傳統的機械式關。

Grove - Touch Sensor 

 Seeed Stduio 料號 : 101020037 包裝內容 :  Touch Sensor模組 X 1  Grove 線材 X 1。




先將Grove 線材插入Touch Sensor模組 。
.

在插入LinkIt Smart 7688 Duo 底座 D5


插入 USB  跟電腦連線。


開啟Arduino IDE 輸入以下程式

//********程式開始*************



const int TouchPin=5;     // 設定 Pin5 名稱為 "TouchPin"
const int ledPin=13;      // 設定 Pin13 名稱為 "ledPin"
void setup() {
pinMode(TouchPin, INPUT);   // 設定"TouchPin"為輸入
pinMode(ledPin,OUTPUT);     // 設定 "ledPin" 為輸出
}

void loop() {
int sensorValue = digitalRead(TouchPin);  //sensorValue = TouchPin 的輸入
if(sensorValue==1)                        //如果sensorValue =1
{
digitalWrite(ledPin,HIGH);              // ledPin 輸出高電位

delay(1000);                           //延遲一秒
}
else                                  //反之
{
digitalWrite(ledPin,LOW);            // ledPin 輸出低電位
}
}

//*****************程式結束************



確認  工具 >  版子 序列埠 的設定正確。


按  "上傳"。


詢問存檔  填 "Touch "  "存檔"。


程式上傳中。


程式上傳完成。


程式上傳完成後觸摸 Touch (不是金屬哪一面 ) LinkIt Smart 7688 Duo LED13 會亮。




參考資料 : 聯發科創意實驗室  http://home.labs.mediatek.com/?lang=zh-hans
                    Arduino LLC            https://www.arduino.cc/

Grove-Encoder 編碼器 測試- 使用 LinkIt Smart 7688 Duo

Grove-Encoder 編碼器 測試- 使用 LinkIt Smart 7688 Duo

****注意 LinkIt 7688 Duo 在 Arduino IDE 1.6.9 有問題 Arduino IDE 要用1.6.7***** 


     Grove-Encoder (編碼器)是增量式旋轉編碼器。增量型編碼器也稱作相對型編碼器,利用檢測脈衝的方式來計算轉速及位置,可輸出有關旋轉軸運動的資訊。

注意:這個Grove-Encoder (編碼器)模組沒按下的功能。
      
      增量型編碼器有二個輸出,分別稱為A和B,二個輸出是正交輸出,相位差為90度。二個訊號有90度的相位差,在不同旋轉方向時,二個訊號的相序也有所不同,可以利用程式將二個訊號進行解碼.根據其相序不同,在有方波時使一計數器上數或是下數,此計數器的值即可對應轉軸的旋轉量。


Grove-Encoder 

Seeed Studio 料號 : 151126041 包裝內容 : 編碼器模組 x 1  Grove 線材 x 1。



將 Grove 線材插入編碼器 。


 Grove 線材另一頭插在 LinkIt Smart 7688 Duo 底座的 D4 , OLED 插在 I2C。



插入 USB 與電腦連線。



開啟 Arduino 輸入以下程式碼 


//*******程式開始********

 /* 此為用 I/O 捕捉編碼器失誤率有點高要降低錯誤率須使用中斷 */
  
  #include <Wire.h>
  #include <SeeedOLED.h>

 int val; 
 int encoder0PinA = 4;     //編碼器 A 接 Pin4
 int encoder0PinB = 5;     //編碼器 B 接 Pin5
 int encoder0Pos = 0;      //初始值為0
 int encoder0PinALast = LOW;
 int n = LOW;

 void setup() 
 { 
    Wire.begin();
   SeeedOled.init();                   //初始化OLED
   SeeedOled.clearDisplay();           //清除OLED
   SeeedOled.setNormalDisplay();      //設定OLED為正常顯示
   SeeedOled.setPageMode();          //設定OLED為頁模式

   pinMode (encoder0PinA,INPUT);      //設定編碼器 A 為輸入 
   pinMode (encoder0PinB,INPUT);      //設定編碼器 B 為輸入

 } 

 void loop() { 
   n = digitalRead(encoder0PinA);                   //開始捕捉編碼器 A 的變化
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
      SeeedOled.setTextXY(0,0);           //游標移至0,0
      SeeedOled.putString("      ");       //列出空白
      SeeedOled.setTextXY(0,0);           //游標移至0,0
      SeeedOled.putNumber(encoder0Pos);  //輸出編器的值
     
   } 
   encoder0PinALast = n;
 } 

//******程式結束*******


確認 工具 > 版子 序列埠 是否正確。



按 "上傳 "。


詢問存檔  "Encoder" 存檔。


程式上傳中。


程式上傳完成。


上傳完成後 旋轉 Encoder 順時針轉數字會增加逆時針轉數字會減少。




參考資料 : 聯發科創意實驗室  http://home.labs.mediatek.com/?lang=zh-hans
                    Arduino LLC            https://www.arduino.cc/

Grove - Relay 測試-使用 LinkIt Smart 7688 Duo

Grove - Relay 測試-使用 LinkIt Smart 7688 Duo

****注意 LinkIt 7688 Duo 在 Arduino IDE 1.6.9 有問題 Arduino IDE 要用1.6.7***** 



       使用繼電器能讓 LinkIt Smart 7688 Duo控制更高的電壓和電流繼電器是一個常開開關。當設為高電為時LED會亮起,繼電器將關閉允許電流流過。峰值電壓能力是10安培250V。



   注意 : 使用繼電器控制市電時請注意安全,會有觸電危險!!!


Grove - Relay

 Seeed Studio 料號 : 103020005 包裝內容 : Relay模組 X 1 Grove 線材 X 1



Grove 線材插入Relay模組 


再將另一頭插入 LinkIt Smert 7688 Duo 底座的 D5 



插入USB 與電腦連線



開啟 Arduino IDE 輸入以下程式碼 

//*********程式開始*********

void setup() {

  pinMode(5, OUTPUT);  //設定 Pin5 為輸出
}

void loop() {
  digitalWrite(5, HIGH);   // 設定 Pin5 為高電位
  delay(1000);              // 等待 1 秒
  digitalWrite(5, LOW);    // 設定 Pin5 為低電位
  delay(1000);              // 等待 1 秒

}

//**********程式結束**********




確認 工具 > 版子 序列埠 設定



按 "上傳 "



詢問存檔  輸入 "Relay" 按  "存檔"



程式上傳中




程式上傳完成



程式上傳完成後, Relay模組 會1秒跳一次聲音很像機車方向燈







參考資料 : 聯發科創意實驗室  http://home.labs.mediatek.com/?lang=zh-hans

                    Arduino LLC            https://www.arduino.cc/

2016年5月19日 星期四

Grove - Light Sensor 測試-使用LinkIt Smart 7688 Duo

Grove - Light Sensor 測試-使用LinkIt Smart 7688 Duo

****注意 LinkIt 7688 Duo 在 Arduino IDE 1.6.9 有問題 Arduino IDE 要用1.6.7***** 


   Grove - Light Sensor 模組使用GL5528光敏電阻來檢測環境光的強度。感測器在光強度增加時電阻降低。使用LM358運算放大器作為電壓隨耦器來獲得準確的數據。它可以在應用如電子玩具,光控開關,監視器使用。


Grove - Light Sensor 

  Seeed Studio 料號 : 1511185005 包裝內容 :  Light Sensor模組 x1 Grove 線材 x 1


先將 Grove 線材一頭插入 Light Sensor模組


再將Grove 線材另一頭插入LinkIt Smart 7688 Duo 底座的 A2, OLED 模組接在 I2C



插上USB與電腦連線


開啟Arduino IDE 輸入以下程式碼


//*********以下是程式碼***********

 #include <Wire.h>
 #include <SeeedOLED.h>

#define LIGHT_SENSOR A2      // Light Sensor 接在 A2

float Rsensor;    //電阻值 單位 K Ohm

void setup()
{
 
  Wire.begin();              
  SeeedOled.init();                    //初始化 OLED
  SeeedOled.setNormalDisplay();      //設定 OLED 正常顯示
  SeeedOled.setPageMode();           //設定 OLED 為頁模式
 
   }
void loop()
{
 
    int sensorValue = analogRead(LIGHT_SENSOR);  //感測器的值 = 類比輸入腳的值
 
    Rsensor = (float)(1023-sensorValue)*10/sensorValue;  // 計算出電阻值
 
 
    SeeedOled.clearDisplay();                //清除 OLED
    SeeedOled.setTextXY(0,0);              //OLE 游標移至 0,0
    SeeedOled.putString("The analog is ");  //顯示字元 The analog is
    SeeedOled.setTextXY(2,0);              //OLE 游標移至 2,0
    SeeedOled.putFloat(sensorValue);        //顯示 感測器的值
    SeeedOled.setTextXY(5,0);              //OLE 游標移至 5,0
    SeeedOled.putString("The RES is ");     //顯示字元 The RES is
    SeeedOled.setTextXY(7,0);              //OLE 游標移至 7,0
    SeeedOled.putFloat(Rsensor,DEC);        //顯示 電阻值
 
    delay(1000);           //延遲 1秒

}

//**********程式碼到此************


檢查 "工具" 內的 "版子" 跟 "序列埠" 是否設定正常 


按 "上傳 " 將程式碼上傳到LinkIt Smart 7688 Duo


Arduino IDE 會詢問存當,輸入 Light "存檔"


程式上傳中


程式上傳完成


     上傳完成後OLED 會顯示目前感測器的值跟計算後的電阻值用手把Light Sensor 遮起來感測器的值會下降電阻值會升高



參考資料 :
                      聯發科創意實驗室   http://home.labs.mediatek.com/
                      Seeed Technology     http://www.seeedstudio.com/