start:arduino:mx1508
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:mx1508 [2023/11/21 17:16] – [Code arduino Exemple] gerardadmin | start:arduino:mx1508 [2023/11/21 17:35] (Version actuelle) – [Fiche technique] gerardadmin | ||
|---|---|---|---|
| Ligne 24: | Ligne 24: | ||
| ==== Fiche technique ==== | ==== Fiche technique ==== | ||
| - | [[https://electropeak.com/learn/interfacing-mx1508-motor-driver-module-with-arduino/# | + | [[https://components101.com/sites/default/ |
| ====Brochage du module pilote de moteur MX1508==== | ====Brochage du module pilote de moteur MX1508==== | ||
| Ligne 30: | Ligne 30: | ||
| Ce capteur possède 10 broches : | Ce capteur possède 10 broches : | ||
| - | *Vs : Alimentation du module (entrée) | + | *Vs : Alimentation du module (entrée |
| *GND : terre | *GND : terre | ||
| *IN1 : Entrée 1 | *IN1 : Entrée 1 | ||
| Ligne 102: | Ligne 102: | ||
| ==== Utlisation avec une bibliotheque ==== | ==== Utlisation avec une bibliotheque ==== | ||
| - | [[https:// | + | [[https:// |
| + | |||
| + | {{ : | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ==== Code utilisation librairie MX1508 ==== | ||
| + | |||
| + | <code c LibMX1508.ino> | ||
| + | #include < | ||
| + | |||
| + | #define PINA 9 | ||
| + | #define PINB 10 | ||
| + | #define NUMPWM 2 | ||
| + | // MX1508 schematics(in Chinese) can be found here at: http:// | ||
| + | /* | ||
| + | * MX1508(uint8_t pinIN1, uint8_t pinIN2, DecayMode decayMode, NumOfPwmPins numPWM); | ||
| + | * DecayMode must be FAST_DECAY or SLOW_DECAY, | ||
| + | * NumOfPwmPins, | ||
| + | * I recommend using 2 pwm pins per motor so spinning motor forward and backward gives similar response. | ||
| + | * if using 1 pwm pin, make sure its pinIN1, then set pinIN2 to any digital pin. I dont recommend this setting because | ||
| + | * we need to use FAST_DECAY in one direction and SLOW_DECAY for the other direction. | ||
| + | */ | ||
| + | MX1508 motorA(PINA, | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | } | ||
| + | /* | ||
| + | * Ramp up to pwm = 100, by increasing pwm by 1 every 50 millisecond. | ||
| + | * then ramp down to pwm = -100, by decreasing pwm every 50 millisecond. | ||
| + | * positive value pwm results in forward direction. | ||
| + | * negative value pwm results in opposite direction. | ||
| + | */ | ||
| + | void loop() { | ||
| + | // put your main code here, to run repeatedly: | ||
| + | static unsigned long lastMilli = 0; | ||
| + | static bool cwDirection = true; // assume initial direction(positive pwm) is clockwise | ||
| + | static int pwm = 1; | ||
| + | |||
| + | if(millis()-lastMilli > 50){ // every 50 millisecond | ||
| + | if (cwDirection && pwm++ > 100 ) { | ||
| + | cwDirection = false; | ||
| + | } else if (!cwDirection && pwm-- < -100) { | ||
| + | cwDirection = true; | ||
| + | } | ||
| + | motorA.motorGo(pwm); | ||
| + | lastMilli = millis(); | ||
| + | Serial.println(motorA.getPWM()); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Differents exemples d' | ||
| + | |||
| + | [[https:// | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/mx1508.1700583418.txt.gz · Dernière modification : de gerardadmin
