□ USB To Serial port 설치 문제( Setup Problem )

 

아두이노 나노를 설치할 때 일반적으로 USB to Serial 포트를 자동 설치하지 못하고 FTDI 드라이버 등을 인스톨하여 수동 설치하는 경우가 일반적이다. 특히, Windows 7 64bit 환경에서는 거의 100% 발생한다.

 

그런데, 일부 아두이노 나노 호환 제품들은 FTDI 또는 PL2302 드라이버로 USB to Serial 포트 인식을 하지 못하는 경우가 있다.

 

이 중 WCH CH240G 칩셋을 사용한 제품이 가장 흔하다.  WCH CH240G 칩셋 오류는 아래와 같이 드라이버를 설치하여 해결할 수 있다.

 

 This device did not work with the FTDI drivers, nor the PL2302 drivers.

 

□ 정품과 USB to Serial port 컨트롤러에 WCH CH240G칩을 사용한 클론칩 구성 비교

정품( Original, FTDI )

클론( Clone, WCH CH240G )

 

 

 

 

 

 

시리얼 포트를 설치할 수 없을 경우

- 뒤면 chip 확인

  WCH CH340G 일 경우

 

 

 

 

 

□ Driver download

  - 제조사            WCH Nanjing QinHeng Electronics

  - 제조사 Driver   http://www.wch.cn/downloads.php?name=pro&proid=5

  - driver file       CH341SER.ZIP

 

 

□ 설치 방법( Setup Guide )

  1) CH341SER.ZIP Download 및 압축해제

 

  2) 드라이버 수동 설치 선택

 

 

  3) 압축을 해제한 디렉토리 지정

 

 

  4) 설치 결과 확인(Result)

 

 

반응형

- If you can try to use sprintf() to convert from a float to a string on Arduino, it doesn't work.

  The function sprintf() return a "?" instead of float format.

  The alternative to solve the problem is to use dtostrf(), the function in the avr-libc library.

 

아두이노에서 부동소수값 출력을 위해

 

sprintf( buf, "%f", 1.1f );

Srial.println( buf );

 

      → output : ?  

 

위와 같이 sprintf() 함수를 사용한 경우 1.1이 아닌 "?" 가 출력된다.

정확한 결과를 위해 

 

dtostrf() 함수를 사용

 

하여 해결 가능하다.

 

□ dtostrf()  개요

  - dtostrf() 함수는 부동소수(double, float) 변수를 주어진 형식에 따른 문자열을 출력

  - The dtostrf() function converts the double value passed in val into an ASCII representation that will be

    stored under s.

 

char* dtostrf

(

double 

__val,

signed char 

__width,

unsigned char 

__prec,

char * 

__s 

)

 

□ 매개변수 정의 

 매개변수

내용

 

 double __val

 - 변경할 부동소수

 - floatvar

   Float variable

 

 signed char __width

 - 음수부호(-)와 소수점을 포함한 전체 자리수

 - StringLengthIncDecimalPoint

   It is the length of the string will be created

 소수점 포함, 음수는 (-)포함

 unsigned char__ prec

 - 소수점을 제외한 소수점 자릿수

 - numVarsAfterDecimal

   The number of digits after the dicimal point 

 소수점 제외 

 char * __s

 - 문자열 버퍼 ( char buffer )

 - charbuf

   The char array to store the result

 

 

 

□ dtostrf() 사례 ( Sample )

#include    <stdio.h>
 
void    setup() {
    Serial.begin( 9600 );
}
 
