Show Posts
Pages: 1 ... 63 64 [65] 66 67 ... 93
961  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: March 29, 2012, 01:42:37 pm
Thanks for your feedback I appreciate your taking the time to look at it.  dw and st07 work for me, but I can see it would be difficult for others to know what it means without reading my mind.  st07 simply means steps going from 0-7.  I could spend time changing it from a case statement to bit arrays, but instead I just copied and pasted that from another Sketch without testing.  I will try to do better by either commenting or using longer variable names in the future.  You can't make me do both!  ;-)  Kidding...  S
962  Using Arduino / Project Guidance / Re: Variation of an inertial navigation system on: March 29, 2012, 01:18:21 pm
Altitude/pressure is the easy one.  I've got it down to 1ft until the weather system changes.  You can determine which direction you're moving with a compass and accel.  If it were a smooth movement you could integrate to find position.  But not with a human jerking around.  That's the problem.  I've tried it for a motorcycle.  Near impossible.  Sorry!

How about measuring distance from a base unit with ultrasonic pings?  Could go 50m?  RF timing?
Probably not Arduino...


963  Using Arduino / Motors, Mechanics, and Power / Re: Can I power arduino with 12 through barrel jack? on: March 29, 2012, 12:49:24 pm
I draw more than 1A all the time from the Vin pin.  But I'm not sure if I did this with my Uno.  I'm positive it works with the Yourduino Aroboto.  Are you certain it's not just between USB power and Vin?  Can you instead power the Uno into the Vin pin instead of the barrel?  This would bypass the diode.  Maybe it can handle 3A for a short while even though it is rated at 1A?  Where would this be on my board so I can see it or feel it when it's hot?  The PCB layout is similar to Uno.
964  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: March 29, 2012, 11:48:47 am
Here it is much easier to see:
Code:
#define dw digitalWrite
#define dm delayMicroseconds
#define de delay
#define P(s) Serial.print(s);
#define P32 Serial.write(32);
#define P13 Serial.write(10);
#define fastout {pinMode(mp1,OUTPUT);pinMode(mp2,OUTPUT);pinMode(mp3,OUTPUT);pinMode(mp4,OUTPUT);}
#define fastin  {pinMode(mp1,INPUT );pinMode(mp2,INPUT );pinMode(mp3,INPUT );pinMode(mp4,INPUT );}
const int mp1 = 2; // Blue   - 28BYJ48 pin 1
const int mp2 = 3; // Pink   - 28BYJ48 pin 2
const int mp3 = 4; // Yellow - 28BYJ48 pin 3
const int mp4 = 5; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 VCC
long motorSpeed=3000;   // set stepper speed, period actually, changed long for 1A not used?
int stepnum=0;          // current microstep 0-7
int movecnt=0;          // running total of steps taken in move(), &=4095 in moveto
long m;                 // millis()

void setup() {
  fastout
  //Serial.begin(9600);
}
void loop(){
//half step wo 1uf cap 1k res st07()
//10x faster, 10x more deg/step than little motor 64:1 gear
//600 fastest
//1000 stronger
//1600 1/4 duty
//2000 1/4 ideal no vibe but weak
//3200 1/4 slowest wo vibe, smoother=full duty
//5000 slowest full duty
//3000 fastest st03aw (3v critical) same speed as 1500 1/4 duty cuz 4/8 steps
//5000 strong w 1uf caps st03aw
//900 full step st03() is 450 faster than half step
//degrpm1Arampduty(0,18000,10000); de(500);
//degrpm1Arampduty(1,18000,10000); de(500);
degrpm1Aslow(1,18000,100); de(500);
}
void st07(){
if(stepnum==-1)stepnum=7;
if(stepnum== 8)stepnum=0;
switch(stepnum){
case 0:
  dw(mp4, HIGH);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, LOW);
  break;
case 1:
  dw(mp4, HIGH);
  dw(mp3, HIGH);
  dw(mp2, LOW);
  dw(mp1, LOW);
  break;
case 2:
  dw(mp4, LOW);
  dw(mp3, HIGH);
  dw(mp2, LOW);
  dw(mp1, LOW);
  break;
case 3:
  dw(mp4, LOW);
  dw(mp3, HIGH);
  dw(mp2, HIGH);
  dw(mp1, LOW);
  break;
case 4:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, HIGH);
  dw(mp1, LOW);
  break;
