#1 Re: Проекты » управление бт машинкой ПРО МИНИ + плата драйвера L298N + 2 DC мотора. » 2016-03-30 14:08:21

Я рад за Ваших детей и Вам мое уважение за такой подход. Только моему сыну всего 3 года, он ещё не разговаривает толком и хочет он машинку, а не дуинку.  С операторами по ходу разбираюсь Чужие программы в слепую не копирую, - стараюсь понять принцип, а потом адаптировать для своей задачи.
Сейчас получил из поднебесной дисплей 16*2 постараюсь посмотреть, что приходит с андроида по зубу в дуинку, потом буду двигаться дальше.
За видео курс спасибо - полезный ресурс. Буду изучать.

#2 Re: Проекты » управление бт машинкой ПРО МИНИ + плата драйвера L298N + 2 DC мотора. » 2016-03-28 08:39:44

И все это я прекрасно понимаю, но  ((( сколько же вас грамотных и все, наверное самоучки, и учитель у всех - интернет... а я сижу, ничего не делаю, в интернет лезть не хочу...  Но с репликами, подобной Вашей, в интернете подсказок больше не становится. А я сажусь заливать в машинку свои куралесы, малый приходит "Дай!" Минут 20 я отговариваюсь, а потом тесты заканчиваются. А принимая во внимание детскую любознательность, в препарированную ребёнком при моём недосмотре машинку заливать что-то будет бессмысленно. )))
Потому и прошу подсказать, куда двигаться.
И еще: есть ли возможность и как, подключив дуину к компу увидеть, какие сигналы приходят (и приходят ли) на неё по зубу? Может не в скетче дело, а в андроиде? (хотя в это я почти не верю).

#3 Re: Проекты » управление бт машинкой ПРО МИНИ + плата драйвера L298N + 2 DC мотора. » 2016-03-06 20:03:41

Убрал указанное нафиг... результат нулевой. сигнал на моторы не приходит. Хоть бы что "зашуршало, цокнуло"...
Насчет   
analogWrite(PIN_MOTOR_............._SPEED, v);  - не уверен, а 
digitalWrite(PIN_MOTOR_..............., LOW);   - по моему, точно не мешает.
Если Вы о случае:

case 'S': 

  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;

- то останавливать машину надо как-то...
если о самой верхней или нижней секции лупа - убрал - без результата.

#5 Проекты » управление бт машинкой ПРО МИНИ + плата драйвера L298N + 2 DC мотора. » 2016-03-06 00:54:49

baspav
відповідей: 11

Собрал машинку с начинкой Ардуино ПРО МИНИ + плата блютуза HC-06 + плата драйвера L298N + 2 DC мотора
Как и положено в таких случаях - в интернете куча разного... с использованием двухколесных китов, есть так же варианты мотор+серво, но вариантов на 2 мотора я не нашел.
Переработал код с сайта RemoteXY - получилось вот такое:

///////////////////////////////////////////// 
//        RemoteXY include library         // 
///////////////////////////////////////////// 

/* RemoteXY select connection mode and include library */ 
#define REMOTEXY_MODE__SOFTWARESERIAL 
#include <SoftwareSerial.h> 
#include <RemoteXY.h> 

/* RemoteXY connection settings */
#define REMOTEXY_SERIAL_RX 2 
#define REMOTEXY_SERIAL_TX 3 
#define REMOTEXY_SERIAL_SPEED 9600 

/* RemoteXY configurate  */  
unsigned char RemoteXY_CONF[] = 
  { 3,0,23,0,1,5,5,15,41,11
  ,43,43,1,2,0,6,5,27,11,5
  ,79,78,0,79,70,70,0 }; 
   
/* this structure defines all the variables of your control interface */  
struct { 

    /* input variable */
  signed char joystick_1_x; /* =-100..100 x-coordinate joystick position */
  signed char joystick_1_y; /* =-100..100 y-coordinate joystick position */
  unsigned char switch_1; /* =1 if switch ON and =0 if OFF */

    /* other variable */
  unsigned char connect_flag;  /* =1 if wire connected, else =0 */

} RemoteXY; 

///////////////////////////////////////////// 
//           END RemoteXY include          // 
///////////////////////////////////////////// 
/* defined the right motor control pins */
#define PIN_MOTOR_STEERING_UP 5
#define PIN_MOTOR_STEERING_DN 4
#define PIN_MOTOR_STEERING_SPEED 10

/* defined the left motor control pins */
#define PIN_MOTOR_RUNNING_UP 7
#define PIN_MOTOR_RUNNING_DN 6
#define PIN_MOTOR_RUNNING_SPEED 9

/* defined the LED pin */
#define PIN_LED 13


/* defined two arrays with a list of pins for each motor */
unsigned char SteeringMotor[3] = 
  {PIN_MOTOR_STEERING_UP, PIN_MOTOR_STEERING_DN, PIN_MOTOR_STEERING_SPEED};
unsigned char RunningMotor[3] = 
  {PIN_MOTOR_RUNNING_UP, PIN_MOTOR_RUNNING_DN, PIN_MOTOR_RUNNING_SPEED};

/*
   speed control of the motor
   motor - pointer to an array of pins
   v - motor speed can be set from -100 to 100
*/



void setup() {
  /* initialization pins */
  pinMode (PIN_MOTOR_STEERING_UP, OUTPUT);
  pinMode (PIN_MOTOR_STEERING_DN, OUTPUT);
  pinMode (PIN_MOTOR_RUNNING_UP, OUTPUT);
  pinMode (PIN_MOTOR_RUNNING_DN, OUTPUT);
  pinMode (PIN_LED, OUTPUT);

  /* initialization module RemoteXY */
  RemoteXY_Init ();
}

