Show Posts
Pages: 1 2 [3] 4 5 ... 596
31  Using Arduino / Project Guidance / Re: Powering Externally While Reading Serial on: April 18, 2014, 08:09:34 pm
I would think a low voltage drop diode would provide adequate USB protection.
32  Using Arduino / Motors, Mechanics, and Power / Re: Newbie - HS-311 Servo 360 Continuous Rotation help on: April 18, 2014, 09:15:34 am
Quote
and cannot goes to a angle which i desire

Most continuous rotation servos can not be commanded to stop at an "angle".
33  Using Arduino / Networking, Protocols, and Devices / Re: Uploading file from SD card to remote server? on: April 18, 2014, 09:05:09 am
The below code provides for serving up four files from the SD card. It is somewhat clunky in that the SD read/client write probably could be put in a single function instead of four separate operations.

Code:
//zoomkat 2/26/13
//SD server slider test code
//open serial monitor to see what the arduino receives
//browser address will look like http://192.168.1.102:84/servosld.htm when submited
//for use with W5100 based ethernet shields
//put the servosld.htm, slider.js, bluev_sl.gif,
//and bluev_bg.gif on the SD card
//download flies at:
// http://web.comporium.net/~shb/pix/servosld.htm
// http://web.comporium.net/~shb/pix/slider.js
// http://web.comporium.net/~shb/pix/bluev_bg.gif
// http://web.comporium.net/~shb/pix/bluev_sl.gif
//

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo
Servo myservoe, myservof, myservog; // myservoh not used due to lack of another free pin
String readString, pos;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  //delay(2000);
  server.begin();
  Serial.println("Ready");

  myservoa.attach(2);  //the pin for the servoa control
  myservob.attach(3);  //the pin for the servob control
  myservoc.attach(5);  //the pin for the servoc control
  myservod.attach(6);  //the pin for the servod control
  myservoe.attach(7);  //the pin for the servoa control
  myservof.attach(8);  //the pin for the servob control
  myservog.attach(9);  //the pin for the servoc control
  //myservoh.attach(10);  //the pin for the servod control

}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

            //select proper header for file to be sent to browser

          client.println("HTTP/1.1 200 OK"); //send new page
          if(readString.indexOf("servosld") >=0) {
            client.println("Content-Type: text/html");
            client.println();
          }

          if(readString.indexOf("slider") >=0) {
            client.println("Content-Type: application/x-javascript");
            client.println();
          }

          if(readString.indexOf("bluev") >=0) {
            client.println("Content-Type: image/gif");
            client.println();
          }

          //select file to send to browser
          if(readString.indexOf("servosld") >=0) {
            File myFile = SD.open("SERVOSLD.HTM");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;             

              while (myFile.available())
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }               
              }
              if(clientCount > 0) client.write(clientBuf,clientCount);           
              myFile.close();
            }
          }

          if(readString.indexOf("slider") >=0) {
            File myFile = SD.open("slider.js");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;             

              while (myFile.available())
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }               
              }
              if(clientCount > 0) client.write(clientBuf,clientCount);
              myFile.close();
            }
          }

          if(readString.indexOf("bluev_sl") >=0) {
            File myFile = SD.open("bluev_sl.gif");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;             

              while (myFile.available())
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }               
              }
              if(clientCount > 0) client.write(clientBuf,clientCount);
              myFile.close();
            }
          }

          if(readString.indexOf("bluev_bg") >=0) {
            File myFile = SD.open("bluev_bg.gif");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;             

              while (myFile.available())
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }               
              }
              if(clientCount > 0) client.write(clientBuf,clientCount);
              myFile.close();
            }
          }

          delay(1);
          //stopping client
          client.stop();

          //process GET string request from client and and position servo

          pos = readString.substring(8, 12); //get the first four characters         
          //Serial.println(pos);
          int n = pos.toInt();  //convert readString into a number   
          Serial.println(n);
          Serial.println();

          if(readString.indexOf("?0") >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf("?1") >0) myservob.writeMicroseconds(n);
          if(readString.indexOf("?2") >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf("?3") >0) myservod.writeMicroseconds(n);
          if(readString.indexOf("?4") >0) myservoe.writeMicroseconds(n);
          if(readString.indexOf("?5") >0) myservof.writeMicroseconds(n);
          if(readString.indexOf("?6") >0) myservog.writeMicroseconds(n);
          //only seven servo pins, so back to myservoa for testing
          if(readString.indexOf("?7") >0) myservoa.writeMicroseconds(n);

          //clearing string for next read
          readString="";
          pos="";
        }
      }
    }
  }
}

34  Topics / Robotics / Re: No life in this Robot on: April 18, 2014, 12:21:42 am
Quote
I have absolutely no idea where to start to fix it. Thoughts?

If you don't have one, get a multimeter to troubleshoot possible power supply issues.
35  Using Arduino / Project Guidance / Re: Elevator project(noob alert) on: April 17, 2014, 11:58:25 pm
How fast does the elevator need to move? A smaller geared motor could probably be used to move the elevator car at slower speeds. I think real elevators are often counter weighted to take some load off of the drive motor. 
36  Using Arduino / Project Guidance / Re: servo question on: April 17, 2014, 10:57:47 pm
Toggle a servo using a button.

And if you hold the button down, it oscillates between the two positions once each second.


True. The OP will need to determine if the button press will be momentary (less than the debounce delay), or extended. If the press goes on for a long time, he will probably need to add flags to his code to record button state changes and act upon the status of the flags for the toggle event.
37  Using Arduino / Motors, Mechanics, and Power / Re: Motorized Valve on: April 17, 2014, 08:01:00 pm
How much money you have to spend? Is this just a simple test setup or will it be permanent? I'd look for a faucet valve as these are easy to turn and usually turn less than 180 deg. so a servo could be used to control the valve.
38  Using Arduino / Project Guidance / Re: send url using a switch.? on: April 17, 2014, 02:58:59 pm
Not sure just what you are trying to do, but below is some combined client/server code.

Code:
//zoomkat 7-03-12, combined client and server
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor and send an g to test client and
//see what the arduino client/server receives
//web page buttons make pin 5 high/low
//use the ' in html instead of " to prevent having to escape the "
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //assign arduino mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan assigned to arduino
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port arduino server will use
EthernetClient client;
char serverName[] = "web.comporium.net"; // (DNS) zoomkat's test web page server
//byte serverName[] = { 208, 104, 2, 86 }; // (IP) zoomkat web page server IP address

String readString; //used by server to capture GET request

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin 5 selected to control
  Ethernet.begin(mac,ip,gateway,gateway,subnet);
  server.begin();
  Serial.begin(9600);
  Serial.println("server/client 1.0 test 7/03/12"); // keep track of what is loaded
  Serial.println("Send an g in serial monitor to test client"); // what to do to test client
}

void loop(){
  // check for serial input
  if (Serial.available() > 0)
  {
    byte inChar;
    inChar = Serial.read();
    if(inChar == 'g')
    {
      sendGET(); // call client sendGET function
    }
  } 

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

            //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println("HTTP/1.1 204 Zoomkat");
            client.println();
            client.println(); 
          }
          else {   
            client.println("HTTP/1.1 200 OK"); //send new page on browser request
            client.println("Content-Type: text/html");
            client.println();

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

            client.println("<H1>Zoomkat's simple Arduino 1.0 button</H1>");

            client.println("<a href='/?on1' target='inlineframe'>ON</a>");
            client.println("<a href='/?off' target='inlineframe'>OFF</a>");

            client.println("<IFRAME name=inlineframe style='display:none'>");         
            client.println("</IFRAME>");

            client.println("</BODY>");
            client.println("</HTML>");
          }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

//////////////////////////
void sendGET() //client function to send and receive GET data from external server.
{
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.1"); //download text
    client.println("Host: web.comporium.net");
    client.println("Connection: close");  //close 1.1 persistent connection 
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed");
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read();
    Serial.print(c);
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop();

}
39  Using Arduino / Motors, Mechanics, and Power / Re: Modified servo for continuous rotation turns one direction only on: April 17, 2014, 02:23:19 pm
When making a continuous rotation servo, one should "calibrate" the servo for best positioning. One way is to send the servo a 90 1500us position command and then carefully take the servo apart for the mod and secure the pot shaft with out moving the shaft. Another way is when the servo is apart, power it up and send it a 1500us command, then carefully adjusrt the pot until the motor stops, then secure the pot shaft in place.
40  Using Arduino / Networking, Protocols, and Devices / Re: arduino ethernet server, TClientSocket on: April 17, 2014, 02:05:01 pm
Quote
Any Idea what I am doing wrong?

