Lecture continue de 3 capteurs
This commit is contained in:
parent
d1b81dbff3
commit
e655b48835
@ -26,10 +26,6 @@ void Selection_capteur_init(void){
|
||||
void Selection_capteur_select(uint32_t capteur){
|
||||
uint32_t io_value;
|
||||
capteur = capteur - 1;
|
||||
/*gpio_put(PIN_ADRESSE_A0, capteur & 0x01);
|
||||
gpio_put(PIN_ADRESSE_A1, (capteur & 0x02) >> 1);
|
||||
gpio_put(PIN_ADRESSE_A2, (capteur & 0x04) >> 2);
|
||||
gpio_put(PIN_ADRESSE_A3, (capteur & 0x08) >> 3);*/
|
||||
|
||||
io_value = 0;
|
||||
io_value |= ((capteur & 0x08) >> 3) << 2;
|
||||
@ -37,8 +33,6 @@ void Selection_capteur_select(uint32_t capteur){
|
||||
io_value |= ((capteur & 0x02) >> 1) << 4;
|
||||
io_value |= (capteur & 0x01) << 5;
|
||||
|
||||
printf("io_value : %x, capteur : %d\n", io_value, capteur);
|
||||
|
||||
gpio_put_masked(0b111100, io_value);
|
||||
}
|
||||
|
||||
|
454
main.c
454
main.c
@ -19,11 +19,8 @@ int continuous_reading(uint8_t device);
|
||||
int calibration(uint8_t device);
|
||||
int change_address(uint8_t * device, uint8_t new_i2c_7bits_address);
|
||||
void initialise_adresses(void);
|
||||
void init_sensors_1_et_2(void);
|
||||
int continuous_multiple_reading(void);
|
||||
void init_sensors(void);
|
||||
void test_changement_adresse_1(void);
|
||||
void test_changement_adresse_2(void);
|
||||
void test_changement_adresse_3(void);
|
||||
void display_menu();
|
||||
|
||||
|
||||
@ -65,31 +62,17 @@ void main(void)
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
printf("Initialisation des adresses\n");
|
||||
initialise_adresses();
|
||||
printf("Initialisation des capteurs\n");
|
||||
init_sensors();
|
||||
initialise_adresses();
|
||||
break;
|
||||
case 'j':
|
||||
case 'J':
|
||||
init_sensors_1_et_2();
|
||||
while(continuous_multiple_reading());
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
ws2812_arc_en_ciel();
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
test_changement_adresse_1();
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
test_changement_adresse_2();
|
||||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
test_changement_adresse_3();
|
||||
break;
|
||||
case 'o':
|
||||
case 'O':
|
||||
while(calibration(VL53L1X_device));
|
||||
@ -107,371 +90,87 @@ void main(void)
|
||||
}
|
||||
|
||||
void initialise_adresses(void){
|
||||
const uint8_t tmp_i2c_adresse = 0x28;
|
||||
const uint8_t default_i2c_adresse = 0x29;
|
||||
uint8_t VL53L1X_device = 0x29;
|
||||
for(uint capteur=1; capteur<12; capteur++){
|
||||
Selection_capteur_select(capteur);
|
||||
if(change_address(&VL53L1X_device, VL53L1X_device+1)){
|
||||
printf("Erreur change adresse : %x => %x, capteur : %d\n", VL53L1X_device, VL53L1X_device+1, capteur);
|
||||
VL53L1X_device++;
|
||||
}else{
|
||||
printf("change adresse : %x => %x, sauf capteur : %d\n", VL53L1X_device-1, VL53L1X_device, capteur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_sensors(void){
|
||||
uint8_t VL53L1X_device = 0x29;
|
||||
uint8_t adresse;
|
||||
// On change l'adresse de tous les capteurs
|
||||
Selection_capteur_deselect();
|
||||
for(uint capteur=0; capteur<12; capteur++){
|
||||
adresse = VL53L1X_device + capteur;
|
||||
if(VL53L1X_SensorInit(adresse)){
|
||||
// Bad init
|
||||
ws2812_set_buffer_rgb(1,0,0, capteur);
|
||||
printf("Init KO : capteur %d, adresse %x\n", capteur, adresse);
|
||||
change_address(&VL53L1X_device, tmp_i2c_adresse);
|
||||
|
||||
// Pour chaque capteur
|
||||
for(uint capteur=1; capteur<=12; capteur++){
|
||||
// reset du capteur
|
||||
Selection_capteur_select(capteur);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
VL53L1X_device = 0x29;
|
||||
|
||||
if(change_address(&VL53L1X_device, 0x30 + capteur)){
|
||||
printf("Erreur change adresse : %x => %x, capteur : %d\n", VL53L1X_device, 0x30 + capteur, capteur);
|
||||
ws2812_set_buffer_rgb(0x4, 0, 0, capteur-1);
|
||||
}else{
|
||||
// Good init
|
||||
ws2812_set_buffer_rgb(0,1,0, capteur);
|
||||
printf("Init ok : capteur %d, adresse %x\n", capteur, adresse);
|
||||
if(VL53L1X_SensorInit(VL53L1X_device)){
|
||||
// bad init
|
||||
ws2812_set_buffer_rgb(0x4, 0, 0, capteur-1);
|
||||
}else{
|
||||
// good init
|
||||
int status;
|
||||
ws2812_set_buffer_rgb(0, 0x4, 0, capteur-1);
|
||||
|
||||
// Custom configuration
|
||||
status = VL53L1X_SetDistanceMode (VL53L1X_device, 1); // Short mode
|
||||
status |= VL53L1X_SetInterMeasurementInMs(VL53L1X_device, 200);
|
||||
status |= VL53L1X_SetTimingBudgetInMs(VL53L1X_device, 200);
|
||||
if(status){
|
||||
printf("Custom config KO, error %d\n", status);
|
||||
ws2812_set_buffer_rgb(0x4, 0, 0, capteur-1);
|
||||
}else{
|
||||
printf("Custom config OK\n");
|
||||
}
|
||||
|
||||
status=VL53L1X_StartRanging(VL53L1X_device);
|
||||
}
|
||||
}
|
||||
}
|
||||
ws2812_affiche_buffer();
|
||||
}
|
||||
|
||||
void init_sensors_1_et_2(void){
|
||||
const uint8_t tmp_i2c_adresse = 0x28;
|
||||
const uint8_t default_i2c_adresse = 0x29;
|
||||
uint8_t VL53L1X_device_1 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_2 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_3 = default_i2c_adresse;
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(10);
|
||||
printf("Changement d'adresse (tous) %x => %x\n", VL53L1X_device_1, 0x30);
|
||||
if(change_address(&VL53L1X_device_1, 0x30)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
|
||||
int continuous_multiple_reading(){
|
||||
for(uint8_t device=0x31; device<0x34; device++){
|
||||
int status;
|
||||
uint8_t data_ready = 0;
|
||||
uint16_t distance;
|
||||
while(!data_ready){
|
||||
status=VL53L1X_CheckForDataReady(device, &data_ready);
|
||||
if(status){
|
||||
printf("CheckForDataReady KO, error %d, capteur:%x\n", status, device);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
status=VL53L1X_GetDistance(device, &distance);
|
||||
if(status){
|
||||
printf("GetDistance KO, error %d, capteur:%x\n", status, device);
|
||||
return 0;
|
||||
}else{
|
||||
printf(">distance%x:%d\n", device, distance);
|
||||
}
|
||||
|
||||
status=VL53L1X_ClearInterrupt(device);
|
||||
if(status){
|
||||
printf("ClearInterrupt KO, error %d, capteur:%x\n", status, device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lettre = getchar_timeout_us(0);
|
||||
if(lettre != PICO_ERROR_TIMEOUT && lettre != 0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* // réinitialisation du capteur 1.
|
||||
printf("Capteur #1 par defaut : 0x29\n");
|
||||
Selection_capteur_select(1);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
VL53L1X_device_1 = 0x29;*/
|
||||
|
||||
/*printf("Changement d'adresse capteur #1 %x => %x\n", VL53L1X_device_1, 0x30);
|
||||
if(change_address(&VL53L1X_device_1, 0x30)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}*/
|
||||
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}
|
||||
|
||||
Selection_capteur_select(1);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}
|
||||
|
||||
if(VL53L1X_SensorInit(default_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", default_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", default_i2c_adresse);
|
||||
}
|
||||
|
||||
|
||||
/* // réinitialisation du capteur 2.
|
||||
Selection_capteur_select(2);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
VL53L1X_device_2 = 0x29;
|
||||
|
||||
printf("Changement d'adresse capteur #2 %x => %x\n", VL53L1X_device_2, 0x31);
|
||||
if(change_address(&VL53L1X_device_2, 0x31)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}*/
|
||||
}
|
||||
|
||||
void test_changement_adresse_1(void){
|
||||
const uint8_t tmp_i2c_adresse = 0x28;
|
||||
const uint8_t default_i2c_adresse = 0x29;
|
||||
uint8_t VL53L1X_device_1 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_2 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_3 = default_i2c_adresse;
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(10);
|
||||
printf("Changement d'adresse (tous) %x => %x\n", VL53L1X_device_1, 0x30);
|
||||
if(change_address(&VL53L1X_device_1, 0x30)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
/*if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}*/
|
||||
|
||||
VL53L1X_device_1 = 0x29;
|
||||
|
||||
printf("Changement d'adresse %x => %x\n", VL53L1X_device_1, 0x31);
|
||||
if(change_address(&VL53L1X_device_1, 0x31)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
if(VL53L1X_SensorInit(0x30)){
|
||||
printf("Init KO : adresse %x\n", 0x30);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", 0x30);
|
||||
}
|
||||
if(VL53L1X_SensorInit(0x31)){
|
||||
printf("Init KO : adresse %x\n", 0x31);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", 0x31);
|
||||
}
|
||||
}
|
||||
|
||||
void test_changement_adresse_2(void){
|
||||
const uint8_t tmp_i2c_adresse = 0x30;
|
||||
const uint8_t default_i2c_adresse = 0x29;
|
||||
uint8_t VL53L1X_device_1 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_2 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_3 = default_i2c_adresse;
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(10);
|
||||
printf("Changement d'adresse (tous) %x => %x\n", VL53L1X_device_1, tmp_i2c_adresse);
|
||||
if(change_address(&VL53L1X_device_1, tmp_i2c_adresse)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
printf("Changement d'adresse (tous) %x => %x\n", VL53L1X_device_2, tmp_i2c_adresse);
|
||||
if(change_address(&VL53L1X_device_2, tmp_i2c_adresse)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
// Réinitialisation du capteur 1.
|
||||
printf("Capteur #1 par defaut : 0x29\n");
|
||||
Selection_capteur_select(1);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
VL53L1X_device_1 = 0x29;
|
||||
|
||||
|
||||
printf("Changement d'adresse %x => %x\n", VL53L1X_device_1, 0x31);
|
||||
if(change_address(&VL53L1X_device_1, 0x31)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
/* // Réinitialisation du capteur 2.
|
||||
printf("Capteur #2 par defaut : 0x29\n");
|
||||
Selection_capteur_select(2);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
|
||||
VL53L1X_device_2 = 0x29;
|
||||
printf("Changement d'adresse %x => %x\n", VL53L1X_device_2, 0x32);
|
||||
if(change_address(&VL53L1X_device_2, 0x32)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}*/
|
||||
|
||||
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_2)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_2);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_2);
|
||||
}
|
||||
if(VL53L1X_SensorInit(tmp_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", tmp_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", tmp_i2c_adresse);
|
||||
}
|
||||
}
|
||||
|
||||
void test_changement_adresse_3(void){
|
||||
const uint8_t tmp_i2c_adresse = 0x30;
|
||||
const uint8_t default_i2c_adresse = 0x29;
|
||||
uint8_t VL53L1X_device_1 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_2 = default_i2c_adresse;
|
||||
uint8_t VL53L1X_device_3 = default_i2c_adresse;
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(10);
|
||||
printf("Changement d'adresse (tous) %x => %x\n", VL53L1X_device_1, tmp_i2c_adresse);
|
||||
if(change_address(&VL53L1X_device_1, tmp_i2c_adresse)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
printf("Changement d'adresse (tous) %x => %x\n", VL53L1X_device_2, tmp_i2c_adresse);
|
||||
if(change_address(&VL53L1X_device_2, tmp_i2c_adresse)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
// Réinitialisation du capteur 1.
|
||||
printf("Capteur #1 par defaut : 0x29\n");
|
||||
Selection_capteur_select(1);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
VL53L1X_device_1 = 0x29;
|
||||
|
||||
|
||||
printf("Changement d'adresse %x => %x\n", VL53L1X_device_1, 0x31);
|
||||
if(change_address(&VL53L1X_device_1, 0x31)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
// Réinitialisation du capteur 3.
|
||||
printf("Capteur #2 par defaut : 0x29\n");
|
||||
Selection_capteur_select(3);
|
||||
sleep_ms(1);
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
|
||||
VL53L1X_device_3 = 0x29;
|
||||
printf("Changement d'adresse %x => %x\n", VL53L1X_device_3, 0x33);
|
||||
if(change_address(&VL53L1X_device_3, 0x33)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
if(VL53L1X_SensorInit(default_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", default_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", default_i2c_adresse);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_2)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_2);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_2);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_3)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_3);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_3);
|
||||
}
|
||||
if(VL53L1X_SensorInit(tmp_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", tmp_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", tmp_i2c_adresse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Réinitialisation du capteur 2.
|
||||
printf("Capteur #2 par defaut : 0x29\n");
|
||||
Selection_capteur_select(2);
|
||||
sleep_ms(1);
|
||||
|
||||
if(VL53L1X_SensorInit(default_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", default_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", default_i2c_adresse);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_2)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_2);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_2);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_3)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_3);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_3);
|
||||
}
|
||||
if(VL53L1X_SensorInit(tmp_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", tmp_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", tmp_i2c_adresse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Selection_capteur_deselect();
|
||||
sleep_ms(1);
|
||||
|
||||
VL53L1X_device_2 = 0x29;
|
||||
printf("Changement d'adresse %x => %x\n", VL53L1X_device_2, 0x32);
|
||||
if(change_address(&VL53L1X_device_2, 0x32)){
|
||||
printf("-> KO\n");
|
||||
}else{
|
||||
printf("-> ok;\n");
|
||||
}
|
||||
|
||||
|
||||
if(VL53L1X_SensorInit(default_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", default_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", default_i2c_adresse);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_1)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_1);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_1);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_2)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_2);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_2);
|
||||
}
|
||||
if(VL53L1X_SensorInit(VL53L1X_device_3)){
|
||||
printf("Init KO : adresse %x\n", VL53L1X_device_3);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", VL53L1X_device_3);
|
||||
}
|
||||
if(VL53L1X_SensorInit(tmp_i2c_adresse)){
|
||||
printf("Init KO : adresse %x\n", tmp_i2c_adresse);
|
||||
}else{
|
||||
printf("Init OK : adresse %x\n", tmp_i2c_adresse);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -479,11 +178,8 @@ void display_menu(){
|
||||
printf("Select action :\n");
|
||||
printf("A - Change I2C address\n");
|
||||
printf("I - Init I2C address\n");
|
||||
printf("J - Init catpeur 1 et 2\n");
|
||||
printf("J - Lecture distance multiple\n");
|
||||
printf("K - Arc en ciel\n");
|
||||
printf("L - Test changement d'adresse, 1 capteur\n");
|
||||
printf("M - Test changement d'adresse, 2 capteurs\n");
|
||||
printf("N - Test changement d'adresse, 3 capteurs\n");
|
||||
printf("O - Offset Calibration\n");
|
||||
printf("R - Read distance\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user