Welcome, %1$s. Please login or register. - Did you miss your activation email?

Login with username, password and session length
 

Author Topic: Need Someone to write some code.  (Read 195 times)

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Need Someone to write some code.
« on: June 05, 2017, 09:47:11 pm »
Hello all I'm looking for some help. I want to use one arduino to run a stepper motor continuously
and blink a light and send a signal with a momentary key press to trigger a key press on a seperate
audio card that can have 8 signals to it one of which will be initiated when opening the lid. I want to use
the Mini Pro Arduino. I might have room for two Arduino's but not sure yet. I am not good enough to
code this can anybody help?

My project is a Star Trek TOS communicator. I had someone give me most of the parts of the Wand communicator.
It has had the electronics gutted from it.
Live Long and Prosper

Cameron Lewis Sr.

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1124
Re: Need Someone to write some code.
« Reply #1 on: June 05, 2017, 10:26:29 pm »
Some of us here (http://scifimodelaction.com/sfmaforum/index.php?topic=5953.msg87130#msg87130) have recently started looking into stepper motors for various model build applications mainly because of how quiet those types of motors are.  Here are a few notes from some of the experimentation that have been going on:

  • If using an Arduino to control stepper motors, you would still need a stepper driver board.  Stepper motors cannot directly connect to an Arduino.  One can try a driver board such as an L298N H-bridge module.
  • Stepper motors generate a lot of heat as they always run at full current regardless of speed.  When continuously spinning, even the tiniest stepper motors will be so hot that one would find it difficult to hold between two fingers.  Adding resistors to each stepper motor coil connection helps to greatly decrease heat in this case.
  • From what I've seen, if one uses a Arduino board to control a stepper motor, that board cannot be used to control anything else.  This is because the code used for the motor is basically telling the motor's coil to start then stop over and over, thus the "stepping."  This introduces the "delay" Arduino function which would continuously interrupt the code for any other desired function.
  • Very small stepper motors can spin in a jerky fashion at low speeds.  This can be solved by finding motors outfitted with gear boxes.  Small stepper motors with gear boxes can be difficult to find.  There are 15mm-diameter stepper motors out there with metal gear boxes.  However, if one is in need of anything smaller, finding something with a gear box becomes much more of a challenge.

If anyone else has experience with stepper motors, please chime in.

:)
"They've done studies, you know.  60% of the time, it works every time."

-----

Google+: https://plus.google.com/109660073537038906328

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: Need Someone to write some code.
« Reply #2 on: June 06, 2017, 12:39:14 am »
To be honest I'm not even sure this is a stepper motor. It is the motor that turns the
moire wheel in this communicator. it is only 6mm in diameter and about 6mm tall.
It has a red and black wire and a yellow with black stripe and a white wire. When I connect
3 volts with ground to the black wire and touch the red wire with positive the motor
pulses once. If I touch the red wire again it will pulse again. This is the motor that came in
the Warp Communicator.
Live Long and Prosper

Cameron Lewis Sr.

Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1329
    • MW ModelWerks
Re: Need Someone to write some code.
« Reply #3 on: June 06, 2017, 07:16:19 am »
Quote
From what I've seen, if one uses a Arduino board to control a stepper motor, that board cannot be used to control anything else.  This is because the code used for the motor is basically telling the motor's coil to start then stop over and over, thus the "stepping."  This introduces the "delay" Arduino function which would continuously interrupt the code for any other desired function.

Not sure this is true.  There are other ways to do this that doesn't involve the delay() function, such as using millis() to turn things on and off as time passes.  Look at the standard "Blink without delay" example.
MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: Need Someone to write some code.
« Reply #4 on: June 06, 2017, 11:57:25 am »
Well it is a stepper it is a two phase stepper motor and the arduino is running it
with it wired direct to it. I used the stepper example and deleted the code for counter clockwise
rotation and changed the delay to 1 and it turns the motor. I will try deleting the delay and adding
a simple blink to the code and see if that will run to.
Live Long and Prosper

Cameron Lewis Sr.

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1124
Re: Need Someone to write some code.
« Reply #5 on: June 06, 2017, 01:16:48 pm »
Directly connecting a stepper motor to an Arduino can work, but an H-bridge is there to provide voltage and current protection.

Each Arduino pin can supply a maximum of 40mA (20mA recommended).  If the motor draws more power than that, then the Arduino can become permanently damaged.

Since the Wand Company communicator comes with a small 6mm stepper motor, it may (probably?) operate with very low current which would be good.
"They've done studies, you know.  60% of the time, it works every time."

-----

Google+: https://plus.google.com/109660073537038906328

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: Need Someone to write some code.
« Reply #6 on: June 06, 2017, 01:27:05 pm »
It is working fine current draw is minimal. I just need to know how to add the blink with no delay code into
the sketch now. Using the standard blink code causes the motor to stop when the led blinks. The arduino is running
very cool after letting it run all night so I don't think I'll have any problems in that area. And if I do burn up the arduino
it is one of the cheap Chinese one's. I have plenty more. After I get the motor to run and blink an LED then I will
see if I can add code to register a button press and sen an output to another board.
Live Long and Prosper

Cameron Lewis Sr.

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1124
Re: Need Someone to write some code.
« Reply #7 on: June 06, 2017, 01:57:45 pm »
I just need to know how to add the blink with no delay code into the sketch now.

Here is something you might want to try:

http://forum.arduino.cc/index.php?topic=137269.msg1031620#msg1031620

