Официальный сайт компании Arduino по адресу arduino.cc
Пытаюсь связать mega 2560+drv8825+ETHER_28J60
- Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии
Пт, 06/01/2017 - 19:42
Пытаюсь наладить управление шаговым двигателем через локальную сеть.
За основу взял это проект
Скетч для управления шагового двигателя вот
#include <Arduino.h> #include "BasicStepperDriver.h" #define MOTOR_STEPS 200 #define DIR 34 #define STEP 33 #define MICROSTEPS 1 BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP); void setup() { stepper.setRPM(120);// скорость вращения } void loop() { stepper.setMicrostep(MICROSTEPS); stepper.rotate(3600);// Угол поворота delay(3000); }
Скетч для управления Мегой через ETHER_28J60 вот
/*В библиотке ETHER28J60 в файле ETHER_28J60.cpp изменил строки *#define BUFFER_SIZE 2000 *#define STR_BUFFER_SIZE 64 *В библиотке etherShield в файле enc28j60.c изменил строки #define ENC28J60_CONTROL_CS 53 // 10 #define SPI_MOSI 51 //11 #define SPI_MISO 50 //12 #define SPI_SCK 52 //13 инструкция http://arduino-project.net/podklyuchenie-enc28j60-arduino-mega-2560/ */ #include "etherShield.h" #include "ETHER_28J60.h" static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; static uint8_t ip[4] = {192, 168, 0, 222}; static uint16_t port = 80; ETHER_28J60 ethernet; int outputPin3 = 13; int outputPin = 11; int outputPin2 = 12; void setup() { ethernet.setup(mac, ip, port); pinMode(outputPin, OUTPUT); pinMode(outputPin2, OUTPUT); pinMode(outputPin3, OUTPUT); } void loop() { char* params; if (params = ethernet.serviceRequest()) { ethernet.print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"); ethernet.print("<img src='https://a.pololu-files.com/picture/0J4124.600.png?91f6a95b143bbb0f34f82c30a47fcced'><p></p>"); ethernet.print("<a href='?cmd=on1' >Включить L1</a><p></p>"); ethernet.print("<a href='?cmd=off1' >Отключить L1</a><p></p>"); ethernet.print("<a href='?cmd=on2' >Включить L2</a><p></p>"); ethernet.print("<a href='?cmd=off2' >Отключить L2</a><p></p>"); ethernet.print("<a href='?cmd=on3' >Включить L3</a><p></p>"); ethernet.print("<a href='?cmd=off3' >Отключить L3</a><p></p>"); ethernet.print("<a href='?cmd=on' >Включить все</a><p></p>"); ethernet.print("<a href='?cmd=off' >Отключить все</a><p></p>"); ethernet.respond(); if (strcmp(params, "?cmd=on1") == 0){digitalWrite(outputPin, HIGH);} if (strcmp(params, "?cmd=off1") == 0){digitalWrite(outputPin, LOW);} if (strcmp(params, "?cmd=on2") == 0){digitalWrite(outputPin2, HIGH);} if (strcmp(params, "?cmd=off2") == 0){digitalWrite(outputPin2, LOW);} if (strcmp(params, "?cmd=on3") == 0){digitalWrite(outputPin3, HIGH);} if (strcmp(params, "?cmd=off3") == 0){digitalWrite(outputPin3, LOW);} if (strcmp(params, "?cmd=on") == 0){digitalWrite(outputPin, HIGH);digitalWrite(outputPin2, HIGH);digitalWrite(outputPin3, HIGH);} if (strcmp(params, "?cmd=off") == 0){digitalWrite(outputPin, LOW);digitalWrite(outputPin2, LOW);digitalWrite(outputPin3, LOW);} } delay(100); }
Дополняю его управлением шаговиком, получаю вот
char* params; if (params = ethernet.serviceRequest()) { ethernet.print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"); ethernet.print("<img src='http://wiki.mchobby.be/images/2/22/A4988-PinOut.jpg'><p></p>"); ethernet.print("<a href='?cmd=on1' >Включить L1</a><p></p>"); ethernet.print("<a href='?cmd=off1' >Отключить L1</a><p></p>"); ethernet.print("<a href='?cmd=on2' >Включить L2</a><p></p>"); ethernet.print("<a href='?cmd=off2' >Отключить L2</a><p></p>"); ethernet.print("<a href='?cmd=on3' >Включить L3</a><p></p>"); ethernet.print("<a href='?cmd=off3' >Отключить L3</a><p></p>"); ethernet.print("<a href='?cmd=on' >Включить все</a><p></p>"); ethernet.print("<a href='?cmd=off' >Отключить все</a><p></p>"); ethernet.respond(); if (strcmp(params, "?cmd=on1") == 0){ digitalWrite(outputPin, HIGH); stepper.setMicrostep(MICROSTEPS); stepper.rotate(3600);// Поворачивает на угол } if (strcmp(params, "?cmd=off1") == 0){digitalWrite(outputPin, LOW);} if (strcmp(params, "?cmd=on2") == 0){digitalWrite(outputPin2, HIGH);} if (strcmp(params, "?cmd=off2") == 0){digitalWrite(outputPin2, LOW);} if (strcmp(params, "?cmd=on3") == 0){digitalWrite(outputPin3, HIGH);} if (strcmp(params, "?cmd=off3") == 0){digitalWrite(outputPin3, LOW);} if (strcmp(params, "?cmd=on") == 0){digitalWrite(outputPin, HIGH);digitalWrite(outputPin2, HIGH);digitalWrite(outputPin3, HIGH);} if (strcmp(params, "?cmd=off") == 0){digitalWrite(outputPin, LOW);digitalWrite(outputPin2, LOW);digitalWrite(outputPin3, LOW);} } delay(300); }