질문게시판 > 적외선 거리센서 VL6180

TODAY231 TOTAL2,696,110
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 적외선 거리센서 VL6180

페이지 정보

작성자 탈창곽 작성일2020-04-28 20:55 조회17,671회 댓글3건

본문

	

안녕하세요. 적외선 거리센서 VL6180 을 이용하게 되었습니다.

입력 전압은 센서가 2.8V 인데 우노 5V와 연결하고 저항을 이용하여 조절하였습니다.

 

코드를 업로드 시키고 시리얼 모니터를 틀면 계속 값이 이상하게 나오네요.

그래서 코드도 인터넷 찾아 2가지 버전으로 다 해봤는데 둘 다 값이 이상하게 나와요.

 

[코드 1]

\

#include

 

#include

#define VL6180X_ADDRESS 0x29

 

VL6180xIdentification identification;

VL6180x sensor(VL6180X_ADDRESS);

 

void setup() {

 

  Serial.begin(115200);

  Wire.begin();

  delay(100);

 

  sensor.getIdentification(&identification);

  printIdentification(&identification);

 

    if(sensor.VL6180xInit() != 0){

    Serial.println("FAILED TO INITALIZE");

  }; 

  

  sensor.VL6180xDefautSettings();

    delay(1000);

}

 

void loop()

{

  Serial.print("Ambient Light Level (Lux) = ");

  Serial.println( sensor.getAmbientLight(GAIN_1) );

  Serial.print("Distance measured (mm) = ");

  Serial.println( sensor.getDistance() ); 

 

  delay(500);  

};

 

void printIdentification(struct VL6180xIdentification *temp){

  Serial.print("Model ID = ");

  Serial.println(temp->idModel);

 

  Serial.print("Model Rev = ");

  Serial.print(temp->idModelRevMajor);

  Serial.print(".");

  Serial.println(temp->idModelRevMinor);

 

  Serial.print("Module Rev = ");

  Serial.print(temp->idModuleRevMajor);

  Serial.print(".");

  Serial.println(temp->idModuleRevMinor);  

 

  Serial.print("Manufacture Date = ");

  Serial.print((temp->idDate >> 3) & 0x001F);

  Serial.print("/");

  Serial.print((temp->idDate >> 8) & 0x000F);

  Serial.print("/1");

  Serial.print((temp->idDate >> 12) & 0x000F);

  Serial.print(" Phase: ");

  Serial.println(temp->idDate & 0x0007);

 

  Serial.print("Manufacture Time (s)= ");

  Serial.println(temp->idTime * 2);

  Serial.println();

  Serial.println();

}

 

이걸 했을 때 값이

e106ba547836f6a4cd8233625b93c272_1588074445_1233.PNG
 

이렇게 나오구요.

 

 

[코드 2]

#include

 

#include

 

#include // Wire.h 호출 I2C통신 관련 함수  

#include // VL6180X.h 호출 VL6180 관련 함수 

 

VL6180X sensor;

 

int LedPin1 = 7;  // 1번 LED의 핀 번호

int LedPin2 = 6;  // 2번 LED의 핀 번호

int LedPin3 = 5;  // 3번 LED의 핀 번호

int LedPin4 = 4;  // 4번 LED의 핀 번호

int LedPin5 = 3;  // 5번 LED의 핀 번호

int LedPin6 = 2;  // 6번 LED의 핀 번호

 

 

void setup() 

{

  Serial.begin(9600); // Serial 모니터 9600 보드레이트 설정 

  Wire.begin(); // I2C 통신 초기화 

  

  sensor.init(); // VL61480 센서 초기화 함수 호출 

  sensor.configureDefault(); //센서 기본 설정 함수 호출

  sensor.setTimeout(500); // 센서가 동작 준비되지 않은 경우 대기시간 설정 

}

 

void loop() 

  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }// 마지막 호출 이후에 읽기 시간 초과가 발생 했는지 여부를 확인

  int range = sensor.readRangeSingleMillimeters(); // 센서 데이터호출 후 int 형 range에 저장 

 

Serial.print("range : ");Serial.print(range); // Serial 모니터에 출력 "range : 데이터 값 "

  Serial.println(); // Serial 입력줄 내리기 

}

 

 

코드를 이렇게 했을 때

e106ba547836f6a4cd8233625b93c272_1588074522_8018.PNG
 

이게 무한 반복 되고 있습니다.

 

아두이노 초보라 어떻게 해야할 지 감이 안 잡히네요.