case 5:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, HIGH);
  dw(mp1, HIGH);
  break;
case 6:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, HIGH);
  break;
case 7:
  dw(mp4, HIGH);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, HIGH);
  break;
}
//for all cases
dm(motorSpeed);
}
void st03(){
if(stepnum==-1)stepnum=3;
if(stepnum== 4)stepnum=0;
switch(stepnum){
case 0:
  dw(mp4, HIGH);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, LOW);
  break;
case 1:
  dw(mp4, LOW);
  dw(mp3, HIGH);
  dw(mp2, LOW);
  dw(mp1, LOW);
  break;
case 2:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, HIGH);
  dw(mp1, LOW);
  break;
case 3:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, HIGH);
  break;
}
//for all cases
dm(motorSpeed);
}
void off(){
  dw(mp1, LOW);
  dw(mp2, LOW);
  dw(mp3, LOW);
  dw(mp4, LOW);
}
void topspeed_nocap(int cw){
motorSpeed=1;
stepnum-=cw;
movecnt++;
st03();
//900,1200 works
if(movecnt%100)dm(1500); else dm(1800);
}
void toppwr(int cw){
//define volt 1 no need
motorSpeed=1;
stepnum-=cw;
movecnt++;
st03();
fastout;  //already?
dm(2000);
}
void degrpm1A(boolean bcw, long deg100, int rpm100) {
int cw;
if(bcw) cw=1; else cw=-1;
//rpm100=10000;  //300RPM max 100RPM 5v runs cold
//motorSpeed overflow when RPM=1 use d in 1Aslow() instead
//use mydelayus() in st07() for multitasking untested
motorSpeed=(long(14630)*4096/4  )/rpm100-20;
//motorSpeed/=4;  //1/4 duty warm 10RPM still ok full duty? IC hotter than motor?
for(int i=0;i<deg100*40/36/100;i++) {
stepnum+=cw;
movecnt++;
st07();  //st07 is half step 1500 fastest
//off();dm(motorSpeed*3);  //1/4 duty
}}
void degrpm1Arampduty(boolean bcw, long deg100, int rpm100) {
int cw;
if(bcw) cw=1; else cw=-1;
rpm100=5000;  //300RPM max 100RPM 5v runs cold 100RPM max 1/4 duty >250 skips on start no load
//cannnot spin DSLR at 100RPM?
//use mydelayus() in st07() for multitasking and dm and delay at bottom untested
motorSpeed=2*(long(14630)*4096/4  )/rpm100-20;
for(int i=0;i<10;i++) {
stepnum+=cw;
movecnt++;
st07();
}
motorSpeed=  (long(14630)*4096/4  )/rpm100-20;
for(int i=0;i<10;i++) {
stepnum+=cw;
movecnt++;
st07();
}
motorSpeed/=4;
for(int i=0;i<deg100*40/36/100-20;i++) {
stepnum+=cw;
movecnt++;
st07();
off();dm(motorSpeed*3);  //1/4 duty
}
st07();delay(500);  //hold for 1/2s
off();
}
void degrpm1Aslow(boolean bcw, long deg100, int rpm100) {
int cw,d;
if(bcw) cw=1; else cw=-1;
//motorSpeed overflow when RPM=1 use d instead
//jerky like drum beat when 5v half step st07() cuz cannot drive 2 coils on same side of board/LED's adjacent
//use st03() instead
motorSpeed=(long(14630)*4096/4  )/rpm100-20;  //*1000 below microsec
d=         (long(1463 )*4096/400)/rpm100; motorSpeed=1;
//d/=2;  //1/2 duty continuous only warm at 10RPM
for(int i=0;i<deg100*40/36/100;i++) {
stepnum+=cw;
movecnt++;
st07();  //st07 is half step 1500 fastest
mydelay(d);  //motorSpeed tiny in st07
//off();mydelay(d);  //1/2 duty
}}
void mydelay(long d){
long ms=millis();
while(millis()<ms+d) {
//10RPM is 15ms
//do anything here instead of delay(1)
delay(1);
}}
void mydelayus(long d){
long ms=micros();
while(micros()<ms+d) {
//100RPM is 1500us
//do anything here instead of delay
delayMicroseconds(100);
}}
/*
need 1uf cap and 1k res:
sto3aw
sinemod
stophold
topspeed
lowpmid
slowpwr
!toppwr
!st03
*/
965  Using Arduino / Motors, Mechanics, and Power / Re: New 28BYJ-48 library on: March 29, 2012, 11:44:00 am
I've modified this library to work with L298N and a big motor see thread below:
http://arduino.cc/forum/index.php/topic,98992.0.html
966  Using Arduino / Motors, Mechanics, and Power / New Libray for L298N on: March 29, 2012, 11:41:11 am
I modified my 28BYJ library for L298N with 1.8 degrees per step on a big powerful motor (<1 deg per half step)
http://arduino-info.wikispaces.com/MotorDrivers
You can buy the boards for cheap above.

