Show Posts
Pages: 1 ... 60 61 [62] 63 64 ... 93
916  Using Arduino / Project Guidance / Re: Parsing image for processing on Arduino on: April 07, 2012, 12:02:05 pm
1. The posted code relates to the beginning of my initial paragraph, using Arduino to detect motion when there's enough light. 

2. After "Instead" I wrote about using Processing on a PC to detect an IR laser dot in the dark.  Sorry for the confusion.

What does the Uno do?

1. In the 1st case, it does it all, without a PC.  Detecting motion, sounding an alarm, printing levels, sending a decent picture only when there is motion.  See posted code above.

2. In the 2nd case, it only sends a small picture.  Depending on the PC to analyze it.  It can do this at 2fps over XBee remotely 1000' away.  The Processing code is long, complex and difficult to read.  Will improve it before I post.
917  Using Arduino / Project Guidance / Re: NEED PROJECT IDEAS on: April 07, 2012, 11:15:04 am
IR laser detection.  When something moves at night it will detect the beam being blocked with no reflector at the other end.
I've got a static demonstration working, next I want to put the laser on a motor and detect WHERE the object is.
918  Using Arduino / Project Guidance / Re: Parsing image for processing on Arduino on: April 07, 2012, 11:12:09 am
You can see this is not Processing.  That code is much longer.  It should work with any Serial JPG camera.  There are a few different brands, but the command set in my code is the same.  It simply looks for a change in the length of the JPG compression.  It does this over 2 time frames, 1 shorter for a fast movement.  And longer for a static change.  SImple?

You can simplify the program flow by commenting out the last 3 if's in loop().
I added a beep and tested by standing still across the room, then moving.
919  Using Arduino / Project Guidance / Re: Parsing image for processing on Arduino on: April 07, 2012, 10:22:39 am
Can detect even the slightest finger movement from 10m.  Person walking towards at 50m.  Perpendicular path at 100m.
These results require good lighting.  It fails when the moving object is the same color as it's background of course.
It works better when there is texture on the background and moving object.
Some parameters require tweaking when it's darker in the room.
A bright window in an otherwise dim room causes problems, the shadows have noise.
It fails to detect a laser dot in the dark, but I've solved that on PC!
It detects a static change to the scene, yet ignores moving shadows by resetting every 200 samples.
It detects fast motion like a baseball being thrown across frame.
Can send the picture to PC for display when detected.

#define FLUSH Serial.flush()
#define WR(s) Serial.print(s)
#define WR13 Serial.write(10);
#define WR32 Serial.write(32);
#define HALT {while(1);}
#define CMD(x,var) for(cii=0;cii<x;cii++)Serial.print(var[cii])
//#define DEBUG1 WR13 for(i=0;i<5;i++){Serial.print( int(,HEX);WR32} WR13
//#define DEBUG2 WR13 for(i=0;i<5;i++){Serial.print(char(    );WR32} WR13
char length[] ={0,0,0,0};
char cmdRST[] ={0x56,0,0x26,0}; //reset then >10ms
char cmdCAP[] ={0x56,0,0x36,1,0};
char cmdLEN[] ={0x56,0,0x34,1,0};
char cmdCON[] ={0x56,0,0x36,1,2};
char cmdGET[] ={0x56,0,0x32,0x0c,0,10,0,0,0,0,0,0,0,0,0,10}; //x=16 10*0.01ms
//0x36,d10-80 56k-8k from CommTool, here 40-255
char cmdCMP[] ={0x56,0,0x31,5,1,1,0x12,4,0x36};
char cmd640[] ={0x56,0,0x31,5,4,1,0,0x19,0};
char cmd320[] ={0x56,0,0x31,5,4,1,0,0x19,0x11};
char cmdOFF[] ={0x56,0,0x3e,3,0,1,1}; //[6]=1,0 x=7,30ma,60ma
char cmdBAU[] ={0x56,0,0x24,3,1,0xae,0xc8}; //9600
int i,j,k,last,cii,dlen,cnt=0,a[10];
unsigned int picLen;
boolean same2x=0;

void setup(){
CMD(4,cmdRST);delay(500);FLUSH;  //need time to get long string
//CMD(9,cmd640);delay(10);  //remembers even with long power off how?  causes image corrupt?
//still in R buffer OK?
void loop(){
CMD(5,cmdCAP);delay(60);  //try while instead?
FLUSH;  //wrong order on purpose
while(Serial.available()<9) ;
picLen=((unsigned int)length[2])*256 +int(length[3]);
if(j<9)CMD(5,cmdCON); //delay(10);
}  //for

if(((dlen>=5)||(j>=10))&&(cnt>5)) {  //20,cnt>50? 5,2
if(cnt%200==0)same2x=0; //200
void getdata(unsigned int len){
const int BSIZE=64;
int count=len/BSIZE;
int tail=len&(BSIZE-1);
unsigned int addr=0;
for(int i=0;i<count;i++){
  delay(10); //10
920  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: April 07, 2012, 09:23:19 am
Each PC app is different.  First they should export.  Then I can use Processing to translate that text file to array syntax.  Then cut and paste into IDE, compile, run.

Alternatively I could write a Sketch to take data from serial port and put it into array.  Still  need Processing to translate exported file to Serial data.  I haven't found an app that exports to serial port yet.  Then I could skip the middle man?
921  Using Arduino / Project Guidance / Re: Variation of an inertial navigation system on: April 07, 2012, 09:15:55 am
Ordered this:
Will try to do something similar to what you wish, with much lower expectations.

Talk about low power!
922  Using Arduino / Project Guidance / Re: Arduino Longterm on: April 07, 2012, 08:46:33 am
I've used GPS to calibrate my Arduino clock to nearly 1ppm.  It's stable and consistent at a given temperature.  The calibration process takes about an hour.  With GPS you do not need an accurate RTC.  Even when you briefly lose the signal.  <10ppm.
923  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.
924  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.
925  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?
926  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()
927  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.
928  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!
929  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.
930  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. 
Pages: 1 ... 60 61 [62] 63 64 ... 93