Pages: [1]   Go Down
Author Topic: Problem with Ethernet Library and Led  (Read 455 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for my bad English.
I Have a simple code with 1 function.

The function is:

void blinking((int time, int color){
// colore = 1 == Red
   // colore = 2 == Yellow
   // colore = 3 == Red and  Yellow
  
  pinMode(RED, OUTPUT);
  pinMode(YELLOW, OUTPUT);
  
  
   for (int i = 0; i <= quanto; i++) {
     switch (colore) {
        case 1:
          digitalWrite(RED, HIGH);
          delay(1000);
          digitalWrite(RED, LOW);
          break;
        case 2:
          digitalWrite(YELLOW, HIGH);
          delay(1000);
          digitalWrite(YELLOW, LOW);
          break;
        case 3:
          digitalWrite(RED, HIGH);
          digitalWrite(YELLOW, HIGH);
          delay(1000);
          digitalWrite(RED, LOW);          
          digitalWrite(YELLOW, LOW);
          break;
        default:
          break;
          // if nothing else matches, do the default
          // default is optional
    }
    delay(1000);
}

This function works without problems until I put in my code these lines and after I recall my function "blinking", it doesn't work, but the call before this code it works


while (FLAG == 0){
        if (Ethernet.begin(mac) == 0) {
            Serial.println("Failed to configure Ethernet using DHCP");              
        } else {
          FLAG=1;
        }
    }

Leds don't blink, why? can you help me? smiley-cry
« Last Edit: January 23, 2013, 09:56:24 am by daquili » Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 109
Posts: 4091
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please can you post your whole program and put it in code tags (# above the smileys)
The problem may not actually be in your function at all but without seeing all of your code it is impossible to help.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are notes in Italian.
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <stdlib.h>

// Definisco il Mac Address della scheda che è stampata sullo shield ethernet
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xAB, 0x50 };
String mac_string="90:A2:DA:0D:AB:50";
String buffer="";
String newbuffer="";
unsigned long nuovo_ip;
int indice1;
int indice2;

// Definisco ip del server su cui cercare info

IPAddress server;         // Default vuoto
IPAddress IPLocale;       // Default vuoto

const int Rosso = 13;           // LED che indica la connessione ethernet
const int Giallo = 12;           // LED che indica la connessione ethernet

int FLAG_Connessione=0;          // Indica se la connessione è avvenuta o meno
int FLAG_Server=0;               // indica che la connsessione con il server [lato dhcp] è avvenuta

EthernetClient client;

void setup() {
 
  // Inizializziamo la seriale
 
  Serial.begin(9600);
 
  // Inizializziamo i LED

  pinMode(Rosso, OUTPUT);
  pinMode(Giallo, OUTPUT);

}

void loop() {
 
  Serial.println("AVVIO PROGRAMMA");
  // Iniziamo la connessione DHCP

  Lampeggio(2,3);  // IT'S OK
 
  while (FLAG_Connessione == 0){
        if (Ethernet.begin(mac) == 0) {
            Serial.println("Failed to configure Ethernet using DHCP");
           
            // Connessione non riuscita
            Serial.println("Connessione = 0");
           
        } else {
         
          // Connessione riuscita
          FLAG_Connessione=1;
          Serial.println("Connessione = 1");
        }
    }
 
  Lampeggio(2,2); // IT DOESN'T WORK
   
  // Stampo ip locale ottenuto
  IPLocale=Ethernet.localIP();

  Serial.println(IPLocale);
 
  server[0]=IPLocale[0];
  server[1]=IPLocale[1];
  server[2]=IPLocale[2];


  //
  // Richiesta IP PRIVATO newip.php
  //
  // Devo ciclare su tutti gli ip per cercare il server
  //
  if (FLAG_Server == 0) {
      for (int i=42; i <= 254; i++){
          server[3]=i;
          Serial.println(server);
          if (client.connect(server, 80)) {
            Serial.println("connected");
            // Make a HTTP request:
            String prova="GET /newip.php?mac="+mac_string;
            //Serial.println(mac[0],HEX);
            Serial.println(prova);
            client.println(prova);
            client.println();
            Serial.print("Parametro ricevuto: ");
            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
              buffer=buffer+c;
            }
            Serial.println(buffer);
           
            // Parser del buffer
            indice1=buffer.indexOf('[');
            indice2=buffer.indexOf(']');
           
           
            /* converto buffer in numero */           
            newbuffer=buffer.substring(indice1+1,indice2);
           
            for (int i=0; i < newbuffer.length(); i++){
                nuovo_ip=nuovo_ip + 10 - (newbuffer[i] - '0');
            }
           
            FLAG_Server=1;
            break;
          }     
       } 
  }
   
  delay(1000);   
}

void Lampeggio(int quanto, int colore){
 
   // colore = 1 == Rosso
   // colore = 2 == Giallo
   // colore = 3 == Rosso e Giallo
     
   for (int i = 0; i <= quanto; i++) {
     switch (colore) {
        case 1:
          digitalWrite(Rosso, HIGH);
          delay(1000);
          digitalWrite(Rosso, LOW);
          break;
        case 2:
          digitalWrite(Giallo, HIGH);
          delay(1000);
          digitalWrite(Giallo, LOW);
          break;
        case 3:
          digitalWrite(Rosso, HIGH);
          digitalWrite(Giallo, HIGH);
          delay(1000);
          digitalWrite(Rosso, LOW);         
          digitalWrite(Giallo, LOW);
          break;
        default:
          break;
          // if nothing else matches, do the default
          // default is optional
    }
    delay(1000);
 
  }
}
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does it display on your Serial Monitor?
Does it ever print "Connessione = 1" ?

Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If this is an Uno, you can't use D10-13 for LEDS when using the SPI. The ethernet shield uses the SPI bus for both the w5100 and uSD. Use other pins.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

tanks, that was the problem!
Where I can read info to understand if a pin it used from w5100?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use the product schematics. D4 is used by the uSD card if there is one in the slot. D2 is used on some for an interrupt line.
Logged

Chicago
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I understand that D4 is used as the chip select for the SD card. what pin is used for the chip select of the W5100 chip?
Thanks
Don
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what pin is used for the chip select of the W5100 chip?
Pin 10.
Logged

Pages: [1]   Go Up
Jump to: