Show Posts
Pages: 1 ... 8 9 [10] 11 12 ... 26
136  Using Arduino / Programming Questions / Re: Arduino WebServer input on: May 29, 2013, 04:12:11 pm
Code:
                    processDir(client);
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
Why not print the GET request first? That way, you'd know what you are parsing.

Why not share that output with us? You are the only one that can see it, so there is only one of us that can actually help you.
Good point. I switched it around. Here's output. I basically first loaded page, then pressed Forward, then Back twice.
Code:
server is at 192.168.1.113
GET / HTTP/1.1
Host: 192.168.1.113
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

GET /?myDir=FW HTTP/1.1
Host: 192.168.1.113
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.1.113/
Connection: keep-alive

Go Forward!
GET /?myDir=BW HTTP/1.1
Host: 192.168.1.113
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.1.113/?myDir=FW
Connection: keep-alive

Go Forward!
Go Back!
GET /?myDir=BW HTTP/1.1
Host: 192.168.1.113
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.1.113/?myDir=BW
Connection: keep-alive

Go Back!
137  Using Arduino / Programming Questions / Re: Arduino WebServer input on: May 29, 2013, 02:29:10 pm
Using Strings (memory leaks) and "indexOf" kind of bothers me, but I'm not sure if there's a better way smiley

There is the standard C string, (array of chars), which in my opinion are easier to use (since I never used the String class). With arrays of chars you use the function strcmp (or maybe better in your case: strncmp) to compare 2 strings. Try it, it will most likely solve your problem smiley-wink

Thank you!
You mean define string as: char myString[X] ?  How would I know that size of array should be?
138  Using Arduino / Programming Questions / Arduino WebServer input on: May 29, 2013, 02:01:21 pm
I'm writing a sketch to control Roomba over internet. However I'm having most problems with processing webpage input in the sketch smiley-sad
Below is the test sketch I use, it just displays page with simple links that pass variables via GET method. It just outputs to serial some text depending on which link is pressed (i.e. Go Forward!).
However for some reason it doesn't work right. For example when I click forward first time, it echoes Go Forward!, but if I now click Backward it echoes "Go Forward! Go Backward!". I have no clue why it does it. It seems to remember last value...
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 113);

EthernetServer server(80);

String HTTP_req;          // stores the HTTP request
boolean LED_status = 0;   // state of LED, off by default
byte LEDPin  = 13;

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(115200);       // for diagnostics
    Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    sendHeader(client);
                    // send web page
                    showBody(client);
                    processDir(client);
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                }
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

void sendHeader(EthernetClient client){
   client.println("HTTP/1.1 200 OK");
   client.println("Content-Type: text/html");
   client.println("Connection: close");
   client.println();
}

void showBody (EthernetClient client){
 client.println ("<html><head><title></title></head>");
 client.println ("<body><h1>Test Page</h1><p><a href='?myDir=FW'>Forward </a>| <a href='?myDir=BW'>Back </a>| <a href='?myDir=ST'>Stop</a></p></p></body></html>");

}

void processDir (EthernetClient client){
  if (HTTP_req.indexOf("myDir=FW") > -1) Serial.println ("Go Forward!");
  if (HTTP_req.indexOf("myDir=BW") > -1) Serial.println ("Go Back!");
  if (HTTP_req.indexOf("myDir=ST") > -1) Serial.println ("All Stop!");
}

And by all means if you can suggest a better way to process input please do. Using Strings (memory leaks) and "indexOf" kind of bothers me, but I'm not sure if there's a better way smiley
139  Using Arduino / Programming Questions / Re: [RESOLVED] SoftwareSerial and Ethernet conflict on Mega? on: May 29, 2013, 12:51:21 pm
Just wanted to post small update. As expected Hardware Serial1 (RX1/TX1) works just fine controlling Roomba 551 from Arduino Mega2560. No need for SoftwareSerial. Hooray!!! smiley
Thanks again guys!
140  Using Arduino / Programming Questions / Re: [RESOLVED] SoftwareSerial and Ethernet conflict on Mega? on: May 28, 2013, 08:20:44 pm
Fair enough smiley I also came to a conclusion that Serial1,2 should work no problem, just didn't have chance to test it smiley is neato hacker friendly?
141  Using Arduino / Programming Questions / Re: SoftwareSerial and Ethernet conflict on Mega? on: May 28, 2013, 04:30:10 pm
First of all you already answered my question, thank you! smiley
As you pointed out SPI  on Mega uses digital ports 50,51,52 and 53 that's why I had conflict.  I should've realized it, but it wasn't obvious because Ethernet shield doesn't touch those pins. After you posted your comment I realized that it connects to those pins the via ICSP header.

You don't need to answer to anything I write below I'm just trying to explain since you asked...

The serial port output TXD from the iRobot Roomba is too weak to drive the RX serial port input of an Arduino properly.
This is because of the USB-Serial converter on the Arduino: it also tries to drive the RX serial port input via a pullup resistor,
but the Roomba does not have enough drive to pull the RX down below about 2.5 volts, which is insufficient to be reliably detected as a TTL serial input of 0.

As for my mentioning of Port 0 and 1, in the context of Serial communication in Arduino, I figured it would be obvious that I'm talking about PIN0 (RX) and PIN1 (TX).

Is this sufficiently clear now? smiley
142  Using Arduino / Programming Questions / Re: SoftwareSerial and Ethernet conflict on Mega? on: May 28, 2013, 10:33:42 am
You need to take a look at the pins that the Ethernet shield uses, on the Mega. Hint: 50, 51, 52, and 53.

Why are you using SoftwareSerial on a device with 4 hardware serial ports?
Oh I didn't realize it. I know on Uno it uses others smiley Thanks for the tip!
Roomba doesn't like standard Serial Ports for some reason (at least on Uno). There have been many reports online about this issue, so people either use some kind of hex buffer or SoftwareSerial. I verified with Port 0 and 1 it doesn't work. Haven't tried other serial ports
143  Using Arduino / Programming Questions / [RESOLVED] SoftwareSerial and Ethernet conflict on Mega? on: May 28, 2013, 09:11:21 am
I'm trying to control Roomba with Arduino Mega 2560 and Ethernet Shield (connected to portable WiFi bridge). On it's own, Arduino has no issues controlling Roomba.  Ethernet shield also works on it's own with default WebServer sketch.
But they do not work together.
Is there a documented conflict issue between SoftwareSerial and Ethernet libraries on Arduino Mega2560? I couldn't find much online. Software serial is setup on PIN50 (RX) and PIN51 (TX) at baud of 115200.
Here's a sketch below just in case...

Code:
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>

int rxPin = 50;
int txPin = 51;
int ledPin = 13;

SoftwareSerial Roomba(rxPin,txPin);

#define bumpright (sensorbytes[0] & 0x01)
#define bumpleft  (sensorbytes[0] & 0x02)

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);

void setup() {
  pinMode(ledPin, OUTPUT);   // sets the pins as output
  Serial.begin(115200);
  Roomba.begin(115200);  
  digitalWrite(ledPin, HIGH); // say we're alive
  Serial.println ("Sending start command...");
  delay (1000);
   // set up ROI to receive commands  
  Roomba.write(128);  // START
  delay(150);
  Serial.println ("Sending Safe Mode command...");
  delay (1000);
  Roomba.write(131);  // CONTROL
  delay(150);
  digitalWrite(ledPin, LOW);  // say we've finished setup
  Serial.println ("Ready to go!");
  delay (5000);
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
  digitalWrite(ledPin, HIGH); // say we're starting loop
  Serial.println ("Go Forward");
  goForward();
  delay (500);
  Serial.println ("Halt!");
  halt();
  Serial.println ("Go Backwards");
  delay (500);
  goBackward();
  delay (500);
  Serial.println ("Halt!");
  halt();
  while(1) { } // Stop program
}

