Show Posts
Pages: 1 ... 59 60 [61] 62 63 ... 93
901  Using Arduino / Project Guidance / Re: simple tracking device on: April 09, 2012, 09:40:15 pm
I'm looking forward to seeing how this turns out?  I will pursue the Serial JPG camera method, we can compare in the end.
902  Using Arduino / Project Guidance / Re: Arduino Web Client to External Server on: April 09, 2012, 09:38:17 pm
Yes, I agree the PC browser must have Javascript for those 2.  Certainly mine does.  What does the Processing code need to make this work?  Did I do something wrong when I translated it from Arduino to Processing?  I assume it worked on Uno?
903  Using Arduino / Project Guidance / Re: Building A self-balancing bicycle on: April 09, 2012, 09:31:09 pm
@retro- That only applies at speed.  Pushing the opposite handlebar.  Below about 20 mph it works the opposite.  At slow speed we balance a motorcycle with our weight shift, and large turns of the bars/bike.
904  Using Arduino / Project Guidance / HMC5883L compass huge error [SOLVED] on: April 09, 2012, 09:27:41 pm
It's a compass when it's held level.  It's repeatable to within 1 degree when you hold it level and don't move, in any direction.  But it can be off by 90 degrees in an absolute sense.  Not accurate at all for finding North.  Any ideas?  Mistakes in code?

It's mounted upside down in my application so I fixed it in the code by 360-heading.  It seems to work very differently when I mount it right side up, but upon further analysis, the error is the same just reversed?

Could I use a simple translation table to translate the error degrees to the correct number?  
At least it's consistent!

I don't see the point of making it 3D using accell data on my board.  The Z data is consistent and constant when I hold it level, it is near the maximum amount when you rotate it.  So I don't understand how knowing the orientation, if it's changing, plus Z data, will help?

It's not as accurate in an absolute sense as this:
HMC6452  
No complicated math if you hold it near level!

Code:
/*
Arduino example for interfacing with the HMC5883L
by: Jordan McConnell SparkFun Electronics
created on: 6/30/11
*/
#include <Wire.h> //I2C Arduino Library
#define address 0x1E //0011110b, I2C 7bit address of HMC5883

int cnt=0;
int x,y,z;
long xx,yy,zz;

void setup(){
  //Initialize Serial and I2C communications
  Serial.begin(9600);
  Wire.begin();  
  //Put the HMC5883 IC into the correct operating mode
  Wire.beginTransmission(address); //open communication with HMC5883
  Wire.send(0x02); //select mode register
  Wire.send(0x00); //continuous measurement mode
  Wire.endTransmission();
}
void loop(){  
  //Tell the HMC5883 where to begin reading data
  Wire.beginTransmission(address);
  Wire.send(0x03); //select register 3, X MSB register
  Wire.endTransmission();
  //Read data from each axis, 2 registers per axis
  Wire.requestFrom(address, 6);
  if(6<=Wire.available()){
    x = Wire.receive()<<8; //X msb
    x |= Wire.receive(); //X lsb
    z = Wire.receive()<<8; //Z msb
    z |= Wire.receive(); //Z lsb
    y = Wire.receive()<<8; //Y msb
    y |= Wire.receive(); //Y lsb
  }
  /*
  //Print out values of each axis
  Serial.print("x: ");
  Serial.print(x);
  Serial.print("  y: ");
  Serial.print(y);
  Serial.print("  z: ");
  Serial.println(z);
  */
//Serial.print(z);Serial.write(32);
//repeatable within 1 deg, but off by 90 deg?
if(avgxyz())
if(zz>4800){  //near level 5200 max down, in MA
  //Serial.print(xx);Serial.write(32);Serial.println(yy);
  float heading=atan2(yy,xx);
  heading*=(180/M_PI);
  //declination here degrees
  if(heading<0)heading+=360;
  if(heading>360)heading-=360;  //for + declination only  
  //upside down on board so...
  heading=360-heading;
  Serial.println(heading);
  }
delay(50);  //50 or 150 more acc 3s
}
boolean avgxyz(){
const int N=20;  //matches delay 20*50=1s
boolean b;
cnt++;
if(cnt%N==1)xx=yy=zz=0;
xx+=x;
yy+=y;
zz+=z;
if(b=!(cnt%N)){
  xx=xx*10/N;yy=yy*10/N;zz=zz*10/N; }
return(b);
}
905  Using Arduino / Project Guidance / Re: Arduino Web Client to External Server on: April 09, 2012, 04:59:42 pm
This is an alternative if you don't have an Ethernet Shield.  Works great with XBee to get data from Uno to PC.
This is Processing code for PC, not Arduino code:

