Go to Post Competing at multiple regionals or Championship events has no bearing on the life lessons you will learn or the unbelievable memories you will have--for that is what FIRST is truly all about. - Alivia [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rating: Thread Rating: 8 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 08-01-2013, 06:42 PM
techhelpbb's Avatar
techhelpbb techhelpbb is offline
Registered User
FRC #0011 (MORT - Team 11)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 1997
Location: New Jersey
Posts: 1,620
techhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond repute
Re: Arduino + Ethernet Shield Help

Somewhere you've lost a line...I highlighted it red.
The line you want to add is shown in green.

Code:
            if(strcmp(buffer,"POST ") == 0)
            {
              client.find("\n\r");
              while(client.findUntil("PinD", "\n\r"))
              {
                int pin = client.parseInt();
                int val = client.parseInt();
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
                Serial.println("I saw the POST and toggled the pin!")
              }
            }
Also I noticed you statically assigned the pin I think it best you start with the original unmodified code for this.
Just add the one green line to the original code.

Be back in 2 or so hours....gotta go to a MORT thing.....

Last edited by techhelpbb : 08-01-2013 at 06:50 PM.
  #2   Spotlight this post!  
Unread 08-01-2013, 07:37 PM
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

Quote:
Originally Posted by techhelpbb View Post
Somewhere you've lost a line...I highlighted it red.
The line you want to add is shown in green.

Code:
            if(strcmp(buffer,"POST ") == 0)
            {
              client.find("\n\r");
              while(client.findUntil("PinD", "\n\r"))
              {
                int pin = client.parseInt();
                int val = client.parseInt();
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
                Serial.println("I saw the POST and toggled the pin!")
              }
            }
Also I noticed you statically assigned the pin I think it best you start with the original unmodified code for this.
Just add the one green line to the original code.

Be back in 2 or so hours....gotta go to a MORT thing.....
Yeah, my bad. I modified the code either yesterday or the day before. I just hardcoded it so that it would digital write on pin 8 no matter what, so that if that was the problem.

Will do, and will post results.
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.
  #3   Spotlight this post!  
Unread 08-02-2013, 12:05 AM
techhelpbb's Avatar
techhelpbb techhelpbb is offline
Registered User
FRC #0011 (MORT - Team 11)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 1997
Location: New Jersey
Posts: 1,620
techhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond repute
Re: Arduino + Ethernet Shield Help

Make sure to put the semicolon at the end of the line I suggested you add.
Guess I nicked it off when I edited the color tags on my phone.

Something to think about as you work this out:

Code:
Press OFF button:

FireFox 19.02 Internet browser sends:
  POST / HTTP/1.1
  Host: 192.168.1.130
  User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.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.130/
  Connection: keep-alive
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 7
  pinD8=0

Arduino Replies:
  HTTP/1.1 200 OK
  Content-Type: text/html
HTML of web page follows.

Press ON button:

FireFox 19.02 Internet browser sends:
  POST / HTTP/1.1
  Host: 192.168.1.130
  User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.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.130/
  Connection: keep-alive
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 7
  pinD8=1

Arduino Replies:
  HTTP/1.1 200 OK
  Content-Type: text/html
HTML of webpage follows.
Captured with LiveHTTPHeaders Add-on for FireFox.
No sense in posting what the HTML looks like here.
It's in the code and major browsers will let you view that as source.

Take a good look at the code as supplied and picture what will happen when it reads that.

As of last night around midnight I had this code fixed and working as it was intended.
I just don't want to deprive anyone of the learning experience
If time is pressing let me know and I'll just send the fixed code to look at.


I wanted to address another statement previously made:

15 LEDs at 20mA each DC current limit.
Driven at 50% duty cycle PWM so you can 'dim' them.
Consume something like an average of 10mA.
If the PWM is sychronized to all 15 LEDs on actual outputs (so this assumes your Arduino has enough digital I/O for this).
Then that's 150mA.
If the PWM signals are 'out of phase' with each other then it's possible this could be as low as 75mA.
Let us assume the likely chance that it's 15 LEDs on 15 digial I/O at 75% duty cycle.
That would, at least to your eye, look like they are almost fully powered on.
So 15 LEDs are probably drawing close to 200mA out of the maximum typical drive of an Atmel AVR of 200mA.
Since R/C hobby servos are usually connected to another circuit or shield.
Since R/C hobby servos are often 6VDC for the motor which is a good reason for the additional circuit.
It's likely the R/C hobby servo control presents a simple 5V CMOS input to the Arduino.
Such an input draws a tiny current.
Usually around 0.1mA or even less.

So that means that you were hovering somewhere between 150mA and 201mA of total drive from the Atmel AVR with that setup.

So previously when it was suggested that an Arduino was able to power 15 LEDs and servos off the same board from a USB port that wasn't entirely a fair assesment of the actual total drive power being demanded of the Atmel AVR on the Arduino itself.

It seems unlikely that the servo power came from the USB port since they typically limit to 1A or even 500mA.

So again be very careful with this.

I can stack CMOS input shift registers on Arduino digital outputs.
Heck I can stack I2C/SPI port expanders and other Arduinos on the digital ouputs of a single Arduino.
So it is possible to have an enormous number of things controlled by a single Arduino.
*However* always consider just how much current as a whole that will demand of the Atmel AVR on the Arduino.
Device count alone can fool you easily.
It is the context that actually matters.

Also seeing as you've driven LEDs with PWM and know how to do that.
Did you know you can drive the opto-isolator LED with PWM?
The relay coil is really slow to respond.
So you can save digital I/O current by driving the LED in the opto-isolators with PWM.
Depends on how you do that.
You could drive half of the relays low.
Then the other half.
So you could reduce 160mA to drive that 8 relay board you have to something like 80mA.

Last edited by techhelpbb : 08-02-2013 at 12:10 PM.
  #4   Spotlight this post!  
Unread 08-06-2013, 02:41 PM
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

Sorry it took so long, I've been too busy to toy with this issue.

I added the Serial.print function where you indicated
Code:
(if(strcmp(buffer,"POST ") == 0)
            {
              client.find("\n\r");
              while(client.findUntil("PinD", "\n\r"))
              {
                int pin = client.parseInt();
                int val = client.parseInt();
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
                Serial.println("I saw the POST and toggled the pin!")
              }
            }
It does not print "I saw the POST and toggled the pin!", it still prints the HTTP and favicon.i

Except it added one character;
Code:
 HTTP
favicon.i¨
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.
  #5   Spotlight this post!  
Unread 08-06-2013, 02:47 PM
techhelpbb's Avatar
techhelpbb techhelpbb is offline
Registered User
FRC #0011 (MORT - Team 11)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 1997
Location: New Jersey
Posts: 1,620
techhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond repute
Re: Arduino + Ethernet Shield Help

Quote:
Originally Posted by jwallace15 View Post
It does not print "I saw the POST and toggled the pin!", it still prints the HTTP and favicon.i

Except it added one character;
Code:
 HTTP
favicon.i¨
You would have gotten the extra character eventually it's a bit of junk from the fact that this code is parsing wrong.

You did not get the message because you never get to that part of the loop.

Look up at my last post.
It shows what my FireFox browser sends to the board.
Then look at the code you have.

Specifically look at the inner conditionals that mention POST.
Look before and look after that.

There are several things wrong there.
  #6   Spotlight this post!  
Unread 08-06-2013, 03:06 PM
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

Quote:
Originally Posted by techhelpbb View Post
Look up at my last post.
It shows what my FireFox browser sends to the board.
Then look at the code you have.

Specifically look at the inner conditionals that mention POST.
Look before and look after that.

There are several things wrong there.
I'm not exactly sure what I'm looking for... Does it have to do with the way I used a " in the line
Code:
if(client.find("/"))
And in the next I used ' ?
Or how I added a space after POST in
Code:
if(strcmp(buffer,"POST ") == 0)
In that line should I change the 0 to a 1?
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.
  #7   Spotlight this post!  
Unread 08-06-2013, 03:10 PM
techhelpbb's Avatar
techhelpbb techhelpbb is offline
Registered User
FRC #0011 (MORT - Team 11)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 1997
Location: New Jersey
Posts: 1,620
techhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond repute
Re: Arduino + Ethernet Shield Help

Nope it's not a single versus double quotation issue.

The first thing a browser will send you after you click the button is the following text:
POST / HTTP/1.1

So remember the original code is trying to read what the browser sends and then act on that information. Plus the original code is obsolete.

So if you look for "/" first what will you find?
Now look at what it looks for next...

Remember each time the Atmel AVR MCU takes a character from the ethernet chip's buffer that character is no longer available in the ethernet chip to read again. So if you look for the "/" first. Will you ever find "POST"?

Last edited by techhelpbb : 08-06-2013 at 03:12 PM.
  #8   Spotlight this post!  
Unread 08-06-2013, 03:19 PM
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

Wait, I think I'm understanding now. Are you saying change the order of the if statements? Take this one
Code:
if(client.find("/"))
And put it in the spot of this (and vice versa)?

Code:
if(strcmp(buffer,"POST ") == 0)
?
That way it looks for POST instead of the "/"?
Or add a new if statement for if(client.find"POST")?
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.
  #9   Spotlight this post!  
Unread 08-06-2013, 03:26 PM
techhelpbb's Avatar
techhelpbb techhelpbb is offline
Registered User
FRC #0011 (MORT - Team 11)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 1997
Location: New Jersey
Posts: 1,620
techhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond repute
Re: Arduino + Ethernet Shield Help

Do you really need to look for: /
Does your *non existent* file system have any subfolders or other pages?

Considering you know this is not going to be a full standards compliant webserver I submit to you that you do not need to look for anything other than POST.

The first time you load the page the browser will use GET anyway.

Now if you plan on actually parsing browser requests for several pages and returning error messages then yes at that point you should mind the: /

For now how about you just look for the "POST". It's handy the code example already shows you how.
Just get rid of the first conditional looking for the: /
Use the client.find as demonstrated in the example to look for: POST

Keep in mind that you'll loose that original serial debug when you do this because you should delete that as well.
So be prepared to not see the "HTTP" or the "favicon.i" in the serial monitor.
If you have not already: leave the serial debug line I offered above in your code.

Let us save 'strcmp' for discussions on buffer security issues. You do not need that for this purpose at all.

Also look at every occurance of 'PinD' you need them all to match when it comes to the case of the text.

Last edited by techhelpbb : 08-06-2013 at 04:58 PM.
  #10   Spotlight this post!  
Unread 08-06-2013, 05:47 PM
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

I no longer see HTTP or favicon.i.

I commented out the line saying if(client.find"/").

Whenever I click a button on the webpage the LED still does not work. However, the serial monitor displays "POST" when I click either button, and then about a second later is displays "GET".

The "I saw the post and toggled the pin" still does not display though.

EDIT: I saw you said make sure the case of PinD matches everywhere and looked and saw it didn't everywhere. Now the debug line prints on the serial monitor (I saw the POST and toggled the pin!)

However, no LED.

ANOTHER EDIT: I forgot that I changed one of the lines to say;

Code:
client.println(" value='LOW'><input type='submit' value='On'/></form>");
client.println(" value='HIGH'><input type='submit' value='On'/></form>");
I changed it back to 0 and 1, and it finally worked!!!
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.

Last edited by jwallace15 : 08-06-2013 at 05:56 PM.
  #11   Spotlight this post!  
Unread 08-06-2013, 06:11 PM
techhelpbb's Avatar
techhelpbb techhelpbb is offline
Registered User
FRC #0011 (MORT - Team 11)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 1997
Location: New Jersey
Posts: 1,620
techhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond reputetechhelpbb has a reputation beyond repute
Re: Arduino + Ethernet Shield Help

Fantastic

Post up your Arudino code because if you Google around you'll discover that this book and that example has had quite a few people scratching their heads.

Just remember: this is no Microsoft Internet Information Server or Apache web server. It is more like the old SitePlayer (only SitePlayer was a lot more polished):
http://www.netmedia.com/siteplayer/webserver/sp1.html

It has no SSL. It has no authentication as you are using it.
If the browsers change dramatically you will need to alter that code.
Make sure you test that with all the browsers you need to use it with.
  #12   Spotlight this post!  
Unread 08-06-2013, 06:31 PM
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

Here is the final working code;

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

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

const int MAX_PAGENAME_LEN = 8;
char buffer[MAX_PAGENAME_LEN+1];

EthernetServer server(80);

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  delay(2000);
}

void loop()
{
  EthernetClient client = server.available();
  if (client)
  {
    int type = 0;
    while (client.connected())
    {
      if (client.available())
      {
        memset(buffer,0, sizeof(buffer));
        //if(client.find("/"))
          if(client.readBytesUntil('/', buffer,sizeof(buffer)))
          {
            Serial.println(buffer);
            if(strcmp(buffer,"POST ") == 0)
            {
              client.find("\n\r");
              while(client.findUntil("PinD", "\n\r"))
              {
                int pin = client.parseInt();
                int val = client.parseInt();
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
              }
            }
            sendHeader(client,"Post example");
            client.println("<h2>Click buttons to turn pin 8 on or off</h2>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
            client.println(" value='0'><input type='submit' value='Off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
            client.println(" value='1'><input type='submit' value='On'/></form>");
            client.println("</body></html>");
            client.stop();
          }
          break;
        }
      }
      delay(1);
      client.stop();
    }
  }
void sendHeader(EthernetClient client, char *title)
{
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();
  client.print("<html><head><title>");
  client.print(title);
  client.println("</title><body>");
}
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:44 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi