Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Arduino + Ethernet Shield Help (http://www.chiefdelphi.com/forums/showthread.php?t=118069)

techhelpbb 01-08-2013 11:41

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1285577)
When I press the buttons, the TX and RX leds blink on both the ethernet shield and the R3, and an LED I connected to pin 13 (it is not in the code though, it's just there to show me if the Arduino LED blinks) gets a little bit brighter when the TX and RX leds blink.

What are you powering this assembly with?
What voltage and current is the power source rated for?
Are you using the USB port for power?

The potential code issues aside make sure that you are not fooling yourself by powering that assembly with a power source that is not sufficient.

jwallace15 01-08-2013 11:46

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by techhelpbb (Post 1285581)
What are you powering this assembly with?
What voltage and current is the power source rated for?
Are you using the USB port for power?

The potential code issues aside make sure that you are not fooling yourself by powering that assembly with a power source that is not sufficient.

It is powered over my USB port.

I know that it is sufficient, I recently made a sketch with my MEGA that had 15+ LED's that would scroll in a marquee and the delay could be adjusted from a trim pot (all the way down to a ~10ms delay).

I also ran a servo off of the mega while doing that, and 3 more trim pots that could adjust the colour of an RGB LED.

daniel_dsouza 01-08-2013 12:14

Re: Arduino + Ethernet Shield Help
 
Can you add some print statements after the conditional logic steps in your code, and tell us what they give you?

I wonder if favicon.i is an icon? I hope not, because that would not make any sense.

It's good to see another person that loves trains.

jwallace15 01-08-2013 12:23

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by daniel_dsouza (Post 1285586)
Can you add some print statements after the conditional logic steps in your code, and tell us what they give you?

I wonder if favicon.i is an icon? I hope not, because that would not make any sense.

Do you mean add like an if-then statement, as in if the On button is pressed, serial.print("The Led is on");

and say the led is off if the Off button is pressed?

EDIT: ^ I added that sort of statement and when I press either the on of off buttons nothing is printed.

Quote:

Originally Posted by daniel_dsouza (Post 1285586)
It's good to see another person that loves trains.

:D

http://www.chiefdelphi.com/forums/at...9&d=1346106255 (as of last year. Much has changed since then. MUCH.)

techhelpbb 01-08-2013 14:31

Re: Arduino + Ethernet Shield Help
 
I put my Arduino Ethernet Shield R3 onto my Arduino Duo R3.

I cut a network cable in half.
Made an ethernet 'cross-over cable' like so:
Orange/White (one half) - Green/White (the other half)
White/Orange (one half) - White/Green (the other half)
Vice-versa
I used Scotch Tape as an insulator after twisting wires together.
MacGyvering during lunch....check.
Good thing that was a high quality dollar store cable ($1.34).

I put my 'cross-over cable' into my laptop (Dell E6400...yes I have several laptops) ethernet port.
I put the other end into the Arduino Ethernet Shield.

I disabled IPV6 (blah) on my laptop wired ethernet interface.
Set my wired connection in Windows 7 to: 192.168.1.131
Looked at the supplied code and it uses: 192.168.1.130
Set the gateway as: 192.168.1.1
Set the netmask to: 255.255.255.0

Loaded up your stored page in Firefox.
Regardless of what webpage button I press (On/Off) I get "HTTP" out the serial monitor.

When I get a chance I'll check the output pins.

However I do not get this:

Quote:

Originally Posted by jwallace15 (Post 1285577)
Code:

HTTP
favicon.i,,


Care to clarify if you are using Internet Exploder....I mean Internet Explorer :)

I have version 1.05 stable of the Arduino software.

jwallace15 01-08-2013 14:58

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by techhelpbb (Post 1285606)
Care to clarify if you are using Internet Exploder....I mean Internet Explorer :)

Nope, Chrome. I openly admitted to using IE at robotics last year and recieved a major lashing for such blasphemy. Then I downloaded Chrome.

techhelpbb 01-08-2013 15:42

