Show Posts
Pages: 1 2 [3] 4 5 ... 597
31  Using Arduino / Programming Questions / Re: multi analog data from 1 arduino to another arduino on: April 19, 2014, 07:07:43 pm
Quote
My question is how can i 3 analog signals from one to another arduino arduino send and then use that data for the motors?

I suggest you work on the receiving code first, making code that is easy to decode the incoming data stream. The receiving code below is for servo, but demonstrates receiving a numeric value with a component identifier, followed by a data packet delimiter. The sending code can be easily formatted in this manner.

Code:
//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added

String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    } 
    else {     
      readString += c; //makes the string readString
    }
  }
}

32  Using Arduino / Project Guidance / Re: Newby ? - mega2560 and Ethernet shield to read (3) 1-5v inputs into desktop app on: April 19, 2014, 06:02:37 pm
Arduino server code that displays the arduino analog pin values in a web page.

Code:
// zoomkat's meta refresh data frame test page 8/17/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

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

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino 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
unsigned long int x=0; //set refresh counter to 0
String readString;

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

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 8/17/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c;
         }
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          //client.println("HTTP/1.1 200 OK");
          //client.println("Content-Type: text/html");
          //client.println();
         
          client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print(F("<HTML><HEAD>"));
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print(F("<meta http-equiv='refresh' content='1'>"));
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print(F("<meta http-equiv='refresh' content='0'>"));
            client.print(F("<title>Zoomkat's meta-refresh test</title></head><BODY><br>"));
            client.print(F("page refresh number: "));
            client.print(x); //current refresh count
            client.print(F("<br><br>"));
           
              //output the value of each analog input pin
            client.print(F("analog input0 is: "));
            client.print(analogRead(analogInPin0));
           
            client.print(F("<br>analog input1 is: "));
            client.print(analogRead(analogInPin1));
                       
            client.print(F("<br>analog input2 is: "));
            client.print(analogRead(analogInPin2));
           
            client.print(F("<br>analog input3 is: "));
            client.print(analogRead(analogInPin3));
                                   
            client.print(F("<br>analog input4 is: "));
            client.print(analogRead(analogInPin4));
           
            client.print(F("<br>analog input5 is: "));
            client.print(analogRead(analogInPin5));
            client.print(F("<br></BODY></HTML>"));
           }
          //generate main page with iframe
          else
          {
            client.print(F("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>"
            "Zoomkat's Arduino frame meta refresh test 8/17/13"
            "<BR><BR>Arduino analog input data frame:<BR>"
            "&nbsp;&nbsp;<a href='/datastart' target='DataBox' title=''yy''>META-REFRESH</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/data' target='DataBox' title=''xx''>SINGLE-STOP</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/datafast' target='DataBox' title=''zz''>FAST-DATA</a><BR>"
            "<iframe src='/data' width='350' height='250' name='DataBox'>"
            "</iframe><BR></HTML>"));
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

33  Using Arduino / Project Guidance / Re: Need some additional guidance on a robotic project on: April 19, 2014, 05:49:13 pm
Quote
He suggested to me to create an audio output depending on what the sensor detects, I was thinking of taking it further and connect it with an android phone, so it displays what the sensor detects if anything and how far it is ahead of it  (with the sensor only capable of detecting 50cm at best)and maybe giving off a small audio, so a beep, faster beeps meaning its getting closer to the object maybe,

I'd suggest that the bot look for something. Perhaps it could remember where it has been (some type of mapping), and continue to search new areas. Something simple like an IR beacon could be the searched for object.
34  Using Arduino / Programming Questions / Re: How to fix this servo code on: April 19, 2014, 05:05:56 pm
Seems some people have a lot idle time.

Code:
#include <Servo.h>

//int motorPinA = 10;
int ledPin = 3;
int repetitions = 0;
int iterations = 0;
//int motorPinB = 5;
//int motorPinC = 8;

//int servoA;
//int servoB;
//int servoC;

Servo servoA;
Servo servoB;
Servo servoC;

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

//Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created

int servoPosA = 0;    // variable to store the servo position, all sevo positions start at zero, as they should.
int servoPosB = 0;
int servoPosC = 0;

void setup()
{
  int ledPin;
  //int motorPin;
  //pinMode (motorPinA, OUTPUT);
  pinMode(ledPin, OUTPUT);
  int repetitions;
  int iterations;
  int myservo;

  //int motorPinB;
  //pinMode(motorPinB, OUTPUT);
  servoA.attach(5);  // attaches the servo (A) on pin 5 to the servo object
  servoB.attach(8);  // a servo (B) is attached to pin 8
  servoC.attach(9);  // a servo (C) is attached to pin 9
}

void loop()
{
  if(iterations >= 2)
  {
    //analogWrite(motorPinA, LOW);
    analogWrite(ledPin, 0);
    //Servo A needs to go to zero, 0, closed, and stay there when   
  }
  else
  {
    for(int repetitions=0;repetitions<2;repetitions++)
    {
      delay(2000);
      analogWrite(ledPin, 1000);
      delay(2000);
      //Servo A needs to go to 90 degrees, open

      for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees
      {                                  // in steps of 1 degree
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
      }
      for(servoPosA = 90; servoPosA>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees
      {                               
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos'
        delay(15);

        //analogWrite(motorPinA, 70);
        delay (3000);

        analogWrite(ledPin, 0);
        //servo A needs to be at 0, closed

        //analogWrite(motorPinA, LOW);
        iterations++;           // # value of iterations is counted up by one.

        if(iterations % 2 ==1) // this will devide iteraions by two and every time there is a remainder of one (AKA each time there is an odd number, AKA every other iteration, an (#.5 number) because that remainder 1 gets divided by two to make a .5*2 = 1, AKA once per day!)
          // This means that we can give her the twice-a-day-pills and then give her the once a day pills! We just need to adjust the timeing to match a 24-hour day!
        {
          delay(10); //debounce the system
          //make servos B and C run for once a day

          //analogWrite(motorPinB, 80);
          //delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
          //analogWrite(motorPinC, 80);
          delay(300); //how long the motors need to run to spit out exactly one pill of each
        }
        else
        {
          delay(10); //debounce the system

          // leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.
          //analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
          //analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
        }
      }
    }
  }
}

35  Using Arduino / Project Guidance / Re: Need some additional guidance on a robotic project on: April 19, 2014, 04:16:25 pm
Quote
You may have seen my last topic on this autonomous robot project which I have started and have made quite a lot of progress on.

Such as...? You really don't need a complete bot to write your programming. You can have the arduino print out what it is doing to the serial monitor without actually controlling motors and such. Below are youtube videos that may have projects similar to what you seek. Bottom are robot kits that might get you started. What have you done so far with your robot project?

https://www.youtube.com/results?search_query=arduino+robot+car

http://www.ebay.com/sch/i.html?_odkw=arduino+robot+car&LH_BIN=1&_sop=15&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313&_nkw=arduino+robot+car+kit&_sacat=0
36  Using Arduino / General Electronics / Re: Inverse multiplexer? on: April 19, 2014, 12:32:06 pm
Quote
Not having heard further from "Oddwired", we have not found out what he really wanted to do; I rather suspect something quite different.

I think the request is fairly straight forward.  smiley-cool
37  Using Arduino / Networking, Protocols, and Devices / Re: Arduino ethernet shield issue on: April 19, 2014, 11:10:53 am
Basic client test code you can try to see if your setup can connect to a web server more than once.

Code:
//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

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

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600);
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  } 
}

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

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    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"); //error message if no client connect
    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(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

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

}


