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:15] – [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 85: | Ligne 86: | ||
</ | </ | ||
+ | Vous pouvez ensuite appeler tcaselect(0) via tcaselect(7) pour configurer le multiplexeur. | ||
+ | Notez que si vous possédez des appareils I2C avec l' | ||
+ | |||
+ | |||
+ | <code c progr002.ino> | ||
+ | /** | ||
+ | * TCA9548 I2CScanner.ino -- I2C bus scanner for Arduino | ||
+ | * | ||
+ | * Based on https:// | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | #include " | ||
+ | |||
+ | #define TCAADDR 0x70 | ||
+ | |||
+ | void tcaselect(uint8_t i) { | ||
+ | if (i > 7) return; | ||
+ | |||
+ | Wire.beginTransmission(TCAADDR); | ||
+ | Wire.write(1 << i); | ||
+ | Wire.endTransmission(); | ||
+ | } | ||
+ | |||
+ | |||
+ | // standard Arduino setup() | ||
+ | void setup() | ||
+ | { | ||
+ | while (!Serial); | ||
+ | delay(1000); | ||
+ | |||
+ | Wire.begin(); | ||
+ | | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(" | ||
+ | | ||
+ | for (uint8_t t=0; t<8; t++) { | ||
+ | tcaselect(t); | ||
+ | Serial.print(" | ||
+ | |||
+ | for (uint8_t addr = 0; addr< | ||
+ | if (addr == TCAADDR) continue; | ||
+ | |||
+ | Wire.beginTransmission(addr); | ||
+ | if (!Wire.endTransmission()) { | ||
+ | Serial.print(" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | 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.1713179707.txt.gz · Dernière modification : 2024/04/15 13:15 de gerardadmin