sabato 10 dicembre 2016

Ethernet Cable tester

Primo progetto interamente creato da me.
Tester per cavi ethernet normali e incrociati.

Visualizza lo stato e verifica se il cavo è normale o incrociato.
Visualizza errore in caso uno o più fili sono interrotti.


Video:




Fotografia:





Schema pratico:


Attenzione ai collegamenti ethernet:

Pin uscita per invio controllo:
SN74HC595
Pin7 = Pin 1 Ethernet
Pin6 = Pin 2 Ethernet
Pin5 = Pin 3 Ethernet
Pin4 = Pin 4 Ethernet
Pin3 = Pin 5 Ethernet
Pin2 = Pin 6 Ethernet
Pin1 = Pin 7 Ethernet
Pin15 = Pin 8 Ethernet

Pin entrata controlli :
A0 = 1
A1 = 2
A2 = 3
A3 = 4
A4 = 5
A5 = 6
D3 = 7
D4 = 8

Codice programma:

/*
  Tester per cavi ethernet
  Andrea Berri
  2016
 */
//Librerie

#include <LiquidCrystal.h>
// inizializzo e assegno porte LCD
LiquidCrystal lcd( 4, 5, 6, 7, 8, 9);
// abilito pin per pilotare IC74HC595
int latchPin = 12;  
int clockPin = 11;  
int dataPin = 13; 
byte pinOut = 0;    // da modificare
int uscita = 0;  // da modificare
int Lo1 = 0;
int Lo2 = 0;
int Lo3 = 0;
int Lo4 = 0;
int Lo5 = 0;
int Lo6 = 0;
int Lo7 = 0;
int Lo8 = 0;
int cavo = 0;
int eth1 = 0;
int eth2 = 0;
int eth3 = 0;
int eth4 = 0;
int eth5 = 0;
int eth6 = 0;
int eth7 = 0;
int eth8 = 0;
int testeth1 = 0;
int verifi1 = 0;


//Assegno variabili alle porte
int ethIn1 = 14;
int ethIn2 = 15;
int ethIn3 = 16;
int ethIn4 = 17;
int ethIn5 = 18;
int ethIn6 = 19;
int ethIn7 = 2;
int ethIn8 = 3;


