반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형




The 74HC595; 74HCT595 is an 8-bit serial-in/serial or parallel-out shift register with a storage register and 3-state outputs. Both th e shift and storage register have separate clocks. The device features a serial input (DS) and a serial output (Q7S) to enable cascading and an asynchronous reset MR input. A LOW on MR will reset the shift register.
Data is shifted on the LOW-to-HIGH transitions of the SHCP input. The data in the shift register is transferred to the storage register on a LOW-to-HIGH transition of the STCP input. If both clocks are connected together, the shift register will always be one clock pulse ahead of the storage register. Data in the storage register appears at the output whenever the output enable input (OE) is LOW. A HIGH on OE causes the outputs to assume a high-impedance OFF-state. Operation of the OE input does not affect the state of the registers. Inputs include clamp diodes. This enables the use of current limiting resistors to interface inputs to voltages in excess of VCC




Display 0~9 and A~E on a 7-segment


Circuit




Source Code 1


const int clockPin = 8; //SH
const int latchPin = 9; //ST
const int dataPin = 10; // DS

const byte seg[10] = {0b00000000, 0b00000001,0b00000010,0b00000100,
                    0b00001000,0b00010000,0b00100000,0b01000000,
                    0b10000000,0b1111111};
const byte digits[17] = {
  0b01110111, //0
  0b00000110, //1
  0b10110011, //2
  0b10010111, //3
  0b11000110, //4
  0b11010101, //5
  0b11110101, //6
  0b01000111, //7
  0b11110111, //8
  0b11010111, //9
  0b11100111, //A
  0b11110100, //B
  0b01110001, //C
  0b10110110, //D
  0b11110001, //E
  0b11110001, //F
  0b11111111  //ALL
};


void setup() {
  // put your setup code here, to run once:
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

}

void LEDs(byte a) {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, a);
  digitalWrite(latchPin, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0; i<10; i++) {
    LEDs(seg[i]);
    delay(500);
  }

  for(int i=0; i<18; i++) {
    LEDs(digits[i]);
    delay(500);
  }
}



Source Code 2


//www.elegoo.com
//2016.06.13

// Lab13 Using a 74hc595 and seven segment display to make reciprocal function
 
// define the LED digit patterns, from 0 - 9
// 1 = LED on, 0 = LED off, in this order:
//                74HC595 pin     Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7
//                Mapping to      a,b,c,d,e,f,g of Seven-Segment LED
byte seven_seg_digits[10] = { B11111100,  // = 0
                              B01100000,  // = 1
                              B11011010,  // = 2
                              B11110010,  // = 3
                              B01100110,  // = 4
                              B10110110,  // = 5
                              B10111110,  // = 6
                              B11100000,  // = 7
                              B11111110,  // = 8
                              B11100110   // = 9
                             };
 
// connect to the ST_CP of 74HC595 (pin 9,latch pin)
int latchPin = 9;
// connect to the SH_CP of 74HC595 (pin 8, clock pin)
int clockPin = 8;
// connect to the DS of 74HC595 (pin 10)
int dataPin = 10;
 
void setup() {
  // Set latchPin, clockPin, dataPin as output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}
 
// display a number on the digital segment display
void sevenSegWrite(byte digit) {
  // set the latchPin to low potential, before sending data
  digitalWrite(latchPin, LOW);
    
  // the original data (bit pattern)
  shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]); 
 
  // set the latchPin to high potential, after sending data
  digitalWrite(latchPin, HIGH);
}
 
void loop() {      
  // count from 9 to 0
  for (byte digit = 10; digit > 0; --digit) {
    delay(1000);
    sevenSegWrite(digit - 1);
  }
  
  // suspend 4 seconds
  delay(4000);
}





74HC595 with 8 LEDs


Circuit



in my case, I used Arduino Uno and changed the pin numbers.


//by Simon Monk
//www.elegoo.com
//2016.06.13

int latchPin = 9;
int clockPin = 8;
int dataPin = 10;

byte leds = 0;

void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}

void loop()
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(500);
  }
}

void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}



Use Serial Monitor


Same Circuit as above


Source Code


//by Simon Monk
//www.elegoo.com
//2016.06.13

int latchPin = 9;
int clockPin = 8;
int dataPin = 10;

byte leds = 0;

void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  updateShiftRegister();
  Serial.begin(9600);
  while (! Serial); // Wait untilSerial is ready - Leonardo
  Serial.println("Enter LED Number 0 to 7 or 'x' to clear");
}

void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch >= '0' && ch <= '7')
    {
      int led = ch - '0';
      bitSet(leds, led);
      updateShiftRegister();
      Serial.print("Turned on LED ");
      Serial.println(led);
    }
    if (ch == 'x')
    {
      leds = 0;
      updateShiftRegister();
      Serial.println("Cleared");
    }
  }
}

void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}


==> Type number on the Serial Monitor -> light on the LED of typed number





반응형

[Arduino] Library and RGB LED

2017. 1. 11. 08:18 | Posted by 솔웅


반응형

Libraries


Arduino 소프트웨어에 익숙해지고 내장 함수를 사용할 수 있게 되면 Arduino 기능을 추가 Library 확장  있습니다.

 


Library?

 

Library 센서디스플레이모듈 등에 쉽게 연결할 수있는 코드 모음입니다예를 들어내장  LiquidCrystal Library 사용하면 문자 LCD 디스플레이와 쉽게 대화   있습니다인터넷에 다운로드  수있는 수백 개의 추가 Library 있습니다내장 Library 이러한 추가 Library  일부는 이곳에 가면 보실 수 있습니다. 추가 Library 사용하려면 Library 설치해야합니다.

 


Library 설치 방법

 


Library 관리자 사용


 

Arduino IDE  Library 설치하려면 Library Manager(IDE 버전 1.6.2에서 사용 가능) 사용하면 됩니다.  IDE 열고 "스케치"메뉴를 클릭  다음 Library 포함> Library Manage 클릭하십시오.

 




그런 다음 Library 관리자가 열리고 이미 설치되었거나 설치할 준비가  Library 목록이 표시됩니다. 예제에서는 Bridge Library 설치합니다목록을 스크롤하여 설치하려는 Library 버전을 선택하십시오경우에 따라 Library  버전  사용할  있습니다버전 선택 메뉴가 나타나지 않아도 걱정하지 마세요정상입니다.



 


