2017년 2월 25일 토요일

16. 두개의 아두이노 통신

개요:

아두이노 보드 2개를 연결하여 통신을 해보겠습니다.


Step1.

두개의 아두이노를 연결한다. A4와 A4, A5와 A5를 연결한다.

Step. 2

마스터 아두이노에 아래 소스를 업로드한다.
port는 10, device는 Arduino로 설정한다.

// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this

// Created 29 March 2006

// This example code is in the public domain.

#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;

void loop()
{
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting

  x++;
  delay(500);
}

Step 3. 

Slave Arduino에 아래 소스를 입력한다. 이때 port는 8로 설정한다.

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop()
{
delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

Step 4.

Serial Moniter를 열어 Mater Arduino 에서 보낸 문자가 Slave Arduino 로 전송되는 모습을 확인한다. 이때 Slave Arduino에서 LED 깜박이며 수신되는 모습을 확인할 수 있다.






















라벨:

2017년 2월 23일 목요일

15. 라즈베리파이에 한글 설치

Step 0.개요:

라즈베리파이 운영체제를 설치하면 기본적으로 영문형 글꼴이 나옵니다. 이때 한글입력을 하면 깨져나오므로 라즈베리용 한글을 설치하는 방법을 설명해 보겠습니다.

step 1.

설치하기 전에 update, upgrade를 실행한다.
터미날 모드에서
sudo apt-get update
sudo apt-get upgrade






step2.

한글폰트를 설치한다.
sudo apt-get install ttf-unfonts-core
sudo apt-get install ibus-hangul

step 3. 

preference(기본설정)에서 한글설정 
메뉴에서 preference - Raspberry Pi Configuration- Locaisation에서 Set Lcal,Set Timezone, SetKeyboard, Set WiFi Country를 각각 설정하고  재부팅한다.



위 그림처림 상단 오른쪽 태극마가 보이면 성공한 것이다.
* Raspberry Pi OS install

라벨:

14. 라즈베리파이 운영체제 설치

Step 0. 개요:

영국에서 개발한 라즈베리파이는 50달러정도의 손바닥에 놓을 수 있는 저렴한 가격으로 만든 교육용 컴퓨터입니다. 운영체제는 리눅스기반으로 제작되었습니다. 프로그래밍, 게임, 인터넷 , 센서실험등 여러가지지를  무궁무진하게 실험을 할 수있도록 설계되어있습니다.실험뿐만 아니라 제품까지 완성할 수도 있습니다.오디오, 게임기,드론, RC CAR 등을 만들 수 있습니다. 라즈베리파이를 사용하기 위해서는 일단 운영체제를 설치해야합니다. 라즈베리파이 사이트에 접속하여 무료로 다운받아 설치합니다.

step 1. 

SDFormatter, Win32DiskImger프로그램 다운받아 설치한다.

Step 2.

Raspberry Pi OS를 다운로드 한다.
Raspberrypi.org 사이트 접속하여 Download 메뉴를 클릭한다.
중간위치 왼쪽 NOOBS를 선택한다.


Step 3.

NOOBS에서 ZIP파일을 다운로드 한다.
다운로드받은 파일을 압축을 푼다.
그러면 2017-01-11-raspbian-jessie.img파일이 생긴다.




Step 4.

SD메모리 카드를 Format한다. 이때 Step1에서 설치한 SDFormatter프로그램을 사용하여 포멧한다.

Step 5.

SD메모리카드에 Step3. 에서 다운로드받은 파일을 SD메로리카드에 복제한다. 이때 Step1.에서 받은 Win32DiskImage프로그램을 실행하여 SD카드로 복사한다.

Step 6.

마지막 단계로 SD메모리카드를 라즈베리파이에 삽입하여 부팅하면 OS설치가 완성된다. 

아래 화면은 Raspberry Pi OS가 설치된 초기 화면이다.











라벨:

2017년 2월 21일 화요일

13. 라즈베리파이 시리얼 통신

개요: 

라즈베리파이에 아두이노를 설치하여 기초적인 시리얼통신을 구현해본다.

자세한 내용 보기 »

라벨:

2017년 2월 19일 일요일

12.라즈베리파이와 아두이노 통신

Step 1.  개요

라즈베리파이에 아두이노를 연결하여 테스트한다.
아두이노 13pin Led등 깜박이는 동작으로 확인한다.


자세한 내용 보기 »

라벨:

2017년 2월 17일 금요일

11. 아두이노에서의 서보모터 제어

1. 개요 :

아두이노와 서버모터를 연결하여 180도 무한 반복한다.

자세한 내용 보기 »

라벨:

2017년 2월 10일 금요일

10. 아두이노 블루투스 제어

 개요: 아두이노 블루투스 통신


아두이노로 블루투스 통신을 시현해 보겠습니다.
아두이노에 블루투스 모듈을 설치하고 스마트폰으로 블루투스와 통신을 하여 LED등을 켜고 끄는 동작을 해보겠습니다.

자세한 내용 보기 »

라벨:

2017년 2월 7일 화요일

9. 아두이노에서의 조이스틱 제어

  Step 0.개요

아두이노를 이용하여 조이스틱 모듈을 이용해보겠습니다. 조이스틱 모듈은 좌우상하, 누름 동작을 할 수 있습니다. 좌우는 X축, 상하는 Y축으로써 모니터를 통하여 움직이는데 따라서X축,Y축의 값을 알 수 있습니다.

Step 1. 준비물

조이스틱
아두이노
점퍼선









Step 2. 회로도
















Step 3. 조립화면









Step 3. Sample source code

먼저 아누이노를 연결하여 아누이노가 이상이 없는지 먼저 테스트해 봅니다. 아두이노를 사용해본 분은 아래 코드를 입력하여 실행합니다. 처음하시는 분은 아누이노에서 파일-예제-basic-blink를  컴파일, 업로드를 실행하여 아누이노에 RX,TX가 교대로 빛이 나는지 확인합니다.그리고 메뉴에서 툴- 포트를 설정합니다. 그리고 나서 아래 코드를 실행하여 같은 방법으로 컴파일, 업로드합니다.


// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600);
}