void    loop() {
    char    CAa [20] = "";
    char    CAb [20] = "";
    char    CAc [ 3] = "";
    char    CAd [ 5] = "0000";
 
    char buf[128];    
 
    dtostrf( 123.123    ,  6, 2, CAa );
    dtostrf( 456.456     , 1, 3, CAb );
    sprintf(buf, "dtostrf( 123.123     ,  6, 2, CAa ) -> %15s\n"
                 "dtostrf( 456.456     ,  1, 3, CAb ) -> %15s"
                 , CAa
                 , CAb          );
    Serial.println(buf);
 
    dtostrf( 123.123    ,  6, 2, CAa );
    dtostrf( 456.4567    , 6, 2, CAb );
    sprintf(buf, "dtostrf( 123.123     ,  6, 2, CAa ) -> %15s\n"
                 "dtostrf( 456.4567    ,  6, 2, CAb ) -> %15s"
                 , CAa
                 , CAb          );
    Serial.println(buf);
 
    dtostrf( 12312.123   , 3, 2, CAa );
    dtostrf( 456.4567789 , 2, 5, CAb );
    sprintf(buf, "dtostrf( 12312.123   ,  3, 2, CAa ) -> %15s\n"
                 "dtostrf( 456.45674444,  2, 5, CAb ) -> %15s"
                 , CAa
                 , CAb          );
    Serial.println(buf);
 
    dtostrf( 123.12345678, 10, 3, CAa );
    dtostrf( 456456.4567 , 11, 4, CAb );
    sprintf(buf, "dtostrf( 123.12345678, 10, 3, CAa ) -> %15s\n"
                 "dtostrf( 456456.4567 , 11, 4, CAb ) -> %15s"
                 , CAa
                 , CAb          );
    Serial.println(buf);
 
    dtostrf( 123.123     , 10, 3, CAa );
    dtostrf( 456456.45   , 10, 4, CAb );
    sprintf(buf, "dtostrf( 123.123     , 10, 3, CAa ) -> %15s\n"
                 "dtostrf( 456456.45   , 10, 4, CAb ) -> %15s"
                 , CAa
                 , CAb          );
    Serial.println(buf); 
 
    dtostrf( 789.789    ,  3, 3, CAc );
    sprintf(buf, "dtostrf( 789.789     ,  3, 3, CAc ) -> %15s\n"
                 "CAd is 0000                         -> %15s"
                 , CAc         
                 , CAd );
    Serial.println(buf);
       
   delay( 2000 );
}       

 

 

□ 결과 (Result)

dtostrf( 123.123     ,  6, 2, CAa ) ->          123.12      // Normal. 정상
dtostrf( 456.456     ,  1, 3, CAb ) ->         456.456      // Error. 전체자리수 무시됨
dtostrf( 123.123     ,  6, 2, CAa ) ->          123.12      // Normal. 정상
dtostrf( 456.4567    ,  6, 2, CAb ) ->          456.46      // Normal. 정상. 소수점 끝자리 반올림됨
dtostrf( 12312.123   ,  3, 2, CAa ) ->        12312.12      // Error. 전체자리수 무시됨
dtostrf( 456.45674444,  2, 5, CAb ) ->       456.45679      // Error. 부동소수 오류(끝자리 4가 아님)
dtostrf( 123.12345678, 10, 3, CAa ) ->         123.123      // Normal. 정상
dtostrf( 456456.4567 , 11, 4, CAb ) ->     456456.4700      // Error. 부동소수 오류 발생
dtostrf( 123.123     , 10, 3, CAa ) ->         123.123      // Normal. 정상
dtostrf( 456456.45   , 10, 4, CAb ) ->     456456.4400      // Error. 소수점 끝자리 오류발생
dtostrf( 789.789     ,  3, 3, CAc ) ->         789.789      // Error. sizeof(CAc)→3, Buffer Over Flow 발생
CAd is 0000                         ->            .789      // Error. CAc의 BoF로 원래 값이 지워짐

 

결과에서 알 수 있듯이 dtostrf()도 정확한 연산이 되는 것은 아니다.

그러나, dtostrf()를 sprintf() 대신 충분히 사용가능하다.

 

As the result, dtostrf () also is not working exactly.
But, however , the dtostrf () is fully available instead of sprintf().

 

반응형

'아두이노 > 일반' 카테고리의 다른 글

[브리핑] 아두이노 강좌  (0) 2016.02.03
Arduino Nano USB to Serial Port 설치-WCH CH340G  (0) 2014.12.31
I2C 통신  (0) 2014.11.21
Arduino 사용자 라이브러리 작성법  (0) 2014.11.16

 

□ HC-SR04

 

 

 

 

□ HC-SR04 특징(Specification)

 항목 

 내용 

 동작 전압(Working Voltage)

 5V

 동작 전류(Working Current)

 15mA

 동작 주파수(Working Frequency)

 40KHz

 측정 거리(Min, Max Range)

 2 cm ~ 4 m

 측정 각도(Measuring Angle)

 15도 (degree)

 트리거 입력 신호(Trigger Input Signal)

 10㎲ TTL Pulse

 응답 출력 신호(Echo Output Signal)

 거리에 비례하는 TTL Pulse

 크기(Dimension)

 45 * 20 * 15 mm

 라인 구성

 Vcc, Trig, Echo, GND 

 

 

□ HC-SR04 아두이노 회로 구성도( HC-SR04 Arduino circuit diagram )

 

 

 

 

□ HC-SR04 와 아두이노 Pin 배열 

 HC-SR04 

 Arduino 

 비고

 VCC

 5V

 

 TRIG

Digital pin 12

 

 ECHO

Digital pin 11

 

 GND

 GND

 

* TRIG와 ECHO는 Digital INPUT 중 어떤 것을 사용해도 무방함

 

 

□ HC-SR04 Sample Source 