마지막으로 install 클릭하고 IDE에서  Library 설치할 때까지 기다립니다연결 속도에 따라 다운로드하는  시간이 걸릴  있습니다설치가 끝나면 Installed 태그가 Bridge Library 옆에 나타납니다.  그러면 Library 매니저를 닫을  있습니다.

 


 


이제  Include Library menu에서  Library 찾을  있습니다나만의 Library 추가하려면 github에서 new issue 엽니다.

 

 

.zip Library 가져 오기

 

Library 종종 ZIP 파일 또는 폴더로 배포됩니다폴더의 이름은 Library 이름입니다폴더 안에는.cpp 파일, .h 파일  종종 keywords.txt 파일예제 폴더  Library 필요한 기타 파일이 있습니다.버전 1.0.5부터는 3rd party Library IDE 설치할  있습니다다운로드  Library 압축을 풀지말고 그대로 두십시오.

 

Arduino IDE에서 스케치> Library 포함으로 이동하십시오드롭 다운 목록의 상단에서 ".ZIP Library추가"옵션을 선택하십시오.

 


 


추가하려는 Library 선택하라는 메시지가 나타납니다. .zip 파일의 위치로 이동하여 엽니 .

 


 


스케치> Library 가져 오기 메뉴로 돌아갑니다이제 드롭 다운 메뉴 하단에 Library 표시됩니다.스케치에서 사용할 준비가되었습니다. zip 파일은 Arduino 스케치 디렉토리의 libraries 폴더에서 확장됩니다.

 

참고 : Library 스케치에서 사용할  있지만 IDE restart  때까지 Library 예제가 파일예제에 표시되지 않습니다.

 


Manual Installation

 

Library 설치하려면 먼저 Arduino 응용 프로그램을 종료하십시오그런 다음 Library 포함  ZIP파일의 압축을 푸십시오예를 들어 "ArduinoParty"라는 Library 설치하는 경우 ArduinoParty.zip압축 해제하십시오. ArduinoParty라는 폴더와 ArduinoParty.cpp  ArduinoParty.h 같은 파일이 있어야합니다. (.cpp  .h 파일이 폴더에 없으면 폴더를 만들어야합니다. 경우 "ArduinoParty"라는폴더를 만들어 ZIP 있던 모든 파일로 이동하십시오 ArduinoParty.cpp  ArduinoParty.h 같은 파일).

 

ArduinoParty 폴더를이 폴더 (Library 폴더) 드래그하십시오. Windows에서는 "My Documents \ Arduino \ libraries"라고합니다. Mac 사용자의 경우 "Documents / Arduino / libraries"라고 불릴 것입니다리눅스에서는 스케치북의 "libraries"폴더가됩니다.

 

Arduino Library 폴더는 다음과 같아야합니다 (Windows 경우).

 

  My Documents\Arduino\libraries\ArduinoParty\ArduinoParty.cpp
  My Documents\Arduino\libraries\ArduinoParty\ArduinoParty.h
  My Documents\Arduino\libraries\ArduinoParty\examples
  ....

 

또는 다음과 같이 (Mac  Linux) :

 

  Documents/Arduino/libraries/ArduinoParty/ArduinoParty.cpp
  Documents/Arduino/libraries/ArduinoParty/ArduinoParty.h
  Documents/Arduino/libraries/ArduinoParty/examples
  ....

 

 

 

.cpp  .h 파일보다 많은 파일이있을  있습니다파일이 모두 있는지 확인하십시오. (.cpp  .h 파일을 Library 폴더에 직접 저장하거나 추가 폴더에 중첩  경우 Library 작동하지 않습니다 ( : Documents \ Arduino \ libraries \ ArduinoParty.cpp  Documents \ Arduino \ libraries \ ArduinoParty \ ArduinoParty \ ArduinoParty.cpp 작동하지 않습니다.)

 

Arduino 응용 프로그램을 다시 시작하십시오 Library 소프트웨어의 스케치 -> Library 가져 오기 메뉴 항목에 나타나는지 확인하십시오그게 다야! Library 설치했습니다!

 

 튜토리얼은 Limor Fried 텍스트를 기반으로합니다.

 

Arduino 시작 안내서의 텍스트는 Creative Commons Attribution-ShareAlike 3.0 라이선스 따라 사용이 허가되었습니다가이드의 코드 샘플은 공개 도메인으로 배포됩니다.

 

https://www.arduino.cc/en/reference/libraries



※ RGB LED with Arduino Mega 2560



Circuit




Source Code


//by Simon Monk
//www.elegoo.com
//2016.06.13

// Define Pins
#define RED 3
#define GREEN 5
#define BLUE 6

#define delayTime 10 // fading time between colors


void setup()
{
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
}

// define variables
int redValue;
int greenValue;
int blueValue;


// main loop
void loop()
{
  redValue = 255; // choose a value between 1 and 255 to change the color.
  greenValue = 0;
  blueValue = 0;

  analogWrite(RED, 0);
  delay(1000);

   for(int i = 0; i < 255; i += 1) // fades out red bring green full when i=255
  {
    redValue -= 1;
    greenValue += 1;
    analogWrite(RED, 255 - redValue);
    analogWrite(GREEN, 255 - greenValue);
    delay(delayTime);
  }

  redValue = 0;
  greenValue = 255;
  blueValue = 0;

  for(int i = 0; i < 255; i += 1)  // fades out green bring blue full when i=255
  {
    greenValue -= 1;
    blueValue += 1;
    analogWrite(GREEN, 255 - greenValue);
    analogWrite(BLUE, 255 - blueValue);
    delay(delayTime);
  }

  redValue = 0;
  greenValue = 0;
  blueValue = 255;


  for(int i = 0; i < 255; i += 1)  // fades out blue bring red full when i=255
  {
  redValue += 1;
  blueValue -= 1;
  analogWrite(RED, 255 - redValue);
  analogWrite(BLUE, 255 - blueValue);
  delay(delayTime);
  }
}




반응형

[Arduino] Servo Motor

2017. 1. 10. 09:53 | Posted by 솔웅


반응형


※ Servo Motor


Circuit




Source Code


Include Servo Library



#include <Servo.h>

Servo myservo;
int pos = 0;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(9);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(pos = 0; pos < 180; pos += 1)
  {
    myservo.write(pos);
    delay(15);
  }
}



※ Servo Motor with variable resistor