void loop() {
  
  RemoteXY_Handler ();
//  analogRead RemoteXY.joystick_1_y;
//  analogRead RemoteXY.joystick_1_x;
 int vr = RemoteXY.joystick_1_x;
 int vs = RemoteXY.joystick_1_y;
if (vr>0)
{
    digitalWrite(RunningMotor[0], HIGH);
    digitalWrite(RunningMotor[1], LOW);
    analogWrite(RunningMotor[2], vr*2.55);
}
else if (vr<0)
  {
    digitalWrite(RunningMotor[0], LOW);
    digitalWrite(RunningMotor[1], HIGH);
    analogWrite(RunningMotor[2], (-vr)*2.55);
  }
  else 
  {
    digitalWrite(RunningMotor[0], LOW);
    digitalWrite(RunningMotor[1], LOW);
    analogWrite(RunningMotor[2], 0);
  }
  
  if (vs>0) {
    digitalWrite(SteeringMotor[0], HIGH);
    digitalWrite(SteeringMotor[1], LOW);
    analogWrite(SteeringMotor[2], vs*2.55);
  }
  else if (vs<0) {
    digitalWrite(SteeringMotor[0], LOW);
    digitalWrite(SteeringMotor[1], HIGH);
    analogWrite(SteeringMotor[2], (-vs)*2.55);
  }
  else {
    digitalWrite(SteeringMotor[0], LOW);
    digitalWrite(SteeringMotor[1], LOW);
    analogWrite(SteeringMotor[2], 0);
  }
  
  
}

Результат положительный - машинка едет как положено. Но есть трабл. Бесплатная версия RemoteXY работает только 30 сек., а с финансами проблема. Стал искать другие варианты.
Нашел такое  https://www.youtube.com/watch?v=46w362K6BDk
Показалось подходящим, но тут используется MotorShieldR3, а у меня его нет. Попробовал перелепить предложенный автором код под мою конфигурацию. Получилось такое:

/*
  Front Motor (Steering) => Channel A
 Back Motor => Channel B
 
 Since the motor shield hijacks 6 pins for the motors'
 control, they are declared in the MotorShieldR3 library.
 */
 #include <SoftwareSerial.h>  
 
 int bluetoothTx = 2;
 int bluetoothRx = 3;
 SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
 
 /* defined the right motor control pins */
#define PIN_MOTOR_STEERING_UP 7
#define PIN_MOTOR_STEERING_DN 6
#define PIN_MOTOR_STEERING_SPEED 10

/* defined the left motor control pins */
#define PIN_MOTOR_RUNNING_UP 4
#define PIN_MOTOR_RUNNING_DN 5
#define PIN_MOTOR_RUNNING_SPEED 9

/* 
 #include <MotorShieldR3.h>
MotorShieldR3 yellowCar;*/
#define pinfrontLights    13    //Pin that activates the Front lights.
#define pinbackLights     12    //Pin that activates the Back lights.   
char command = 'S';
int v = 250;   
int timer0 = millis();
int timer1 = 0;


void setup() 
{       
  //Setup Bluetooth serial connection to android
  Serial.begin(115200);  //Set the baud rate to that of your Bluetooth module.
  pinMode(pinfrontLights , OUTPUT);
  pinMode(pinbackLights , OUTPUT);
  
  pinMode (PIN_MOTOR_STEERING_UP, OUTPUT);
  pinMode (PIN_MOTOR_STEERING_DN, OUTPUT);
  pinMode (PIN_MOTOR_RUNNING_UP, OUTPUT);
  pinMode (PIN_MOTOR_RUNNING_DN, OUTPUT);
  
 }

