Capteur ST

Dependencies:   VL6180x mbed Servo

Fork of VL6180X_Explorer by Ian Kilburn

Committer:
pierro42100
Date:
Fri Sep 11 11:04:25 2015 +0000
Revision:
4:113727f4b649
Parent:
3:27076d13c756
Capteur/servo serie

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>
pierro42100 3:27076d13c756 29 #include "Servo.h"
highroads 0:47f8714fe967 30
highroads 0:47f8714fe967 31 /*const float GAIN_1 = 1.01; // Actual ALS Gain of 1.01
highroads 0:47f8714fe967 32 const float GAIN_1_25 = 1.28; // Actual ALS Gain of 1.28
highroads 0:47f8714fe967 33 const float GAIN_1_67 = 1.72; // Actual ALS Gain of 1.72
highroads 0:47f8714fe967 34 const float GAIN_2_5 = 2.6; // Actual ALS Gain of 2.60
highroads 0:47f8714fe967 35 const float GAIN_5 = 5.21; // Actual ALS Gain of 5.21
highroads 0:47f8714fe967 36 const float GAIN_10 = 10.32; // Actual ALS Gain of 10.32
highroads 0:47f8714fe967 37 const float GAIN_20 = 20; // Actual ALS Gain of 20
highroads 0:47f8714fe967 38 const float GAIN_40 = 40; // Actual ALS Gain of 40
highroads 0:47f8714fe967 39 */
highroads 0:47f8714fe967 40
highroads 0:47f8714fe967 41 #define VL6180X_ADDRESS 0x29
highroads 0:47f8714fe967 42
pierro42100 3:27076d13c756 43 Serial pc(SERIAL_TX, SERIAL_RX);
pierro42100 3:27076d13c756 44
julientiron 2:083c1efc951f 45 DigitalInOut sda_D(PB_9);
julientiron 2:083c1efc951f 46 DigitalInOut scl_D(PB_8);
julientiron 2:083c1efc951f 47
julientiron 2:083c1efc951f 48
highroads 0:47f8714fe967 49 VL6180xIdentification identification;
highroads 0:47f8714fe967 50 // mbed uses 8bit addresses shift address by 1 bit left
julientiron 2:083c1efc951f 51 VL6180x sensor_D(PB_9, PB_8, VL6180X_ADDRESS<<1);
highroads 0:47f8714fe967 52
highroads 0:47f8714fe967 53 void printIdentification(struct VL6180xIdentification *temp){
highroads 0:47f8714fe967 54 printf("Model ID = ");
highroads 0:47f8714fe967 55 printf("%d\n",temp->idModel);
highroads 0:47f8714fe967 56
highroads 0:47f8714fe967 57 printf("Model Rev = ");
highroads 0:47f8714fe967 58 printf("%d",temp->idModelRevMajor);
highroads 0:47f8714fe967 59 printf(".");
highroads 0:47f8714fe967 60 printf("%d\n",temp->idModelRevMinor);
highroads 0:47f8714fe967 61
highroads 0:47f8714fe967 62 printf("Module Rev = ");
highroads 0:47f8714fe967 63 printf("%d",temp->idModuleRevMajor);
highroads 0:47f8714fe967 64 printf(".");
highroads 0:47f8714fe967 65 printf("%d\n",temp->idModuleRevMinor);
highroads 0:47f8714fe967 66
highroads 0:47f8714fe967 67 printf("Manufacture Date = ");
highroads 0:47f8714fe967 68 printf("%d",((temp->idDate >> 3) & 0x001F));
highroads 0:47f8714fe967 69 printf("/");
highroads 0:47f8714fe967 70 printf("%d",((temp->idDate >> 8) & 0x000F));
highroads 0:47f8714fe967 71 printf("/1");
highroads 0:47f8714fe967 72 printf("%d\n",((temp->idDate >> 12) & 0x000F));
highroads 0:47f8714fe967 73 printf(" Phase: ");
highroads 0:47f8714fe967 74 printf("%d\n",(temp->idDate & 0x0007));
highroads 0:47f8714fe967 75
highroads 0:47f8714fe967 76 printf("Manufacture Time (s)= ");
highroads 0:47f8714fe967 77 printf("%d\n",(temp->idTime * 2));
highroads 0:47f8714fe967 78 printf("\n\n");
highroads 0:47f8714fe967 79 }
highroads 0:47f8714fe967 80 int main() {
highroads 0:47f8714fe967 81
pierro42100 3:27076d13c756 82 Servo myservo(D7); // Create the servo object
pierro42100 3:27076d13c756 83 float butee_droite=0.1;
pierro42100 3:27076d13c756 84 float butee_gauche=1;
pierro42100 3:27076d13c756 85 double position=0.1;
pierro42100 3:27076d13c756 86 myservo.calibrate(0.00095, 90.0); // Calibrate the servo
pierro42100 3:27076d13c756 87
pierro42100 3:27076d13c756 88 pc.baud(115200);
pierro42100 3:27076d13c756 89
highroads 0:47f8714fe967 90 wait_ms(100); // delay .1s
julientiron 2:083c1efc951f 91 sda_D.mode(PullUp);
julientiron 2:083c1efc951f 92 scl_D.mode(PullUp);
julientiron 2:083c1efc951f 93 //sensor_D.getIdentification(&identification); // Retrieve manufacture info from device memory
julientiron 2:083c1efc951f 94 //printIdentification(&identification); // Helper function to print all the Module information
highroads 0:47f8714fe967 95
julientiron 2:083c1efc951f 96 if(sensor_D.VL6180xInit() != 0){
highroads 0:47f8714fe967 97 printf("FAILED TO INITALIZE\n"); //Initialize device and check for errors
highroads 0:47f8714fe967 98 };
highroads 0:47f8714fe967 99
julientiron 2:083c1efc951f 100 sensor_D.VL6180xDefautSettings(); //Load default settings to get started.
julientiron 2:083c1efc951f 101 wait_ms(100); // delay
highroads 0:47f8714fe967 102
julientiron 2:083c1efc951f 103 while(1) {
highroads 0:47f8714fe967 104
pierro42100 3:27076d13c756 105 while(position<butee_gauche){
pierro42100 3:27076d13c756 106 myservo.write(position);
pierro42100 3:27076d13c756 107 //printf("capteur: %d %f\n", sensor_D.getDistance(), position);
pierro42100 3:27076d13c756 108 pc.printf("%d\n\r", sensor_D.getDistance());
pierro42100 3:27076d13c756 109 pc.printf("%f\n\r", position);
pierro42100 3:27076d13c756 110 wait_ms(10);
pierro42100 3:27076d13c756 111 position = position + 0.01;
pierro42100 3:27076d13c756 112
pierro42100 3:27076d13c756 113 }
pierro42100 3:27076d13c756 114
pierro42100 3:27076d13c756 115 myservo.write(butee_droite);
pierro42100 3:27076d13c756 116 position = 0.1;
pierro42100 3:27076d13c756 117 wait_ms(10);
pierro42100 3:27076d13c756 118
pierro42100 3:27076d13c756 119
julientiron 2:083c1efc951f 120 }
highroads 0:47f8714fe967 121 }
highroads 0:47f8714fe967 122
highroads 0:47f8714fe967 123
highroads 0:47f8714fe967 124
highroads 0:47f8714fe967 125
highroads 0:47f8714fe967 126