start:arduino:i2c:tca9548a
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:i2c:tca9548a [2024/04/15 13:18] – [Câblage et test Arduino] gerardadmin | start:arduino:i2c:tca9548a [2024/04/15 13:25] (Version actuelle) – gerardadmin | ||
|---|---|---|---|
| Ligne 43: | Ligne 43: | ||
| Référence Adafruit: ADA2717 | Référence Adafruit: ADA2717 | ||
| + | http:// | ||
| Son utilisation est assez simple : le multiplexeur lui-même est sur l' | Son utilisation est assez simple : le multiplexeur lui-même est sur l' | ||
| Ligne 143: | Ligne 144: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | Par exemple, l' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | |||
| + | Ensuite, vous devrez ajuster le code dont vous disposez pour sélectionner le bon port multiplexé ! | ||
| + | |||
| + | Assurez-vous avant d' | ||
| + | |||
| + | |||
| + | <code c prog003.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #define TCAADDR 0x70 | ||
| + | |||
| + | /* Assign a unique ID to this sensor at the same time */ | ||
| + | Adafruit_HMC5883_Unified mag1 = Adafruit_HMC5883_Unified(1); | ||
| + | Adafruit_HMC5883_Unified mag2 = Adafruit_HMC5883_Unified(2); | ||
| + | |||
| + | void displaySensorDetails(Adafruit_HMC5883_Unified *mag) | ||
| + | { | ||
| + | sensor_t sensor; | ||
| + | mag-> | ||
| + | Serial.println(" | ||
| + | Serial.print | ||
| + | Serial.print | ||
| + | Serial.print | ||
| + | Serial.print | ||
| + | Serial.print | ||
| + | Serial.print | ||
| + | Serial.println(" | ||
| + | Serial.println("" | ||
| + | delay(500); | ||
| + | } | ||
| + | |||
| + | void tcaselect(uint8_t i) { | ||
| + | if (i > 7) return; | ||
| + | |||
| + | Wire.beginTransmission(TCAADDR); | ||
| + | Wire.write(1 << i); | ||
| + | Wire.endTransmission(); | ||
| + | } | ||
| + | |||
| + | |||
| + | void setup(void) | ||
| + | { | ||
| + | Serial.begin(9600); | ||
| + | Serial.println(" | ||
| + | | ||
| + | /* Initialise the 1st sensor */ | ||
| + | tcaselect(2); | ||
| + | if(!mag1.begin()) | ||
| + | { | ||
| + | /* There was a problem detecting the HMC5883 ... check your connections */ | ||
| + | Serial.println(" | ||
| + | while(1); | ||
| + | } | ||
| + | | ||
| + | /* Initialise the 2nd sensor */ | ||
| + | tcaselect(6); | ||
| + | if(!mag2.begin()) | ||
| + | { | ||
| + | /* There was a problem detecting the HMC5883 ... check your connections */ | ||
| + | Serial.println(" | ||
| + | while(1); | ||
| + | } | ||
| + | | ||
| + | /* Display some basic information on this sensor */ | ||
| + | tcaselect(2); | ||
| + | displaySensorDetails(& | ||
| + | tcaselect(6); | ||
| + | displaySensorDetails(& | ||
| + | } | ||
| + | |||
| + | void loop(void) | ||
| + | { | ||
| + | /* Get a new sensor event */ | ||
| + | sensors_event_t event; | ||
| + | | ||
| + | tcaselect(2); | ||
| + | mag1.getEvent(& | ||
| + | |||
| + | /* Display the results (magnetic vector values are in micro-Tesla (uT)) */ | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | | ||
| + | tcaselect(6); | ||
| + | mag2.getEvent(& | ||
| + | /* Display the results (magnetic vector values are in micro-Tesla (uT)) */ | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | | ||
| + | delay(500); | ||
| + | } | ||
| + | </ | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/i2c/tca9548a.1713179925.txt.gz · Dernière modification : de gerardadmin