#define DEFN_TRIGGER 12
#define DEFN_ECHO    11
#define DEFN_DELAY   1000
#define DEFN_BIT_RATE 9600
 
void setup(){
 pinMode(DEFN_TRIGGER, OUTPUT);
 pinMode(DEFN_ECHO   , INPUT );
 Serial.begin(DEFN_BIT_RATE);    
}
 
void loop() {
 digitalWrite(DEFN_TRIGGER, LOW);                  
 DEFN_DELAYMicroseconds(2);
 digitalWrite(DEFN_TRIGGER, HIGH);
 DEFN_DELAYMicroseconds(10);
 digitalWrite(DEFN_TRIGGER, LOW);
 
 long time_us = pulseIn(DEFN_ECHO, HIGH);  // Get DEFN_ECHO time in microsecs
 long dist_mm = time_us * 0.17;            // 0.34 / 2
 
 Serial.print("Time(us) : ");        Serial.print(time_us); 
 Serial.print("\tDistance(mm) : ");  Serial.print(dist_mm);
 Serial.println("");
 
 DEFN_DELAY(DEFN_DELAY);
}

 

 

□ HC-SR04 참고자료

HC-SR04 001 datasheet.pdf

 

 

 

 

 

반응형

'아두이노 > 센서' 카테고리의 다른 글

스위치 : 푸시형 NON-LOCK PB86-A1  (0) 2014.11.26
스위치 : 푸시형 NON-LOCK DJP2213  (0) 2014.11.26
I2C Address  (0) 2014.11.21
801s : 진동센서  (0) 2014.11.20
BMP180 : 고도센서, 기압센서, 온도센서  (0) 2014.11.20

 

□ GP2Y1010AU0F : 먼지 센서 

 

 

 

 

□ GP2Y1010AU0F 특징(Specification)

 항목

 내용

 비고(Remark)

 공급전원(Supply Voltage)

 5 ~ 7 V

 Vcc 

 동작온도(Operating Temperature)

 -10 ~ 56 도(Celsius)

 

 납땜허용온도(Soldering Temperature)

 -20 ~ 80 도(Celsius)

 

 전류소모(Comsumption current)

 MAX 20 mA

 

 터미널전원(Input Terminal Voltage)

 -0.3 to Vcc

 V-Led

 

 

□ GP2Y1010AU0F와 아두이노 핀 배열(Arduino pin map)

 

 

* 1번 ~ 3번은 LED 신호와 관계된 것으로 LED확인이 필요하지 않을 경우 연결 필요 없음

 

 

 

□ GP2Y1010AU0F 핀 구성도(Pin Design) 

 핀 구성도

 (Pin Design)

 

 

 설명

 (Detail)

GP2Y1010AU0F 

 Arduino

 비고(Remark)

 ① V-Led

5V (150ohm resistor) 

 LED 신호용

 ② LED-GND

 GND

 ③ LED

 Digital pin 2

 ④ S-GND

 GND

 Data 출력용

 ⑤ Vo

 Analog pin 0

 ⑥ Vcc

 5V

* V-Led, LED-GND, LED(1번~3번)는 LED 신호와 관계된 것으로 LED확인이 필요하지 않을 경우 연결 필요 없음

 

 

□ GP2Y1010AU0F 샘플(Sample Source) 

 

/*
 Standalone Sketch to use with a Arduino UNO and a
 Sharp Optical Dust Sensor GP2Y1010AU0F
*/
  
int measurePin = 0; //Connect dust sensor to Arduino A0 pin
int ledPower = 2;   //Connect 3 led driver pins of dust sensor to Arduino D2
  
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
  
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
  
void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}
  
void loop(){
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
  
  voMeasured = analogRead(measurePin); // read the dust value
  
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  
  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);
  
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
  // Chris Nafis (c) 2012
  dustDensity = 0.17 * calcVoltage - 0.1;
  
  Serial.print("Raw Signal Value (0-1023): ");
  Serial.print(voMeasured);
  
  Serial.print(" - Voltage: ");
  Serial.print(calcVoltage);
  
  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity); // unit: mg/m3
  
  delay(1000);
}

 

 

□ GP2Y1010AU0F 참고자료

 - Datasheet         먼지센서 001 gp2y1010au_e.pdf

 

 

 

반응형

'아두이노 > 센서' 카테고리의 다른 글

BMP180 : 고도센서, 기압센서, 온도센서  (0) 2014.11.20
복합 센서  (0) 2014.11.19
Piezo Disk Sensor  (0) 2014.11.18
DHT22-AM2302 : 디지털 온습도 센서  (0) 2014.11.17
사운드 감지 센서  (0) 2014.11.17

+ Recent posts