void loop() {
  Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print("\n");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print("\n");
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_pin));
  Serial.print("\n\n");
  delay(500);
}


출처: <https://brainy-bits.com/tutorials/arduino-joystick-tutorial/>

Step 4. 결과 화면

업로드가 성공했다면 아두이노 메뉴에서 툴-시리얼 모니터를 실행하면 아래와 같은 화면을 볼 수 있을 겁니다.
조이스틱을 움직일 때마다 x, y축의 값이 바뀐 것을 확인할 수 있습니다.





라벨:

8. IR Remote Control

1. 회로도











2. 실체도

















3. 시연 장면

라벨:

7. RGB MOUBLE

1. 실체도





















2. Sample Source Code

/*     ---------------------------------------------------------
 *     |  Experimentation Kit for Arduino Example Code         |
 *     |  CIRC-RGB .: Colourful Light :. (RGB LED)             |
 *     ---------------------------------------------------------
 *
 * We've blinked an LED and controlled eight in sequence now it's time to
 * control colour. Using an RGB LED (actual 3 LEDs in a single housing) 
 * we can generate any colour our heart desires.
 *
 * (we'll also use a few programming shortcuts to make the code
 * more portable/readable)
 */


//RGB LED pins
int ledDigitalOne[] = {10, 11, 9}; //the three digital pins of the digital LED
                                   //10 = redPin, 11 = greenPin, 9 = bluePin

const boolean ON = HIGH;     //Define on as LOW (this is because we use a common
                            //Anode RGB LED (common pin is connected to +5 volts)
const boolean OFF = LOW;   //Define off as HIGH

//Predefined Colors
const boolean RED[] = {ON, OFF, OFF};   
const boolean GREEN[] = {OFF, ON, OFF};
const boolean BLUE[] = {OFF, OFF, ON};
const boolean YELLOW[] = {ON, ON, OFF};
const boolean CYAN[] = {OFF, ON, ON};
const boolean MAGENTA[] = {ON, OFF, ON};
const boolean WHITE[] = {ON, ON, ON};
const boolean BLACK[] = {OFF, OFF, OFF};