혹시 방법을 아신다면 도움 부탁드립니다!!

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 3

조회수 17,671

master님의 댓글

master 작성일

아두이노용 예제가 있지 않나요?
라이브러리 설치하면 예제도 함께 설치됩니다.
//
I2C는 적당한 풀업저항 사용해야 합니다.
통신속도도 지나치게 빠르게 하면 안됩니다.
적당히 느린 속도로 테스트 하세요 (예제소스의 속도 그대로 테스트하면 됩니다.)

탈창곽님의 댓글

탈창곽 작성일

예제도 해봤어요..
/******************************************************************************
 * SparkFun_VL6180X_demo.ino
 * Example Sketch for VL6180x time of flight range finder.
 * Casey Kuhns @ SparkFun Electronics
 * 10/29/2014
 * https://github.com/sparkfun/SparkFun_ToF_Range_Finder-VL6180_Arduino_Library
 *
 * The VL6180x by ST micro is a time of flight range finder that
 * uses pulsed IR light to determine distances from object at close
 * range.  The average range of a sensor is between 0-200mm
 *
 * Resources:
 * This library uses the Arduino Wire.h to complete I2C transactions.
 *
 * Development environment specifics:
 * IDE: Arduino 1.0.5
 * Hardware Platform: Arduino Pro 3.3V/8MHz
 * VL6180x Breakout Version: 1.0
 *  **Updated for Arduino 1.6.4 5/2015**

 *
 * This code is beerware. If you see me (or any other SparkFun employee) at the
 * local pub, and you've found our code helpful, please buy us a round!
 *
 * Distributed as-is; no warranty is given.
 ******************************************************************************/

#include <Wire.h>

#include <SparkFun_VL6180X.h>

/*const float GAIN_1    = 1.01;  // Actual ALS Gain of 1.01
const float GAIN_1_25 = 1.28;  // Actual ALS Gain of 1.28
const float GAIN_1_67 = 1.72;  // Actual ALS Gain of 1.72
const float GAIN_2_5  = 2.6;  // Actual ALS Gain of 2.60
const float GAIN_5    = 5.21;  // Actual ALS Gain of 5.21
const float GAIN_10  = 10.32; // Actual ALS Gain of 10.32
const float GAIN_20  = 20;    // Actual ALS Gain of 20
const float GAIN_40  = 40;    // Actual ALS Gain of 40
*/
#define VL6180X_ADDRESS 0x29

VL6180xIdentification identification;
VL6180x sensor(VL6180X_ADDRESS);

void setup() {

  Serial.begin(115200); //Start Serial at 115200bps
  Wire.begin(); //Start I2C library
  delay(100); // delay .1s

  sensor.getIdentification(&identification); // Retrieve manufacture info from device memory
  printIdentification(&identification); // Helper function to print all the Module information

    if(sensor.VL6180xInit() != 0){
    Serial.println("FAILED TO INITALIZE"); //Initialize device and check for errors
  };

  sensor.VL6180xDefautSettings(); //Load default settings to get started.
 
    delay(1000); // delay 1s


}

void loop() {

  //Get Ambient Light level and report in LUX
  Serial.print("Ambient Light Level (Lux) = ");
 
  //Input GAIN for light levels,
  // GAIN_20    // Actual ALS Gain of 20
  // GAIN_10    // Actual ALS Gain of 10.32
  // GAIN_5      // Actual ALS Gain of 5.21
  // GAIN_2_5    // Actual ALS Gain of 2.60
  // GAIN_1_67  // Actual ALS Gain of 1.72
  // GAIN_1_25  // Actual ALS Gain of 1.28
  // GAIN_1      // Actual ALS Gain of 1.01
  // GAIN_40    // Actual ALS Gain of 40
 
  Serial.println( sensor.getAmbientLight(GAIN_1) );

  //Get Distance and report in mm
  Serial.print("Distance measured (mm) = ");
  Serial.println( sensor.getDistance() );

  delay(500);
};