void goForward() {
  Roomba.write(137);   // DRIVE
  Roomba.write((byte)0x00);   // 0x00c8 == 200
  Roomba.write(0xc8);
  Roomba.write(0x80);
  Roomba.write((byte)0x00);
}
void goBackward() {
  Roomba.write(137);   // DRIVE
  Roomba.write(0xff);   // 0xff38 == -200
  Roomba.write(0x38);
  Roomba.write(0x80);
  Roomba.write((byte)0x00);
}

void halt(){
 byte j = 0x00;
 Roomba.write(137);  
 Roomba.write(j);  
 Roomba.write(j);
 Roomba.write(j);
 Roomba.write(j);
}

When I comment out these two lines below, Roomba starts to work...
Code:
Ethernet.begin(mac, ip);
  server.begin();

Is there any workaround for this or my own choice is to go with WiFi shield?
144  Topics / Robotics / Re: Controlling Roomba [solved] on: May 26, 2013, 11:59:06 pm
Anyway I found solution on my own.  Little by little I figured out that 500 series Roomba undergone significant change in Open Interface (OI) format. All the books, tutorials, etc. are severely outdated unfortunately smiley-sad
Major changes are:
1. Baud rate is now 115200 by default
2. No more DD pin. Instead this pin (#5) is now used to change baud rate
3. Command 130 (Control) is no longer needed (but still supported). Instead command 131 (Safe Mode) does same thing.

I modified RoombaComm BumpTurn sketch to work with SoftwareSerial and series 500 Roombas. I also simplified it to just Move forward to half a second, stop and then move backwards (sort of Hello World).
Code:

 #include <SoftwareSerial.h>

int rxPin = 3;
int txPin = 4;
int ledPin = 13;

SoftwareSerial Roomba(rxPin,txPin);

#define bumpright (sensorbytes[0] & 0x01)
#define bumpleft  (sensorbytes[0] & 0x02)

void setup() {
  pinMode(ledPin, OUTPUT);   // sets the pins as output
  Serial.begin(115200);
  Roomba.begin(115200);  
  digitalWrite(ledPin, HIGH); // say we're alive
  Serial.println ("Sending start command...");
  delay (1000);
   // set up ROI to receive commands  
  Roomba.write(128);  // START
  delay(150);
  Serial.println ("Sending Safe Mode command...");
  delay (1000);
  Roomba.write(131);  // CONTROL
  delay(150);
  digitalWrite(ledPin, LOW);  // say we've finished setup
  Serial.println ("Ready to go!");
  delay (5000);
}

void loop() {
  digitalWrite(ledPin, HIGH); // say we're starting loop
  Serial.println ("Go Forward");
  goForward();
  delay (500);
  Serial.println ("Halt!");
  halt();
  Serial.println ("Go Backwards");
  delay (500);
  goBackward();
  delay (500);
  Serial.println ("Halt!");
  halt();
  while(1) { } // Stop program
}

void goForward() {
  Roomba.write(137);   // DRIVE
  Roomba.write((byte)0x00);   // 0x00c8 == 200
  Roomba.write(0xc8);
  Roomba.write(0x80);
  Roomba.write((byte)0x00);
}
void goBackward() {
  Roomba.write(137);   // DRIVE
  Roomba.write(0xff);   // 0xff38 == -200
  Roomba.write(0x38);
  Roomba.write(0x80);
  Roomba.write((byte)0x00);
}

void halt(){
 byte j = 0x00;
 Roomba.write(137);  
 Roomba.write(j);  
 Roomba.write(j);
 Roomba.write(j);
 Roomba.write(j);
}

Found Specs PDF here
145  Topics / Robotics / Controlling Roomba [solved] on: May 25, 2013, 01:25:47 pm
Hi,

I have Roomba 551 which I'm trying to control from Arduino Uno. I've read "Hacking Roomba" and other examples online how it should be connected, but no matter what I try, I can't get it to respond. I know there are issues with RX/TX lines so I'm using Software Serial, here's example of the sketch:

Code:
#include <SoftwareSerial.h>
SoftwareSerial roomba(5,3);  // RX,TX
int rxPin = 5;
int txPin = 3;
int ddPin = 7;
int ledPin = 13;
void setup() {
 pinMode(ddPin,  OUTPUT);   // sets the pins as output
 pinMode(ledPin, OUTPUT);   // sets the pins as output
 Serial.begin(57600);
 roomba.begin(57600);
 digitalWrite(ledPin, HIGH); // say we're alive
 // wake up the robot
 digitalWrite(ddPin, HIGH);
 delay(100);
 digitalWrite(ddPin, LOW);
 delay(500);
 digitalWrite(ddPin, HIGH);
 delay(2000);
 // set up ROI to receive commands  
 roomba.write(128);  // START as defined in manual(adim)
 delay(50);
 roomba.write(130);  // CONTROL adim
 delay(50);
 digitalWrite(ledPin, LOW);  
}

void loop() {
  goForward();
  delay(50);
  halt();  
}

void goForward() {
 byte j = 0x00;
 roomba.write(137);
 roomba.write(j);  
 roomba.write(0xc8);
 roomba.write(0x80);
 roomba.write(j);
}

void halt(){
 byte j = 0x00;
 roomba.write(137);  
 roomba.write(j);  
 roomba.write(j);
 roomba.write(j);
 roomba.write(j);
}

I made cable from old PS/2 miniDin connector. Pin 1 is V+, Pin 8 i GND, 3 is RX, 5 is TX, 5 is DD. I connected Roomba's RX to Arduino TX (pin 3) and TX to pin 5. DD is on Pin 7.
Roomba powers up my Uno board no problems, but it's not moving at all smiley-sad
Also I read that CSI voltage should be around 18V, but it's actually measures as 8 Volts. Is this because I only connected one V+ pin (I have no idea if they split voltage between two) ?
Any ideas on how to get it moving? smiley

EDIT: I found out that default baud is 115200. Changed code but it still doesn't work.
I have Roostick and was able to control Roomba from my computer via SCITest program.
146  Using Arduino / General Electronics / Re: Low profile push button on: May 20, 2013, 09:57:25 pm
Thanks! Something like this prob will work http://www.digikey.com/product-detail/en/GPB556A05BA/CWI280-ND/3193549
smiley
147  Using Arduino / General Electronics / Re: Low profile push button on: May 20, 2013, 10:15:25 am
Real button will do smiley i.e. momentary switch
I don't have any specific requirements other than for it to be as little protruding on the bottom as possible..
148  Using Arduino / Microcontrollers / Re: Help needed with ATMega644P bootloader on: May 20, 2013, 09:45:08 am
and signature bytes
Where do I specify signature bytes? In boards.txt file?

I also need to update my 644p with Optiboot version via Arduino IDE (I don't have ISP). Sanguino boot-loader is horrendous smiley-sad
Would changing boards.txt file and be sufficient or I need to do something else?
149  Using Arduino / General Electronics / Low profile push button on: May 20, 2013, 09:19:12 am
Can someone recommend a nice panel mounted push-buttons that have very low "backend" profile (i.e. mechanical part underneath is very short)?  I have very little space between panel and inside components, and regular buttons I have just don't fit smiley-sad
150  Using Arduino / Microcontrollers / Re: Beginner AVRDude questions on: May 15, 2013, 10:23:59 pm
1.  Do you have an auto-reset circuit hooked up from the FTDI RTS/DTR to the reset pin?  Also for auto-reset to work with uploads you should be using -carduino instead of -cstk500v1 with avrdude.

2.  The avrdude v5.10 lacks the wiring protocol support Arduino Mega2560 boards.  The avrdude.conf file with v5.10 also lacks some newer AVR chip definitions and the wiring programmer definition.


Awesome! Yes I do have auto-reset circuit. Thank you, -carduino works much better!
Pages: 1 ... 8 9 [10] 11 12 ... 26