Capteur ST

Dependencies:   VL6180x mbed Servo

Fork of VL6180X_Explorer by Ian Kilburn

Committer:
julientiron
Date:
Thu Sep 10 12:32:36 2015 +0000
Revision:
2:083c1efc951f
Parent:
1:126b6cd0f4f5
Child:
3:27076d13c756
capteur ST;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
highroads 0:47f8714fe967 1 /******************************************************************************
highroads 0:47f8714fe967 2 * Developed from
highroads 0:47f8714fe967 3 * VL6180X_demo.ino
highroads 0:47f8714fe967 4 * Example Sketch for VL6180x time of flight range finder.
highroads 0:47f8714fe967 5 * Casey Kuhns @ SparkFun Electronics
highroads 0:47f8714fe967 6 * 10/29/2014
highroads 0:47f8714fe967 7 * https://github.com/sparkfun/ToF_Range_Finder-VL6180_Library
highroads 0:47f8714fe967 8 *
highroads 0:47f8714fe967 9 * The VL6180x by ST micro is a time of flight range finder that
highroads 0:47f8714fe967 10 * uses pulsed IR light to determine distances from object at close
highroads 0:47f8714fe967 11 * range. The average range of a sensor is between 0-200mm
highroads 0:47f8714fe967 12 *
highroads 0:47f8714fe967 13 * Resources:
highroads 0:47f8714fe967 14 * This library uses the Arduino Wire.h to complete I2C transactions.
highroads 0:47f8714fe967 15 *
highroads 0:47f8714fe967 16 * Development environment specifics:
highroads 0:47f8714fe967 17 * IDE: Arduino 1.0.5
highroads 0:47f8714fe967 18 * Hardware Platform: Arduino Pro 3.3V/8MHz
highroads 0:47f8714fe967 19 * VL6180x Breakout Version: 1.0
highroads 0:47f8714fe967 20 *
highroads 0:47f8714fe967 21 *
highroads 0:47f8714fe967 22 * This code is beerware. If you see me (or any other SparkFun employee) at the
highroads 0:47f8714fe967 23 * local pub, and you've found our code helpful, please buy us a round!
highroads 0:47f8714fe967 24 *
highroads 0:47f8714fe967 25 * Distributed as-is; no warranty is given.
highroads 0:47f8714fe967 26 ******************************************************************************/
highroads 0:47f8714fe967 27 #include "mbed.h"
highroads 0:47f8714fe967 28 #include <VL6180x.h>
highroads 0:47f8714fe967 29
highroads 0:47f8714fe967 30 /*const float GAIN_1 = 1.01; // Actual ALS Gain of 1.01
highroads 0:47f8714fe967 31 const float GAIN_1_25 = 1.28; // Actual ALS Gain of 1.28
highroads 0:47f8714fe967 32 const float GAIN_1_67 = 1.72; // Actual ALS Gain of 1.72
highroads 0:47f8714fe967 33 const float GAIN_2_5 = 2.6; // Actual ALS Gain of 2.60
highroads 0:47f8714fe967 34 const float GAIN_5 = 5.21; // Actual ALS Gain of 5.21
highroads 0:47f8714fe967 35 const float GAIN_10 = 10.32; // Actual ALS Gain of 10.32
highroads 0:47f8714fe967 36 const float GAIN_20 = 20; // Actual ALS Gain of 20
highroads 0:47f8714fe967 37 const float GAIN_40 = 40; // Actual ALS Gain of 40
highroads 0:47f8714fe967 38 */
highroads 0:47f8714fe967 39
highroads 0:47f8714fe967 40 #define VL6180X_ADDRESS 0x29
highroads 0:47f8714fe967 41
julientiron 2:083c1efc951f 42 DigitalInOut sda_D(PB_9);
julientiron 2:083c1efc951f 43 DigitalInOut scl_D(PB_8);
julientiron 2:083c1efc951f 44
julientiron 2:083c1efc951f 45
highroads 0:47f8714fe967 46 VL6180xIdentification identification;
highroads 0:47f8714fe967 47 // mbed uses 8bit addresses shift address by 1 bit left
julientiron 2:083c1efc951f 48 VL6180x sensor_D(PB_9, PB_8, VL6180X_ADDRESS<<1);
highroads 0:47f8714fe967 49
highroads 0:47f8714fe967 50 void printIdentification(struct VL6180xIdentification *temp){
highroads 0:47f8714fe967 51 printf("Model ID = ");
highroads 0:47f8714fe967 52 printf("%d\n",temp->idModel);
highroads 0:47f8714fe967 53
highroads 0:47f8714fe967 54 printf("Model Rev = ");
highroads 0:47f8714fe967 55 printf("%d",temp->idModelRevMajor);
highroads 0:47f8714fe967 56 printf(".");
highroads 0:47f8714fe967 57 printf("%d\n",temp->idModelRevMinor);
highroads 0:47f8714fe967 58
highroads 0:47f8714fe967 59 printf("Module Rev = ");
highroads 0:47f8714fe967 60 printf("%d",temp->idModuleRevMajor);
highroads 0:47f8714fe967 61 printf(".");
highroads 0:47f8714fe967 62 printf("%d\n",temp->idModuleRevMinor);
highroads 0:47f8714fe967 63
highroads 0:47f8714fe967 64 printf("Manufacture Date = ");
highroads 0:47f8714fe967 65 printf("%d",((temp->idDate >> 3) & 0x001F));
highroads 0:47f8714fe967 66 printf("/");
highroads 0:47f8714fe967 67 printf("%d",((temp->idDate >> 8) & 0x000F));
highroads 0:47f8714fe967 68 printf("/1");
highroads 0:47f8714fe967 69 printf("%d\n",((temp->idDate >> 12) & 0x000F));
highroads 0:47f8714fe967 70 printf(" Phase: ");
highroads 0:47f8714fe967 71 printf("%d\n",(temp->idDate & 0x0007));
highroads 0:47f8714fe967 72
highroads 0:47f8714fe967 73 printf("Manufacture Time (s)= ");
highroads 0:47f8714fe967 74 printf("%d\n",(temp->idTime * 2));
highroads 0:47f8714fe967 75 printf("\n\n");
highroads 0:47f8714fe967 76 }
highroads 0:47f8714fe967 77 int main() {
highroads 0:47f8714fe967 78
highroads 0:47f8714fe967 79 wait_ms(100); // delay .1s
julientiron 2:083c1efc951f 80 sda_D.mode(PullUp);
julientiron 2:083c1efc951f 81 scl_D.mode(PullUp);
julientiron 2:083c1efc951f 82 //sensor_D.getIdentification(&identification); // Retrieve manufacture info from device memory
julientiron 2:083c1efc951f 83 //printIdentification(&identification); // Helper function to print all the Module information
highroads 0:47f8714fe967 84
julientiron 2:083c1efc951f 85 if(sensor_D.VL6180xInit() != 0){
highroads 0:47f8714fe967 86 printf("FAILED TO INITALIZE\n"); //Initialize device and check for errors
highroads 0:47f8714fe967 87 };
highroads 0:47f8714fe967 88
julientiron 2:083c1efc951f 89 sensor_D.VL6180xDefautSettings(); //Load default settings to get started.
julientiron 2:083c1efc951f 90 wait_ms(100); // delay
highroads 0:47f8714fe967 91
julientiron 2:083c1efc951f 92 while(1) {
highroads 0:47f8714fe967 93
julientiron 2:083c1efc951f 94 printf("capteur: %d\n\r", sensor_D.getDistance());
julientiron 2:083c1efc951f 95 //printf("capteur gauche: %d\n\r",/*sensor_G.getAmbientLight(GAIN_1),*/ sensor_G.getDistance());
julientiron 2:083c1efc951f 96 wait_ms(1000);
julientiron 2:083c1efc951f 97 }
highroads 0:47f8714fe967 98 }
highroads 0:47f8714fe967 99
highroads 0:47f8714fe967 100
highroads 0:47f8714fe967 101
highroads 0:47f8714fe967 102
highroads 0:47f8714fe967 103