See if that works for you.
"They've done studies, you know.  60% of the time, it works every time."

-----

Google+: https://plus.google.com/109660073537038906328

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: Need Someone to write some code.
« Reply #8 on: June 07, 2017, 12:01:19 am »
That shows how to do blink without delay and run a servo but doesn't help.
All I want to do is run the stepper and make an led blink at the same time maybe
two leds. I just don't know how to tie the script together. I can't just paste the
two codes together without getting a void setup error win it gets to the second code.

BTW I know nothing about arduino coding everything I've done till now has been copy and paste
working sketches.
« Last Edit: June 07, 2017, 12:03:14 am by Tankton »
Live Long and Prosper

Cameron Lewis Sr.

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: Need Someone to write some code.
« Reply #9 on: June 07, 2017, 12:36:20 am »
Made it work two blinking led's at different rates and stepper motor running continuously.
I wasn't pasting code in the right places. Now if someone has some code to send signals
out to pins in sequence from a momentary push button?

Here is the code I have working now.

( #include <Stepper.h>

const int stepsPerRevolution = 25;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

// These variables store the flash pattern
// and the current state of the LED

int ledPin1 =  7;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis1 = 10;        // will store last time LED was updated
long OnTime1 = 200;           // milliseconds of on-time
long OffTime1 = 750;          // milliseconds of off-time

int ledPin2 =  13;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 5;        // will store last time LED was updated
long OnTime2 = 1000;           // milliseconds of on-time
long OffTime2 = 4000;          // milliseconds of off-time

void setup()
{
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);     
  pinMode(ledPin2, OUTPUT);
   // set the speed at 10 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);     
}

void loop()
{
  // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();
 
  if((ledState1 == HIGH) && (currentMillis - previousMillis1 >= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis1 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis1 >= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis1 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);    // Update the actual LED
  }
 
  if((ledState2 == HIGH) && (currentMillis - previousMillis2 >= OnTime2))
  {
    ledState2 = LOW;  // Turn it off
    previousMillis2 = currentMillis;  // Remember the time
    digitalWrite(ledPin2, ledState2);  // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis2 >= OffTime2))
  {
    ledState2 = HIGH;  // turn it on
    previousMillis2 = currentMillis;   // Remember the time
    digitalWrite(ledPin2, ledState2);   // Update the actual LED
  }
  {
     // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  }
 
} )

Live Long and Prosper

Cameron Lewis Sr.

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: Need Someone to write some code.
« Reply #10 on: June 07, 2017, 01:53:15 am »
I think I have the rest of the code done. If it works to send a ground to my trigger points
on the audio board and then disconnects that pin from the circuit. I don't want the pin going
high after pressing the button again, don't want to send voltage back to the audio board.
Here is the complete code. Maybe one of you guys that know more than I do can look at it
and tell me if it will do what I want.


(
#include <Stepper.h>

const int stepsPerRevolution = 25;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

// These variables store the flash pattern
// and the current state of the LED

int ledPin1 =  7;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis1 = 10;        // will store last time LED was updated
long OnTime1 = 200;           // milliseconds of on-time
long OffTime1 = 750;          // milliseconds of off-time

int ledPin2 =  13;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 5;        // will store last time LED was updated
long OnTime2 = 1000;           // milliseconds of on-time
long OffTime2 = 4000;          // milliseconds of off-time
const int buttonPin = 2; // the pin number of the pushbutton input pin 
int ledPins[] = {3, 4, 5, 6, 12}; 
 // variables will change: 
 int buttonState = 0; // variable for reading the pushbutton status 
 int buttonPressCount = 0; 
 int numberOfLED = 5; 
void setup()
{
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);     
  pinMode(ledPin2, OUTPUT);
   // set the speed at 10 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
   // initialize the LED pin as an output: 
  for (int i = 0; i < numberOfLED; i++) { 
   pinMode(ledPins, OUTPUT); 
  } 
  pinMode(buttonPin, INPUT);     
}

void loop()
{
  // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();
 
  if((ledState1 == HIGH) && (currentMillis - previousMillis1 >= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis1 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis1 >= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis1 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);    // Update the actual LED
  }
 
  if((ledState2 == HIGH) && (currentMillis - previousMillis2 >= OnTime2))
  {
    ledState2 = LOW;  // Turn it off
    previousMillis2 = currentMillis;  // Remember the time
    digitalWrite(ledPin2, ledState2);  // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis2 >= OffTime2))
  {
    ledState2 = HIGH;  // turn it on
    previousMillis2 = currentMillis;   // Remember the time
    digitalWrite(ledPin2, ledState2);   // Update the actual LED
  }
  {
     // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  }
  {
  // read the state of the pushbutton value: 
  buttonState = digitalRead(buttonPin); 
  // check if the pushbutton is pressed. 
  // if it is, the buttonState is HIGH: 
  if (buttonState == HIGH) { 
   for (int i = 0; i < numberOfLED; i++) { 
    if (buttonPressCount % numberOfLED == i) { 
     // turn LED on: 
     digitalWrite(ledPins, LOW); 
    } else { 
     // turn LED off: 
     digitalWrite(ledPins, INPUT); 
    } 
   } 
   buttonPressCount++; 
   delay(400); 
  }
 }
}  )
 
« Last Edit: June 07, 2017, 01:59:33 am by Tankton »
Live Long and Prosper

Cameron Lewis Sr.

 




Enterprise © Bloc