In addition to this simple library attached as zip, I have another more complex Sketch which requires lots of wiring to 8 pins on the Uno.  It uses PWM to vary the average voltage on each pin.  This drives the stepper in Sine step mode.  It is much smoother without vibration and runs cooler at slow speeds.  It also goes significantly faster.  Yet without removing the hardware you can run in digital mode with the sketch below.  This sketch does not require any special circuit beyond the driver board itself.  That's why I decided to start with this one first.  You will recognize the variables and function names because I got them from my old library.  Like before you can supply my 1v motor with 5v and it will run very cold.  I used the regulator on the Uno.  Or 12v using 1/4 duty cycle and it will only get warm, with much more torque.  At the full voltage you cannot stop a 3/4" bolt from turning with your fingers no matter how hard you squeeze.  I've gotten it to go 350RPM with PWM or 300RPM without using this sketch.  There is a torque difference.  

I've included limited simple speed ramping, and the ability to run other tasks at the same time, even at full speed.
The functions look like this:

void degrpm1A(boolean bcw, long deg100, int rpm100)

Please test it.
Questions?
Steve
967  Using Arduino / Motors, Mechanics, and Power / Re: New 28BYJ-48 library on: March 28, 2012, 03:23:15 pm
The library is setup to run other code in loop while spinning the motor non-blocking without using interrupts.  First initialize the move you want to make 1x.  This could be done in setup or an if statement in loop for example:

void degrpm_nowait (boolean bcw, long deg100, int rpm100)

Then call this function often:

int calloften_micro (boolean bcw)

At faster speeds you have to call it more often or it will get behind and run slower.  You can look at d in loop to see how much time you have in micros.  There are lines to uncomment if you want it to be more smooth consistent and partly blocking, some of the time.  The calloften functions use little integer math so they are fast.

There is another pair of functions for going slower and cooler using 12v:
void degrpmslowCool4_nowait (boolean bcw, long deg100, int rph100)
int calloften()

With these functions you have much more free time to process in loop, d milliseconds.  If you miss a step it's no big deal, the motor will catch up to keep the speed mostly constant.  It will move the correct distance no matter what you do wrong with timing.

To run 2 motors at the same time you have to copy and paste these few short functions to create a duplicate, changing the names of the global variables with a motor number at the end of each.  I have a sketch to test that myself.  It works with 3.

Global vars:
step2
d
m
ii
stepnum

You also have to duplicate st07() or ccw,off() with different pin numbers.  You can delete ar[] if you're not using it.

