generated from mhausenblas/mkdocs-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ajout de m5stack atom encoder et tof
- Loading branch information
1 parent
58e6489
commit 5fa89d8
Showing
7 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
rel-electro-immersif-src/m5stack/mstack_atom_encoder/mstack_atom_encoder.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Le code de base pour le M5Stack Atom | ||
|
||
// Inclure la librairie M5 (version pour M5Atom) : | ||
// https://github.com/m5stack/M5Atom | ||
#include <M5Atom.h> | ||
|
||
// Inclure la librairie FastLED qui va gérer le pixel : | ||
// https://github.com/FastLED/FastLED | ||
#include <FastLED.h> | ||
|
||
// Un tableau qui contient une variable de type CRGB. | ||
// Il y a un seul pixel, mais il doit être dans un tableau. | ||
// CRGB est un type de couleur défini par la lirairie FastLed : | ||
// https://github.com/FastLED/FastLED/wiki/Pixel-reference#crgb-reference | ||
CRGB mesPixels[1]; | ||
|
||
|
||
#include "Unit_Encoder.h" | ||
Unit_Encoder myEncoder; | ||
int myEncoderPreviousRotation; | ||
|
||
unsigned long myChronoStart; | ||
|
||
|
||
void setup() { | ||
// Démarrer la libraire M5 avec toutes les options de pré-configuration désactivées : | ||
M5.begin(false, false, false); | ||
|
||
// Démarrer la connexion sérielle : | ||
Serial.begin(115200); | ||
|
||
// Ajouter le pixel (il y en a un seul) du M5Atom à la librairie FastLED : | ||
FastLED.addLeds<WS2812, DATA_PIN, GRB>(mesPixels, 1); | ||
|
||
Wire.begin(); | ||
|
||
myEncoder.begin(); | ||
|
||
// Animation de démarrage | ||
while (millis() < 5000) { | ||
mesPixels[0] = CHSV((millis() / 5) % 255, 255, 255 - (millis() * 255 / 5000)); | ||
FastLED.show(); | ||
delay(50); | ||
} | ||
mesPixels[0] = CRGB(0, 0, 0); | ||
FastLED.show(); | ||
} | ||
|
||
void loop() { | ||
// Toujours inclure M5.update() au début de loop() : | ||
M5.update(); | ||
|
||
if (millis() - myChronoStart >= 50) { | ||
myChronoStart = millis(); | ||
|
||
int encoderRotation = myEncoder.getEncoderValue(); | ||
int encoderRotationChange = encoderRotation - myEncoderPreviousRotation; | ||
myEncoderPreviousRotation = encoderRotation; | ||
|
||
int encoderButton = myEncoder.getButtonStatus(); | ||
|
||
uint32_t myColorOn = 0xFFFFFF; | ||
uint32_t myColorOff = 0x000000; | ||
|
||
if (encoderButton == 0) { | ||
myEncoder.setLEDColor(2, myColorOn); | ||
myEncoder.setLEDColor(1, myColorOn); | ||
} else { | ||
if ( encoderRotationChange > 0) { | ||
myEncoder.setLEDColor(1, myColorOn); | ||
myEncoder.setLEDColor(2, myColorOff); | ||
} else if (encoderRotationChange < 0) { | ||
myEncoder.setLEDColor(1, myColorOff); | ||
myEncoder.setLEDColor(2, myColorOn); | ||
} else { | ||
myEncoder.setLEDColor(1, myColorOff); | ||
myEncoder.setLEDColor(2, myColorOff); | ||
} | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
rel-electro-immersif-src/m5stack/mstack_atom_lite_tof/mstack_atom_lite_tof.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Le code de base pour le M5Stack Atom | ||
|
||
// Inclure la librairie M5 (version pour M5Atom) : | ||
// https://github.com/m5stack/M5Atom | ||
#include <M5Atom.h> | ||
|
||
// Inclure la librairie FastLED qui va gérer le pixel : | ||
// https://github.com/FastLED/FastLED | ||
#include <FastLED.h> | ||
|
||
// Un tableau qui contient une variable de type CRGB. | ||
// Il y a un seul pixel, mais il doit être dans un tableau. | ||
// CRGB est un type de couleur défini par la lirairie FastLed : | ||
// https://github.com/FastLED/FastLED/wiki/Pixel-reference#crgb-reference | ||
CRGB mesPixels[1]; | ||
|
||
|
||
#include <VL53L0X.h> | ||
VL53L0X myTOF; | ||
|
||
unsigned long myChronoStart; | ||
|
||
void setup() { | ||
// Démarrer la libraire M5 avec toutes les options de pré-configuration désactivées : | ||
M5.begin(false, false, false); | ||
|
||
// Démarrer la connexion sérielle : | ||
Serial.begin(115200); | ||
|
||
// Ajouter le pixel (il y en a un seul) du M5Atom à la librairie FastLED : | ||
FastLED.addLeds<WS2812, DATA_PIN, GRB>(mesPixels, 1); | ||
|
||
|
||
Wire.begin(); | ||
|
||
myTOF.init(); | ||
myTOF.setTimeout(500); | ||
myTOF.startContinuous(); | ||
|
||
// Animation de démarrage | ||
while (millis() < 5000) { | ||
mesPixels[0] = CHSV((millis() / 5) % 255, 255, 255 - (millis() * 255 / 5000)); | ||
FastLED.show(); | ||
delay(50); | ||
} | ||
mesPixels[0] = CRGB(0, 0, 0); | ||
FastLED.show(); | ||
} | ||
|
||
void loop() { | ||
// Toujours inclure M5.update() au début de loop() : | ||
M5.update(); | ||
|
||
if (millis() - myChronoStart >= 50) { | ||
myChronoStart = millis(); | ||
|
||
uint16_t value = myTOF.readRangeContinuousMillimeters(); | ||
if (myTOF.timeoutOccurred()) { | ||
Serial.println("TOF TIMEOUT"); | ||
} else { | ||
Serial.println(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# M5Stack Unit Encoder | ||
|
||
## Introduction | ||
|
||
Le [M5Stack Unit Encoder](https://docs.m5stack.com/en/unit/encoder) est un capteur de rotation infinie équipé de 2 pixels RGB. | ||
|
||
C'est un *Unit* de type I²C tel qu'identifié par son connecteur rouge. | ||
|
||
 | ||
|
||
## Bibliothèque M5Unit-Encoder | ||
|
||
La bibliothèque [M5Unit-Encoder](https://github.com/m5stack/M5Unit-Encoder) permet d'interfacer avec le [M5Stack Unit Encoder](https://docs.m5stack.com/en/unit/encoder). | ||
|
||
### Installation | ||
|
||
La bibliothèque [M5Unit-Encoder](https://github.com/m5stack/M5Unit-Encoder) est disponible dans le gestionnaire de bibliothèques d'Arduino. | ||
|
||
### Code à ajouter à l'espace global, i.e. avant setup() | ||
|
||
Importer la bibliothèque, créer une instance de la classe `Unit_Encoder` et créer une variable pour mémoriser la rotation précédente : | ||
```arduino | ||
#include "Unit_Encoder.h" | ||
Unit_Encoder myEncoder; | ||
int myEncoderPreviousRotation; | ||
``` | ||
|
||
### Code à ajouter à setup() | ||
|
||
Dans `setup()`, démarrer la connexion I2C (si elle n'a pas déjà été démarrée) et démarrer la connexion avec l'encodeur : | ||
```arduino | ||
Wire.begin(); // Démarrer la connexion I2C | ||
myEncoder.begin(); // Démarrer la connexion avec l'encodeur | ||
``` | ||
|
||
### Code à utiliser dans loop() | ||
|
||
Obtenir la rotation accumulée de l'encodeur: | ||
```arduino | ||
int encoderRotation = myEncoder.getEncoderValue(); | ||
``` | ||
|
||
**Alternativement**, obtenir la rotation effectuée depuis la dernière récupération de rotation et mémoriser cette valeur dans `encoderRotationChange`: | ||
```arduino | ||
int encoderRotation = myEncoder.getEncoderValue(); | ||
int encoderRotationChange = encoderRotation - myEncoderPreviousRotation; | ||
myEncoderPreviousRotation = encoderRotation; | ||
``` | ||
|
||
Obtenir l'état du bouton (0=appuyé, 1=relâché): | ||
```arduino | ||
int encoderButton = myEncoder.getButtonStatus(); | ||
``` | ||
|
||
Changer la couleur du **premier** pixel en blanc ([la couleur est en valeur hexadécimale](https://htmlcolorcodes.com/color-picker/) où le symbole # est remplacé par 0x) : | ||
```arduino | ||
myEncoder.setLEDColor(1, 0xFFFFFF); | ||
``` | ||
|
||
Changer la couleur du **deuxième** pixel en noir ([la couleur est en valeur hexadécimale](https://htmlcolorcodes.com/color-picker/) où le symbole # est remplacé par 0x) : | ||
```arduino | ||
myEncoder.setLEDColor(2, 0x000000); | ||
``` | ||
|
||
Exemples de couleurs hexadécimales en C++ : | ||
```arduino | ||
uint32_t rouge = 0xFF0000; | ||
uint32_t orange = 0xFF8800; | ||
uint32_t vert = 0x00FF00; | ||
uint32_t cyan = 0x00FFFF; | ||
uint32_t mauve = 0xFF00FF; | ||
``` | ||
|
||
## Exemple avec M5Unit-Encoder | ||
```arduino | ||
{{#include ./mstack_atom_encoder/mstack_atom_encoder.ino}} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# M5Stack Unit TOF | ||
|
||
## Introduction | ||
|
||
Le [M5Stack Unit TOF](https://docs.m5stack.com/en/unit/tof) permet de mesurer des distances jusqu'à 2 mètres avec la technologie *Time of Flight*. | ||
|
||
C'est un *Unit* de type I²C tel qu'identifié par son connecteur rouge. | ||
|
||
 | ||
|
||
## Bibliothèque vl53l0x-arduino | ||
|
||
|
||
La bibliothèque [vl53l0x-arduino](https://github.com/pololu/vl53l0x-arduino) permet d'interfacer avec le [M5Stack Unit TOF](https://docs.m5stack.com/en/unit/tof). | ||
|
||
### Installation | ||
|
||
La bibliothèque [vl53l0x-arduino](https://github.com/pololu/vl53l0x-arduino) est disponible dans le gestionnaire de bibliothèques d'Arduino. | ||
|
||
### Code à ajouter à l'espace global, i.e. avant setup() | ||
|
||
Importer la bibliothèque et créer une instance de la classe `VL53L0X` : | ||
```arduino | ||
#include <VL53L0X.h> | ||
VL53L0X myTOF; | ||
``` | ||
|
||
### Code à ajouter à setup() | ||
|
||
Dans `setup()`, démarrer la connexion I2C (si elle n'a pas déjà été démarrée), initialiser le TOF, définir un *timeout* et démarrer la lecture en continue du TOF : | ||
```arduino | ||
Wire.begin(); | ||
myTOF.init(); | ||
myTOF.setTimeout(500); | ||
myTOF.startContinuous(); | ||
``` | ||
|
||
|
||
### Code à utiliser dans loop() | ||
|
||
Obtenir la mesure en millimètres : | ||
```arduino | ||
uint16_t value = myTOF.readRangeContinuousMillimeters(); | ||
``` | ||
|
||
Déterminer s'il y a eu une erreur de communication avec le TOF : | ||
```arduino | ||
int error = myTOF.timeoutOccurred(); | ||
``` | ||
|
||
## Exemple avec vl53l0x-arduino | ||
```arduino | ||
{{#include ./mstack_atom_lite_tof/mstack_atom_lite_tof.ino}} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.