void loop(){
 
  
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
  
  if(Serial.available() > 0){ 
    command = Serial.read(); 
    //Change pin mode only if new command is different from previous.   
    //Serial.println(command);
    switch(command){
    case 'F':  
    //  yellowCar.Forward_4W(velocity);
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, HIGH);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;
    case 'B':  
    //  yellowCar.Back_4W(velocity);
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, HIGH);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;
    case 'L':  
    //  yellowCar.Left_4W();
  digitalWrite(PIN_MOTOR_STEERING_UP, HIGH);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;
    case 'R':
    //  yellowCar.Right_4W();  
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, HIGH);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;
    case 'S':  
    //  yellowCar.Stopped_4W();
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break; 
    case 'I':  //FR  
    //  yellowCar.ForwardRight_4W(velocity);
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, HIGH);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, HIGH);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break; 
    case 'J':  //BR  
    //  yellowCar.BackRight_4W(velocity);
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, HIGH);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, HIGH);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;        
    case 'G':  //FL  
    //  yellowCar.ForwardLeft_4W(velocity);
  digitalWrite(PIN_MOTOR_STEERING_UP, HIGH);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, HIGH);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break; 
    case 'H':  //BL
    //  yellowCar.BackLeft_4W(velocity);
  digitalWrite(PIN_MOTOR_STEERING_UP, HIGH);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, HIGH);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;
    case 'W':  //Font ON 
      digitalWrite(pinfrontLights, HIGH);
      break;
    case 'w':  //Font OFF
      digitalWrite(pinfrontLights, LOW);
      break;
    case 'U':  //Back ON 
      digitalWrite(pinbackLights, HIGH);
      break;
    case 'u':  //Back OFF 
      digitalWrite(pinbackLights, LOW);
      break; 
    case 'D':  //Everything OFF 
      digitalWrite(pinfrontLights, LOW);
      digitalWrite(pinbackLights, LOW);
    //  yellowCar.Stopped_4W();
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
      break;         
    default:  //Get velocity
      if(command=='q'){
        v = 255;  //Full velocity
     //   yellowCar.SetSpeed_4W(velocity);
     
      }
      else{ 
          //Chars '0' - '9' have an integer equivalence of 48 - 57, accordingly.
          if((command >= 48) && (command <= 57)){ 
            //Subtracting 48 changes the range from 48-57 to 0-9.
            //Multiplying by 25 changes the range from 0-9 to 0-225.
            v = (command - 48)*25;       
      //      yellowCar.SetSpeed_4W(velocity);
      
          }
        }
      }
    }
  
  else
  {
    timer0 = millis();  //Get the current time (millis since execution started).
    //Check if it has been 500ms since we received last command.
    if((timer0 - timer1)>500){  
      //More tan 500ms have passed since last command received, car is out of range.
      //Therefore stop the car and turn lights off.
      digitalWrite(pinfrontLights, LOW);
      digitalWrite(pinbackLights, LOW);
   //   yellowCar.Stopped_4W();
  digitalWrite(PIN_MOTOR_STEERING_UP, LOW);
  digitalWrite(PIN_MOTOR_STEERING_DN, LOW);
  analogWrite(PIN_MOTOR_STEERING_SPEED, v);
  digitalWrite(PIN_MOTOR_RUNNING_UP, LOW);
  digitalWrite(PIN_MOTOR_RUNNING_DN, LOW);
  analogWrite(PIN_MOTOR_RUNNING_SPEED, v);
    }
  }  
}

Код компилируется, но моторы двигаться не хотят.
Пожалуйста, помогите найти и исправить ошибку. Или ссылку на рабочий код под мою конфигурацию, если находил кто. Только не отсылайте курить интернет - у меня за пол года от всего этого дыма голова раскалывается уже...

#6 Re: Програмування Arduino » Ардуино ПРО МИНИ + 2 ULN2003A + 2 шаговика » 2015-05-05 13:41:05

Ок. Механическая часть пока не готова, как работает сама электроника, "с руки" так сказать могу показать уже. Или Вам полностью готовый нужен?

#7 Re: Програмування Arduino » Ардуино ПРО МИНИ + 2 ULN2003A + 2 шаговика » 2015-05-03 13:11:53

Все оказалось намного проще. Там для этого предусмотрено
   sensitivity = 10; // this controls the sensitivity of the tracker. lower number = higher sensitivity. if your tracker is constantly jittering back and forth increase the number

и дальше в скетче
if ...  && (diff > sensitivity)...

Просто я был настолько занят глобальной переделкой, что  обратил на это внимание только после тщательной проверкой всех строк.

В результате, после регулировок параметров есть скетч, который полностью удовлетворяет моим требованиям
Так что если кому-то нужен
Солнечный трекер на Ардуино ПРО МИНИ  + 2 ULN2003A + 2 шаговика - вот он:

Solar-Tracker-Duino-Pro-Mini.jpeg

Детали:
Макетная плата - 1шт
Подставка под микросхему подходящая к ПРО МИНИ - 1 шт
Ардуино ПРО МИНИ - 1 шт
ULN2003A  - 2 шт
шаговики - 2 шт
Резисторы 10 КОм - 5 шт
Фото резисторы - 3 шт
Проводки, гнезда, гнезда питания - по потребности



Скетч:

#define TILTL 2
 #define TILTH 3
 #define BOTTOM 2
 #define TOPLEFT 0
 #define TOPRIGHT 1
// #include <AccelStepper.h>
 #include "math.h"

// Назначение пинов выводам для UNL 2003A 1 мотора
int motorPin1 = 6; 
int motorPin2 = 7; 
int motorPin3 = 8; 
int motorPin4 = 9; 

// Назначение пинов выводам для UNL 2003A 2 мотора
int motorPin5 = 10;
int motorPin6 = 11;
int motorPin7 = 12; 
int motorPin8 = 13;

// Назначение пинов выводам кнопок (один вывод кнопок - соответственно, а второй - на GND)
int tlsense;
 int trsense;
 int bsense;
 int tavg;
 int diff;
 int spd;
 int divisor;
 int sensitivity;
 int tiltl;
 int tilth;                   


// установить скорость шагового двигателя.
//variable to set stepper speed.
int motorSpeed = 14000;        