You do not have to read the torque pin yourself unless you want to.  My function ccwss() measures torque and halts program if spike to prevent damage.  Look in that function for example code to see how you could read it to print a warning instead of halting.  But you do have to wire it up.  Just hook any motor winding to analog pin 0.  If you're worried about damage use a resistor like 1k.  Pin 0 does not give you any absolute data, only relative.  After it has been running the code stores the normal value at the normal load.  Anything abnormal will cause the program to halt.  It detects increased torque as well as zero torque if a linkage were to break.  The current the motor consumes is a constant amperage with a given voltage supply.  You can measure this with an ammeter and store it as a constant as it will not change much, even when not moving.  Use the function off() to save power and keep the motor cool when not moving.

With my new PWM library you can vary the average voltage and therefore power.  It is not so useful for this hardware setup.

1. Did I say that?  I think you misunderstood.  I was proposing to lower the speed when the torque load causes the motor to stall at high speeds.  Keep lowering it until it does not stall anymore.  The way to detect this is with pin 0.  It is easy to implement.  To be clear you cannot adjust the torque of a stepper motor, or it will skip when there is not enough voltage/current.  You keep the speed constant with timing using rpm100 variable in my code.

2. 3 of my functions support simple acceleration of large objects like a spinning DSLR.
ramp, unramp, unramp1
You can change the code to fit the desired accel and mass of the object.  I use unramp so that when it comes to a stop it does not bounce back and forth.

Many of my functions include a quick accel from stop otherwise it would stall.  Even without any rotating mass you cannot immediately start at the maximum speed.

My new library for natural easing motion allows for complex speed changes (accel) from a script stored in an array.

More soon.
968  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: March 28, 2012, 01:19:07 pm
Yes, in my simple experiments.  Only 10 lines of code it is easy to follow.  I've been sidetracked by a few other projects hope to get back to this.  The whole point of Bresenham is to make a straight line while moving to arbitrary x,y.
969  Using Arduino / Motors, Mechanics, and Power / Re: two-wire control of unipolar stepper with ULN2003 on: March 28, 2012, 01:06:17 pm
My point is that you do not need to change the hardware from the stock ULN2003 to achieve 2000 steps/sec.
970  Using Arduino / Project Guidance / Re: Simple data logger for newbie on: March 27, 2012, 01:42:26 pm
It will log about 1000 events if you are not concerned with 1-second accuracy.
With an SD card millions.
971  Using Arduino / Motors, Mechanics, and Power / Re: New 28BYJ-48 library on: March 27, 2012, 01:37:47 pm
So far all we have is at the top of this post listing the functions and a brief description.  Some more documentation would be nice eh?  The easiest way is to dive right in.  To get started you only need to define which pins you have connected the motor IC to.  For many of the functions I provided, no setup or initialization is needed.  Just call them with the parameters they require.  One line of new code.  Experiment.  Try it.  It won't cause any harm until your motor gets very hot over an extended period.  There are many examples commented out in loop() in stepper2.pde.  Just un-comment one line at a time.  Ask me specific questions here or PM.  I'm willing to help anyone getting started.

Start by calling this function in your loop():
void degrpmEZ (boolean bcw, long deg100, int rpm100)
Does it work for you?
972  Using Arduino / Project Guidance / Re: Simple data logger for newbie on: March 27, 2012, 08:54:50 am
If you buy this for $10, I will write the Sketch for you to log switch changes:
http://www.ebay.com/itm/270921982348?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
973  Using Arduino / Project Guidance / Re: [SOLVED] Temperature trend calculation problem on: March 26, 2012, 09:41:42 am
It feels great to be helpful!
It's easier for everyone when the person who needs help listens like you did.
I wish everyone was so capable of listening to suggestions...
974  Using Arduino / Motors, Mechanics, and Power / Re: two-wire control of unipolar stepper with ULN2003 on: March 26, 2012, 09:37:11 am
I've gotten this code to work at 2000 steps/sec using 12v.
http://arduino.cc/forum/index.php/topic,89159.0.html
975  Using Arduino / Motors, Mechanics, and Power / Re: New 28BYJ-48 library on: March 26, 2012, 09:35:53 am
Can anyone suggest any improvements?  Additional functionality?
Pages: 1 ... 63 64 [65] 66 67 ... 93