Pokud chceme připojit k merkurinu přímo jeden až tři motory, použijeme obvykle toto zapojení:

Doporučené napětí je 9V dc.
Na Merkurinu jsou vyvedeny všechny PWM výstupy nahoře na dvouřadém konektoru (out-pwm).
Výstupy označené 3 5 6 9 10 11 odpovídají na arduinu D3, D5, D6, D9, D10 a D11.
Horní řada jsou země (gnd).
Neosazené 2 otvory jsou připraveny pro ty, kteří potřebují dalších +5V.
Abychom mohli připojit motory k procesoru, musíme použít zesilovač proudu, takzvané H-můstky. Na obrázku jsou vpravo.
Poznámka: H-můstky jsou oddělené od ostatních součástek, společná je pouze zem (gnd).
Vstupy s TTL logikou jsou přes nezámkový jednořadý konektor.
Výstupy jsou zámkové „bílé“ konektory, zapojené signál-zem-signál.
Předtím, než motory připojíte, můžete sledovat výstupní signál (napětí) přes dvojici antiparalelních LED.
Pokud potřebujete otočit směr motoru a nechcete zasahovat do kódu programu, nemusíte přepojovat motor, ale stačí přehodit (otočit) vstupy.
Pro napájení můstků můžete použít jeden ze dvou způsobů:
- hlavní vstupní napětí zleva, konektor A1 powerjack.
V tom případě spojíte spojkou (zde červený jumper vpravo)
- externí napětí od 3V do 9V na konektoru PwrBridge vpravo nahoře.
V tom případě MUSÍTE rozpojit červený jumper – napájecí napětí by se „pohádala“ a deska by „shořela“.
UPOZORNĚNÍ: Nezapomínejte na maximální výkonovou ztrátu h-můstků (to je maximální odebíraný proud motorů). Doporučené je použití PWM od 30%, pak zvyšujete výkon a prstem můžete otestovat, jestli se můstky (pod LCD displejem vlevo) nadměrně nezahřívají.
Zkouška teploty: připojím motor a postupně navyšuji výkon
analogWrite(3, fadeValue);
//3 = výstup D3; fadeValue = výstupní PWM "výkon" , hodnota plnění je 0 až 255
pokud prst udržím = ok,
pokud se zahřeje během 5 sekund tak, že neudržím prst = něco je špatně.
Testovací program je zde:
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
/*******************************************************
upravil Ladislav Vohralik 2015, MerkurRobot.cz
********************************************************/
// select the pins used on the LCD panel
LiquidCrystal lcd(13, 12, 8, 7, 4, 2);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
int motor_sel =0;
int motor1_speed = 0;
int motor2_speed = 0;
int motor3_speed = 0;
int motor1a_out = 3; // motor 1a connected to PWM digital pin 3
int motor1b_out = 5; // motor 1a connected to PWM digital pin 5
int motor2a_out = 6; // motor 1a connected to PWM digital pin 6
int motor2b_out = 9; // motor 1a connected to PWM digital pin 9
int motor3a_out = 10; // motor 1a connected to PWM digital pin 10
int motor3b_out = 11; // motor 1a connected to PWM digital pin 11
int x =0; // pomocná
int y =0; // pomocná
int fadeValue = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnESC 5
#define btnNONE 6
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; //
if (adc_key_in < 12) return btnESC;
if (adc_key_in < 25) return btnLEFT;
if (adc_key_in < 111) return btnDOWN;
if (adc_key_in < 222) return btnUP;
if (adc_key_in < 555) return btnRIGHT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("motor/speed"); // print a simple message
// set motor: up/down
// motor: 1..3
// motor=4 all=stop Low
// motor=0 lock setting
// set speed: left/right
// speed: -99..0..99%
}
void loop()
{
// test output -----------------
for(fadeValue = -255 ; fadeValue <= 255; fadeValue +=25) {
// sets the value (range from 0 to 255):
if (fadeValue >= 0) {
analogWrite(3, fadeValue);
analogWrite(5, 0);
}
x = abs(fadeValue);
x = x * 1;
if (fadeValue < 0) {
analogWrite(3, 0);
analogWrite(5, x);
}
vypis_na_lcd();
// wait for 550 milliseconds to see the dimming effect
delay(550);
}
for(int fadeValue = 255 ; fadeValue > -255; fadeValue -=25) {
// sets the value (range from 0 to 255):
if (fadeValue >= 0) {
analogWrite(3, fadeValue);
analogWrite(5, 0);
}
x = abs(fadeValue);
x = x * 1;
if (fadeValue < 0) {
analogWrite(3, 0);
analogWrite(5, x);
}
// wait for 550 milliseconds to see the dimming effect
delay(550);
}
// konec test output -----------------
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
//set speed up
if ((motor_sel == 1) and (motor1_speed < 99)) {
motor1_speed = motor1_speed + 11;
lcd.setCursor(3,1);
//lcd.print("");
lcd.print(motor1_speed);
lcd.print(" ");
x = abs(motor1_speed);
if (motor1_speed > 0) {
analogWrite(motor1a_out, x);
analogWrite(motor1b_out, 0);
}
if (motor1_speed <= 0) {
analogWrite(motor1a_out, 0);
analogWrite(motor1b_out, x);
}
}
delay(100);
break;
}
case btnLEFT:
{
//set speed down
if ((motor_sel == 1) and (motor1_speed > -99)) {
motor1_speed = motor1_speed - 11;
lcd.setCursor(3,1);
//lcd.print("");
lcd.print(motor1_speed);
lcd.print(" ");
}
delay(100);
break;
}
case btnUP:
{
//select motor
if (motor_sel < 3) {
motor_sel = motor_sel+1;
lcd.setCursor(1,1);
//lcd.print(" m");
lcd.print(motor_sel);
}
delay(300);
break;
}
case btnDOWN:
{
//select motor
if (motor_sel > 1) {
motor_sel = motor_sel-1;
lcd.setCursor(1,1);
//lcd.print("");
lcd.print(motor_sel);
}
delay(300);
break;
}
case btnSELECT:
{
lcd.print("SELECT ");
break;
}
case btnESC:
{
lcd.print("ESC ");
break;
}
case btnNONE:
{
lcd.setCursor(0,1);
lcd.print("M");
break;
}
}
lcd.setCursor(8,0);
//lcd.print(motor_sel);
//lcd.print(" ");
lcd.print("m");
lcd.print(motor1_speed);
lcd.print("x");
lcd.print(x);
} // konec loop ------------
int test_output(int x,int y){ // funkce test_output ------------
int led_1 = x;
int led_2 = y;
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(led_1, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(led_1, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
int result = led_1;
return result;
} // konec funkce test_output ------------
int vypis_na_lcd(){
lcd.setCursor(0,0);
lcd.print(" x ");
lcd.print(x);
lcd.print(" y ");
lcd.print(fadeValue);
lcd.print(" ");
}