Re: Arduino + Ethernet Shield Help
 
I only get the 'favicon.i' if the serial monitor is open when the board first connects. Other than that just "HTTP" out of the serial monitor.

It did not appear on my DMM that either pin 7 or 8 was toggling with the webpage button presses (not sure if it's one or zero oriented).

Will look into it more later.

What I suspect is wrong here is that:

1. If you look there is only one call to serial to output from this code.
2. What you should see is what is in the buffer.
3. When you alter the form it fires a POST event.
4. That should cause the page to reload (with the same content).
5. During that post event parameters follow.
6. We both only see "HTTP".
7. However this is a POST so look at this link:
http://www.jmarshall.com/easy/http/#postmethod
(Link altered to something more related and friendly)
8. Therefore when the code reloads and tries to parse these parameters...it can not find what is not in the buffer.
9. Therefore the page simply reloads but does not change the pins (it thinks it's the first time you loaded it).
10. This *might* have worked for someone at some point but this is likely time sensitive.
11. The browser is doing all the work to display the HTML form.
12. When the browser toggles something it's just a silly drawing to the browser.
13. Even if this was a slider (it's a button) it would likely slide as you might expect.
14. Even if the browser does not successfully communicate the change it will tend to draw the changes.
15. HTTP is stateless so unless you put something more intelligent like Javascript in there you can't ask the browser after the fact what happened without another HTML form submission.
16. If your HTML forms never send valid data you are trapped in a vicious loop where things *appear* to be happening.

This is a typical problem for web applications of any sort.
Often form submissions recall the same code and that code needs to get parameters (either GET or POST).
If that code does not get parameters HTTP is stateless so it thinks you were *never there before*.

So since I am not the student here :)
Put a serial print statement *inside* the conditional that toggles the pin.
See if it ever prints.
You sort of did this already above just put *only* the print statement not any additional conditionals.

Then we can go from there.

BTW when was this book you have written? Look at the copyright date.
It's this book right: http://shop.oreilly.com/product/9780596802486.do

Whistles innocently:
https://bugzilla.mozilla.org/show_bug.cgi?id=260500

jwallace15 01-08-2013 17:53

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by techhelpbb (Post 1285613)
BTW when was this book you have written? Look at the copyright date.
It's this book right: http://shop.oreilly.com/product/9780596802486.do

No, it is the second edition; http://shop.oreilly.com/product/0636920022244.do

techhelpbb 01-08-2013 17:58

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1285620)
No, it is the second edition

Try my suggestion above.

In the conditional already in the example code just try to print anything out the serial port.

Things change and when someone writes a *tiny* webserver they sometimes forget that they control the part they write. They do not control the browser part that is written by someone to whom they have no immediate contact.

So let's think about this:
What happens when the browser part does something different then it did before? How does the example written in a hard copy book evolve when the authors and editors of the book can't predict the future? It doesn't.

This code is obsolete (for people with current browsers) but it's actually not terribly hard to fix it.

So let's do this step by step. Start with my request above. Tell us if you ever see that line print.

jwallace15 01-08-2013 18:27

Re: Arduino + Ethernet Shield Help
 
So in the code line...

Code:

while(client.findUntil("PinD", "\n\r"))
{
 int val = client.parseInt();
pinMode(8, OUTPUT);
digitalWrite(8, val); 
}

Add...

Code:

while(client.findUntil("PinD", "\n\r"))
{
int val = client.parseInt();
pinMode(8, OUTPUT);
digitalWrite(8, val);
if(val == 1)
{
Serial.print("The LED is on")
}
else
{
Serial.print("The LED is off")
}
}

?

techhelpbb 01-08-2013 18:42

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

jwallace15 01-08-2013 19:37

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by techhelpbb (Post 1285625)
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.

techhelpbb 02-08-2013 00:05

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.

jwallace15 06-08-2013 14:41

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¨


techhelpbb 06-08-2013 14:47

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1286117)
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.


All times are GMT -5. The time now is 16:48.

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