Not reading #7 below?

http://forum.arduino.cc/index.php/topic,148850.0.html
41  Using Arduino / Networking, Protocols, and Devices / Re: Uploading file from SD card to remote server? on: April 17, 2014, 01:54:32 pm
Very basic arduino server serving up the HYPNO.JPG file from the SD card.

Code:
//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = {
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = {
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString;

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  //delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

            client.println("HTTP/1.1 200 OK"); //send new page
          //client.println("Content-Type: text/html");
          client.println("Content-Type: image/jpeg");
          //client.println("Content-Type: image/gif");
          //client.println("Content-Type: application/x-javascript");
          //client.println("Content-Type: text");

          client.println();

          //File myFile = SD.open("boom.htm");
          File myFile = SD.open("HYPNO.JPG");
          //File myFile = SD.open("BLUEH_SL.GIF");
          //File myFile = SD.open("SERVOSLD.HTM");

          if (myFile) {

            byte clientBuf[64];
            int clientCount = 0;

            while(myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++;

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
            }
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);           
            // close the file:
            myFile.close();
          }
          delay(1);
          //stopping client
          client.stop();
          readString="";
        }
      }
    }
  }
}

42  Using Arduino / Project Guidance / Re: Serial commands from computer through arduino to another device on: April 17, 2014, 01:24:37 pm
Quote
Bad information that is becoming a forum urban legend, probably because many don't understand the TTL operations. The arduino can send tx to a large number of rx, and the arduino can receive rx from a large numbet of tx if each tx has a properly aligned diode in the tx line.

Zoomkat.  My bad then.  This is the first that I have heard of this and would like to know more about the technique.  Would one also need a protocol to identify the sender and/ or receiver?

The key to the TTL serial tx/rx is that both the tx and rx pins are normally held high at 5v when no transmission is occurring. The rx pin is internally "lightly' held high at 5v so that it is not susceptible to line noise. The tx pin is normally at 5v, but goes to ground when it sends a bit. This also pulls the connected rx pin to ground, which tells the rx it is receiving a bit. The tx goes back to 5v at the completion of the bit send. This causes/allows the rx pin to go back to 5v indicating the end of the bit send. So one tx pin can pull a number of connected rx pins low. For a number of tx pins to be connected to a single rx pin, a diode is needed on each tx pin connected to the rx pin. With out the diodes, all the tx pins would be holding the single rx pin high, preventing a single tx pin being able to pull the rx pin low. The diodes (band end connected to the tx pin) prevent the tx pins from feeding 5v to the rx pin keeping it high at 5v. Each tx pin can still pull the rx pin low. With the arduino USB serial connection, a diode can't be put on the internal tx pin, but in my test the USB tx pin did not prevent another external tx pin from pulling the arduino rx pin low. YMMY. You will still need to add identity features to the slave arduino code.
43  Using Arduino / Project Guidance / Re: Serial commands from computer through arduino to another device on: April 17, 2014, 10:21:29 am
Quote
If you are using the hardware serial (pins 0, 1) to communicate with the PC you can't also use it the connect with another device.

Bad information that is becoming a forum urban legend, probably because many don't understand the TTL operations. The arduino can send tx to a large number of rx, and the arduino can receive rx from a large numbet of tx if each tx has a properly aligned diode in the tx line.
44  Using Arduino / Project Guidance / Re: A network of Arduinos reporting to a central device or computer? on: April 17, 2014, 10:15:23 am
For starters, the simple thing to do would have the master in turn query the slaves for information. Having the slaves call the master could result in transmission conflicts. 
45  Using Arduino / Project Guidance / Re: *PLEASE READ* servo question on: April 17, 2014, 10:09:20 am
Toggle a servo using a button.

Code:
//zoomkat servo button toggle test 4-28-2012

#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;

void setup()
{
  pinMode(button, INPUT); //arduino monitor pin state
  servo.attach(7); //pin for servo control signal
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {
      servo.write(160);
      toggle = !toggle;
    }
    else
    {
      servo.write(20);
      toggle = !toggle;
    }
  }
  delay(500);  //delay for debounce
}
Pages: 1 2 [3] 4 5 ... 596