int lookup_1[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
int lookup_2[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
  
/////////////////////////////////////////////////////////////////

 void setup () {
   divisor = 10; // this controls the speed of the servo. lower number = higher speed
   sensitivity = 30; // this controls the sensitivity of the tracker. lower number = higher sensitivity. if your tracker is constantly jittering back and forth increase the number
   Serial.begin(9600); // open serial com
   Serial.print("SolarTracker ready!");
 pinMode(BOTTOM, INPUT); // set the inputs
 pinMode(TOPLEFT, INPUT);
 pinMode(TOPRIGHT, INPUT);
 pinMode(TILTL, INPUT);
 pinMode(TILTH, INPUT);
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
 pinMode(motorPin5, OUTPUT);
 pinMode(motorPin6, OUTPUT);
 pinMode(motorPin7, OUTPUT);
 pinMode(motorPin8, OUTPUT);
 //digitalWrite(TILTL, HIGH);
 //digitalWrite(TILTH, HIGH);
  
   }

///////////////////////////////////////////////////////

 void loop () {

 tiltl = digitalRead(TILTL); // read the tilt sensor
 tilth = digitalRead(TILTH);
 tlsense = analogRead(TOPLEFT); // read the light sensors
 trsense = analogRead(TOPRIGHT);
 bsense = analogRead(BOTTOM);
 bsense = bsense * 1.05; // I had to adjust the value of this sensor to make it more accurate. you might have to do the same but start by leaving it alone
 tavg = (tlsense + trsense)/2; // get an average value for the top 2 sensors
 diff = abs(tavg - bsense); // this judges how far the tracker must turn
 spd = diff/divisor; // and adjusts the speed of the reaction accordingly
 spd = max(spd, 1); // sets the minimum speed to 1
 Serial.print("\nTOP: "); Serial.print(tavg, DEC); // print the sensor values to the serial com
 Serial.print("\tBOTTOM:"); Serial.print(bsense, DEC);
 Serial.print("\tLEFT:"); Serial.print(tlsense, DEC);
 Serial.print("\tRIGHT:"); Serial.print(trsense, DEC);

 if((tavg < bsense) && (diff > sensitivity) && (tiltl == HIGH) && (tilth == HIGH)){ // if the average value of the top sensors is smaller (more light) than the bottom sensor and the tilt sensor is in the correct range
  
  clockwise_1(); // Мотор 1 крутим вправо.
 
 Serial.print("\tState: "); Serial.print("V_UP!");
 }else if((tavg < bsense) && (diff > sensitivity) && (tiltl == HIGH) && (tilth == LOW)){ // if the average value of the top sensors is smaller (more light) than the bottom sensor and the tilt sensor is in the correct range
 
 //clockwise_1(); // Мотор 1 крутим вправо.
 
  digitalWrite(motorPin1, LOW); //останавливаем мотор
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 
 Serial.print("\tState: "); Serial.print("V_STOP!");
 }else if((tavg > bsense) && (diff > sensitivity) && (tiltl == HIGH) && (tilth == HIGH)){ // if the value of the bottom sensor is smaller (more light) than the average value of the top sensors and the tilt sensor is in the correct range
  
 anticlockwise_1(); // Мотор 1 крутим влево.
 
 Serial.print("\tState: "); Serial.print("V_DOWN!");
 }else if((tavg > bsense) && (diff > sensitivity) && (tiltl == LOW) && (tilth == HIGH)){ // if the value of the bottom sensor is smaller (more light) than the average value of the top sensors and the tilt sensor is in the correct range
 
 //anticlockwise_1(); // Мотор 1 крутим влево.
  
  digitalWrite(motorPin1, LOW); //останавливаем мотор
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 
 Serial.print("\tState: "); Serial.print("V_STOP!");
 }else{ // for every other instance
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 
 //clockwise_1(); // Мотор 1 крутим вправо.
 
 // digitalWrite(motorPin1, LOW);
 // digitalWrite(motorPin2, LOW);
 // digitalWrite(motorPin3, LOW);
 // digitalWrite(motorPin4, LOW);
 //Serial.print("\tState: "); Serial.print("STOP!");
 }

 tlsense = analogRead(TOPLEFT); // read the top 2 sensors again because they have probably changed
 trsense = analogRead(TOPRIGHT);
 trsense = trsense * 1.03; // again I had to adjust the value of one sensor to make the tracker more accurate
 diff = abs(tlsense - trsense); // reset the diff variable for the new values
 spd = diff/divisor; // and generate a speed accordingly
 spd = max(spd, 1); // set the minimum speed to 1

 if((tlsense < trsense) && (diff > sensitivity)){ // if the top left sensor value is smaller (more light) than the top right sensor
 
  clockwise_2(); // Мотор 2 крутим вправо.
 
 Serial.print("\tState: "); Serial.print("H_RIGHT!");
 }else if((tlsense > trsense) && (diff > sensitivity)){ // if the top left sensor value is larger (less light) than the top right sensor
  
  anticlockwise_2(); // Мотор 2 крутим влево.
 
 Serial.print("\tState: "); Serial.print("H_LEFT!");
 }else{ // for every other instance
 
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
 
 Serial.print("\tState: "); Serial.print("H_STOP!");
 }

 delay(10); // delay 10ms
 }

     // //////////////////////////////////////////////////////////////

// функция поворачивает мотор 1 против часовой стрелки.
void anticlockwise_1()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 1 по часовой стрелке.
void clockwise_1()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}
// функция поворачивает мотор 2 против часовой стрелки.
void anticlockwise_2()
{
  for(int j = 0; j < 8; j++)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 2 по часовой стрелке.
void clockwise_2()
{
  for(int j = 7; j >= 0; j--)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

/////////////////////////////////////////////////////////////

 void setOutput_1(int out)
{
  digitalWrite(motorPin1, bitRead(lookup_1[out], 0));
  digitalWrite(motorPin2, bitRead(lookup_1[out], 1));
  digitalWrite(motorPin3, bitRead(lookup_1[out], 2));
  digitalWrite(motorPin4, bitRead(lookup_1[out], 3));
}

void setOutput_2(int out)
{
  digitalWrite(motorPin5, bitRead(lookup_2[out], 0));
  digitalWrite(motorPin6, bitRead(lookup_2[out], 1));
  digitalWrite(motorPin7, bitRead(lookup_2[out], 2));
  digitalWrite(motorPin8, bitRead(lookup_2[out], 3));
}

Успехов!

#8 Re: Програмування Arduino » Ардуино ПРО МИНИ + 2 ULN2003A + 2 шаговика » 2015-04-27 06:05:54

Спасибо, нашел.
Ну что ж, склеил части двух скетчей и получил следующее:

Двуосевой трекер для солнечной батареи на шаговых двигателях.
Ардуино ПРО МИНИ + 2 ULN2003A + 2 28BYJ-48-5V

#define TILTL 2
 #define TILTH 3
 #define BOTTOM 2
 #define TOPLEFT 0
 #define TOPRIGHT 1
// #include <AccelStepper.h>
 #include "math.h"

// Назначение пинов выводам для UNL 2003A 1 мотора
int motorPin1 = 6; 
int motorPin2 = 7; 
int motorPin3 = 8; 
int motorPin4 = 9; 

// Назначение пинов выводам для UNL 2003A 2 мотора
int motorPin5 = 10;
int motorPin6 = 11;
int motorPin7 = 12; 
int motorPin8 = 13;

// Назначение пинов выводам кнопок (один вывод кнопок - соответственно, а второй - на GND)
int tlsense;
 int trsense;
 int bsense;
 int tavg;
 int diff;
 int spd;
 int divisor;
 int sensitivity;
 int tiltl;
 int tilth;                   

// фиксируем нажатие на первую и вторую кнопку соответственно.
boolean  q;    
boolean  w;   

// установить скорость шагового двигателя.
//variable to set stepper speed.
int motorSpeed = 14000;        

int lookup_1[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
int lookup_2[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
  
/////////////////////////////////////////////////////////////////

 void setup () {
   // divisor = 10; // this controls the speed of the servo. lower number = higher speed
   sensitivity = 10; // this controls the sensitivity of the tracker. lower number = higher sensitivity. if your tracker is constantly jittering back and forth increase the number
   Serial.begin(19200); // open serial com
   Serial.print("SolarTracker ready!");
   pinMode(BOTTOM, INPUT); // set the inputs
 pinMode(TOPLEFT, INPUT);
 pinMode(TOPRIGHT, INPUT);
 pinMode(TILTL, INPUT);
 pinMode(TILTH, INPUT);
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
 pinMode(motorPin5, OUTPUT);
 pinMode(motorPin6, OUTPUT);
 pinMode(motorPin7, OUTPUT);
 pinMode(motorPin8, OUTPUT);
 digitalWrite(TILTL, HIGH);
 digitalWrite(TILTH, HIGH);
  }

///////////////////////////////////////////////////////

 void loop () {

 tiltl = digitalRead(TILTL); // read the tilt sensor
 tilth = digitalRead(TILTH);
 tlsense = analogRead(TOPLEFT); // read the light sensors
 trsense = analogRead(TOPRIGHT);
 bsense = analogRead(BOTTOM);
 bsense = bsense * 1.05; // I had to adjust the value of this sensor to make it more accurate. you might have to do the same but start by leaving it alone
 tavg = (tlsense + trsense)/2; // get an average value for the top 2 sensors
 diff = abs(tavg - bsense); // this judges how far the tracker must turn
 spd = diff/divisor; // and adjusts the speed of the reaction accordingly
 spd = max(spd, 1); // sets the minimum speed to 1
 //Serial.print("\nTOP: "); Serial.print(tavg, DEC); // print the sensor values to the serial com
 //Serial.print("\tBOTTOM:"); Serial.print(bsense, DEC);
 //Serial.print("\tLEFT:"); Serial.print(tlsense, DEC);
 //Serial.print("\tRIGHT:"); Serial.print(trsense, DEC);

 if((tavg < bsense) && (diff > sensitivity) && (tiltl == HIGH) && (tilth == HIGH)){ // if the average value of the top sensors is smaller (more light) than the bottom sensor and the tilt sensor is in the correct range
  
  clockwise_1(); // Мотор 1 крутим вправо.
 
 //Serial.print("\tState: "); Serial.print("UP!");
 }else if((tavg < bsense) && (diff > sensitivity) && (tiltl == LOW) && (tilth == HIGH)){ // if the average value of the top sensors is smaller (more light) than the bottom sensor and the tilt sensor is in the correct range
 
 clockwise_1(); // Мотор 1 крутим вправо.
 
// Serial.print("\tState: "); Serial.print("UP!");
 }else if((tavg > bsense) && (diff > sensitivity) && (tiltl == HIGH) && (tilth == HIGH)){ // if the value of the bottom sensor is smaller (more light) than the average value of the top sensors and the tilt sensor is in the correct range
  
 anticlockwise_1(); // Мотор 1 крутим влево.
 
 //Serial.print("\tState: "); Serial.print("DOWN!");
 }else if((tavg > bsense) && (diff > sensitivity) && (tiltl == HIGH) && (tilth == LOW)){ // if the value of the bottom sensor is smaller (more light) than the average value of the top sensors and the tilt sensor is in the correct range
 
 anticlockwise_1(); // Мотор 1 крутим влево.
 
 //Serial.print("\tState: "); Serial.print("DOWN!");
 }else{ // for every other instance
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 
 clockwise_1(); // Мотор 1 крутим вправо.
 
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 //Serial.print("\tState: "); Serial.print("STOP!");
 }

 tlsense = analogRead(TOPLEFT); // read the top 2 sensors again because they have probably changed
 trsense = analogRead(TOPRIGHT);
 trsense = trsense * 1.03; // again I had to adjust the value of one sensor to make the tracker more accurate
 diff = abs(tlsense - trsense); // reset the diff variable for the new values
 spd = diff/divisor; // and generate a speed accordingly
 spd = max(spd, 1); // set the minimum speed to 1

 if((tlsense < trsense) && (diff > sensitivity)){ // if the top left sensor value is smaller (more light) than the top right sensor
 
  clockwise_2(); // Мотор 2 крутим вправо.
 
 //Serial.print("\tState: "); Serial.print("LEFT!");
 }else if((tlsense > trsense) && (diff > sensitivity)){ // if the top left sensor value is larger (less light) than the top right sensor
  
  anticlockwise_2(); // Мотор 2 крутим влево.
 
 //Serial.print("\tState: "); Serial.print("RIGHT!");
 }else{ // for every other instance
 
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
 
 //Serial.print("\tState: "); Serial.print("STOP!");
 }

 delay(10); // delay 10ms
 }

     // //////////////////////////////////////////////////////////////

// функция поворачивает мотор 1 против часовой стрелки.
void anticlockwise_1()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 1 по часовой стрелке.
void clockwise_1()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}
// функция поворачивает мотор 2 против часовой стрелки.
void anticlockwise_2()
{
  for(int j = 0; j < 8; j++)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 2 по часовой стрелке.
void clockwise_2()
{
  for(int j = 7; j >= 0; j--)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

/////////////////////////////////////////////////////////////

void setOutput_1(int out)
{
  digitalWrite(motorPin1, bitRead(lookup_1[out], 0));
  digitalWrite(motorPin2, bitRead(lookup_1[out], 1));
  digitalWrite(motorPin3, bitRead(lookup_1[out], 2));
  digitalWrite(motorPin4, bitRead(lookup_1[out], 3));
}

void setOutput_2(int out)
{
  digitalWrite(motorPin5, bitRead(lookup_2[out], 0));
  digitalWrite(motorPin6, bitRead(lookup_2[out], 1));
  digitalWrite(motorPin7, bitRead(lookup_2[out], 2));
  digitalWrite(motorPin8, bitRead(lookup_2[out], 3));
}

void setStop_1(int out)
{
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
}

void setStop_2(int out)
{
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
}

Мне посоветовали сделать его на библиотеке Accelstepper, но я в ней только запутался - с Ардуино столкнулся впервые и то именно по причине монтажа солар трекера. - и потому сделал, как смог.
Скетч скомпилился и в дуинке успешно заработал.
Но хотелось бы увеличить "слепую" зону, чтоб трекер не дергался туда-сюда при малейшем изменении освещености.
Поможете?

#9 Re: Програмування Arduino » Ардуино ПРО МИНИ + 2 ULN2003A + 2 шаговика » 2015-04-26 11:04:35

Нашел способ заставить моторы крутиться только в случае нажатой кнопки. Но почему-то работает только с первой кнопкой. Когда аналогично прописываю вторую кнопку - пишет: collect2.exe: error: ld returned 5 exit status.

/* Исходный скетчДмитрий Осипов. http://www.youtube.com/user/d36073?feature=watch
 
 v.01 button resistor Arduino Шаговый двигатель 28BYJ-48 – 5V Stepper Motor
 
 ----------------------------------------
 Скачать sketch.
 v.01 вправо влево Arduino Шаговый двигатель 28BYJ-48 – 5V Stepper Motor
 https://yadi.sk/d/9trcfiK7ULkQS
 
 v.01 button resistor Arduino Шаговый двигатель 28BYJ-48 – 5V Stepper Motor
 
  */


///////////////////////////////////////////////////////////////

// Назначение пинов выводам для UNL 2003A 1 мотора
int motorPin1 = 6; 
int motorPin2 = 7; 
int motorPin3 = 8; 
int motorPin4 = 9; 

// Назначение пинов выводам для UNL 2003A 2 мотора
int motorPin5 = 10;
int motorPin6 = 11;
int motorPin7 = 12; 
int motorPin8 = 13;

// Назначение пинов выводам кнопок (один вывод кнопок - соответственно, а второй - на GND)
int buttonPin_1 = 2;                      
int buttonPin_2 = 3;                       

// фиксируем нажатие на первую и вторую кнопку соответственно.
boolean  q;    
boolean  w;   

// установить скорость шагового двигателя.
//variable to set stepper speed.
int motorSpeed = 14000;        

int lookup_1[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
int lookup_2[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
  
/////////////////////////////////////////////////////////////////

void setup() {
  // Заявляем пины моторов как выходные
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);

  pinMode(motorPin5, OUTPUT);
  pinMode(motorPin6, OUTPUT);
  pinMode(motorPin7, OUTPUT);
  pinMode(motorPin8, OUTPUT);
  
  // Заявляем пины кнопок как входные

  pinMode(buttonPin_1, INPUT);
  pinMode(buttonPin_2, INPUT);
  
  //Устанавливаем высокий сигнал на пинах отжатых кнопок  
  digitalWrite(buttonPin_1, HIGH);
  digitalWrite(buttonPin_2, HIGH);
  // Serial.begin(9600);
}

////////////////////////////////////////////////////////////////

void loop(){

  if (digitalRead(buttonPin_1) == LOW) // если кнопка 1 нажата.
  {
    q = !q; // меняем значение q на противоположное 0 на 1 или 1 на 0.
    delay(500); // защита от дребезга кнопки.
  }

 if (digitalRead(buttonPin_1) == LOW) {// если кнопка 1 нажата.
  
  if (q == 1){
     while (digitalRead(buttonPin_1) == LOW){
    anticlockwise_1(); // Мотор 1 крутим влево.
  }

} else {
   while (digitalRead(buttonPin_1) == LOW){
  clockwise_1(); // Мотор 1 крутим вправо.
   }
 }
 } else {

  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 }
 
 ///////////////////////////// 
  if (digitalRead(buttonPin_2) == LOW) // если кнопка 2 нажата.
  {
    w = !w; // меняем значение q на противоположное 0 на 1 или 1 на 0.
    delay(500); // защита от дребезга кнопки.
  }
// эти две строки - работают, но постоянно с перерывом на время работы мотора_1
  if (w == 1) anticlockwise_2(); // Мотор_2 крутим влево.
  else clockwise_2(); // Мотор_2 крутим вправо.
 
 }
/* // А вот с этим фрагментом вместо предыдущих двух строчек почему-то не работает пишет collect2.exe: error: ld returned 5 exit status.

  if (w == 1){
     while (digitalRead(buttonPin_2) == LOW){
    anticlockwise_2(); // Мотор 2 крутим влево.
  }

} else {
   while (digitalRead(buttonPin_2) == LOW){
  clockwise_2(); // Мотор 2 крутим вправо.
   }
 }
 } else {

  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
 }
 */
 
// //////////////////////////////////////////////////////////////

// функция поворачивает мотор 1 против часовой стрелки.
void anticlockwise_1()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 1 по часовой стрелке.
void clockwise_1()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}
// функция поворачивает мотор 2 против часовой стрелки.
void anticlockwise_2()
{
  for(int j = 0; j < 8; j++)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 2 по часовой стрелке.
void clockwise_2()
{
  for(int j = 7; j >= 0; j--)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

/////////////////////////////////////////////////////////////

void setOutput_1(int out)
{
  digitalWrite(motorPin1, bitRead(lookup_1[out], 0));
  digitalWrite(motorPin2, bitRead(lookup_1[out], 1));
  digitalWrite(motorPin3, bitRead(lookup_1[out], 2));
  digitalWrite(motorPin4, bitRead(lookup_1[out], 3));
}

void setOutput_2(int out)
{
  digitalWrite(motorPin5, bitRead(lookup_2[out], 0));
  digitalWrite(motorPin6, bitRead(lookup_2[out], 1));
  digitalWrite(motorPin7, bitRead(lookup_2[out], 2));
  digitalWrite(motorPin8, bitRead(lookup_2[out], 3));
}

void setStop_1(int out)
{
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
}

void setStop_2(int out)
{
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
}

Все проверил - вроде все правильно. Убираю  "while (digitalRead(buttonPin_1) == LOW)"  - ошибки нет, но мотор_2 продолжает крутиться при разомкнутой кнопке.
Мне же нужно чтоб кнопка_2 работала точно так же, как кнопка_1 и при замыкании двух кнопок оба мотора работали одновременно и независимо.
Помогите, пожалуйста.

#10 Програмування Arduino » Ардуино ПРО МИНИ + 2 ULN2003A + 2 шаговика » 2015-04-15 08:01:26

baspav
відповідей: 10

Собираю самонаводящийся солар трекер. после ДОЛГОГО И УПОРНОГО серфинга в нете нарыл проэкт мистера Адама http://www.instructables.com/id/Arduino … /?ALLSTEPS, но в нем используются отсутствующие у меня (по причине зашитых карманов) 360-градусные серво. Решил переделать его под 2 ULN2003A + 2 28BYJ-48-5V (по цене 2+2 дешевле чем 1 серво-360). Статей о подключении такой схемы не нашел. Решил попробовать запустить сперва схему без фотосенсора.  Нашел в нете понятный мне скетч и, поколдовав, получил это:

-----------------------------------------------------------------------------------

/* Исходный скетч: 
Дмитрий Осипов. [url]http://www.youtube.com/user/d36073?feature=watch[/url]
 
 v.01 button resistor Arduino Шаговый двигатель 28BYJ-48 – 5V Stepper Motor
 

 Скачать sketch.
 v.01 вправо влево Arduino Шаговый двигатель 28BYJ-48 – 5V Stepper Motor
 [url]https://yadi.sk/d/9trcfiK7ULkQS[/url]
 
 v.01 button resistor Arduino Шаговый двигатель 28BYJ-48 – 5V Stepper Motor
 
  */


///////////////////////////////////////////////////////////////

// Назначение пинов выводам для UNL 2003A 1 мотора
int motorPin1 = 6; 
int motorPin2 = 7; 
int motorPin3 = 8; 
int motorPin4 = 9; 

// Назначение пинов выводам для UNL 2003A 2 мотора
int motorPin5 = 10;
int motorPin6 = 11;
int motorPin7 = 12; 
int motorPin8 = 13;

// Назначение пинов выводам кнопок (один вывод кнопок - соответственно, а второй - на GND)
int buttonPin_1 = 2;                      
int buttonPin_2 = 3;                       

// фиксируем нажатие на первую и вторую кнопку соответственно.
boolean  q;    
boolean  w;   

// установить скорость шагового двигателя.
//variable to set stepper speed.
int motorSpeed = 14000;        

int lookup_1[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
int lookup_2[8] = {
  B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
  
/////////////////////////////////////////////////////////////////

void setup() {
  // Заявляем пины моторов как выходные
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);

  pinMode(motorPin5, OUTPUT);
  pinMode(motorPin6, OUTPUT);
  pinMode(motorPin7, OUTPUT);
  pinMode(motorPin8, OUTPUT);
  
  // Заявляем пины кнопок как входные

  pinMode(buttonPin_1, INPUT);
  pinMode(buttonPin_2, INPUT);
  
  //Устанавливаем высокий сигнал на пинах отжатых кнопок  
  digitalWrite(buttonPin_1, HIGH);
  digitalWrite(buttonPin_2, HIGH);
  // Serial.begin(9600);
}

////////////////////////////////////////////////////////////////

void loop(){

  if (digitalRead(buttonPin_1) == LOW) // если кнопка 1 нажата.
  {
    q = !q; // меняем значение q на противоположное 0 на 1 или 1 на 0.
    delay(500); // защита от дребезга кнопки.
  }

  if (q == 1)anticlockwise_1(); // Мотор 1 крутим влево.

  else clockwise_1(); // Мотор 1 крутим вправо.
  
  
  if (digitalRead(buttonPin_2) == LOW) // если кнопка 2 нажата.
  {
    w = !w; // меняем значение q на противоположное 0 на 1 или 1 на 0.
    delay(500); // защита от дребезга кнопки.
  }

  if (w == 1)anticlockwise_2(); // Мотор 2 крутим влево.

  else clockwise_2(); // Мотор 2 крутим вправо.
}

// //////////////////////////////////////////////////////////////

// функция поворачивает мотор 1 против часовой стрелки.
void anticlockwise_1()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 1 по часовой стрелке.
void clockwise_1()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput_1(i);
    delayMicroseconds(motorSpeed);
  }
}
// функция поворачивает мотор 2 против часовой стрелки.
void anticlockwise_2()
{
  for(int j = 0; j < 8; j++)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

// функция поворачивает мотор 2 по часовой стрелке.
void clockwise_2()
{
  for(int j = 7; j >= 0; j--)
  {
    setOutput_2(j);
    delayMicroseconds(motorSpeed);
  }
}

/////////////////////////////////////////////////////////////

void setOutput_1(int out)
{
  digitalWrite(motorPin1, bitRead(lookup_1[out], 0));
  digitalWrite(motorPin2, bitRead(lookup_1[out], 1));
  digitalWrite(motorPin3, bitRead(lookup_1[out], 2));
  digitalWrite(motorPin4, bitRead(lookup_1[out], 3));
}

void setOutput_2(int out)
{
  digitalWrite(motorPin5, bitRead(lookup_2[out], 0));
  digitalWrite(motorPin6, bitRead(lookup_2[out], 1));
  digitalWrite(motorPin7, bitRead(lookup_2[out], 2));
  digitalWrite(motorPin8, bitRead(lookup_2[out], 3));
}

--------------------------------------------------------------------

Заработало. Направление кнопками меняется успешно.
Но:
1. шаговики ступают по очереди
Вопрос: как сделать, чтоб они крутились независимо?
2. При нажатии на одну кнопку останавливаются оба двигателя, а потом на соответствующем меняется направление.
Вопрос: как сделать, чтоб при нажатии на одну кнопку останавливался только один мотор, который должен менять направление?

Если заинтересует - могу залить видео работы сборки.

#11 Re: Апаратні питання » Arduino pro mini + 2 ULN2003A Вопрос новичка. » 2015-04-08 22:13:26

Спасибо, исправил - все в норме.
Минька - после многодневного лазания по сайтам заметил, что так некоторые ардуинеры называют ПРО МИНИ.

#12 Апаратні питання » Arduino pro mini + 2 ULN2003A Вопрос новичка. » 2015-04-07 21:57:05

baspav
відповідей: 2

Имею Arduino pro mini + 2 китайских готовых ULN2003A в перспективе нацепить два 28BYJ-48-5V для создания переносного солнечного трекера
На данный момент движков нет. Спаял все на монтажке, миньку, чтоб съемная была,  нацепил на подставку под биос со старого принтера - подошло, проверил, залил пробный скетч

int motorPin1 = 13;
int motorPin2 = 12;
int motorPin3 = 11;
int motorPin4 = 10;
int motorPin5 = 9;
int motorPin6 = 8;
int motorPin7 = 7;
int motorPin8 = 6;
int motorSpeed = 10000;         

int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
//int lookup[8] = {B01000, B00100, B00010, B00001};

void setup()
{
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(motorPin5, OUTPUT);
pinMode(motorPin6, OUTPUT);
pinMode(motorPin7, OUTPUT);
pinMode(motorPin8, OUTPUT);
}

void loop()

{
  for(int i = 0; i < 8; i++)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}
void setOutput(int out)
     {
      digitalWrite(motorPin1, bitRead(lookup[out], 3));
      digitalWrite(motorPin2, bitRead(lookup[out], 2));
      digitalWrite(motorPin3, bitRead(lookup[out], 1));
      digitalWrite(motorPin4, bitRead(lookup[out], 0));
      digitalWrite(motorPin5, bitRead(lookup[out], 0));
      digitalWrite(motorPin6, bitRead(lookup[out], 1));
      digitalWrite(motorPin7, bitRead(lookup[out], 2));
      digitalWrite(motorPin8, bitRead(lookup[out], 3));
     }

Сигнал пошел на оба драйвера, но четкого перемещения сигнала на светодиодах драйвера не наблюдается - все сливается в мерцание. При касании к кварцу скорость замедляется и четко прослеживается движение сигнала по светодиодам.
Так и должно быть? или тут какая то лажа с минькой?

Підвал форуму