start:arduino:esp32:spi:start
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:esp32:spi:start [2022/11/15 04:40] – [Broches SPI par défaut ESP32] gerardadmin | start:arduino:esp32:spi:start [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 57: | Ligne 57: | ||
Si vous n' | Si vous n' | ||
+ | |||
+ | <code c brochesspi.ino> | ||
+ | /* | ||
+ | Rui Santos | ||
+ | Complete project details at https:// | ||
+ | | ||
+ | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
+ | of this software and associated documentation files. | ||
+ | | ||
+ | The above copyright notice and this permission notice shall be included in all | ||
+ | copies or substantial portions of the Software. | ||
+ | */ | ||
+ | |||
+ | //Find the default SPI pins for your board | ||
+ | //Make sure you have the right board selected in Tools > Boards | ||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | Serial.begin(115200); | ||
+ | Serial.print(" | ||
+ | Serial.println(MOSI); | ||
+ | Serial.print(" | ||
+ | Serial.println(MISO); | ||
+ | Serial.print(" | ||
+ | Serial.println(SCK); | ||
+ | Serial.print(" | ||
+ | Serial.println(SS); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // put your main code here, to run repeatedly: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Important : assurez-vous de sélectionner la carte que vous utilisez dans Outils > carte , sinon vous risquez de ne pas obtenir les bonnes broches. | ||
+ | |||
+ | Après avoir téléchargé le code, ouvrez le moniteur série, RST votre carte et vous verrez les broches SPI. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | ====Utilisation de broches ESP32 SPI personnalisées==== | ||
+ | |||
+ | Lorsque vous utilisez des bibliothèques pour vous interfacer avec vos périphériques SPI, il est généralement simple d' | ||
+ | |||
+ | Par exemple, jetez un coup d'œil à l' | ||
+ | |||
+ | |||
+ | <code c bibliothequeadafruitexempleOO1.ino> | ||
+ | |||
+ | |||
+ | /* | ||
+ | Rui Santos | ||
+ | Détails complets du projet sur https:// | ||
+ | Basé sur l' | ||
+ | |||
+ | Permission est accordée, sans frais, à toute personne obtenant une copie | ||
+ | de ce logiciel et des fichiers de documentation associés. | ||
+ | | ||
+ | L'avis de droit d' | ||
+ | des copies ou des parties substantielles du Logiciel. | ||
+ | */ | ||
+ | |||
+ | #comprendre | ||
+ | | ||
+ | #comprendre | ||
+ | | ||
+ | |||
+ | #comprendre | ||
+ | |||
+ | | ||
+ | |||
+ | #comprendre | ||
+ | | ||
+ | |||
+ | #define BME_SCK 25 | ||
+ | #define BME_MISO 32 | ||
+ | #define BME_MOSI 26 | ||
+ | #define BME_CS 33 | ||
+ | #define SEALEVELPRESSURE_HPA (1013.25) | ||
+ | |||
+ | // | ||
+ | // | ||
+ | Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // logiciel SPI | ||
+ | |||
+ | délai long non signé ; | ||
+ | |||
+ | void setup() { | ||
+ | Série.begin(9600); | ||
+ | Serial.println(F(" | ||
+ | |||
+ | état booléen ; | ||
+ | |||
+ | // paramètres par défaut | ||
+ | // (vous pouvez également passer un objet de bibliothèque Wire comme &Wire2) | ||
+ | status = bme.begin(); | ||
+ | si (!statut) { | ||
+ | Serial.println(" | ||
+ | tandis que (1); | ||
+ | } | ||
+ | |||
+ | Serial.println(" | ||
+ | delayTime = 1000 ; | ||
+ | |||
+ | Serial.println(); | ||
+ | } | ||
+ | |||
+ | |||
+ | boucle vide() { | ||
+ | printValeurs(); | ||
+ | retard(delayTime); | ||
+ | } | ||
+ | |||
+ | void printValues() { | ||
+ | Serial.print(" | ||
+ | Serial.print(bme.readTemperature()); | ||
+ | Serial.println(" | ||
+ | | ||
+ | // Convertir la température en Fahrenheit | ||
+ | / | ||
+ | Serial.print(1.8 * bme.readTemperature() + 32); | ||
+ | Serial.println(" | ||
+ | | ||
+ | Serial.print(" | ||
+ | Serial.print(bme.readPressure() / 100.0F); | ||
+ | Serial.println(" | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); | ||
+ | Serial.println(" | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(bme.readHumidity()); | ||
+ | Serial.println(" | ||
+ | |||
+ | Serial.println(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Vous pouvez facilement transmettre vos broches SPI personnalisées au constructeur de la bibliothèque. | ||
+ | | ||
+ | <code c biblio002.ino> | ||
+ | Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); | ||
+ | </ | ||
+ | |||
+ | Dans ce cas, j' | ||
+ | |||
+ | <code c biblio003.ino> | ||
+ | #define BME_SCK 25 | ||
+ | #define BME_MISO 32 | ||
+ | #define BME_MOSI 26 | ||
+ | #define BME_CS 33 | ||
+ | </ | ||
+ | |||
+ | Si vous n' | ||
+ | |||
+ | <code c bliblio004.ino> | ||
+ | SPI.begin(SCK, | ||
+ | </ | ||
+ | |||
+ | Vous pouvez voir un exemple de ce scénario dans ce tutoriel , dans lequel nous initialisons un émetteur-récepteur SPI LoRa qui est connecté à des broches SPI personnalisées. Ou cet exemple montrant comment utiliser des broches SPI personnalisées avec un module de carte microSD . | ||
+ | | ||
+ | ====== Liens web ====== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
+ |
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/spi/start.1668483654.txt.gz · Dernière modification : 2023/01/27 16:08 (modification externe)