Circuit


Source Code


#include <Servo.h>

Servo myservo;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(9);
}

void loop() {
  // put your main code here, to run repeatedly:
  myservo.write(map(analogRead(A0),0,1023,0,120));
  delay(15);
}


refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=s_B8KYE7xvI&index=10&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w



반응형

[Arduino] LCD and 7 Segment

2017. 1. 10. 09:27 | Posted by 솔웅


반응형


※  Control LCD with illuminance sencor



Circuit




Source Code


LiquidCrystal Library. This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs.


include LiquidCrystal Library.




#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,2,3,4,5);

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  lcd.print("More Fun Life");
  Serial.print("Test");
}

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(0,1);
  lcd.print(analogRead(A0));
  delay(200);
}


==> Display Illuminance sensor value on LCD



※ Control LCD using ultrasonic sencor


Circuit




Source Code


#include <LiquidCrystal.h>
#define TRIG 8
#define ECHO 9

LiquidCrystal lcd(12,11,2,3,4,5);

void setup() {
  // put your setup code here, to run once:
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  lcd.begin(16,2);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  long distance = pulseIn(ECHO, HIGH)/58.2;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(distance);
  lcd.print(" cm");
  delay(200);
}


refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=coFwvg_O1q4&index=8&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w




7 Segment Anode


7 Segment Cathode




※ 7 Segment



Circuit



Source Code


// Common Anode version
byte digits[10][7] =
{
  {0,0,0,0,0,0,1 }, // display '0'
  {1,0,0,1,1,1,1 }, // display '1'
  {0,0,1,0,0,1,0 }, // display '2'
  {0,0,0,0,1,1,0 }, // display '3'
  {1,0,0,1,1,0,0 }, // display '4'
  {0,1,0,0,1,0,0 }, // display '5'
  {0,1,0,0,0,0,0 }, // display '6'
  {0,0,0,1,1,1,1 }, // display '7'
  {0,0,0,0,0,0,0 }, // display '8'
  {0,0,0,1,1,0,0 }  // display '9'
};

// Common Cathode version
/*
byte digits[10][7] = {
  {1,1,1,1,1,1,0 }, // display '0'
  {0,1,1,0,0,0,0 }, // display '1'
  {1,1,0,1,1,0,1 }, // display '2'
  {1,1,1,1,0,0,1 }, // display '3'
  {0,1,1,0,0,1,1 }, // display '4'
  {1,0,1,1,0,1,1 }, // display '5'
  {1,0,1,1,1,1,1 }, // display '6'
  {1,1,1,0,0,0,0 }, // display '7'
  {1,1,1,1,1,1,1 }, // display '8'
  {1,1,1,0,0,1,1 }  // display '9'
};
*/
void setup() {
  // put your setup code here, to run once:
  for(int i=2;i<10;i++) {
    pinMode(i,OUTPUT);
  }
  digitalWrite(9,HIGH); // turn off DP LED
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0; i<10;i++) {
    delay(1000);
    displayDigit(i);
  }
}

void displayDigit(int num) {
  int pin = 2;
  for(int i=0; i<7; i++) {
    digitalWrite(pin+i, digits[num][i]);
  }
}



※ 7 Segment with buttons


Circuit


Source Code


#define PLUS 11
#define MINUS 12

int digit = 0;

// Common Anode version
byte digits[10][7] =
{
  {0,0,0,0,0,0,1 }, // display '0'
  {1,0,0,1,1,1,1 }, // display '1'
  {0,0,1,0,0,1,0 }, // display '2'
  {0,0,0,0,1,1,0 }, // display '3'
  {1,0,0,1,1,0,0 }, // display '4'
  {0,1,0,0,1,0,0 }, // display '5'
  {0,1,0,0,0,0,0 }, // display '6'
  {0,0,0,1,1,1,1 }, // display '7'
  {0,0,0,0,0,0,0 }, // display '8'
  {0,0,0,1,1,0,0 }  // display '9'
};

void setup() {
  // put your setup code here, to run once:
  pinMode(PLUS,INPUT);
  pinMode(MINUS, INPUT);

  for(int i=2;i<10;i++) {
    pinMode(i,OUTPUT);
  }
  digitalWrite(9,HIGH); // turn off DP LED
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(PLUS) == HIGH)
  {
    ++digit;
    if(digit > 9)
    {
      digit=0;
    }
  }

  if(digitalRead(NINUS) == HIGH)
  {
    --digit;
    if(digit < 0)
    {
      digit=9;
    }
  } 

  displayDigit(digit);
  delay(100);
}

void displayDigit(int num) {
  int pin = 2;
  for(int i=0; i<7; i++) {
    digitalWrite(pin+i, digits[num][i]);
  }
}


refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=SRtYpBnmPfA&index=9&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w

반응형


반응형


더 재밌게 놀기 연구소



Illuminance sensor with LED


Need to use Analog pin of Arduino

Analog input pins

AnalogRead


Circuit



Source Code


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(9,map(analogRead(A0),0,1023,0,255);
}



※ Illuminance sensor with Buzzer



Circuit




Source Code


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  tone(8,map(analogRead(A0),0,1023,31,4978),20);
  delay(500);
}



Youtube Tutorial of above examples (in Korean) : https://www.youtube.com/watch?v=w397cxZQ5IA&index=6&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w






Ultrasonic Sensor with LED


Circuit




Source Code


#define TRIG 2
#define ECHO 3
#define RED 11
#define RED2 12
#define GREEN 10
#define BLUE 9


void setup() {
  // put your setup code here, to run once:
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(TRIG,LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG,LOW);

  long distance = pulseIn(ECHO, HIGH)/58.2;

  analogWrite(RED, 0);
  analogWrite(GREEN, 0);
  analogWrite(BLUE, 0);

  if(distance < 10) {
    analogWrite(RED2,255);
  }else if(distance < 20) {
    analogWrite(GREEN,255);
    analogWrite(RED2,0);
  } else if(distance < 30) {
    analogWrite(BLUE,255);
    analogWrite(RED2,0);
  }

  delay(100);
}


Note : Red of 3 color LED of mine is not working properly so I've added Red LED to port number 12.




Ultrasonic Sensor with Buzzer



Circuit





Source Code



#define TRIG 2
#define ECHO 3

