Go Down

Topic: DS1820 - No more adresses (Read 255 times) previous topic - next topic

drVrh

Hello,

I am newbie in Arduino. I work project show temperature on webpage and on LCD, but  I have a problem. Without ethernet config  show temperature on LCD normal, soon add function for Ethernet case no working more. On webpage showing temperature but on LCD no. On sensor have 4k2 ohm resistor. I also tried with 2k2 ohm resistor, but no working.

Where is the problem? Here is a code:

Code: [Select]
#include <OneWire.h>            //lib za senzor
#include <LiquidCrystal.h>      //lib za lcd
#include <SPI.h>                //lib za SPI komunikacijo z ETH modulom
#include <Ethernet.h>           //lib za ETHernet

// LCD=======================================================
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define LCD_WIDTH 16
#define LCD_HEIGHT 2
// LCD=======================================================

//ETHERNET server konfiguracija
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0x3F, 0x15 };                      //MAC NASLOV ETH MODULA
IPAddress ip(164,8,22,53);                                   //IP NASLOV RACUNALNIKA V SOLI
EthernetServer server(80);                  //port, po default = 80

/* DS18S20 Temperature chip i/o */
OneWire  ds(7);  // on pin 7
#define MAX_DS1820_SENSORS 1
byte addr[MAX_DS1820_SENSORS][8];

void setup(void)
{
    lcd.begin(LCD_WIDTH, LCD_HEIGHT,1);
  lcd.setCursor(0,0);
  lcd.print("DS1820 Test");   
  //preverjanje ce ni 0 in ce ni 1 potem ni naslovov
  if (!ds.search(addr[0]))
  {
    lcd.setCursor(0,0);
    lcd.print("0No more addresses.");
    ds.reset_search();
    delay(250);
    return;
  }
  if (!ds.search(addr[1]))
  {
    lcd.setCursor(0,0);
    lcd.print("1No more addresses.");
    ds.reset_search();
    delay(250);
    return;
  }

  ETH_config();
  //  return;
}


void ETH_config(void){
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP()); 
}

int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
char buf[20];

void pisiHTML(int cela, int decimalka){
  // 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>");
          /*TU SEM JAZ ZA?EL ZA PROBAT PISAT*/
          client.println("<b>Grega MOCNIK</b>");   
          client.println("<br />");
          client.println("<b>Senzor za temperaturo</b>");
          client.println("<br />");
          client.print("Temperatura: ");
          client.print(cela);
          client.print(".");
          client.print(decimalka);         
          client.println("<br />");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }

}




void loop(void)
{
  byte i, sensor;
  byte present = 0;
  byte data[12];

  for (sensor=0;sensor<MAX_DS1820_SENSORS;sensor++)
  {
    //*****************preverjamo o senzorjih, za CRC in ce je prikljucen senzor***************
    if ( OneWire::crc8( addr[sensor], 7) != addr[sensor][7])
    {
      lcd.setCursor(0,0);
      lcd.print("CRC is not valid");
      return;
    }

    if ( addr[sensor][0] != 0x10)
    {
      lcd.setCursor(0,0);
      lcd.print("Device is not a DS18S20 family device.");
      return;
    }
    //******************************preverjanje CRC in senzor**************************************

    ds.reset();
    ds.select(addr[sensor]);
    ds.write(0x44,1);         // start conversion, with parasite power on at the end

    delay(1000);     // maybe 750ms is enough, maybe not
    // we might do a ds.depower() here, but the reset will take care of it.

    present = ds.reset();
    ds.select(addr[sensor]);   
    ds.write(0xBE);         // Read Scratchpad

    for ( i = 0; i < 9; i++)
    {           // we need 9 bytes
      data[i] = ds.read();
    }

    LowByte = data[0];
    HighByte = data[1];
    TReading = (HighByte << 8) + LowByte;
    SignBit = TReading & 0x8000;  // test most sig bit
    if (SignBit) // negative
    {
      TReading = (TReading ^ 0xffff) + 1; // 2's comp
    }
    Tc_100 = (TReading*100/2);   

    Whole = Tc_100 / 100;  // separate off the whole and fractional portions
    Fract = Tc_100 % 100;
    pisiHTML(Whole, Fract);          //poslje na spletno stran temperaturo
    sprintf(buf, "%d:%c%d.%d\337C     ",sensor,SignBit ? '-' : '+', Whole, Fract < 10 ? 0 : Fract);

    lcd.setCursor(0,sensor%LCD_HEIGHT);
    lcd.print(buf);
  }
}

Nick_Pyner

OK, I understand you have either temp on LCD, or temp on Ethernet, but not both. In that case I don't think there is anything wrong with DS18B20 and you have not run out of addresses.

It looks like a clash between Ethernet and LCD .

Ethernet uses SPI bus, pins 10,11,12,13. It is unusual for LCD to be on those pins and you should be able to move them to 8,9 and edit the programme accordingly. Yes, I know the Hello World example uses those 11,12 but it isn't a good idea. Using pin 4 is something you may later regret also, as it is normally used for SD card..

What counts is the order of the pins - RS, enable, D4,5,6,7.

Code: [Select]
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2


For example, you can connect D5 anywhere you like, so long as you list the pin in that position. My 16x2 Is on a shield which goes on a sensor shield and is always called

Code: [Select]
LiquidCrystal lcd(8,9,A2,5,6,7);


Go Up