Show Posts
|
|
Pages: 1 ... 5 6 [7] 8
|
|
91
|
Using Arduino / General Electronics / Re: best way to drive some speakers
|
on: February 26, 2011, 05:19:08 pm
|
|
yeah...i thought it was weird, too. it says on the back of the speaker 6(with the little omega sign)13W I've been using it with just a 100ohm resistor and it works fine... but will it destroy the arduino eventually? thanks for any help
|
|
|
|
|
92
|
Using Arduino / General Electronics / best way to drive some speakers
|
on: February 26, 2011, 05:08:45 pm
|
|
Hello, I'm working on a project that has two speakers (6V, 13W) in the Arduino and they make a bunch of noises just using the tone() function. Everything would be powered from a converter plug in the wall... I was recently told that if I do this, eventually the pins are going to get worn out on the Arduino and that I should drive the speakers through an LM386 IC. Would they also need a separate power source? I'm having a hard time finding any tutorials on how to do this...is it necessary? If I use some 100ohm (or around there) resistors, will the pins be fine? If I do need the LM386...does anyone know some decent tutorials on how to wire this up? Thanks!
|
|
|
|
|
93
|
Using Arduino / Programming Questions / Re: servo moving with hand motion
|
on: February 14, 2011, 09:59:52 am
|
Thank you so much for your help! You've really helped me with my programming... Here is the new code. It works pretty good. Just the sensor is a little jittery with its readings...but I bought the cheapest one I could find :-) #include <Servo.h> Servo myservo; int inchesOLD, clockwise;
const int pwPin = 7;
long pulse, inches, cm; void setup() {
myservo.attach(9); Serial.begin(9600);
}
void loop() {
pinMode(pwPin, INPUT); pulse = pulseIn(pwPin, HIGH); inches = pulse/147;
clockwise=0;
if(inches < inchesOLD) clockwise=1;
if (inches == inchesOLD) clockwise=2;
Serial.print(inches); Serial.print("in"); Serial.println(); delay(50);
int off = 0;
if (inches>30) off=0; else if (inches >27) off = 10; else if (inches >24) off = 20; else if (inches > 21) off = 30; else if (inches > 18) off = 40; else if (inches > 15) off = 50; else if (inches > 10) off = 60; else if (inches > 5) off = 70;
int pos = 90 + off;
if(clockwise) pos = 90 - off; if (clockwise==2) //if nothing changes, keep servo still pos = 90; myservo.write(pos);
inchesOLD=inches;
}
|
|
|
|
|
94
|
Using Arduino / Programming Questions / Re: servo moving with hand motion
|
on: February 12, 2011, 09:22:07 pm
|
|
i'm powering it from the arduino...how do you power a servo without an arduino anyway? well...i know how to do it from a battery...but do you know how to do it from an adapter? i still am pretty sure my code is a little out of whack. i'm trying to say when the variable before is greater than then new one, do this, when it's smaller, do that. I feel like i've read about this algorithm before...but I can't find it anywhere. thanks for any help!
|
|
|
|
|
95
|
Using Arduino / Programming Questions / servo moving with hand motion
|
on: February 12, 2011, 05:07:48 pm
|
Hi, I have a MaxSonar EZ1 Ultrasonic Range Finder hooked up to my arduino with a 360 degree servo. I'm trying to make it so that how I move my hand the servo will move. So if i'm moving my hand toward the range finder, the servo will move clockwise, when I pull away it will move counterclockwise...or visa versa I don't care. Right now it sort of does that but I feel like it could work a lot more solid. I feel like there's a better algorithm than what I have now. Sometimes it doesn't move counterclockwise when it should and sometimes the servo is very choppy. It works best when my hand is moving back in forth in the middle...but up close and far away it's much more choppy and erratic. I'm getting very good reads in my serial monitor, though, so I know it's not the sensor...just my terrible programming. :-) thanks for any help! #include <Servo.h> Servo myservo; int inchesOLD, clockwise;
const int pwPin = 7;
long pulse, inches, cm; void setup() {
myservo.attach(9); Serial.begin(9600);
}
void loop() {
pinMode(pwPin, INPUT); pulse = pulseIn(pwPin, HIGH); inches = pulse/147; if (inches>=inchesOLD){ //if inches are increasing i.e. you're pulling away, it should spin clockwise clockwise=0; } else if (inches<inchesOLD){ clockwise=1; //or else it should go counter clockwise when you're } Serial.print(inches); Serial.print("in"); Serial.println(); delay(50);
if (inches>30) { myservo.write(90); } if ((inches<=29)&&(inches>=28)) { if (clockwise==1){ myservo.write(80); } else { myservo.write(110); } }
if ((inches<=27)&&(inches>=24)) { if (clockwise==1){ myservo.write(70); } else { myservo.write(130); } }
if ((inches<=23)&&(inches>=20)) { if (clockwise==1) { myservo.write(50); } else{ myservo.write(150); } }
if ((inches<=19)&&(inches>=16)) { if (clockwise==1){ myservo.write(5); } else{ myservo.write(160); } }
if ((inches<=15)&&(inches>=11)) { if(clockwise==1){ myservo.write(50); } else { myservo.write(175); } }
if ((inches<=10)&&(inches>=9)){ if(clockwise==1){ myservo.write(80); } else { myservo.write(170); } } if ((inches<=8)&&(inches>=7)){ if(clockwise==1){ myservo.write(85); } else{ myservo.write(95); } } if (inches==5){ myservo.write(90);
} inchesOLD=inches;
}
|
|
|
|
|
96
|
Using Arduino / Motors, Mechanics, and Power / quick servo questions
|
on: February 12, 2011, 01:55:26 pm
|
Hello, I have a 360 degree full rotation servo from SparkFun. I have a range finer sensor in front of it and I'm just trying to get it to turn to one angle when someone steps in front of it and then back to its beginning angle when the person leaves. So I'm noticing that with these 360 degree servos...when you do myservo.write(x);, the number you write doesn't give an angle but rather a speed and direction. When I type in 90, the servo is still, if the number is below 90 it goes in one direction, the further from 90 the faster...when the number is between 90 and 180 it goes in the opposite direction...the further from 90 the faster. So my question is...can I just get it to go in specific angles? So if I want the servo at a 90 degree angle, switch to a 45 and then back to 90...can I do that? It seems difficult to get it back to a specific angle...do I just have the wrong servo? Any way to do this with a 360? Thanks for any help! This is the code I have now... #include <Servo.h> Servo myservo; int potpin = 0; int val; boolean moving=false; boolean needtomoveback=false;
void setup() { myservo.attach(9); Serial.begin(9600); }
void loop() { val = analogRead(potpin); Serial.println("RADAR:"); Serial.println(val); Serial.println("SERVO ANGLE:"); int servoangle = myservo.read(); Serial.println(servoangle); myservo.write(90); delay(15);
if ((val>50)&&(moving==true)&&(needtomoveback==false)) { myservo.write(90); moving = false; } if ((val<50)&&(moving==false)) { myservo.write(40); //was 40 delay(500); myservo.write(90); moving = true; needtomoveback=true; } if ((val>50)&&(needtomoveback==true)) { myservo.write(120); delay(500); needtomoveback=false; } }
|
|
|
|
|
98
|
Using Arduino / Project Guidance / camera to sd to twitter
|
on: January 31, 2011, 10:46:55 am
|
Hello, I want to make this kind of sculptural thing where the viewer would sit in a chair with an FSR on it, so the Arduino would know someone is there. When they sit down and look at the sculpture a servo would start spinning on the sculpture, spinning a mechanism to turn a wheel and then when the wheel is in the right place (probably the arduino would know with a light sensor or something), take a picture of the person sitting in the chair and save that picture to an SD card on the Ethernet shield and upload it to Twitter. So it'd be like the artwork would have a twitter account of all the people looking at it...and it would have a database accessible on an SD card inside the sculpture. I've done most of this stuff before, just not together, and I've never used a camera with an arduino. Here are some questions: What's the difference between a TTL interface camera ( http://www.sparkfun.com/products/10061) and a CMOS one? ( http://www.sparkfun.com/products/8739) Is one easier than the other to put the picture on an SD card? I couldn't really find anywhere to get started with cameras and arduinos...how do I wire them, hook them up and everything? Most of the stuff I've found is for more specific projects and I didn't really understand it. Could all of this be powered from a duemilanove or Mega? I really don't want to use a PC...I want everything to be contained within the sculpture and to turn on with the flip of a switch. Any other advice on how to get started? Thanks for any help!
|
|
|
|
|
99
|
Forum 2005-2010 (read only) / Syntax & Programs / simple boolean question
|
on: January 23, 2011, 03:25:22 pm
|
Hello, I'm sure this is simple...but I'm so bad at math and logic and I can't figure it out and I can't seem to find the problem anywhere else in the forums. I just want a potentiometer to make a few bleeps on each turn and then stop. So for example, if the potentiometer is between 0-400, I want it to make three tones and stop. If it's any other number, I don't want it to do anything. Very, very simple, no? I just can't figure it out. What am I don't wrong? Here is my code: boolean no_sound;
void setup() { no_sound=true; }
void loop() { int pot = analogRead(0); if ((pot > 0) && (pot < 400) && (no_sound=true)) { tone (28, 1999, 400); delay(50); tone (28, 500, 800); delay(50); tone (28, 3000, 200); no_sound=false; }else { no_sound=true; } }
|
|
|
|
|
101
|
Forum 2005-2010 (read only) / Interfacing / Re: simple web server problem
|
on: January 09, 2011, 12:17:52 pm
|
|
Shoot that worked! Thanks! But it's really crucial for this program that I use the LCD! Any ideas what I can do? With all the LCD stuff commented out it works fine. I've never run into this problem. So am I using too many libraries or something? The strange thing is, is that this code worked fine in the past.
|
|
|
|
|
102
|
Forum 2005-2010 (read only) / Interfacing / Re: simple web server problem
|
on: January 09, 2011, 11:55:20 am
|
|
Hi and thanks for your help!
When I type in Serial.print(var);, the var does not print into the serial monitor. The SD card and all its contents do print out and when I try to open an htm file off the sdcard the serial monitor refreshes but the page doesn't open in my browser....it just hangs. (A simple webserver does work...i am connected to the right network and everything)
I am having both the problems you mentioned. I do not get a serial output of the variable 'var' in my monitor and I am unable to open an .htm file. Something appears to be stuck somewhere.
Here is my output in the serial monitor. I should be getting a 0 a 1 or 2 somewhere, right? I put Serial.print(var); right before the conditionals that do the html redirects...(if I put it right after my 'pot' conditionals I will get one number that doesn't repeat and once again a hang...also the Serial monitor doesn't refresh when I try to load a page)
Free RAM: 151 Volume is FAT16
Files found in root: TWO.HTM 2011-01-07 15:02:02 86 CIR1.HTM 2011-01-07 14:57:18 82 CIR2.HTM 2011-01-07 14:57:32 82 CIR3.HTM 2011-01-07 14:57:46 84 ONE.HTM 2011-01-07 15:01:46 77 SQ1.HTM 2011-01-07 14:58:22 81 SQ2.HTM 2011-01-07 14:58:36 81 SQ3.HTM 2011-01-07 14:58:50 83 THREE.HTM 2011-01-07 15:02:16 86 TR1.HTM 2011-01-07 14:59:02 83 TR2.HTM 2011-01-07 14:59:16 83 TR3.HTM 2011-01-07 14:59:30 85
Files found in all dirs: TWO.HTM CIR1.HTM CIR2.HTM CIR3.HTM ONE.HTM SQ1.HTM SQ2.HTM SQ3.HTM THREE.HTM TR1.HTM TR2.HTM TR3.HTM
Done
|
|
|
|
|
103
|
Forum 2005-2010 (read only) / Interfacing / simple web server problem
|
on: January 09, 2011, 10:42:04 am
|
i'm trying to run a simple webserver program on a duemilanova with an ethernet shield with a built in sdcard reader. i also want the program to do html redirects depending on where i have a potentiometer pointed. i.e., if the pot is between 0-400, and the user access one.htm, he will be redirected to square.htm. if the pot is between 401-800 and the user access one.htm, he will be redirected to triangle.htm. simple enough, right? however, when i put the if conditionals into the webserver program the .html pages don't load. I will paste the code down below. this little problem has been consuming my entire weekend! #include <SPI.h> #include <SdFat.h> #include <SdFatUtil.h> #include <Ethernet.h> #include <LiquidCrystal.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; char rootFileName[] = "index.htm"; Server server(80); LiquidCrystal lcd(7, 6, 5, 8, 3, 2); /************ SDCARD STUFF ************/ Sd2Card card; SdVolume volume; SdFile root; SdFile file; // store error strings in flash to save RAM #define error(s) error_P(PSTR(s))
void error_P(const char* str) { PgmPrint("error: "); SerialPrintln_P(str); if (card.errorCode()) { PgmPrint("SD error: "); Serial.print(card.errorCode(), HEX); Serial.print(','); Serial.println(card.errorData(), HEX); } while(1); }
void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.print("booting up..."); PgmPrint("Free RAM: "); Serial.println(FreeRam()); // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with // breadboards. use SPI_FULL_SPEED for better performance. pinMode(10, OUTPUT); // set the SS pin as an output (necessary!) digitalWrite(10, HIGH); // but turn off the W5100 chip!
if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!"); // initialize a FAT volume if (!volume.init(&card)) error("vol.init failed!");
PgmPrint("Volume is FAT"); Serial.println(volume.fatType(),DEC); Serial.println(); if (!root.openRoot(&volume)) error("openRoot failed");
// list file in root with date and size PgmPrintln("Files found in root:"); root.ls(LS_DATE | LS_SIZE); Serial.println(); // Recursive list of all directories PgmPrintln("Files found in all dirs:"); root.ls(LS_R); Serial.println(); PgmPrintln("Done"); // Debugging complete, we start the server! Ethernet.begin(mac, ip); server.begin(); }
// How big our line buffer should be. 100 is plenty! #define BUFSIZ 100
void loop() {
/////if pot is in x number range print to LCD and assign a different value to var///////// int pot = analogRead(0); int var; if ((pot > 0)&&(pot < 400)) { lcd.clear(); lcd.print("FIRST CHAMBER"); delay(40); var=0; }
if ((pot > 401)&&(pot < 800)) { lcd.clear(); lcd.print("SECOND CHAMBER"); delay(40); var=1; } if ((pot > 801)&&(pot < 1024)) { lcd.clear(); lcd.print("THIRD CHAMBER"); delay(40); var=2; } /////////////webserver code i got from the adafruit forums/ char clientline[BUFSIZ]; char *filename; int index = 0; int image = 0;
Client client = server.available(); if (client) { // an http request ends with a blank line boolean current_line_is_blank = true; // reset the input buffer index = 0; while (client.connected()) { if (client.available()) { char c = client.read(); // If it isn't a new line, add the character to the buffer if (c != '\n' && c != '\r') { clientline[index] = c; index++; // are we too big for the buffer? start tossing out data if (index >= BUFSIZ) index = BUFSIZ -1; // continue to read more data! continue; } // got a \n or \r new line, which means the string is done clientline[index] = 0; filename = 0; // Print it out for debugging Serial.println(clientline); // Look for substring such as a request to get the root file if (strstr(clientline, "GET / ") != 0) { filename = rootFileName; } if (strstr(clientline, "GET /") != 0) { // this time no space after the /, so a sub-file if (!filename) filename = clientline + 5; // look after the "GET /" (5 chars) // a little trick, look for the " HTTP/1.1" string and // turn the first character of the substring into a 0 to clear it out. (strstr(clientline, " HTTP"))[0] = 0; // print the file we want Serial.println(filename);
if (! file.open(&root, filename, O_READ)) { client.println("HTTP/1.1 404 Not Found"); client.println("Content-Type: text/html"); client.println(); client.println("<h2>File Not Found!</h2>"); break; } Serial.println("Opened!"); client.println("HTTP/1.1 200 OK"); if (strstr(filename, ".htm") != 0) client.println("Content-Type: text/html"); else if (strstr(filename, ".jpg") != 0) client.println("Content-Type: image/jpeg"); else if (strstr(filename, ".gif") != 0) client.println("Content-Type: image/gif"); else client.println("Content-Type: text");
client.println(); int16_t c; while ((c = file.read()) >= 0) { // uncomment the serial to debug (slow!) //Serial.print((char)c); client.print((char)c); } file.close(); } else { // everything else is a 404 client.println("HTTP/1.1 404 Not Found"); client.println("Content-Type: text/html"); client.println(); client.println("<h2>File Not Found!</h2>"); } //////int conditionals for html redirect...THIS DOESN'T WORK///////// if ((strstr(filename, "one.htm") !=0)&&(var==0)){ client.println("<head>"); client.println("<meta HTTP-EQUIV='REFRESH' content='0; url=http://192.168.1.177/sq1.htm'>"); client.println("</head>");
} if ((strstr(filename, "one.htm") !=0)&&(var==1)){ client.println("<head>"); client.println("<meta HTTP-EQUIV='REFRESH' content='0; url=http://192.168.1.177/tr1.htm'>"); client.println("</head>");
} if ((strstr(filename, "one.htm") !=0)&&(var==2)){ client.println("<head>"); client.println("<meta HTTP-EQUIV='REFRESH' content='0; url=http://192.168.1.177/cir1.htm'>"); client.println("</head>");
} if ((strstr(filename, "two.htm") !=0)&&(var==0)){ client.println("<head>"); client.println("<meta HTTP-EQUIV='REFRESH' content='0; url=http://192.168.1.177/sq2.htm'>"); client.println("</head>");
} ///etc...had to delecte other conditionals for post size///////////////////////////
break; } } // give the web browser time to receive the data delay(1); client.stop(); } }
|
|
|
|
|
104
|
Forum 2005-2010 (read only) / Interfacing / Problem with ethernet shield and LCD screen
|
on: January 07, 2011, 12:44:44 pm
|
Hello, I'm having a very strange problem using my ethernet shield, an lcd and a potentiometer. Any help would be soooo appreciated!!! I want to be able to use the ethernet shield and at the same time use the potentiometer to change text on the lcd screen (sending html redirects when certain .htm files are accessed on the sdcard). I swear that I had this working no problem for awhile but when I went back into the program to make some changes (and later removing the changes) it's no longer working. The lcd screen only now refreshes with new text when a file is accessed on the sdcard. Why would that be? i am using the code for a webserver i found in the adafruit forums here...i will paste it below. Right now I'm just trying to get this very simple code to work in the "if (client.available())" statement so that I can do the html redirects with client.println. (right now none of this redirect stuff is in the code...just trying to get the text to work first) Here is the simple code that isn't working in the webserver (but works on it's own): int pot = analogRead(0); if ((pot > 0)&&(pot < 400)) { lcd.clear(); lcd.print("FIRST CHAMBER"); }
if ((pot > 401)&&(pot < 800)) { lcd.clear(); lcd.print("SECOND CHAMBER"); } if ((pot > 801)&&(pot < 1024)) { lcd.clear(); lcd.print("THIRD CHAMBER"); } and here is the webserver code i found in the adafruit forums. You can see below where I used to have the if statements...i've tried placing them all over to no avail: #include <SPI.h>
/* * Web Server * * A simple web server that shows the value of the analog input pins. */
#include <SdFat.h> #include <SdFatUtil.h> #include <Ethernet.h> #include <LiquidCrystal.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; char rootFileName[] = "index.htm"; Server server(80); LiquidCrystal lcd(7, 6, 5, 8, 3, 2); /************ SDCARD STUFF ************/ Sd2Card card; SdVolume volume; SdFile root; SdFile file;
// store error strings in flash to save RAM #define error(s) error_P(PSTR(s))
void error_P(const char* str) { PgmPrint("error: "); SerialPrintln_P(str); if (card.errorCode()) { PgmPrint("SD error: "); Serial.print(card.errorCode(), HEX); Serial.print(','); Serial.println(card.errorData(), HEX); } while(1); }
void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.print("booting up..."); PgmPrint("Free RAM: "); Serial.println(FreeRam()); // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with // breadboards. use SPI_FULL_SPEED for better performance. pinMode(10, OUTPUT); // set the SS pin as an output (necessary!) digitalWrite(10, HIGH); // but turn off the W5100 chip!
if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!"); // initialize a FAT volume if (!volume.init(&card)) error("vol.init failed!");
PgmPrint("Volume is FAT"); Serial.println(volume.fatType(),DEC); Serial.println(); if (!root.openRoot(&volume)) error("openRoot failed");
// list file in root with date and size PgmPrintln("Files found in root:"); root.ls(LS_DATE | LS_SIZE); Serial.println(); // Recursive list of all directories PgmPrintln("Files found in all dirs:"); root.ls(LS_R); Serial.println(); PgmPrintln("Done"); // Debugging complete, we start the server! Ethernet.begin(mac, ip); server.begin(); }
// How big our line buffer should be. 100 is plenty! #define BUFSIZ 100
void loop() { char clientline[BUFSIZ]; char *filename; int index = 0; int image = 0; Client client = server.available(); if (client) { // an http request ends with a blank line boolean current_line_is_blank = true; // reset the input buffer index = 0; while (client.connected()) { if (client.available()) { char c = client.read(); // If it isn't a new line, add the character to the buffer if (c != '\n' && c != '\r') { clientline[index] = c; index++; // are we too big for the buffer? start tossing out data if (index >= BUFSIZ) index = BUFSIZ -1; // continue to read more data! continue; } // got a \n or \r new line, which means the string is done clientline[index] = 0; filename = 0; // Print it out for debugging Serial.println(clientline); // Look for substring such as a request to get the root file if (strstr(clientline, "GET / ") != 0) { filename = rootFileName; } if (strstr(clientline, "GET /") != 0) { // this time no space after the /, so a sub-file if (!filename) filename = clientline + 5; // look after the "GET /" (5 chars) // a little trick, look for the " HTTP/1.1" string and // turn the first character of the substring into a 0 to clear it out. (strstr(clientline, " HTTP"))[0] = 0; // print the file we want Serial.println(filename);
if (! file.open(&root, filename, O_READ)) { client.println("HTTP/1.1 404 Not Found"); client.println("Content-Type: text/html"); client.println(); client.println("<h2>File Not Found!</h2>"); break; } Serial.println("Opened!"); client.println("HTTP/1.1 200 OK"); if (strstr(filename, ".htm") != 0) client.println("Content-Type: text/html"); else if (strstr(filename, ".jpg") != 0) client.println("Content-Type: image/jpeg"); else if (strstr(filename, ".gif") != 0) client.println("Content-Type: image/gif"); else client.println("Content-Type: text");
client.println(); ///////////////i used to have the simple potentiometer/lcd code here and it worked for ///////////////the longest time...now new text only appears if a file is accessed int16_t c; while ((c = file.read()) >= 0) { // uncomment the serial to debug (slow!) //Serial.print((char)c); client.print((char)c); } file.close(); } else { // everything else is a 404 client.println("HTTP/1.1 404 Not Found"); client.println("Content-Type: text/html"); client.println(); client.println("<h2>File Not Found!</h2>"); } break; } } // give the web browser time to receive the data delay(1); client.stop(); } }
Thanks so much for any help!!!
|
|
|
|
|