//An Array that stores the predefined colors (allows us to later randomly display a color)
const boolean* COLORS[] = {RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE, BLACK};

void setup(){
  for(int i = 0; i < 3; i++){
   pinMode(ledDigitalOne[i], OUTPUT);   //Set the three LED pins as outputs
  }
}

void loop(){

/* Example - 1 Set a color
   Set the three LEDs to any predefined color
*/
   setColor(ledDigitalOne, GREEN);    //Set the color of LED one

/* Example - 2 Go through Random Colors
  Set the LEDs to a random color
*/
   randomColor();

}

void randomColor(){
  int rand = random(0, sizeof(COLORS) / 2);  //get a random number within the range of colors
  setColor(ledDigitalOne, COLORS[rand]);  //Set the color of led one to a random color
  delay(1000);
}

/* Sets an led to any color
   led - a three element array defining the three color pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin)
   color - a three element boolean array (color[0] = red value (LOW = on, HIGH = off), color[1] = green value, color[2] =blue value)
*/
void setColor(int* led, boolean* color){
 for(int i = 0; i < 3; i++){
   digitalWrite(led[i], color[i]);
 }
}

/* A version of setColor that allows for using const boolean colors
*/
void setColor(int* led, const boolean* color){
  boolean tempColor[] = {color[0], color[1], color[2]};
  setColor(led, tempColor);

}

라벨:

6. 1602 Character LCD

1. 1602LCD 실체








2. Sample source code

//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>                            // I2C control library
#include <LiquidCrystal_I2C.h>          // LCD library

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd

  // Print a message to the LCD.
  lcd.backlight();  // turn on backlight
  //lcd.print("  Hellow !");
 
 
}

void loop()
{
  lcd.print("  Hellow !");
 
  delay(2000);
  lcd.clear();

  delay(2000);

라벨:

5. SRD-05VDC-SL-C

1. 구성도















2.회로도











3. sample source code

int relay = 10; //릴레이에 5V 신호를 보낼 핀설정
void setup ()
{
  pinMode (relay, OUTPUT); // relay output으로 설정한다.
}
void loop ()
{
  digitalWrite (relay, HIGH); // 릴레이 ON
  delay (10000);              //10 delay
  digitalWrite (relay, LOW); // 릴레이 OFF

  delay (5000);               //5 delay

라벨:

4. 적외선센서를 이용한 아두이노

2. 그림 설명:적외선센서에 물체를 가까이하면 붉은색 led등이 켜진다.

3. 연결방법

적외선 센서(FC-51)
VCC     -   5V
GND    -   GND
OUT     -   3~

LED                       
+          -    2
-           -   GND


3. 소스 코드
const int irDetectPin = 3; //FC-51 Pin 설정
 const int ledPin = 2; //LED Pin 설정
void setup() {
 pinMode(irDetectPin, INPUT); //FC-51 입력으로 설정
 pinMode(ledPin, OUTPUT); //LED 출력으로 설정 }

 void loop() {
 int noDetect = digitalRead(irDetectPin); //FC-51 상태 읽어오기
 if(noDetect) //FC-51포트가 HIGH이면 즉, 감지 안되었다면
 digitalWrite(ledPin, 0); //LED Off
else //LOW 즉, 감지 되었다면
 digitalWrite(ledPin, 1); //LED ON
 }

FC-51에서 나오는 값이 HIGH 이면 감지가 안되고 있다는 얘기이고
LOW 떨어지면 장애물이 감지되었다는 것이다.



라벨:

3. 진동센서 실험


1. 회로도



2017-01-
15 오전 8:53 - 화
면 캡처









2. 회로설명: 진동센서에 건드리면 불이 켜진다.

3. 소스코드

int vib_pin=7;
int led_pin=13;
void setup()
{
 pinMode(vib_pin,INPUT);
  pinMode(led_pin,OUTPUT);        
}

void loop()
{
  int val;
  val=digitalRead(vib_pin);
  if(val==1)
  {
    digitalWrite(led_pin,HIGH);
    delay(1000);
    digitalWrite(led_pin,LOW);
    delay(1000);
  }
   else
   digitalWrite(led_pin,LOW);
}

라벨: