Show Posts
Pages: 1 ... 60 61 [62] 63 64 ... 93
916  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: April 07, 2012, 08:32:33 am
The apparent torque depends on the RPM you choose.  You can use up to 10x the rated continuous voltage for a stepper.  But you cannot leave this voltage on to hold it into position for long.  Be careful!  Steppers can run hot safely, but there is a limit.
917  Using Arduino / Motors, Mechanics, and Power / Re: New 28BYJ-48 library on: April 07, 2012, 08:28:29 am
Pasted from above:

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.

All you have to do is choose the RPM and *100.
918  Using Arduino / Project Guidance / Re: Parsing image for processing on Arduino on: April 07, 2012, 08:17:57 am
I've got WORKING code to detect movement from a Grove serial camera.  That's all it does, nothing more.  It can do this at about 10fps on Arduino.  It's a little tricky but it's well tested!  This method does not work for detecting a laser dot in the dark, due to all the noise and compression artifacts.  Instead I did it like this:  Change the compression so the jpg file is only 4k.  Send it to PC over XBee in 1/2 sec.  The Arduino doesn't even see the data, it's sent directly from camera to PC, with Uno sending commands to camera.  Using Processing it is only a few lines of code to uncompress the file and access each pixel by x,y.  Then I can track the location of the IR laser in the dark at 50m.  This is like blob tracking?  Except there is only one blob in the image when it's dark.  Finished today!  Testing and working at 2fps!  Is this useful to anyone?
919  Using Arduino / Project Guidance / Re: Using Arduino to send texts and photos on: April 07, 2012, 07:40:20 am
You can do it in text mode.  See sndmsg().  I have not looked at this for awhile, but it works with my phone.

Code:
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <cdcacm.h>
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>
#include "pgmstrings.h" 

#define IF0 if(0){
#define NDREC rcvd=64;rcode=Acm.RcvData(&rcvd,buf);
#define DELREC delay(2000);NDREC
#define DELREC1 delay(500);NDREC
#define PBUF for(i=0;i<rcvd;i++)Serial.print(buf[i]);
#define PRCV Serial.print(rcvd);
#define PHLIGHT sndstr("ATD611");delay(500);sndstr("/r");
#define CALLHU(num) sndstr(num);delay(15000);sndstr("/rATH");DELREC1;DELREC;
#define P32 Serial.write(32);
#define P13 Serial.write(13);

int first=1;
int j,svc,rss,hr,mi,se;
long k;
uint8_t  rcode,buf[64];           
uint16_t rcvd=64,i;
String s="1234567890123456789012345678901234567890123456789012345678901234"; //64
char t[12]="AT+CMSS=nn";
char cmgr[12]="AT+CMGR=nn";
char mnum[3]="nn";

int pirPin = 3;
int pirVal;

void(* resetFunc)(void)=0; //declare reset function @ address 0
class ACMAsyncOper : public CDCAsyncOper {
public: virtual uint8_t OnInit(ACM *pacm);
};
uint8_t ACMAsyncOper::OnInit(ACM *pacm) {
    uint8_t rcode;
    rcode = pacm->SetControlLineState(3);
    if (rcode) {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;  }
    LINE_CODING lc;
    lc.dwDTERate = 115200;
    lc.bCharFormat = 0;
    lc.bParityType = 0;
    lc.bDataBits = 8;
    rcode = pacm->SetLineCoding(&lc);
    if (rcode)ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
    return rcode;
}
USB           Usb;
ACMAsyncOper  AsyncOper;
ACM           Acm(&Usb, &AsyncOper);

