/*
http://www.bristolwatch.com/radio/arduino_coil_winder.htm
Arduino Stepper Motor Coil Winder
Lewis Loflin
lewis@bvu.net
*/
#define yellow 9 //Q1
#define orange 10 //Q2
#define brown 11 // Q3
#define black 12 // Q4
#define SW0 2
#define SW1 3
#define SW2 4
#define SW3 5
#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// set the LCD address to 0x27
int i, j;
void setup() {
pinMode(SW0, INPUT);
pinMode(SW1, INPUT);
pinMode(SW2, INPUT);
pinMode(SW3, INPUT);
digitalWrite(SW0, 1); // pull up on
digitalWrite(SW1, 1); // pull up on
digitalWrite(SW2, 1);
digitalWrite(SW3, 1);
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(black, OUTPUT);
pinMode(brown, OUTPUT);
pinMode(orange, OUTPUT);
pinMode(yellow, OUTPUT);
all_coils_off();
lcd.clear();
lcd.home();
lcd.print("Wait 2 sec.");
delay(2000); // wait for 2 seconds
lcd.setCursor(0, 1); // is Home
lcd.print("Ready to go!");
j = 0;
}
void loop() {
// set turns
if (!digitalRead(SW0) == 1) {
delay(1000);
j = 0;
lcd.clear();
lcd.home();
lcd.print("Turns = 0 ");
while (!digitalRead(SW0) == 1) {
delay(1000);
if (!digitalRead(SW1) == 1) j = j + 1;
if (!digitalRead(SW2) == 1) j = j + 10;
lcd.setCursor(8, 0);
lcd.print(j);
} // end while
lcd.setCursor(0, 1);
lcd.print("Ready to wind.");
}
if (!digitalRead(SW3)) {
lcd.clear();
lcd.home();
lcd.print("Turns 0 ");
for (i = 1; i <= j; i++) {
reverse(200);
lcd.setCursor(6, 0);
lcd.print(i);
}
all_coils_off();
lcd.setCursor(0, 1);
lcd.print("Finished ");
}
} // end loop
void all_coils_off(void) {
digitalWrite(black, 0);
digitalWrite(brown, 0);
digitalWrite(orange, 0);
digitalWrite(yellow, 0);
}
void reverse(int i) {
while (1) {
digitalWrite(black, 1);
digitalWrite(brown, 0);
digitalWrite(orange, 0);
digitalWrite(yellow, 1);
delay(analogRead(0) / 4 + 5);
i--;
if (i < 1) break;
digitalWrite(black, 0);
digitalWrite(brown, 1);
digitalWrite(orange, 0);
digitalWrite(yellow, 1);
delay(analogRead(0) / 4 + 5);
i--;
if (i < 1) break;
digitalWrite(black, 0);
digitalWrite(brown, 1);
digitalWrite(orange, 1);
digitalWrite(yellow, 0);
delay(analogRead(0) / 4 + 5);
i--;
if (i < 1) break;
digitalWrite(black, 1);
digitalWrite(brown, 0);
digitalWrite(orange, 1);
digitalWrite(yellow, 0);
delay(analogRead(0) / 4 + 5);
i--;
if (i < 1) break;
}
}
that is the code i uploaded to my uno,for some reason the buttons are not getting read,do i need to install a special library for it the read the buttons,if so what is i called so i can install it via the ide?,thanks.
It cannot read while delay() is blocking it. See:
I moved your topic to an appropriate forum category @m3vuv .
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
so what needs to be done to fix the code?.
If you need to read buttons at the same time as you are doing other things, then you have "do several things at the same time"/multitasking problem. One way of solving it for buttons is doing the counting on the change-of-button-press-state with tricks as in:
-
So where is your schematic ?
-
So give us links to your hardware.
-
So get rid of delay(. . .) and avoid using while( . . . )
-
Describe your project.
look at the link for details,its the coil winder project,i am using an arduino uno with a homebrew mosfet driver,the info is here ok Arduino Stepper Motor Drive Coil Winder
-
Do you understand that delay( ) and while( ) can make your sketches unresponsive ?
-
Most people here will not go to off site information.
You should always put all pertinent information in your posts here.
So other volunteers here don't have to hunt for things.
-
Do you know your switch inputs are floating if you are using the above schematic ?
-
What are A, B, C and D connected to ?
-
You should always show us your schematic you are using.
Also we need good images of your actual wiring.
hi larry,thats the schematic i am using,i built that winder about 3 years ago and all was fine,when i came to remake it a few days ago the winder txt link gave a 404 error,i informed mr lofflin about this via youtube and he fixed it and the code link was working againe,looks like the code may of been corrupted?,i know about zero at best about code,i am more involved in the hardware ok,cheers Paul.
- We have no idea what controller you are using
.
Your schematic should be updated to include the actual controller being used and the A,B,C, and D connections.
do the switch inputs need pullups then?,if so its strange as i made this about 2yrs ago and it worked fine,the schemstic is slightly different as the neg side of the led's go strait to gates of logic level n type fets,or at least thats how my working version was wired.
abcd go to each stepper coil.
- Yes
- What stepper ?
- This is why we need to see an updated schematic, i.e. as you are currently wired.
the steppers are nima 23 hybrid motors,see datasheet,regardless that wont have anything to do with button pushes not redgistering!
57BYGH420.PDF (50.6 KB)
-
When we help with a project we need to see all your information.
-
We ask questioners to provide all the information so we can give the best help.
with all due respect can we stick to the button issues,the motors are fine,explaine the button delay you sais was preventing the buttons from working,you are sidetracking the main issue!.
-
Did you turn on the internal pull-up resistors yet ?
-
What controller are you using ?
- Is this you circuit ?