It serves a simple web page with pin values.  You must write the Arduino code to send the data serially to PC first.
But that's the easy part right?

Code:
import processing.net.*;
Server myServer;
void setup(){
size(200,200);
//myClient=new Client(this,"192.168.1.2",80);
myServer=new Server(this,69);
}
void draw(){
delay(1000);  //reduce CPU
Client client=myServer.available();
if(client!=null) {
println("New connection");
boolean currentLineIsBlank = true;

while (true) {  //uses break
char c=char(client.read());
if(c!=-1) {
        // Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
  if (c == '\n' && currentLineIsBlank) {
    client.write("HTTP/1.1 200 OK\n");
    client.write("Content-Type: text/html\n");
    client.write("Connnection: close\n");
    client.write("\n");
    client.write("<!DOCTYPE HTML>\n");
    client.write("<html>\n");
        // add a meta refresh tag, so the browser pulls again every 5 seconds:
    client.write("<meta http-equiv=\"refresh\" content=\"5\">\n");
    client.write("Hi\n");
   
    //client.write your digital and analog pin values from XBee here
   
    client.write("</html>\n");
    break;   
    }
  if (c == '\n') currentLineIsBlank = true;
  else if (c != '\r') currentLineIsBlank = false;
}}
delay(10);
client.stop();
}}  //draw, new connection
906  Using Arduino / Project Guidance / Re: Arduino Web Client to External Server on: April 09, 2012, 04:49:15 pm
I changed your code to work on PC with Processing.  Will be getting data from XBee to serve it.
Why does DIY buttons work, but not the other 2 on PC?

Code:
import processing.net.*;
Server myServer;
String readString=".";
void setup(){
size(200,200);
//myClient=new Client(this,"192.168.1.2",80);
myServer=new Server(this,69);
}
void draw(){
delay(1000);  //reduce CPU
Client client=myServer.available();
if(client!=null) {
println("New connection");
boolean currentLineIsBlank = true;

while (true) {  //uses break
char c=char(client.read());
if(c!=-1) {
        // Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
  if (readString.length() < 100) readString+=c;
  if (c == '\n' && currentLineIsBlank) {
   
          client.write("HTTP/1.1 200 OK\n"); //send new page
          client.write("Content-Type: text/html\n");
          client.write("\n");

          client.write("<HTML>\n");
          client.write("<HEAD>\n");
          client.write("<TITLE>Arduino GET test page</TITLE>\n");
          client.write("</HEAD>\n");
          client.write("<BODY>\n");

          client.write("<H1>Zoomkat's simple Arduino button</H1>\n");
         
          // DIY buttons
          client.write("<a href=\"/?on\"\">ON</a>\n");
          client.write("<a href=\"/?off\"\">OFF</a><br />\n");

          // mousedown buttons
          client.write("<br><input type=\"button\" value=\"ON\" onmousedown=\"location.href ('/?on');\"/>\n");
          client.write("<input type=\"button\" value=\"OFF\" onmousedown=\"location.href ('/?off');\"/>\n");       
         
          // mousedown radio buttons
          client.write("<br><br><input type=\"radio\" value=\"ON\" onmousedown=\"location.href ('/?on');\"\">ON</>\n");
          client.write("<input type=\"radio\" value=\"OFF\" onmousedown=\"location.href ('/?off');\"\">OFF</>\n");       
 
          client.write("</BODY>\n");
          client.write("</HTML>\n");
         
//println(readString);
          if(readString.indexOf("on") >0) print("On");
          if(readString.indexOf("off") >0) print("Off");
          readString=".";
   
    break;   
    }
  if (c == '\n') currentLineIsBlank = true;
  else if (c != '\r') currentLineIsBlank = false;
}}
delay(1);
client.stop();
}}  //draw, new connection
907  Using Arduino / Project Guidance / Re: Serial communication stops after long periods. on: April 09, 2012, 11:22:57 am
I had a similar problem.  The TX light stops blinking.  The Sketch continues to run, but the PC doesn't see the data.  It has something to do with the USB chip on the Uno.  When you run the same sketch on a Pro mini using only 1 wire connected to the serial TX, obviously an LED will still blink if you connect one.  You can read this data with serial TTL to USB converter.  I'm not saying the USB chip is defective or stops on it's own.  It's reacting to something on the PC.  Perhaps closing the PC port inadvertently.  I'm going to say something obvious here:  Something is changing on the PC causing this to happen after a few hours.  You can prove this by disconnecting the USB cable, then restarting the sketch without it.