void setup() {
    lcd.begin(16,2);
    lcd.setCursor(0,0);
    lcd.print("Progetto Tester");
    lcd.setCursor(4,1);
    lcd.print("Ethernet");
    delay(3000);
    lcd.clear();
    Serial.begin(9600);
  
  //configuro uscita IC
    pinMode(latchPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
    pinMode(clockPin, OUTPUT);

    pinOut = 0;

  //Assegno gli stati alle porte

  pinMode(ethIn1, INPUT);
  pinMode(ethIn2, INPUT);
  pinMode(ethIn3, INPUT);
  pinMode(ethIn4, INPUT);
  pinMode(ethIn5, INPUT);
  pinMode(ethIn6, INPUT);
  pinMode(ethIn7, INPUT);
  pinMode(ethIn8, INPUT);
  

}

void loop() {

    Serial.print("---------------INIZIO----------------"); 
    cavo = 0;
    Lo1 = 0;
    Lo2 = 0;
    Lo3 = 0;
    Lo4 = 0;
    Lo5 = 0;
    Lo6 = 0;
    Lo7 = 0;
    Lo8 = 0;
    lcd.clear();
    lcd.print("Processo: ");
    lcd.setCursor(0,1);
    //inserisco ciclo
    for (int uscita=0; uscita<= 7; uscita++){
       
    Serial.println();
    Serial.print("Pin uscita: ");
    Serial.print(uscita);
    
    //lcd.begin(16, 2);
    lcd.print(uscita + 1);
    pinOut = 0;

    bitSet(pinOut, uscita);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, pinOut);
    digitalWrite(latchPin, HIGH);
    

  //leggo stato entrata ethIn1
  int eth1 = digitalRead(ethIn1);
  int eth2 = digitalRead(ethIn2);
  int eth3 = digitalRead(ethIn3);
  int eth4 = digitalRead(ethIn4);
  int eth5 = digitalRead(ethIn5);
  int eth6 = digitalRead(ethIn6);
  int eth7 = digitalRead(ethIn7);
  int eth8 = digitalRead(ethIn8);
  int testeth1 = analogRead(ethIn1);
  
    //inserisco verifica

    if (uscita == 0 && eth1 == 1)
    {
      Lo1 = 1;
    }
    else
    {
      if (uscita == 0 && eth3 == 1) // se incrociato cambia valore
      {Lo1 = 256 ;
      }
    }
       
        
        if (uscita == 1 && eth2 == 1)
    {
      Lo2 = 2 ;
    }
    else
    {
            if (uscita == 1 && eth6 == 1) // se incrociato cambia valore
      {Lo2 = 512 ;
      }
    }
      
      
      if (uscita == 2 && eth3 == 1)
    {
      Lo3 = 4 ;
    }
    else
    {
            if (uscita == 2 && eth1 == 1) // se incrociato cambia valore
      {Lo4 = 1024 ;
      }
    }
        
        
        if (uscita == 3 && eth4 == 1)
    {
      Lo4 = 8 ;
    }
    else
    {
      
    }
        
        
        if (uscita == 4 && eth5 == 1)
    {
      Lo5 = 16; 
    }
    else
    {
      
    }
        
        
        if (uscita == 5 && eth6 == 1)
    {
      Lo6 = 32; 
    }
    else
    {
            if (uscita == 5 && eth2 == 1) // se incrociato cambia valore
      {Lo6 = 2024 ;
      }
    }
      
      
      if (uscita == 6 && eth7 == 1)
    {
      Lo7 = 64; 
    }
    else
    {
      
    }
        
        
        if (uscita == 7 && eth8 == 1)
    {
      Lo8 = 128; 
    }
    else
    {
      
    }
      Serial.println();
      Serial.print("Stato lettura porte: ");
      Serial.print(eth1);    
      Serial.print(eth2);   
      Serial.print(eth3);
      Serial.print(eth4);
      Serial.print(eth5);
      Serial.print(eth6);
      Serial.print(eth7);
      Serial.print(eth8);
      
      
      cavo = Lo1 + Lo2 + Lo3 + Lo4 + Lo5 + Lo6 + Lo7 + Lo8 ;
      Serial.println();
      Serial.print("Somma valori riscontrati: ");
      Serial.print(cavo);
   }
      
      
      
    
      
      
      if ( cavo == 255 )
      {
        lcd.clear();
        lcd.print("cavo dritto   ok");
        delay(2000);
        
      }
        else
    {
            if (cavo == 3008 )
              {
               lcd.clear();
                lcd.print("cavo inc.  ok");
                delay(2000);
              }
              else
              {
              lcd.clear();
              lcd.print("Cavo diverso");
              lcd.setCursor(0,1);
              lcd.print("o difettoso");
              
              delay(1000);
              lcd.clear();
              if ( cavo == 2496 )
              {
                lcd.print("Pin 2 / 6 ");
                delay(2000);
              }
              else
              {
                  
              }

              }
              }
              // insserisco sistema verifica pin per eventuale errore
              //inserisco ciclo

              
              lcd.print("Inizio verifica");
              delay(1000);
              lcd.clear();
              lcd.print("out: ");
              lcd.setCursor(0,1);
              lcd.print("in : ");
             uscita = 0;
    for (int uscita=0; uscita<= 7; uscita++){
    delay(250);
   
    
    pinOut = 0;
    bitSet(pinOut, uscita);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, pinOut);
    digitalWrite(latchPin, HIGH);
  //leggo stato entrata ethIn1
  int eth1 = digitalRead(ethIn1);
  int eth2 = digitalRead(ethIn2);
  int eth3 = digitalRead(ethIn3);
  int eth4 = digitalRead(ethIn4);
  int eth5 = digitalRead(ethIn5);
  int eth6 = digitalRead(ethIn6);
  int eth7 = digitalRead(ethIn7);
  int eth8 = digitalRead(ethIn8);

  //invio info al seriale stato porte
        Serial.println();
      Serial.print("Stato lettura porte verifica finale: ");
      Serial.print(eth1);    
      Serial.print(eth2);   
      Serial.print(eth3);
      Serial.print(eth4);
      Serial.print(eth5);
      Serial.print(eth6);
      Serial.print(eth7);
      Serial.print(eth8);
  
    //inserisco verifica porta1

    if (eth1 == 1)
    {
      verifi1 = 1;
    }
    else
    {
          if (eth2 == 1) 
          {verifi1 = 2;
          }
          else
          {
              if (eth3 == 1) 
              {verifi1 = 3;
              }
              else
              {
                  if (eth4 == 1) 
                   {verifi1 = 4;
                   }
                   else
                   {
                        if (eth5 == 1) 
                        {verifi1 = 5;
                        }
                        else
                        {
                            if (eth6 == 1) 
                            {verifi1 = 6;
                             }
                             else
                             {
                                  if (eth7 == 1) 
                                   {verifi1 = 7;
                                   }
                                   else
                                   {
                                        if (eth8 == 1) 
                                        {verifi1 = 8;
                                        }
                                        else
                                        {
                                        }
                                    }
                               }
                           }
                       }
                     }
                   }                               
                  }
       
              
              
              //lcd.print("Errore: ");
              
              lcd.setCursor(uscita+5,0);
              
              lcd.print(uscita+1);
              lcd.setCursor(uscita+5,1);
              
              lcd.print(verifi1);
              //delay(250);
              verifi1 = 0;
              //fine verifica errori
              }
               delay(2000);
             // }
              //}
    //}
}