38  Using Arduino / Programming Questions / Re: Webserver failure to communicate on: April 19, 2014, 10:29:37 am
Server code that demonstrates the use of the F() macro on static character strings that saves memory.

Code:
// zoomkat's meta refresh data frame test page 8/17/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

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

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino 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
unsigned long int x=0; //set refresh counter to 0
String readString;

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

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 8/17/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c;
         }
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          //client.println("HTTP/1.1 200 OK");
          //client.println("Content-Type: text/html");
          //client.println();
         
          client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print(F("<HTML><HEAD>"));
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print(F("<meta http-equiv='refresh' content='1'>"));
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print(F("<meta http-equiv='refresh' content='0'>"));
            client.print(F("<title>Zoomkat's meta-refresh test</title></head><BODY><br>"));
            client.print(F("page refresh number: "));
            client.print(x); //current refresh count
            client.print(F("<br><br>"));
           
              //output the value of each analog input pin
            client.print(F("analog input0 is: "));
            client.print(analogRead(analogInPin0));
           
            client.print(F("<br>analog input1 is: "));
            client.print(analogRead(analogInPin1));
                       
            client.print(F("<br>analog input2 is: "));
            client.print(analogRead(analogInPin2));
           
            client.print(F("<br>analog input3 is: "));
            client.print(analogRead(analogInPin3));
                                   
            client.print(F("<br>analog input4 is: "));
            client.print(analogRead(analogInPin4));
           
            client.print(F("<br>analog input5 is: "));
            client.print(analogRead(analogInPin5));
            client.print(F("<br></BODY></HTML>"));
           }
          //generate main page with iframe
          else
          {
            client.print(F("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>"
            "Zoomkat's Arduino frame meta refresh test 8/17/13"
            "<BR><BR>Arduino analog input data frame:<BR>"
            "&nbsp;&nbsp;<a href='/datastart' target='DataBox' title=''yy''>META-REFRESH</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/data' target='DataBox' title=''xx''>SINGLE-STOP</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/datafast' target='DataBox' title=''zz''>FAST-DATA</a><BR>"
            "<iframe src='/data' width='350' height='250' name='DataBox'>"
            "</iframe><BR></HTML>"));
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

39  Using Arduino / Project Guidance / Re: Elevator project(noob alert) on: April 19, 2014, 01:54:40 am
Below is a recent discussion of lifting a weight with a motor, and bottom are some motor options.

http://forum.arduino.cc/index.php?topic=207394.0

http://www.target.com/p/black-decker-alkaline-screwdriver-with-3-bits/-/A-10540882?ref=tgt_adv_XSG10001&AFID=Google_PLA_df&LNM=%7C10540882&CPNG=Unassigned&kpid=10540882&LID=PA&ci_src=17588969&ci_sku=10540882&gclid=CIbqjKvE3bsCFSdp7Aod4h4A1w

http://www.ebay.com/sch/i.html?_odkw=worm+gear&_osacat=0&_from=R40&_trksid=p2045573.m570.l1311.R4.TR12.TRC2.A0.Xworm+gear+&_nkw=worm+gear+motor&_sacat=0
40  Topics / Robotics / Re: uArmⅠ:An open source robot arm on: April 18, 2014, 11:29:00 pm
For a quick temporary base the below lazy Susan could be used with a servo underneath to rotate the arm. Bottom is a good video on laser cutting gears. The other larger wooden arm previously posted uses wooden gearing in the arm.

http://www.homedepot.com/p/Everbilt-6-in-Lazy-Susan-Turntable-49548/203661089

https://www.youtube.com/watch?v=Yz10C0U6tM0
41  Using Arduino / General Electronics / Re: Crosstalk in analogreads on: April 18, 2014, 10:15:16 pm
If the multiplex chip control pins float when not high then unusual readings might be observed. If the arduino control pins go to ground when off/low, then that should prevent the multiplex control pins from floating.
42  Using Arduino / General Electronics / Re: Inverse multiplexer? on: April 18, 2014, 10:03:27 pm
The below CD74HC4067 chip might be of interest. I think this chip is analog and bidirectional.

https://www.sparkfun.com/products/9056
43  Using Arduino / Project Guidance / Re: wifi web server that doesn't slow down a robot? on: April 18, 2014, 08:51:55 pm
Quote
I imagine the routines in the web server example where it waits for the client before disconnecting

The 1ms delay on the server code is not a lot and will only occur every five seconds. The "client.println("Refresh: 5");" is for the browser and has no effect on the server except have the browser refresh the page every 5 seconds.
44  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.
45  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".
Pages: 1 2 [3] 4 5 ... 597