void setup() {
  // put your setup code here, to run once:
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(TRIG,LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG,LOW);

  long distance = pulseIn(ECHO, HIGH)/58.2;

  tone(4,1000,20);
  delay(100);
  tone(4,1000,20);

  delay(distance);
}


Youtube Tutorial of above examples (in Korean) : https://www.youtube.com/watch?v=XzNHUctzjOM&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w&index=7





Application

Let's add some more LEDs and make Buzzer Piano with Ultrasonic sensor. Wow


#define TRIG 2
#define ECHO 3
#define RED 11
#define RED2 12
#define GREEN 10
#define GREEN2 7
#define YELLOW 8
#define BLUE 9
#define BLUE2 5
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440

int pins[] = {2,3,4};
int notes[] = {NOTE_E4, NOTE_D4, NOTE_C4};


void setup() {
  // put your setup code here, to run once:
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(TRIG,LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG,LOW);

  long distance = pulseIn(ECHO, HIGH)/58.2;

  analogWrite(RED, 0);
  analogWrite(GREEN, 0);
  analogWrite(BLUE, 0);

  if(distance < 10) {
    analogWrite(RED2,255);
    tone(4,NOTE_C4,20);
  }else if(distance < 15) {
    analogWrite(GREEN,255);
    analogWrite(BLUE2,0);
    analogWrite(RED2,0);
    analogWrite(YELLOW,0);
    analogWrite(GREEN2,0);
    tone(4,NOTE_D4,20);
  } else if(distance < 20) {
    analogWrite(BLUE,255);
    analogWrite(BLUE2,0);
    analogWrite(RED2,0);
    analogWrite(YELLOW,0);
    analogWrite(GREEN2,0);
    tone(4,NOTE_E4,20);
  } else if(distance < 25) {
    analogWrite(YELLOW,255);
    analogWrite(BLUE2,0);
    analogWrite(RED2,0);
    analogWrite(GREEN2,0);
    tone(4,NOTE_F4,20);
  } else if(distance < 30) {
    analogWrite(GREEN2,255);
    analogWrite(BLUE2,0);
    analogWrite(RED2,0);
    analogWrite(YELLOW,0);
    tone(4,NOTE_G4,20);
  } else if(distance < 30) {
    analogWrite(BLUE2,255);
    analogWrite(RED2,0);
    analogWrite(YELLOW,0);
    analogWrite(GREEN2,0);
    tone(4,NOTE_A4,20);
  }

  delay(100);
}





반응형

[Arduino] Tri LED and Buzzer

2017. 1. 9. 01:33 | Posted by 솔웅


반응형

PWM (Pulse Width Modulation)
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.




※ Tri LED control


Circuit


Source Code


#define RED 11
#define GREEN 10
#define BLUE 9

void setup() {
  // put your setup code here, to run once:
  randomSeed(analogRead(0));
}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(RED, random(255));
  analogWrite(GREEN, random(255));
  analogWrite(BLUE, random(255));
  delay(1000);
}



※ Control Tri LED using Buttons




Source Code


#define RED 11
#define GREEN 10
#define BLUE 9
#define RED_BUTTON 4
#define GREEN_BUTTON 3
#define BLUE_BUTTON 2

int r=0, g=0, b=0;

void setup() {
  // put your setup code here, to run once:
  pinMode(RED_BUTTON, INPUT);
  pinMode(GREEN_BUTTON, INPUT);
  pinMode(BLUE_BUTTON, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(RED_BUTTON) == HIGH) {
    ++r;
    if(r>255) {
      r=0;
    }
  }

   if(digitalRead(GREEN_BUTTON) == HIGH) {
    ++g;
    if(g>255) {
      g=0;
    }
  }

  if(digitalRead(BLUE_BUTTON) == HIGH) {
    ++b;
    if(b>255) {
      b=0;
    }
  }

  analogWrite(RED,r);
  analogWrite(GREEN,g);
  analogWrite(BLUE,b);
  delay(10);
}


Youtube Tutorial of above examples (in Korean) : https://www.youtube.com/watch?v=7h8TJtRekNI&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w&index=4





※ Passive Buzzer (piezo speaker)




Source Code


To include pitches.h, first copy the file to Sketch.

(Examples - 02. Digital - toneMelody)


#include "pitches.h"

int melody[] = {
  NOTE_G4,
  NOTE_G4,
  NOTE_A5,
  NOTE_A5,
  NOTE_G4,
  NOTE_G4,
  NOTE_E4,
  NOTE_G4,
  NOTE_G4,
  NOTE_E4,
  NOTE_E4,
  NOTE_D4,
  0,
  NOTE_G4,
  NOTE_G4,
  NOTE_A5,
  NOTE_A5,
  NOTE_G4,
  NOTE_G4,
  NOTE_E4,
  NOTE_G4,
  NOTE_E4,
  NOTE_D4,
  NOTE_E4,
  NOTE_C4,
  0 };

  int noteDurations[] = {
  1,1,1,1,
  1,1,2,
  1,1,1,1,
  3,1,
  1,1,1,1,
  1,1,2,
  1,1,1,1,
  3,1
  };
 
void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int thisNote = 0; thisNote < 26; thisNote++) {
    int noteDuration = 250 * noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(8);
  }
}


==> Buzzer (Piezo speaker) will play the Korean children song.





※ Let's make a Piano using the Buzzer


Circuit


Source Code


#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330

int pins[] = {2,3,4};
int notes[] = {NOTE_E4, NOTE_D4, NOTE_C4};

void setup() {
  // put your setup code here, to run once:
  for(int i=0; i<3; i++) {
    pinMode(pins[i], INPUT);
  }
  pinMode(8, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0; i<3; i++) {
    if(digitalRead(pins[i] == HIGH)) {
      tone(8, notes[i], 20);
    }
  }
}


Youtube Tutorial of above examples (in Korean) : https://www.youtube.com/watch?v=irbyDUGmNYk&index=5&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w

반응형


반응형


Arduino Basic


Open Source Hardware

- Arduino UNO : 8 bit CPU

- Arduino DUE

- Arduino TRE : Arduino + Beaglebone black

