|
Post by shieldbuddy on May 16, 2018 5:02:58 GMT
Hi, Do you know if the accelstepper.h liberary works? We really need this one to work. Accelstepper specstnx N
|
|
|
Post by Admin on May 16, 2018 5:51:02 GMT
It should work. We will try it.
|
|
|
Post by Admin on May 16, 2018 7:35:23 GMT
It compiles OK so it should work!
|
|
|
Post by shieldbuddy on May 16, 2018 7:41:38 GMT
Ok, tnx. I first have to convert my Mega code to Buddyshield compatible code. After that i can test it.
tnx for the fast reply.
|
|
|
Post by shieldbuddy on May 17, 2018 18:23:10 GMT
Hi, I have done testing and it seems to be some problems with this liberary and ShieldBuddy. The most important one is that the steppermotors are only moving in one direction even though the accelstepper liberary speaks about negative numbers that make the stepper do clockwise or counterclockwise movements. See the reference page of the libarery here: www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#ace236ede35f87c63d18da25810ec9736The libarery works fine with the arduino boards like the mega. We are a starting "machine building company" ( from the Netherland) and used Arduino Mega to build this machine. After having issues with the clockspeed i was referenced from the arduino forum to you. We have another machine that is finished soon and are planning to use the second Shieldbuddy but that machine have to use accelstapper.h liberary as wel. Hope you can help and we can fix this together. Thanx a lot. This is the motor driver used for both steppers: www.banggood.com/nl/5PCS-TB6600-Upgraded-Version-32-Segments-4A-40V-5786-Stepper-Motor-Driver-p-1145693.html?gmcCountry=NL¤cy=EUR&utm_source=googleshopping&utm_medium=cpc_elc&utm_content=zouzou&utm_campaign=pla-nl-ele-3D-pc&gclid=Cj0KCQjw0PTXBRCGARIsAKNYfG2IQQrARu2J0SLs5b8dPWZVL2MabI5nfo1YSO5cJ4eXCel62XfI71UaAuQ_EALw_wcB&cur_warehouse=CNThis i my converted (Mega) sketch for ShieldBuddy. Because we are not used to work with multicore processors i have put the code in Core 1 just for testing. If necessary we will use other cores.
/* LMU uninitialised data *//* Put your LMU RAM fast access variables that have no initial values here e.g. uint32 LMU_var; */
StartOfUninitialised_LMURam_Variables
EndOfUninitialised_LMURam_Variables
/* LMU uninitialised data *//* Put your LMU RAM fast access variables that have an initial value here e.g. uint32 LMU_var_init = 1; */
StartOfInitialised_LMURam_Variables
#include <Adafruit_NeoPixel.h>
#define PIN 15
#define NUMPIXELS 8 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 200;
#include <AccelStepper.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(53, 50, 45, 41, 33, 31);
int passFlag = 10;
//_____________________________________________________________
unsigned long currentMillis;
unsigned long endFirstRunMillis;
const long interval = 3000;
enum motorStateENUM {
WAITING,
FIRSTRUN,
BETWEENRUNS,
SECONDRUN,
SECONDRUNDONE,
THIRDRUN,
FINISHED,
};
motorStateENUM motorState = WAITING;
//_______________________________________________________________
//LDR
//const int ledPinLDR = 52;
const int crashPin1 = A1; //was=A1;
int crashPin1State;
boolean crashButtonPressed = false;
//ACTUATOR
AccelStepper stepperA(AccelStepper::DRIVER, 4, 3); // (DRIVER, Step, Directon)
int enableA = 2;
const int homePinA = 26;
int homePin2StateA;
int potPinA = A4;
int motorSpeedA;
int mapMinSpeedA = 2000;
int mapMaxSpeedA = 3000;
//STARTBUTTON
const int startButton = 39;
int startButtonState = 0; //1 = open->not pressed
//STRATBUTTON TOGGLE
int startButtonReading; // the current reading from the input pin
int previouStartButtonReading = 0; // the previous reading from the input pin
//NEMA 23 (LINEAR MOTION MOTOR)
AccelStepper stepperL(AccelStepper::DRIVER, 7, 8); // (DRIVER, Step, Directon)
int enableL = 9;
const int homePinL = 34;
int homePinStateL;
int potPinL = A0;
int motorSpeedL;
int mapMinSpeed = 1500;
int mapMaxSpeed = 3000;
boolean directionL;
boolean atStartPosition;
//SERVO
#include <Servo.h>
Servo myservo;
int servo = 11;
int pos = 0;
//STABELIZING ANALOG READ
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int total = 0; // the running total
//STEPPERL
int readIndexL = 0; // the index of the current reading
int averageL = 0; // the average
//SPEEDCONTROL
int EnterLED = 42;
int EnterButton = 51;
EndOfInitialised_LMURam_Variables
/* If you do not care where variables end up, declare them here! */
/********************************************** Core 0 ************************************************************************/
void setup() {
// put your setup code for core 0 here, to run once:
}
void loop() {
// put your main code for core 0 here, to run repeatedly:
}
/*********************************************** CORE 1 ************************************************************************/
/*********************************************** CORE 1 ************************************************************************/
void setup1() {
lcd.begin(16, 2);
lcd.print("STYLEMATHOT");
lcd.setCursor(0, 1);
lcd.print("WRAPPER 2000!");
pixels.begin();
//myservo.attach(servo);
//myservo.write(0);
//delay(500);
pinMode(EnterLED, OUTPUT);
pinMode(EnterButton, INPUT);
pinMode(potPinL, INPUT);
//pinMode(potPinA, INPUT);
// pinMode(ledPinLDR, OUTPUT);
pinMode(crashPin1, INPUT);
pinMode(startButton, INPUT_PULLUP);
pinMode(homePinA, INPUT);
pinMode(homePinL, INPUT);
pinMode(enableA, OUTPUT);
pinMode(enableL, OUTPUT);
// digitalWrite(enableA, HIGH);
digitalWrite(enableL, HIGH);
SerialASC.begin(250000);
delay(2000);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
homePin2StateA = digitalRead(homePinA);
homePinStateL = digitalRead(homePinL);
if (homePin2StateA == 0 or homePinStateL == 1) {
atStartPosition = false;
}
else {
atStartPosition = true;
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 150, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
lcd.clear();
stepperA.setMaxSpeed(1000);
stepperA.setAcceleration(1000);
}
void loop1() {
//**********************STEPPERS GO TO START POSITION****************************//
SerialASC.print("In de main loop");
SerialASC.print(startButtonState);
SerialASC.print(homePin2StateA);
SerialASC.println(homePinStateL);
if (atStartPosition == false)
{
SerialASC.println("Startposition = false");
neoLed();
homePin2StateA = digitalRead(homePinA);
homePinStateL = digitalRead(homePinL);
SerialASC.print(homePin2StateA);
SerialASC.println(homePinStateL);
if (homePin2StateA == 0 ) // 0 = not at his start position [ 1 = at his position]
{
//digitalWrite(enableA, LOW);
stepperA.move(1000);
stepperA.setSpeed(500);
stepperA.runSpeed();
}
if (homePin2StateA == 1) stepperA.setCurrentPosition(0);
if (homePinStateL == 1 )
{
// myservo.write(70);
digitalWrite(enableL, LOW);
stepperL.setMaxSpeed(1000);
stepperL.setSpeed(-1000);
stepperL.runSpeed();
}
if (homePinStateL == 0 )
{
stepperL.setCurrentPosition(0);
}
if (stepperA.currentPosition() == 0 and stepperL.currentPosition() == 0 )
{
(atStartPosition = true);
// digitalWrite(enableA, HIGH);
//digitalWrite(enableL, HIGH);
}
}
//**********************STEPPERS AT START POSITION****************************//
// if (digitalRead(EnterButton) == 1) {
// total = total - readings[readIndexL];
// readings[readIndexL] = map(analogRead(potPinL), 0, 1023, mapMinSpeed, mapMaxSpeed);
// total = total + readings[readIndexL];
// readIndexL = readIndexL + 1;
// if (readIndexL >= numReadings) {
// readIndexL = 0;
// }
// averageL = total / numReadings;
// // Serial.print(averageL);
// //Serial.print("-");
// //delay(1); // delay in between reads for stability
// motorSpeedL = averageL;//map(analogRead(averageL), 0, 1023, mapMinSpeed, mapMaxSpeed);
// motorSpeedA = map(analogRead(potPinA), 0, 1023, mapMinSpeedA, mapMaxSpeedA);
// //Serial.print(map(motorSpeedL,mapMinSpeed,mapMaxSpeed,0,100));
// int motorSpeedLDisplay = map(motorSpeedL, mapMinSpeed, mapMaxSpeed, 20, 99);
// int motorSpeedADisplay = map(motorSpeedA, mapMinSpeedA, mapMaxSpeedA, 20, 99);
//
//
// lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print("Speed Left: ");
// lcd.print(motorSpeedLDisplay);
// lcd.setCursor(0, 1);
// lcd.print("Speed right: ");
// lcd.print(motorSpeedADisplay);
//
// lcd.setCursor(0, 0);
// lcd.print("Speed left: ");
// lcd.print(motorSpeedLDisplay);
// lcd.setCursor(0, 1);
// lcd.print("Speed right: ");
// lcd.print(motorSpeedADisplay);
// digitalWrite(EnterLED, HIGH);
// }
startbutton();
crashPin1State = digitalRead(crashPin1);
homePin2StateA = digitalRead(homePinA);
homePinStateL = digitalRead(homePinL);
//////////////////////////READ THE LDR/////////////////////////////////////////
if (crashPin1State == 1 and homePin2StateA == 1 )
{
//digitalWrite(ledPinLDR, HIGH);
crashButtonPressed = true;
}
/*else {
digitalWrite(ledPinLDR, LOW);
}*/
////////////////////////ENABLE OR DISABLE STAPPER-L///////////////
if (homePinStateL == 0 && startButtonState == 1)
{
digitalWrite(enableL, HIGH);
}
else {
digitalWrite(enableL, LOW);
}
//////////////////////////STEPPER L DIRECTION/////////////////////////////////////////
if (homePinStateL == 0 and stepperL.currentPosition() == 0)
{
directionL = 1;
}
if (stepperL.currentPosition() == 4920)
{
directionL = 0;
}
//////////////////////////FORWARD MOVE STEPPER L/////////////////////////////////////////
// SerialASC.print(digitalRead(crashPin1));
// SerialASC.println("- Nermin");
if (directionL == 1)
{
if (startButtonState == 0 && homePin2StateA == 1 && crashButtonPressed == false
&& stepperL.currentPosition() == 0)
{
stepperL.setMaxSpeed(1000);
stepperL.setAcceleration(1000);
stepperL.move(2600);
}
if (startButtonState == 0 && crashButtonPressed == false
&& stepperL.currentPosition() == 2600 && stepperL.targetPosition() == 2600)
{
stepperL.setMaxSpeed(1000);
stepperL.setAcceleration(1000);
stepperL.setSpeed(1000 / 2);
stepperL.moveTo(4920);
}
}
if (directionL == 0)
{
if (homePinStateL == 1) {
//homePinStateL = digitalRead(homePinL);
if (stepperL.currentPosition() == 4300) {
myservo.attach(servo);
for (pos = 0; pos <= 80; pos += 1) {
myservo.write(pos);
}
}
if (stepperL.currentPosition() == 200) {
for (pos = 80; pos >= 50; pos -= 1) {
myservo.write(pos);
}
}
if (stepperL.currentPosition() < 500) {
stepperL.setMaxSpeed(500);
stepperL.setSpeed(-500);
stepperL.runSpeed();
}
if (stepperL.currentPosition() > 201) {
stepperL.setMaxSpeed(1600);
stepperL.setSpeed(-1600);
stepperL.runSpeed();
}
}
if (homePinStateL == 0)
{
stepperL.setCurrentPosition(0);
startButtonState = 1;
for (pos = 50; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
}
}
stepperL.run();
stepperL.runSpeed();
///////////////////////////////ACTUATOR MOVE//////////////////////////
while (crashButtonPressed == true and homePin2StateA == 1)
{
SerialASC.print("in the actuator While loop");
digitalWrite(enableA, LOW);
currentMillis = millis();
if (motorState == WAITING) {
stepperA.move(5600);
motorState = FIRSTRUN;
}
if (motorState == BETWEENRUNS) {
if (currentMillis - endFirstRunMillis >= interval)
{
stepperA.move(4400);
motorState = SECONDRUN;
}
}
if (motorState == SECONDRUNDONE) {
stepperA.move(-10000);
motorState = THIRDRUN;
}
if (stepperA.distanceToGo() == 0 ) {
if (motorState == FIRSTRUN) {
endFirstRunMillis = currentMillis;
motorState = BETWEENRUNS;
}
if (motorState == SECONDRUN) {
motorState = SECONDRUNDONE;
}
if (motorState == THIRDRUN) {
motorState = WAITING;
crashButtonPressed = false;
digitalWrite(enableA, HIGH);
}
}
stepperA.run();
}
}
void startbutton() {
startButtonReading = digitalRead(startButton);
if (startButtonReading == 1 && previouStartButtonReading == 0)
{ if (startButtonState == 1)
startButtonState = 0;
else
startButtonState = 1;
}
previouStartButtonReading = startButtonReading;
}
void neoLed() {
if (atStartPosition == false)
{
pixels.setPixelColor(0, 255, 0, 0); //RED
pixels.setPixelColor(1, 255, 0, 0);
pixels.setPixelColor(2, 255, 0, 0);
pixels.setPixelColor(3, 255, 0, 0);
pixels.setPixelColor(4, 255, 0, 0);
pixels.setPixelColor(5, 255, 0, 0);
pixels.setPixelColor(6, 255, 0, 0);
pixels.setPixelColor(7, 255, 0, 0);
pixels.show();
}
}
/************************************************ Core 2 ****************************************************************************/
/* CPU2 Uninitialised Data */
StartOfUninitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have no initial values here e.g. uint32 CPU2_var; */
EndOfUninitialised_CPU2_Variables
/* CPU2 Initialised Data */
StartOfInitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have an initial value here e.g. uint32 CPU2_var_init = 1; */
EndOfInitialised_CPU2_Variables
void setup2() {
// put your setup code for core 2 here, to run once:
}
void loop2() {
// put your main code for core 2 here, to run repeatedly:
}
|
|
|
Post by Admin on May 17, 2018 20:00:02 GMT
Which motor shield are you using?
|
|
|
Post by shieldbuddy on May 18, 2018 6:10:37 GMT
No motor shield. Just the motordriver metioned in de previouse post, connected to 3 pins on the shieldbuddy.
|
|
|
Post by Admin on May 18, 2018 7:53:40 GMT
There seems to be a servo in this as well as two stepper motors. I assume that the servo is on separate pins to the stepper motors? Does the servo work OK?
|
|
|
Post by shieldbuddy on May 18, 2018 8:20:36 GMT
Servo seems to works ok. But i did notice when using myservo.attach() in de Voidloop() the servo goes to 90 degree position. While in the Arduino sketch this doesn't happen. There (after using attach()) the servo then just waits for the myservo.write() command to move. Because of this i commented "//" the myservo.attach() and myservo.write() in de void loop in the sketch above. Cause i wanted to test the steppermotor functions and thought i'll get to the servo later assuming it woks ok.
They are on seperate pins.
|
|
|
Post by shieldbuddy on May 18, 2018 8:28:14 GMT
And just for more info for you. I have also used just a clean sketch with only stepper code like below and get the same issue.
In de sketch below on line: stepperL.moveTo(3500) should get the mottor stepping in one direction and changing it to stepperL.moveTo(-3500) should make it run to the opposite direction (relative to de zero position of the motor). Zero = every time shieldbuddy resets.
Hope this info helps
/*** Don't worry, the normal Arduino setup() and loop() are below this block! ***/
/* LMU uninitialised data */
StartOfUninitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have no initial values here e.g. uint32 LMU_var; */
EndOfUninitialised_LMURam_Variables
/* LMU uninitialised data */
StartOfInitialised_LMURam_Variables
#include <AccelStepper.h>
AccelStepper stepperL(AccelStepper::DRIVER, 7, 8); // (DRIVER, Step, Directon)
int enableL = 9;
const int homePinL = 34;
int homePinStateL;
int potPinL = A2;
int motorSpeedL;
int mapMinSpeed = 1050;
int mapMaxSpeed = 1650;
AccelStepper stepperA(AccelStepper::DRIVER, 4, 3); // (DRIVER, Step, Directon)
int enableA = 2;
const int homePinA = 26;
int homePin2StateA;
int potPinA = A4;
int motorSpeedA;
int mapMinSpeedA = 2000;
int mapMaxSpeedA = 3000;
EndOfInitialised_LMURam_Variables
/* If you do not care where variables end up, declare them here! */
/*** Core 0 ***/
void setup() {
// put your setup code for core 0 here, to run once:
}
void loop() {
// put your main code for core 0 here, to run repeatedly:
}
/*** Core 1 ***/
/* CPU1 Uninitialised Data */
StartOfUninitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have no initial values here e.g. uint32 CPU1_var; */
EndOfUninitialised_CPU1_Variables
/* CPU1 Initialised Data */
StartOfInitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have an initial value here e.g. uint32 CPU1_var_init = 1; */
EndOfInitialised_CPU1_Variables
void setup1() {
// put your setup code for core 1 here, to run once:
stepperL.setMaxSpeed(12000);
stepperL.setAcceleration(14000);
}
void loop1() {
// put your main code for core 1 here, to run repeatedly:
// stepperL.setMaxSpeed(500);
// stepperL.setSpeed(500);
//stepperL.runSpeed();
stepperL.moveTo(3500);
stepperL.run();
}
/*** Core 2 ***/
/* CPU2 Uninitialised Data */
StartOfUninitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have no initial values here e.g. uint32 CPU2_var; */
EndOfUninitialised_CPU2_Variables
/* CPU2 Initialised Data */
StartOfInitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have an initial value here e.g. uint32 CPU2_var_init = 1; */
EndOfInitialised_CPU2_Variables
void setup2() {
// put your setup code for core 2 here, to run once:
}
void loop2() {
// put your main code for core 2 here, to run repeatedly:
}
|
|
|
Post by Admin on May 18, 2018 8:32:46 GMT
Does the DIR pin ever change state on the TB6600?
|
|
|
Post by shieldbuddy on May 18, 2018 8:51:30 GMT
Uhh i don't know the answer to that question. But all the stepper drivers like the TB6600 work the same way. I have used other drivers like this one: www.leadshine.com/UploadFile/Down/ES-Dhm_V1.1.pdfMaybe you can find the answer in the Datasheet?
|
|
|
Post by Admin on May 18, 2018 9:00:39 GMT
Put it another way, does the pin on the s Shieldbuddy that goes to the DIR- pin on the TB6600 ever change state?
|
|
|
Post by shieldbuddy on May 18, 2018 9:35:47 GMT
The DIR- on the TB6600 is connected to the ground of schieldbuddy and all the other (negative) connections of both TB6600. So it is the DIR+ that changes the state of the direction. And the DIR- doesnot.
|
|
|
Post by Admin on May 18, 2018 10:32:22 GMT
OK, does the DIR+ pin change state?
|
|