A power surge from the refrigerator could effect the USB chip without resetting the 328?
908  Using Arduino / Project Guidance / Re: simple tracking device on: April 09, 2012, 10:57:38 am
I've been able to track a laser dot, the reflection, with a camera on a servo. 
I'm curious to see how you do it without a camera?
All you need is a light sensor that varies with the angle?
For example 2 sensors with a thin wall between them so one side is partially blocked until it's straight on?
If there is other light sources you will need to modulate it somehow.

It's easy to detect a dot in the dark with a camera.
How can I do it when it's light, with IR laser?  Here's my idea:
Sample 2 frames, laser off, then on.
Calculate the threshold where 99% pixels are darker.
Count number of pixels above this, compare on to off.
The count alone will tell you IF there's a dot.
The pixels that changed, where.
This will work when the scene is moving a little, wind blowing trees.

When the scene is completely static, you can look for any pixels that got brighter near to each other.
Brighter by more than a constant threshold.
What do you think?
909  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.
910  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.
911  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.
912  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.

Code:
#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(Serial.read()),HEX);WR32} WR13
//#define DEBUG2 WR13 for(i=0;i<5;i++){Serial.print(char(Serial.read())    );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
//x=9:
//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(){
pinMode(13,OUTPUT);
Serial.begin(115200);
CMD(4,cmdRST);delay(500);FLUSH;  //need time to get long string
//CMD(7,cmdBAU);delay(500);Serial.begin(9600);
cmdCMP[8]=200;
CMD(9,cmdCMP);delay(10);
//CMD(9,cmd640);delay(10);  //remembers even with long power off how?  causes image corrupt?
//still in R buffer OK?
}
void loop(){
for(k=0,j=0;j<10;j++){
digitalWrite(13,1);
CMD(5,cmdCAP);delay(60);  //try while instead?
digitalWrite(13,0);
CMD(5,cmdLEN);
FLUSH;  //wrong order on purpose
while(Serial.available()<9) ;
for(i=0;i<5;i++)Serial.read();
for(i=0;i<4;i++)length[i]=Serial.read();
//if(Serial.available())WR("Err");
picLen=((unsigned int)length[2])*256 +int(length[3]);
if(j<9)CMD(5,cmdCON); //delay(10);
k+=picLen/30;
a[j]=picLen/30;
}  //for
WR13
i=abs(k-last)/5-6;
if(i<0)i=0;
WR(dlen=i);WR32
for(j=0,i=0;i<10;i++)
  j+=abs(a[i]-k/10);
j-=50;
if(j<0)j=0;
WR(j/5);WR32

cnt++;
if(((dlen>=5)||(j>=10))&&(cnt>5)) {  //20,cnt>50? 5,2
  WR13
  //getdata(picLen); 
  cnt=0;
  same2x=0;
}
CMD(5,cmdCON);
if(abs(k-last)/5<=2)same2x=1;
if(cnt%200==0)same2x=0; //200
if(!same2x)
  last=k;
//delay(500);
}
void getdata(unsigned int len){
const int BSIZE=64;
int count=len/BSIZE;
int tail=len&(BSIZE-1);
unsigned int addr=0;
cmdGET[6]=cmdGET[7]=cmdGET[8]=cmdGET[9]=0;
cmdGET[13]=BSIZE;
for(int i=0;i<count;i++){
  //cmdGET[15]=10;
  CMD(16,cmdGET);
  delay(10); //10
  if(Serial.available()!=BSIZE+10)HALT
//Serial.read();Serial.read();
//if(Serial.read()!=0x32)Serial.println("Halt?");
  FLUSH;
  addr+=BSIZE;
  cmdGET[8]=addr>>8;
  cmdGET[9]=addr;
  }
cmdGET[13]=tail;
CMD(16,cmdGET);
delay(100);
//Serial.read();Serial.read();
//if(Serial.read()!=0x32)Serial.println("Halt?");
FLUSH;
}
913  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?
914  Using Arduino / Project Guidance / Re: Variation of an inertial navigation system on: April 07, 2012, 09:15:55 am
Ordered this:
http://www.ebay.com/itm/330708102771?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
Will try to do something similar to what you wish, with much lower expectations.

Talk about low power!
http://www.fastraxgps.com/products/gpsantennamodules/400series/uc430/
915  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.
Pages: 1 ... 59 60 [61] 62 63 ... 93