Show Posts
Pages: 1 2 [3] 4 5 ... 631
31  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet.begin() FAILS and I can't figure out why on: July 10, 2014, 08:29:51 pm
Well, you have internet connectivity, so you may need to simplify your code to determine which part interferes with the Ethernet.begin().
32  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet.begin() FAILS and I can't figure out why on: July 10, 2014, 07:25:52 pm
Simple client code you can try to test if you have some network issues or possible hardware issues.

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

}

33  Using Arduino / Networking, Protocols, and Devices / Re: POST over Bridge on Arduino Yun on: July 10, 2014, 07:19:00 pm
I don't see where you actually send any content, and measure the "Content-length:" and send that value. Perhaps you should just use a simpler GET request.
34  Topics / Home Automation and Networked Objects / Re: HTML/Arduino coding for single ON/OFF button on: July 10, 2014, 06:53:54 pm
Quote
In terms of the arduino sketch, I was thinking along similar lines as your sketch, but it looks like your sketch uses two pins - 1 for the relay (set to output), and one to monitor the state of the other switch/button (set to input). Extending this principle, I assume that in the case of a three-way switch (eg. a hallway, with 1) an upstairs switch, 2) a downstairs switch, and 3) an Arduino controlled relay), I would need to use three pins with two of these set to monitor the state of each of the manual switches?

Setting up new momentary pushbuttons to toggle a light should be fairly easy. Integrating a toggle setup into an existing three way light switch setup will probably be challenging. As to an arduino switch control setup, the toggle code could be modified to set a simple variable status flag that could be included in a web page. Any number of momentary pushbuttons could be put in parallel to actuate the toggle code. The server code probably could also check for a toggle command from a web browser GET request and actuate the toggle code when received. I suggest you start with simple proof of concept code and develop from there.
35  Using Arduino / Motors, Mechanics, and Power / Re: How to prevent servos from breaking on: July 09, 2014, 11:18:39 pm
The "economy" 9g servos have weak gears that will strip if pushed against the internal hard stops or rotated by hand. The HXT900 is reported to be more robust. You need to test each servo to find the rotation limits and then not exceed those limits.
36  Topics / Home Automation and Networked Objects / Re: HTML/Arduino coding for single ON/OFF button on: July 09, 2014, 11:06:13 pm
You might use some basic toggle code with the arduino so that both a web page and a local push button could toggle the same light relay connected to the arduino.

Code:
//zoomkat LED button toggle test 11-08-2012

int button = 5; //button pin, connect to ground as button
int press = 0;
boolean toggle = true;

void setup()
{
  pinMode(13, OUTPUT); //LED on pin 13
  pinMode(button, INPUT); //arduino monitor pin state
  digitalWrite(5, HIGH); //enable pullups to make pin 5 high
}

void loop()
{
  press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {
      digitalWrite(13, HIGH);   // set the LED on
      toggle = !toggle;
    }
    else
    {
      digitalWrite(13, LOW);    // set the LED off
      toggle = !toggle;
    }
  }
  delay(500);  //delay for debounce
}
37  Using Arduino / Programming Questions / Re: Please provide sample program for NRF24L01 communication. on: July 08, 2014, 10:16:18 pm
Previous post that might have information.

https://www.google.com/search?as_q=NRF24L01&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fforum.arduino.cc%2Findex&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=&gws_rd=ssl

38  Using Arduino / General Electronics / Re: 12V relay not cooperating on: July 08, 2014, 07:55:08 pm
Basic info.

https://www.google.com/search?lr=&as_qdr=all&biw=1185&bih=627&tbm=isch&sa=1&q=arduino+relay+schematic&oq=arduino+relay+schematic&gs_l=img.12..0.18406.21560.0.24504.5.5.0.0.0.0.109.484.4j1.5.0....0...1c.1.48.img..4.1.95.ACmBrbCPWXM

39  Using Arduino / Programming Questions / Re: Help with online Thermostat Please on: July 08, 2014, 06:07:16 pm
Below is an example of how to put static text strings inside the F() macro function.

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(F("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="";
        }
      }
    }
  }
}

40  Using Arduino / Project Guidance / Re: Rolly Bot on: July 08, 2014, 05:40:44 pm
Quote
The servos aren't even. They often drift when it's sitting.

