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.

#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;  }
    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 );
  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++) {
  j=Acm.SndData(1,&k); //could do all at once?
  if(j) return j;
return j;
uint8_t sndnocr(char *s) {
uint8_t i,j,k;
for(i=0;s[i]!=0;i++) {
  if(j) return j;
//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);  //"
i=34; Acm.SndData(1,&i);
i=13; Acm.SndData(1,&i);
i=26; Acm.SndData(1,&i);
//t="AT+CMSS=nn"; already init above/below
if(t[9]==13) t[9]=0; //single digit
//Serial.print  (int(t[8]));
sndstr(t); //comment this for testing
//no return yet
void waitsvc(int d) {
for(j=0;svc==0;j++) { //j<100 should be svc==0 for/while no service signal ==1 skips
//NDREC  //flush from PHLIGHT below
sndstr("AT+CIND?");  //only works 1x w/svc OK now!
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?
} //for svc==0
void waitSMS() {
while(rcvd==6) {  //CRLFokCRLF
  sndstr("AT+CMGL=\"REC UNREAD\"");  //READ to test UNREAD when ready
  while(rcvd==0) {DELREC1 PRCV PBUF P32}
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
//if(s.indexOf("curb")>0) Serial.println("Found");  //-1 is not found
cmgr[9]=mnum[1]=buf[10]; //could be 13 CR single digit fix later
for(k=0;k<12;k++) {DELREC1 PRCV P32}
void loop()
{   Usb.Task(); 
if( Usb.getUsbTaskState() == USB_STATE_RUNNING){ 
  if(first==1) {
//IF0 allows to keep formatting/colors in code
     DELREC //needed or will crash! check for this error everywhere
//PHLIGHT DELREC  //to make sure its running in field
//if(s.indexOf("CMGLnot")>0)  //if pw not found crashes without sending, +CMGL always
//k is long int
for(j=0,k=1;pirVal==HIGH;k++){ //no movement
  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
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

    DELREC Serial.println(buf[10]); //'1'=49?=100% battery or 7 or 9 is 90%
    Serial.print(hr); Serial.print(':');
    Serial.print(mi); Serial.print(':');
    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=;
    rcode = Acm.SndData(1, &data);
    if (rcode)ErrorMessage<uint8_t>(PSTR("SndData"), rcode); }
  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.print("Size: ");
    for(uint16_t i=0; i < rcvd; i++ ) {
     if(j==13) {
        //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);
  } //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:


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.

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!
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

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