giovedì 8 dicembre 2016

Movimento Servo

Piccolo progetto per dovere un servo, con aggiunta Display LCD per visualizzare valori inviati al Servo.


Schema:




Codice:

#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd( 3, 4, 5, 6, 7, 8);

Servo myservo;

int pos = 0;

void setup()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Progetto Berri");
  lcd.setCursor(0,1);
  lcd.print("SERVO TEST");
  delay(2000);
  lcd.begin(16,2);
  lcd.setCursor(0,0); 
  Serial.begin(9600);
  myservo.attach(9);
  while (!Serial);
}

void loop()
{
  for(pos = 0; pos < 180; pos += 1)
  {
    Serial.println(pos);
    lcd.begin(16,2);
    lcd.print(pos);
    lcd.setCursor(0,0); 
    myservo.write(pos);
    delay(50);
  }
  for(pos = 180; pos>=1; pos-=1)
  {
    Serial.println(pos);
    lcd.begin(16,2);
    lcd.print(pos);
    lcd.setCursor(0,0); 
    myservo.write(pos);
    delay(50);
    myservo.write(pos);
    delay(15);
  }
}

sabato 3 dicembre 2016

IR Tester

Progetto IR TESTER

In pratica decodifico e mostro sul LCD il codice dell'tasto premuto con qualsiasi telecomando.
Aggiunto due LED, rosso si accende quando premo 1, verde quando premo 2 e si spengono quando premo 0

Foto:

Codice:
/*
RDecodifica IR per test
*/

#include <IRremote.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd( 3, 4, 5, 6, 7, 8);

const int RECV_PIN = 11;
int redpin=12;
int redpin2=13;
IRrecv irrecv(RECV_PIN);

decode_results results;// simile al discorso che facevamo per la variabile "motore" nel progetto 8

void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Progetto Berri");
lcd.setCursor(0,1);
lcd.print("IR TESTER");
delay(2000);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Premi un tasto");
  Serial.begin(9600);// attiviamo il display
  irrecv.enableIRIn(); //Avvia ricezione
  pinMode(redpin,OUTPUT); //imposta il pin in modalità OUTPUT
  pinMode(redpin2,OUTPUT); //imposta il pin in modalità OUTPUT
}


void loop() {



  if (irrecv.decode(&results)) // se il sensore infrarosso riceve un'informazione ARDUINO  fa quello che c'è in queste parentesi graffe
  {
   Serial.println(results.value); // scrive sul monitor seriale il valore in un codice numerico numerico del tasto del telecomando che è stato premuto: ogni tasto di ogni telecomando ha un codice

 if (results.value==16724175){        // equivale al tasto 1
    
     digitalWrite(redpin,HIGH); //quando premete quel pulsante arduino deve fare questa azione ossia accendere il led
  
    
   } if(results.value==16738455){ 
     digitalWrite(redpin,LOW); //equivale tasto 0 e spengo il led
  
   }
if (results.value==16718055){        // equivale al tasto 2
    
     digitalWrite(redpin2,HIGH); //quando premete quel pulsante arduino deve fare questa azione ossia accendere il led
  
    
   } if(results.value==16738455){ 
     digitalWrite(redpin2,LOW); //equivale tasto 0 e spengo il led
  
   }
    
   lcd.print(results.value);
   delay(1000);
   lcd.begin(6,2);
    //lcd.setCursor(5,0);
    irrecv.resume(); //Attesa ricezione prossimo valore

 }
}



venerdì 2 dicembre 2016

Progetto Temperatura e umidità su WEB

Foto progetto ultimato:



Link fonte:


Schema montaggio:


File programmazione

#include <Adafruit_Sensor.h>

#include <DHT.h>
#include <DHT_U.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd( 3, 4, 5, 6, 7, 8);
#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xCC, 0xEF, 0xFE, 0xAD
};
IPAddress ip(192, 168, 1, 129);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {

  lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Progetto Berri");
lcd.setCursor(0,1);
lcd.print("WEB-Te/umi");
delay(2000);


  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  lcd.begin(16,2);
  dht.begin();

  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();


lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("IP");
lcd.setCursor(0,1);
lcd.print(Ethernet.localIP());
delay(1000);
}


void loop() {
   // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  int t = dht.readTemperature();

    // set the cursor to (0,0):
  lcd.setCursor(0, 0);
  // print from 0 to 9:
  
   lcd.print("Temp: ");
   lcd.print(t);
   lcd.print("C");
  // set the cursor to (16,1):
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");
    delay(200);

    
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
            client.print("<center>");
            client.print("<font size=20>");
            client.print("Temperatura : ");
            client.print(t);
            client.print("C");
            client.println("<br />");
            client.print("Umidita : ");
            client.print(h);
            client.print("%");
            client.println("<br />");
          client.println("</html>");
          break;
        }
        
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}




Particolarità:

Scaricare libreria DHT22 da sito