- Arduino Yun :(Built-in Wifi

- Arduino Mini Nano

- Netduino

- Raspberry Pi : 32 bit, Linux, 700 MB

- Beaglebone black : 32 bit, 1 GB, 512 MB Memory, Android O

- Intel Galileo : Pentium CPU,  can share Arduino shield

 

IDE

- Arduino Sketch : Language - C/C++

- Arduino Scratch : GNU Development Tool

- Arduino Processing : for Art

 

Arduino Shields


Sensor & Actuator

 

Breadboard

 

 



◎ Control Arduino Built-in LED


Source Code (Sketch Sample : Blink)


`/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino model, check
  the Technical Specs of your board  at https://www.arduino.cc/en/Main/Products
 
  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 
  modified 2 Sep 2016
  by Arturo Guadalupi
 
  modified 8 Sep 2016
  by Colby Newman
*/


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}


==> The built-in LED will blink every second.




◎ Control External LED


circuit diagram




Source Code : Same Source Code as above one


==> The External LED will blink every second.


Youtube Tutorial of above examples (in Korean) : https://www.youtube.com/watch?v=YcAdhH3Y-HU&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w&index=2




◎ Control multiple external LEDs


LED : Light-emitting diode 


circuit diagram




Source Code


#define DELAY_TIME 100

void setup() {
  // put your setup code here, to run once:
  pinMode(2. OUTPUT);
  pinMode(3. OUTPUT);
  pinMode(4. OUTPUT);
  pinMode(5. OUTPUT);
  pinMode(6. OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(2, HIGH);
  delay(DELAY_TIME);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  delay(DELAY_TIME);
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  delay(DELAY_TIME);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
  delay(DELAY_TIME);
  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  delay(DELAY_TIME);
  digitalWrite(6, LOW);
  digitalWrite(5, HIGH);
  delay(DELAY_TIME);
  digitalWrite(5, LOW);
  digitalWrite(4, HIGH);
  delay(DELAY_TIME);
  digitalWrite(4, LOW);
  digitalWrite(3, HIGH);
  delay(DELAY_TIME);
  digitalWrite(3, LOW);
 
}


==> The LEDs will turn on and off sequentially.



Refactoring above code using FOR statement


#define DELAY_TIME 100

void setup() {
  // put your setup code here, to run once:
  for(int thisPin = 2; thisPin < 7; thisPin++) {
    pinMode(thisPin,OUTPUT);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  // loop from the lowest pin to the highest:
  for (int thisPin = 2; thisPin < 7; thisPin++) {
    // turn the pin on:
    digitalWrite(thisPin, HIGH);
    delay(DELAY_TIME);
    // turn the pin off:
    digitalWrite(thisPin, LOW);
  }

  // loop from the highest pin to the lowest:
  for (int thisPin = 6; thisPin >= 2; thisPin--) {
    // turn the pin on:
    digitalWrite(thisPin, HIGH);
    delay(DELAY_TIME);
    // turn the pin off:
    digitalWrite(thisPin, LOW);
  }
 
}



◎ Button Control


circuit diagram



Source Code


#define LED 12
#define BUTTON 7

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(BUTTON) == HIGH) {
    digitalWrite(LED, HIGH);
    delay(500);
    digitalWrite(LED,LOW);
  }
}


==> If press the button then turn on the LED for 0.5 second.


Youtube Tutorial of above examples (in Korean) : https://www.youtube.com/watch?v=wtbjzGIQe_I&index=3&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w





Application

I am going to combine both Button control and Multiple LEDs control source codes.



Source Code



#define BUTTON 8
#define DELAY_TIME 100

void setup() {
  // put your setup code here, to run once:
  for(int thisPin = 2; thisPin < 7; thisPin++) {
    pinMode(thisPin,OUTPUT);
  }
  pinMode(BUTTON, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(BUTTON) == HIGH) {
    // loop from the lowest pin to the highest:
     for (int thisPin = 2; thisPin < 7; thisPin++) {
      // turn the pin on:
       digitalWrite(thisPin, HIGH);
      delay(DELAY_TIME);
       // turn the pin off:
      digitalWrite(thisPin, LOW);
     }

    // loop from the highest pin to the lowest:
    for (int thisPin = 6; thisPin >= 2; thisPin--) {
      // turn the pin on:
      digitalWrite(thisPin, HIGH);
      delay(DELAY_TIME);
      // turn the pin off:
      digitalWrite(thisPin, LOW);
    }
  }
}


==> The LEDs will turn on and off sequentially when press button





반응형

Things I want to do in 2017

2017. 1. 1. 23:06 | Posted by 솔웅


반응형



My 16 years journey on IT field





Things I want to do in 2017


◎ IoT - The Internet of Things



○ Predix


Predix is General Electric's software platform for the collection and analysis of data from industrial machines.[1] General Electric plans to support the growing industrial internet of things with cloud servers and an app store.[2] GE is a member of the Industrial Internet Consortium which works to aid the development and use of industrial internet technologies.




○ Arduino


Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects.





◎ Planed personal Projects



○ at lease 1 Arduino Project
: i.e. Automated mung bean sprouts growing machine


will be similar to this image



○ Making Wind Turbines




○ Making Solar Generator




Wising you a Happy new year filled with happiness and peace.

May your home be filled with joy and Happiness. Happy new year.



반응형


반응형

[Predix] Understanding Platform Services 3


Using UAAC to Create an OAuth2 Client

UAA Dashboard 대신 UAAC (UAA Command-Line Interface)를 사용하여 OAuth2 클라이언트를 만들 수 있습니다.

UAAC를 사용하여 UAA 인스턴스를 관리 할 수 있습니다. command-line 인터페이스 설치에 대한 자세한 내용은 https://github.com/cloudfoundry/cf-uaac를 참조하십시오.

    1. UAA 인스턴스를 원하는 대상으로 지정하십시오.
    uaac target <uaa_instance_url>
   
    <uaa_instance_url>은 신뢰할 수있는 발급자의 URL입니다 (예 :


https://11fa0273-9e2a-37e2-9d06-2c95a1f4f5ea.predix-uaa.run.aws-usw02-pr.ice.predix.io . UAA 인스턴스를 응용 프로그램에 바인딩 한 후 VCAP_SERVICES 환경 변수에서이 URL을 검색 할 수 있습니다.
   
    2.  administrative client를 사용해 로그인 하세요.
    uaac token client get admin
   
    3. 프롬프트에서 administrative client secret 을 정하세요.
   
    4. 아래 명령어를 사용해서 OAuth2 client 를 생성하세요.
    uaac client add [client_name]
    --authorities "uaa.resource"
    --scope "openid"
    --autoapprove "openid"
    --authorized_grant_types [authorization_code|implicit|password|client_credentials|refresh_token]
    --redirect_uri [redirect_uri_1, redirect_uri_2, ...]
   
    범위 및 authorized_grant_types와 같은 UAA 옵션에 대한 자세한 내용은 https://github.com/GESoftware-CF/uaa/blob/master/docs/UAA-APIs.rst에서 UAA 설명서를 참조하십시오.
   



Updating the OAuth2 Client for Services

OAuth2 클라이언트를 업데이트하여 각 플랫폼 서비스에 특정한 권한 또는 범위를 추가하는 절차.

응용 프로그램이 플랫폼 서비스에 액세스 할 수있게하려면 JSON Web Token (JWT)에 플랫폼 서비스에 필요한 범위가 있어야합니다. 예를 들어 액세스 제어 서비스에 필요한 일부 범위는 acs.policies.read acs.policies.write입니다. 서비스에 필요한 전체 범위 목록은 각 서비스의 관련 섹션을 참조하십시오.

OAuth2 클라이언트는 권한 부여를 사용하여 액세스 토큰을 요청합니다. OAuth2는 4 가지 부여 유형을 정의합니다. 사용한 권한 부여 유형에 따라 필요한 JWT를 생성하도록 OAuth2 클라이언트를 업데이트해야합니다. OAuth2 클라이언트 생성 방법에 대한 자세한 내용은 OAuth2 클라이언트 생성을 참조하십시오.

UAA 인스턴스를 만들면 UAA 인스턴스를 구성 할 수 있도록 admin client가 자동으로 만들어집니다. admin client에는 기본적으로 필요한 권한 및 범위가 지정됩니다.

UAA 대시 보드를 사용하여 추가 클라이언트를 만드는 경우 기본적으로 클라이언트는 client_credentials 부여 유형에 대해 만들어집니다. 또한 필요한 권한과 범위 중 일부가 자동으로 클라이언트에 추가됩니다. 각 서비스에 특정한 권한이나 범위를 추가해야합니다.

또한 admin client에는 기본적으로 사용자 암호를 변경할 수있는 권한이 지정되지 않습니다. 사용자 암호를 업데이트하거나 변경해야하는 경우 uaa.admin 권한을 admin client에 추가해야합니다.

다음 절차는 클라이언트 자격 증명 권한 부여를 사용하는 OAuth2 클라이언트를 업데이트하는 데 필요한 단계를 보여줍니다.

1. Console view에서 서비스가 위치한 공간을 선택하십시오.
2. 서비스 인스턴스 페이지에서 구성해야하는 UAA 인스턴스를 선택하십시오.
3. 서비스 인스턴스 구성 옵션을 선택하십시오.
4. UAA 대시 보드 로그인 페이지에서 관리자 클라이언트 비밀번호를 지정하고 로그인을 클릭하십시오.
5. UAA 대시 보드에서 클라이언트 관리 탭을 선택합니다.
   클라이언트 관리 탭에는 클라이언트 및 서비스 인스턴스의 두 섹션이 있습니다. 서비스 인스턴스 섹션은 서비스에 대해 생성 한 서비스 인스턴스를 표시합니다.

   참고 : 여기에 표시된 서비스 인스턴스는 구성하려는 UAA를 사용하여 만든 인스턴스입니다. 다른 UAA 인스턴스를 사용하여 만든 서비스 인스턴스는이 페이지에 표시되지 않습니다.
  
6. 서비스 인스턴스 섹션에서 클라이언트를 업데이트해야하는 서비스의 + 클라이언트 인증 옵션을 클릭합니다.
7. 목록에서 기존 클라이언트를 선택하거나 새 클라이언트 추가 옵션을 선택하십시오. 새 클라이언트를 추가하기로 선택한 경우 OAuth2 클라이언트 생성의 단계를 따르십시오.
8. Submit을 클릭하십시오.
9. 클라이언트 관리 탭에서 이전 단계에서 추가 한 클라이언트에 해당하는 편집 아이콘을 클릭하십시오.
10. 클라이언트 편집 양식에서 다음 값을 지정하십시오.


Field


Description
Authorized Grant Types Choose one or more of the following grant types:
  • authorization_code

    When you use the authorization code grant type, the client directs the resource owner to UAA, which in turn directs the resource owner back to the client with the authorization code.

  • client_credentials

    When you use the client credentials grant type, the OAuth2 endpoint in UAA accepts the client ID and client secret and provides Access Tokens.

  • password

    When you use the resource owner password credentials grant type, the OAuth2 endpoint in UAA accepts the username and password and provides Access Tokens.

  • refresh_token

    The refresh tokens are credentials used to obtain access tokens. You can choose this option to obtain refresh token from UAA. You can then use the refresh token to obtain a new access token from UAA when the current access token becomes invalid or expires, or to obtain additional access tokens with identical or narrower scope.

  • implicit

    When you use the implicit grant type, UAA directly issues an Access Token to the client without authenticating the client. This reduces the number of round trips required to obtain an access token.

For more information on grant types, see RFC 6749.

Redirect URI Specify a redirect URI to redirect the client after login (for example, http://example-app.com/welcome).

This URI is used when you start using UAA as service provider for your external Identify provider.

Scopes By default, the client is assigned a few required scopes. For a new client, an administrator can select the scopes to be added based on the selected grant type.

If you select the authorization_code, password and implicit grant type, you must update the scopes with service specific scopes.

For a complete list of required scopes, see Authorities or Scopes Required for Platform Services.

For a list of available UAA scopes, see Scopes Authorized by the UAA.

Authorities By default, the client is assigned a few required authorities. For a new client, an administrator can select the authorities to be added based on the selected grant type.

If you select the client_credentials grant type, you must update the authorities with service specific authorities.

For a complete list of scopes to be added for each service, see Authorities or Scopes Required for Platform Services.

For a list of available UAA authorities, see Scopes Authorized by the UAA.

Auto Approved Scopes Specify scopes that can be approved automatically for the client without explicit approval from the resource owner.
Allowed Providers Specify the names of the external identity providers, if any. This field is required if you are using external identity providers with UAA as a service provider.
Access Token Validity Specifies the access token expiration time in ms.
Refresh Token Validity Specifies the refresh token expiration time in ms.

Next Steps:

You can complete the following additional tasks in UAA Dashboard:

  • If you are using authorization grant type as Authorization Code, Implicit, or Resource Owner Password, you can manage users in UAA.
  • You can create password policies for user passwords.
  • You can set up external identity provider or use UAA as an identity provider. See Managing Identity Providers.

If you have completed your OAuth2 client setup, you can bind your application to your service instance.




Authorities or Scopes Required for Platform Services

새 OAuth2 클라이언트를 만들면 클라이언트에 기본 범위와 권한이 할당됩니다. 각 서비스에 특정한 권한이나 범위를 추가해야합니다.

다음 표에는 OAuth2 클라이언트에 추가해야하는 각 플랫폼 서비스에 대한 범위와 권한이 나열되어 있습니다.

Service Name
Authorities/Scopes
Access Control
  • acs.policies.read
  • acs.policies.write
  • acs.attributes.read
  • acs.attributes.write
  • predix-acs.zones.<acs_instance_guid>.user

    This value is added by default if you use the UAA Dashboard. It is also generated in the VCAP_SERVICES environment variable as oauth-scope when you bind your application to your ACS service instance.

Tenant Management
  • tms.tenant.read
  • tms.tenant.write
  • predix-tms.zones.<tms_instance_guid>.user (added by default)
Analytics Catalog analytics.zones.<service_instance_guid>.user (added by default)
Analytics Runtime analytics.zones.<service_instance_guid>.user (added by default)
Asset predix-asset.zones.<service_instance_guid>.user (added by default)
Event Hub
  • Publish
    • predix-event-hub.zones.<Predix-Zone-Id>.user
    • predix-event-hub.zones.<Predix-Zone-Id>.wss.publish
    • predix-event-hub.zones.<Predix-Zone-Id>.grpc.publish
  • Subscribe
    • predix-event-hub.zones.<Predix-Zone-Id>.user
    • predix-event-hub.zones.<Predix-Zone-Id>.grpc.subscribe
Time Series
  • Data ingestion
    • timeseries.zones.<Predix-Zone-Id>.user (added by default)
    • timeseries.zones.<Predix-Zone-Id>.ingest
  • Data queries
    • timeseries.zones.<Predix-Zone-Id>.user (added by default)
    • timeseries.zones.<Predix-Zone-Id>.query
View
  • views.zones.<view_instanceId>.user (added by default)
  • views.admin.user
  • views.power.user

   
Updating the OAuth2 Client Using UAAC

Predix.io의 그래픽 사용자 인터페이스 대신 UAAC를 사용하여 OAuth2 클라이언트를 업데이트하기위한 선택적 절차.

응용 프로그램이 플랫폼 서비스에 액세스 할 수있게하려면 JSON Web Token (JWT)에 플랫폼 서비스에 필요한 범위가 있어야합니다. 예를 들어 액세스 제어 서비스에 필요한 일부 범위는 acs.policies.read acs.policies.write입니다. 서비스에 필요한 전체 범위 목록은 각 서비스의 관련 섹션을 참조하십시오.

OAuth2 클라이언트는 권한 부여를 사용하여 액세스 토큰을 요청합니다. OAuth2는 4 가지 부여 유형을 정의합니다. 사용한 권한 부여 유형에 따라 필요한 JWT를 생성하도록 OAuth2 클라이언트를 업데이트해야합니다. OAuth2 클라이언트 생성 방법에 대한 자세한 내용은 OAuth2 클라이언트 생성을 참조하십시오.






Updating the OAuth2 Client that uses Client Credentials Authorization Grant Types

Before you begin
이 절차에서는 UAAC (UAA Command Line Interface)를 사용합니다. UAAC 설치에 대한 자세한 내용은 https://github.com/cloudfoundry/cf-uaac를 참조하십시오.

다음 절차는 클라이언트 자격 증명 권한 부여를 사용하는 OAuth2 클라이언트를 업데이트하는 데 필요한 단계를 보여줍니다.

Procedure

1. UAA 인스턴스를 원하는 대상으로 지정하십시오.
uaac target <uaa_instance_url>
<uaa_instance_url>은 신뢰할 수있는 발급자의 URL입니다 (예 : https://11fa0273-9e2a-37e2-9d06-2c95a1f4f5ea.predix-uaa.run.aws-usw02-pr.ice.predix.io). UAA 인스턴스를 응용 프로그램에 바인딩 한 후 VCAP_SERVICES 환경 변수에서이 URL을 검색 할 수 있습니다.

2. Administrative client 를 사용해서 UAAC에 로그인 하세요.
uaac token client get admin
프롬프트에  <client_secret> 을 명시하세요.

3. UAA안의 플랫폼 서비스에 대해 필요한 그룹을 생성합니다.
uaac group add <service_scope>

여기서 <service_scope>는 서비스를 위해 만들어야하는 그룹입니다.

Predix 플랫폼 서비스에 필요한 그룹은 다음과 같습니다.


Service Name


Authorities
Access Control
  • acs.policies.read
  • acs.policies.write
  • acs.attributes.read
  • acs.attributes.write
  • predix-acs.zones.<acs_instance_guid>.user
Tenant Management
  • tms.tenant.read
  • tms.tenant.write
  • predix-tms.zones.<tms_instance_guid>.user
Analytics Catalog analytics.zones.<service_instance_guid>.user
Analytics Runtime analytics.zones.<service_instance_guid>.user
Asset predix-asset.zones.<service_instance_guid>.user
Time Series
  • Data ingestion
    • timeseries.zones.<Predix-Zone-Id>.user
    • timeseries.zones.<Predix-Zone-Id>.ingest
  • Data queries
    • timeseries.zones.<Predix-Zone-Id>.user
    • timeseries.zones.<Predix-Zone-Id>.query
View
  • views.zones.<view_instanceId>.user
  • views.admin.user
  • views.power.user


   
4. UAA에 새로운 유저를 생성합니다. 이 유저는 플랫폼 서비스의 administer 입니다.
Note :  이미 해당 유저가 있으면 이 단계는 건너뛰어도 괜찮습니다.
uaac user add <user_name> -p [password] --emails <user_name>@example.com

5. 필요한 scope 들에 멤버십을 할당합니다.
uaac member add <service_scope> <user_name>

콤마로 분리해 여러개의 유저를 명시할 수 있습니다.

6. OAuth2 클라이언트를 플랫폼 서비스에 필요한 범위로 업데이트하십시오.
uaac client update <client_name>
\ --scope <service_scopes>
\ --authorized_grant_types <grant_type>
\ --authorities uaa.resource

<grant_type>은 authorization_code, 암시 적, 암호 및 refresh_token 중 하나 일 수도 있고 조합 일 수도 있습니다. 여러 부여 유형을 쉼표로 구분 된 목록으로 지정할 수 있습니다.

7. administrative user를 사용해서 UAAC에 로그인 합니다.
uaac token owner get <service_client> <service_user>

프롬프트에 <client_secret>을 명시합니다.

8. 토큰에서 범위가 업데이트되었는지 확인하려면 다음 명령을 사용하십시오.
uaac token decode



Connecting Your Application to a Platform Service Instance

작성한 서비스 인스턴스와 응용 프로그램 사이의 통신을 설정하려면 응용 프로그램을 서비스 인스턴스에 바인드하십시오.

Before You Begin

Cloud Foundry에 애플리케이션을 배포하십시오.

응용 프로그램을 서비스 인스턴스에 바인딩하면 Cloud Foundry는 VCAP_SERVICES 환경 변수에 서비스의 연결 정보를 제공합니다. Cloud Foundry 런타임은 환경에 대해 배포 된 응용 프로그램과 통신하기 위해 VCAP_SERVICES 환경 변수를 사용합니다.

VCAP_SERVICES 환경 변수에서 다음 인스턴스 정보를 검색 할 수 있습니다.

    서비스 인스턴스의 instance_uri.
    instance_GUID는 서비스 인스턴스의 zoneID입니다.
    서비스 인스턴스에 액세스하기위한 HTTP 헤더 정보. 그것은 다음을 포함합니다 :
        Predix-Zone-Id로서의 http-header-name
        http-header-value
    인스턴스의 oauth 범위. 최종 사용자 토큰은 범위가 특정 서비스 인스턴스에 액세스해야합니다.

UAA 서비스 인스턴스에 바인딩하는 경우 instance_uri 및 instance_GUID 외에도 다음 정보가 표시됩니다.

    인스턴스에 대한 uaa_instance_issuerId. issuerID는 인증에 UAA 인스턴스를 사용하는 다른 서비스의 인스턴스를 만들 때 필요합니다.






Procedure
1. Cloud Foundry에 로그인 할 때는 Cloud Foundry CLI 를 사용합니다.
cf login -a <API_Endpoint>

<API_Endpoint>의 값은 Predix.io 사용자 계정에 등록 할 때 받게되는 Predix 환영 전자 메일에서 사용할 수 있습니다. Predix.io 등록에 따라 <API_Endpoint> 값은 다음 중 하나입니다.


    Predix US-West

    https://api.system.aws-usw02-pr.ice.predix.io
    Predix US-East

    https://api.system.asv-pr.ice.predix.io
    Predix Japan

    https://api.system.aws-jp01-pr.ice.predix.io
    Predix UK

    https://api.system.dc-uk01-pr.ice.predix.io

For example,

cf login -a https://api.system.aws-usw02-pr.ice.predix.io

이러면 아래와 같은 화면을 보실 겁니다.

Email> <your_predix_login> 
Password> <your_predix_password> 
Authenticating...OK 
Targeted org <your_predix_org> 
Targeted space dev     
API endpoint: https://api.system.aws-usw02-pr.ice.predix.io (API version: <version>)   
User: <your_predix_login> 
Org:  <your_predix_org>  
Space: dev



2. 다음 명령을 입력하여 응용 프로그램을 서비스 인스턴스에 바인드하십시오.
cf bind-service <your_app_name> <service_instance_name>

응용 프로그램이 <service_instance_name> 인스턴스에 바인딩되고 다음 메시지가 반환됩니다.

Binding service <service_instance_name> to app <your_app_name> in org predix-platform / space predix as userx@ge.com...
OK
TIP: Use 'cf restage' to ensure your env variable changes take effect

3. 아래와 같은 명령어를 사용해 binding 을 verify 합니다.
cf env <your_app_name>

응용 프로그램 myApp를 UAA 인스턴스에 바인딩하면 다음 메시지가 반환됩니다.

Getting env variables for app myApp in org predix-platform / space security as userx@ge.com...
OK
...
  ],
  "predix-uaa": [
        {
        "credentials":
        {
         "issuerId":
          "https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io/oauth/token",
         "uri": 
           "https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io",
          "zone": {
                    "http-header-name": "X-Identity-Zone-Id",
                    "http-header-value": "ff27c315-d027-4d1d-a30c-64f49b369ed9"
                   }
        },
        "label":
        "predix-uaa",
        "name":
        "my_uaa_instance",
        "plan":
        "free",
        "tags":
        []
        }
        ],


       
이 예제에서는 아래와 같은 값들이 표시됩니다.


    uaa_instance_issuerId = https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io/oauth/token
    uaa_instance_uri = https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io
    uaa_instance_GUID = ff27c315-d027-4d1d-a30c-64f49b369ed9

응용 프로그램 myApp를 ACS 서비스 인스턴스에 바인딩하면 다음 메시지가 반환됩니다.

Getting env variables for app myApp in org predix-platform / space security as userx@ge.com...
OK
...
  ],
"predix-acs": [
   {
    "credentials": {
     "uri": "https://predix-acs.run.aws-usw02-pr.ice.predix.io",
     "zone": {
      "http-header-name": "Predix-Zone-Id",
      "http-header-value": "9615a95a-9275-4a82-926d-89f06cbe04e1",
      "oauth-scope": "predix-acs.zones.9615a95a-9275-4a82-926d-89f06cbe04e1.user"
     }
    },
    "label": "predix-acs",
    "name": "acs-sample-instance",
    "plan": "Tiered",
    "provider": null,
    "syslog_drain_url": null,
    "tags": []
   }
  ],
 
  이 예제에서는 아래와 같은 값들이 표시됩니다.
 
 
    acs_instance_uri = https://predix-acs.run.aws-usw02-pr.ice.predix.io
    acs_instance_GUID = 9615a95a-9275-4a82-926d-89f06cbe04e1
    http-header-name = Predix-Zone-Id
    http-header-value = 9615a95a-9275-4a82-926d-89f06cbe04e1
    oauth-scope = predix-acs.zones.9615a95a-9275-4a82-926d-89f06cbe04e1.user

반응형
이전 1 2 다음