void setup(){
  Serial.begin( 115200 );
  if (Usb.Init() == -1)
      Serial.println("OSCOKIRQ failed to assert");     
  delay( 200 );
  pinMode(pirPin,INPUT);
  //pinMode(13,OUTPUT);
  digitalWrite(pirPin,HIGH);  //instead 10k pullup but not enough
}
uint8_t sndstr(char *s) {
uint8_t i,j,k;
for(i=0;s[i]!=0;i++) {
  k=s[i];
  j=Acm.SndData(1,&k); //could do all at once?
  if(j) return j;
}
i=13;
Acm.SndData(1,&i);
return j;
}
uint8_t sndnocr(char *s) {
uint8_t i,j,k;
for(i=0;s[i]!=0;i++) {
  k=s[i];
  j=Acm.SndData(1,&k);
  if(j) return j;
}
i=13;
//Acm.SndData(1,&i); only difference from above
return j;
}
uint8_t sndmsg(char *n, char *msg) {
uint8_t i;
sndnocr("AT+CMGW=");  //CMGW or S when online, doesn't work ERROR
i=34; Acm.SndData(1,&i);  //"
sndnocr(n);
i=34; Acm.SndData(1,&i);
i=13; Acm.SndData(1,&i);
sndnocr(msg);
i=26; Acm.SndData(1,&i);
DELREC1 DELREC
//t="AT+CMSS=nn"; already init above/below
t[8]=buf[9];
t[9]=buf[10];
if(t[9]==13) t[9]=0; //single digit
//Serial.print  (int(t[8]));
//Serial.println(int(t[9]));
//Serial.println(t);
sndstr(t); //comment this for testing
//no return yet
}
void waitsvc(int d) {
svc=0;
for(j=0;svc==0;j++) { //j<100 should be svc==0 for/while no service signal ==1 skips
//buf[11]=48;
//NDREC  //flush from PHLIGHT below
sndstr("AT+CIND?");  //only works 1x w/svc OK now!
DELREC
svc=buf[11]-48; rss=buf[17]-48;
//Serial.print(svc); Serial.print(rss);
//if(svc==1) {PHLIGHT} //does not need immediate DELREC like above ATE0?
delay(d*1000);
} //for svc==0
NDREC
}
void waitSMS() {
rcvd=6;
while(rcvd==6) {  //CRLFokCRLF
  sndstr("AT+CMGL=\"REC UNREAD\"");  //READ to test UNREAD when ready
  DELREC1 PRCV PBUF P32
  while(rcvd==0) {DELREC1 PRCV PBUF P32}
  }
//if(rcvd!=6)
sndstr("/r"); //stops much data
for(i=0;i<rcvd;i++)  s.setCharAt(i,buf[i]);  //starts with 0!
for(i=rcvd;i<64;i++) s.setCharAt(i,0);  //clear the rest
//Serial.println(s);   
//if(s.indexOf("curb")>0) Serial.println("Found");  //-1 is not found
cmgr[8]=mnum[0]=buf[9];
cmgr[9]=mnum[1]=buf[10]; //could be 13 CR single digit fix later
mnum[2]=0;
P13
for(k=0;k<12;k++) {DELREC1 PRCV P32}
P13
}
void loop()
{   Usb.Task(); 
if( Usb.getUsbTaskState() == USB_STATE_RUNNING){ 
  if(first==1) {
     first=0;
//IF0 allows to keep formatting/colors in code
//IF0
     sndstr("AT+MODE=2");
     sndstr("ATE0");
     DELREC //needed or will crash! check for this error everywhere
//}
//delay(5000);
//PHLIGHT DELREC  //to make sure its running in field
//waitsvc(15);
//waitSMS();
//if(s.indexOf("CMGLnot")>0)  //if pw not found crashes without sending, +CMGL always
//k is long int
pirVal=HIGH;
for(j=0,k=1;pirVal==HIGH;k++){ //no movement
  pirVal=digitalRead(pirPin);
  if(pirVal==LOW){j++;delay(2000);}
  if(j<4)pirVal=HIGH;
  if(k%(20*60*5)==0)j=0; //every 5 mins overflow 30min? No k is long now
  if(k%(20*60*30)==0)break; //test every 30 min
  delay(50); //1/20 sec
  }
CALLHU("ATD9785443562")
DELREC;
DELREC; //req?
//sndmsg("2626969619","Hello Beaver"); //still in buffer
for(j=0;j<5*60;j++)delay(1000); //5min
resetFunc();  //call reset does not initialize registers

IF0
    sndstr("AT+CBC");
    DELREC Serial.println(buf[10]); //'1'=49?=100% battery or 7 or 9 is 90%
    sndstr("AT+CCLK?");
    DELREC
    hr=(int(buf[19])-48)*10+buf[20]-48;
    mi=(int(buf[22])-48)*10+buf[23]-48;
    se=(int(buf[25])-48)*10+buf[26]-48;
    Serial.print(hr); Serial.print(':');
    Serial.print(mi); Serial.print(':');
    Serial.print(se);
    while(rcvd!=8) {DELREC1 PRCV PBUF}
    //probably RING?
    //cmgr[8]=mnum[0]; cmgr[9]=mnum[1]; already done in waitSMS()
    //sndstr(cmgr); //gets timestamp too for specific SMS, no other purpose
} //IF0
} //first=1
//modified from ACM terminal:
  if(Serial.available()) {
    uint8_t data= Serial.read();
    rcode = Acm.SndData(1, &data);
    if (rcode)ErrorMessage<uint8_t>(PSTR("SndData"), rcode); }
  delay(50);
  rcvd=64;
  rcode = Acm.RcvData(&rcvd, buf);
  if(rcode && rcode != hrNAK) ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
  if( rcvd ) { //more than zero bytes received
  //modified by me:
  Serial.println();
  Serial.print("Size: ");
  Serial.println(rcvd);
    for(uint16_t i=0; i < rcvd; i++ ) {
     j=buf[i];
     if(j==13) {
        Serial.write(13);
        //Serial.write(10);
        //i+=3;  //for single line results
        }
     if((j!=13)&&(j!=10)) {
        Serial.print(buf[i]); //printing on the screen
        Serial.print(" "); Serial.print(i); Serial.print(" "); Serial.println(j);
        }
     }
  }
  delay(10);           
  } //USB_STATE_RUNNING top of loop()
} //loop()
920  Using Arduino / Project Guidance / Re: Arduino Longterm on: April 04, 2012, 11:29:51 am
Good point Peter!  The solution is simple as you illustrated.  Most people will not see the difference in your 2 examples.
921  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: April 03, 2012, 06:52:33 pm
Did you try the 2 lines I suggested above?
For every hour:

degrpm(1,3000,1000);

If you are using 28byj motor then you are using the wrong code of mine.  Use stepper2.pde instead.  Did you see the other thread on this forum? 

I don't know what to do about vibration when you are moving at the speed of a clock second hand.  You can use the analog pins as digital in or out. 

Sorry I'm not following the intentions of your code.  That's not how I meant it to be used.  That's great if it works for you!
922  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: April 02, 2012, 08:40:21 pm
I don't understand what you did in the code.  But I can see some misunderstandings.  All the degrpm functions have deg then rpm as parameters.  So you put 10RPM where deg goes in loop.  I didn't mean for you to call mydelay in loop.  You can use it for that instead, but I meant it to be called where I put it in the function.  Here's how I would do it.  I have verified this does not drift on my motors.

degrpm1A(1,9000,1000);
Serial.println("At 0,9,18,270");

I'd be happy to send you my easing library, but it's not so "easy" as this one is.  I'm concerned you might need some help with it.

Yes! I will make it into a class.  It's under development.

I'm not really microstepping.  In this code I am half stepping.  The vibration depends on the speed you choose.  For big motors my PWM library helps with this.  But the circuit is more complex.  What motor are you using?  What speed is vibrating?  I know some tricks.

For x,y line drawing all you'd have to do is glue a laser on a 28BYJ motor shaft (x).  Then glue that to another perpendicular (y).  Each step is movement in the x or y direction.  I haven't gotten to this yet.  Maybe it is not fast enough to be persistent.
923  Using Arduino / Programming Questions / Re: Arduino won't go to sleep! on: April 02, 2012, 07:03:22 pm
I agree.  I will use my method when I need 1-2ms accuracy for each sample.  You are correct, this error accumulates.  If I need more accuracy I will be forced to use the method you were discussing. 
924  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: April 02, 2012, 06:36:35 pm
You are correct.  But it depends on your perspective.  I am sending the maximum voltage that I have available from my PS to a motor which is designed to run continuously on 1-2v.  The 12v supply can only provide 2A instead of the 4A that it might draw.  Because there is no sense resistor I am letting too MUCH current flow.  It would overheat if it were allowed to continue without pause.  If it is running for only a short movement and period I ignore this limit.  At top speeds there is no other choice, the running time is limited before the motor overheats (without PWM).  At slower speeds you can choose to apply the maximum voltage for 50-100us, then rest between steps.  This keeps it running cool and achieves results similar to chopping, but with a manual adjustment instead of sensing.  In effect I am choosing the timing of when to chop manually.  Instead of using peak current as my criteria, I am maximizing the temperature after running for 5 minutes, to keep it from overheating.  I am forced to work within the current limitations of my small power supply.  I don't think 12v is a restraining limit for my motor.  2A is below the maximum current.  Alternatively I could buy a bigger supply, or use a large capacitor to supply more current for 50us.  A chopper circuit would increase the peak current, if it were available from the supply.  This would not lower the temperature at the torque I have already achieved.  So I am not motivated to make any changes to my circuit.  Summary: In my setup the temperature of the motor and IC are the limiting factors.  Chopping would not reduce them at the same torque.

I would love to hear a different point of view?

@joogaa- I do like low resistance coils for that reason!
925  Using Arduino / Programming Questions / Re: Arduino won't go to sleep! on: April 02, 2012, 04:33:26 pm
Not so simple with the Narcoleptic library.  The clock is not running when it's asleep.
926  Using Arduino / Project Guidance / Re: Alternative to Google Tap on: April 02, 2012, 07:18:25 am
Being a Ham Radio Operator for years I can see how this could work for me!
KB3SF
927  Using Arduino / Programming Questions / Re: Arduino won't go to sleep! on: April 02, 2012, 07:11:53 am
Do you think my idea will work if I want to sleep for 10s?  Even if I change the code in loop?
Within a few ms?  It seems to.
Any ideas where the extra 42ms comes from in overhead?
928  Using Arduino / Motors, Mechanics, and Power / Re: New Libray for L298N on: April 02, 2012, 06:44:15 am
http://www.bgmicro.com/mot1070.aspx

What is the advantage of a high coil resistance compared to a 1v motor?
929  Using Arduino / Project Guidance / Re: Stepper motor off sync on: April 02, 2012, 06:38:32 am
Is your speed critical?  The time between steps?  That's the error he's referring to when you use millis().
930  Using Arduino / Motors, Mechanics, and Power / Re: Can I power arduino with 12 through barrel jack? on: April 02, 2012, 06:35:43 am
Mine says SS14 also 1A.  But it doesn't get warm at 3A.  I hear you...
Pages: 1 ... 60 61 [62] 63 64 ... 93