You will probably get more control of the servos using writeMicroseconds. If you made your own continuous rotation servos, you might send the servos a 1500us signal, then tweak the pot (if available) such that the servo will not rotate. If drift continues to be a problem, you probably can use the servo detach function to stop the servo rotation. Below is some servo test code that includes the detach function.

Code:
// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  Serial.println();
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string

      // attach or detach servo if desired
    if (readString == "d") {
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }   

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

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");   
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}
41  Using Arduino / Networking, Protocols, and Devices / Re: How to set up HTTP request... on: July 07, 2014, 11:47:33 pm
Quote
Does that seem right?

Well, did it work as you expected?
42  Using Arduino / Project Guidance / Re: Reading a RS232 frame and extracting a byte on: July 07, 2014, 10:59:00 pm
Quote
Now how do I know which byte I'm reading?

Below is very simple code that converts the bytes being received into various formats that are printable for inspection.

Code:
//zoomkat serial echo test 7-31-2011

char c; // incoming serial data

void setup() {
  Serial.begin(9600); // set serial port at desired value
  Serial.println("serial echo test 0021"); // echo test
  Serial.println();
}

void loop() {

  if (Serial.available() > 0) { // check for serial buffer input
    c = Serial.read(); // read the incoming byte:

    Serial.println(c); // print the input
    //select an output format
    Serial.println(c, DEC);  // print as an ASCII-encoded decimal
    Serial.println(c, HEX);  // print as an ASCII-encoded hexadecimal
    Serial.println(c, OCT);  // print as an ASCII-encoded octal
    Serial.println(c, BIN);  // print as an ASCII-encoded binary
    Serial.println();
    //Serial.println(); // print new line for better reading
  }
}

43  Using Arduino / Programming Questions / Re: Serial read more than one thing on: July 07, 2014, 10:34:55 pm
Very basic serial code.

Code:
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(3); 
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if (readString == "on")     
    {
      digitalWrite(ledPin, HIGH);
    }
    if (readString == "off")
    {
      digitalWrite(ledPin, LOW);
    }

    readString="";
  }
}

44  Using Arduino / Programming Questions / Re: Problem with creating a string from serial data on: July 07, 2014, 10:03:04 pm
Test code

Code:
//zoomkat 7-7-14 String capture and parsing 
//from serial port input (via serial monitor)
//and print result out serial port
//copy test strings and use ctrl/v to paste in
//serial monitor if desired
// \n is used as the data string delimiter
// ' ' is used to delimit individual data
// change serial monitor to add both NL & CR

String readString; //main captured String
String topdir; //data String
String subdir;
String data;
int n;
int ind1; // , locations
int ind2;
 
void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 7-7-14"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like 2790 1 0100,
  //or 5100 3 368, or 606C 2 250
  //followed by lf/cr

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == '\n') {  //looks for end of data packet marker
      Serial.read(); //gets rid of following \r
     
      //do stuff
      Serial.println();
      Serial.print("captured String is : ");
      Serial.println(readString); //prints string to serial port out
     
      ind1 = readString.indexOf(' ');  //finds location of first space
      Serial.println(ind1); //debugging print
     
      topdir = readString.substring(0, ind1);   //captures first data String
      ind2 = readString.indexOf(' ', ind1+1 );   //finds location of second space
      Serial.println(ind2);
     
      subdir = readString.substring(ind1+1, ind2);   //captures second data String
      data = readString.substring(ind2+1);  //captures last data in readString

      Serial.print("the object directory is: ");
      Serial.println(topdir);
      Serial.print("the sub directory is: ");
      Serial.println(subdir);
      Serial.print("data in DEC is: ");
      n = data.toInt();  //convert "data" into a number
      Serial.println(n);
   
      Serial.println();
      Serial.println();
     
      readString=""; //clears variable for new input
      topdir="";
      subdir="";
      data="";
    } 
    else {     
      readString += c; //makes the string readString
    }
  }
}
45  Using Arduino / Programming Questions / Re: Serial selection on: July 07, 2014, 08:04:05 pm
Code for controlling several servos

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
// Powering a servo from the arduino usually *DOES NOT WORK*.

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
    }
  }
}

Pages: 1 2 [3] 4 5 ... 631