void printIdentification(struct VL6180xIdentification *temp){
  Serial.print("Model ID = ");
  Serial.println(temp->idModel);

  Serial.print("Model Rev = ");
  Serial.print(temp->idModelRevMajor);
  Serial.print(".");
  Serial.println(temp->idModelRevMinor);

  Serial.print("Module Rev = ");
  Serial.print(temp->idModuleRevMajor);
  Serial.print(".");
  Serial.println(temp->idModuleRevMinor);

  Serial.print("Manufacture Date = ");
  Serial.print((temp->idDate >> 3) & 0x001F);
  Serial.print("/");
  Serial.print((temp->idDate >> 8) & 0x000F);
  Serial.print("/1");
  Serial.print((temp->idDate >> 12) & 0x000F);
  Serial.print(" Phase: ");
  Serial.println(temp->idDate & 0x0007);

  Serial.print("Manufacture Time (s)= ");
  Serial.println(temp->idTime * 2);
  Serial.println();
  Serial.println();
}

위 예제로 했구요. 결과는
FAILED TO INITALIZE
Model ID = 255
Model Rev = 255.255
Module Rev = 255.255
Manufacture Date = 31/15/115 Phase: 7
Manufacture Time (s)= 65534


FAILED TO INITALIZE
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
Distance measured (mm) = 255
Ambient Light Level (Lux) = 31.68
(생략)
이런 식으로 똑같은 값만 계속 나오고 있습니다.

master님의 댓글

master 댓글의 댓글 작성일

오실로스코프를 사용해서 정상적으로 데이터가 얻어지는지 체크해보세요

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 19668
공지 사이트 이용 안내댓글[28] master 17-10-29 34155
질문 아두이노 리니어 제어 모듈 설계중입니다. 도와주세요 새글 갓비타 23-06-06 15
질문 dc모터 제어 관련 질문 드려요 ㅠㅠ!! 새글 dpwl 23-06-06 15
질문 pixy2 cam 을 이용한 색상인식 모터 제어 새글 가나다라 23-06-05 13
질문 안녕하세요 제품 품목 이름에 대해서 궁금합니다. 이미지새글첨부파일 알려주시면감사합니다 23-06-05 18
질문 Atmega128 온도센서로 led제어 질문드려요 이미지새글첨부파일 얍얍 23-06-05 23
질문 아구이노 코드를 atmega 128 코드로 변환 하고 싶습니다 ㅠㅠ 새글 기로롱 23-06-05 22
질문 atmega128 uart 질문입니다. bme12 23-06-05 23
질문 라즈베리파이에 풀 프레임 이미지센서 활용에 대한 질문이 있습니다. 이미지첨부파일 KYLO 23-06-04 19
질문 아두이노 시리얼 번호를 이용해 led 제어 wnion 23-06-04 21
질문 ATMEGA128 혹시 여기서 왜 인터럽트 기능이 안되는지 알 수 있나요 IEEE 23-06-04 33
질문 stm32f767을 이용해서 자이로가속도 센서의 값 받아오기 rlchwjswk 23-06-03 22
질문 아두이노 모터제어 관련해서 질문드립니다!댓글[1] 이미지첨부파일 아두이노어렵잖아 23-06-03 46
질문 atmega128 디지털조도센서 코드오류댓글[1] 이미지 까미 23-06-02 41
질문 atmega128 디지털 조도 센서댓글[1] 까미 23-06-02 41
질문 적외선리모콘으로 부저를제어 하는방법 질문입니다.댓글[4] Tell 23-06-02 24
질문 lora 무선 모듈에 관한 질문입니다.댓글[1] 로이스10 23-06-01 22
질문 적외선 송수신기 DC모터2개 제어 질문입니다.댓글[5] Tell 23-06-01 40
질문 스텝모터 제어 코드 질문댓글[5] pmh11 23-05-31 46
질문 초음파 센서를 이용한 인원 카운팅댓글[1] 초음파야 23-05-31 38
질문 모터 Hall 스위치 연결 문의댓글[1] 오후 23-05-31 26
질문 아두이노 lcd 문자 스크롤디스플레이 wnion 23-05-31 34
답변 답변글 답변 : 아두이노 lcd 문자 스크롤디스플레이댓글[1] master 23-05-31 34
질문 아두이노 타이머 인터럽트 미ㅏㄴㅇ 23-05-30 48
답변 답변글 답변 : 아두이노 타이머 인터럽트댓글[7] master 23-05-30 55
질문 THC-Soil Sensor with TTL 모듈 아두이노 센서값 받아오기댓글[1] ppiickle 23-05-30 34
질문 stm32 psd센서구동 질문댓글[2] 수포자 23-05-29 31
질문 앱인벤터 아두이노 보드 LCD 글씨 나타내기 질문댓글[7] 이미지 당찬병아리 23-05-29 49
질문 atmega128 led와 fan댓글[3] 이라 23-05-28 56
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기