Hola, tengo el proyecto de abajo, consiste en un Sistema de control de temperaturas y publicación en Xively, usando una placa Arduino R3 , modulo ethernet ENC28J60 , 3 sensores DS18B20 y una keypad shield 1602. Lo que me ocurre es que no hay manera de que el modulo ethernet funcione si activo la parte del código que muestra los valores en el LCD, además para que se muestren los valores en el LCD debo volver a hacer un lcd.begin, si no, aparecen caracteres raros.
// Sistema de control de temperaturas usando modulo ethernet ENC28J60 y sensor DS18B20
// 2011-07-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
//PIN CONNECTION FOR ENC28J60 ETHERNET CARD
//CS...8
//SI...11
//SO...12
//SCK..13
//VCC...3.3v
//GND...GND
// Conexion del sensor DS18B20:
// Se ha elegido el modo de alimentación parásita que consiste en conectar VCC (+3,3v) y GND
//juntos y unir DATA a +3,3v con una resistencia de 4K7 Ohm.Este modo permite conectar los
//tres polos a un conector GND-DATA-VCC actuando como desequivocador, ya que DATA nunca cambia
//de posicion.
// arduino +3.3v-----R 4K7Ohm----DATA------Pin Digital 2 Arduino
// ****************************DS18B20***************************
// Arduino GND------------------VCC-GND
#include <EtherCard.h>
#include <stdio.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 10, 4, 5, 6, 7);
float tempmin = 2; //Variable donde guardamos la temperatura minima registrada
float tempmax = 8; //Varibale donde guardamos la temperatura maxima registrada
float temp01; //Varibale donde guardamos la temperatura actual sensor 01
float temp02; //Varibale donde guardamos la temperatura actual sensor 02
float temp03; //Varibale donde guardamos la temperatura actual sensor 02
// change these settings to match your own setup (son de mi cuenta Xively)
#define FEED "numero de feed"
#define APIKEY "codigo de apikey"
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// ethernet interface mac address, must be unique on the LAN
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// mac address
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address
static byte myip[] = { 192,168,1,32 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
// mask address
static byte mymask[] = { 255,255,255,0 };
// dnsip address
static byte dnsip[] = { 192,168,1,1 };
#endif
char website[] PROGMEM = "api.pachube.com";
byte Ethernet::buffer[700];
BufferFiller bfill;
uint32_t timer;
uint32_t timer01 = 240000; // 60000 = 1 minuto Tiempo para dar estabilidad temperatura sensor
Stash stash;
void setup () {
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Starting...."); // print a simple message
lcd.setCursor(0,1);
lcd.print("Max/Min delay"); //Warning about 4 min delay in Max/Min
delay(2000);
// Start up the library
sensors.begin();
Serial.begin(38400);
Serial.println("Trying to get an IP...");
Serial.print("MAC: ");
for (byte i = 0; i < 6; ++i) {
Serial.print(mymac[i], HEX);
if (i < 5)
Serial.print(':');
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
Serial.println( "Getting static IP.");
if (!ether.staticSetup(myip, gwip)){
Serial.println( "could not get a static IP");
}
#else
Serial.println("Setting up DHCP");
if (!ether.dhcpSetup()){
Serial.println( "DHCP failed");
blinkLed(); // blink forever to indicate a problem
}
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
ether.printIp("SRV: ", ether.hisip);
}
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
}
void loop () {
char temp_string[10];
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperatures...\n");
/*
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp Request...");
*/
sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.println("DONE");
float temp01 = sensors.getTempCByIndex(0);// Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
float temp02 = sensors.getTempCByIndex(1);
float temp03 = sensors.getTempCByIndex(2);
//INICIO ANULACION SERIE
Serial.print("Sensor 1: ");
Serial.print(temp01);
Serial.print("Min Sensor1: ");
Serial.print(tempmin);
Serial.print("Max Sensor1: ");
Serial.print(tempmax);
Serial.print("Sensor 2: ");
Serial.print(temp02);
Serial.print("Sensor 3: ");
Serial.print(temp03);
Serial.print("\n");
// FIN ANULACION SERIE
ether.packetLoop(ether.packetReceive());
//Timer para permitir estabilizarse la temperatura en el lugar donde colocar la sonda, para evitar
// falsos maximos y minimos
if (millis() < timer01)
{
tempmin=temp01;
tempmax=tempmin;
}
if (millis() > timer) {
timer = millis() + 60000; // Temporizador toma temperaturas 1000 = 1 seg
// Comparador temperaturas para saber Max y Min
if (temp01<tempmin)
tempmin=temp01;
if (temp01>tempmax)
tempmax=temp01;
// generate two fake values as payload - by using a separate stash,
// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.print("Sensor_1_T_Max,");
stash.println(tempmax);
stash.print("Sensor_1_T_Min,");
stash.println(tempmin);
stash.print("Sensor_1_Actual,");
stash.println(temp01);
stash.print("Sensor_2_Actual,");
stash.println(temp02);
stash.print("Sensor_3_Actual,");
stash.println(temp03);
stash.save();
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n"
"Host: $F" "\r\n"
"X-PachubeApiKey: $F" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
//Escribe datos temperatura en el LCD
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("T.Act.");
lcd.setCursor(6,0);
lcd.print(temp01);
lcd.setCursor(0,1);
lcd.print("Min");
lcd.setCursor(3,1);
lcd.print(tempmin);
lcd.setCursor(8,1);
lcd.print("Max");
lcd.setCursor(11,1);
lcd.print(tempmax);
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("T.Sens2");
lcd.setCursor(10,0);
lcd.print(temp02);
lcd.setCursor(0,1);
lcd.print("T.Sens3");
lcd.setCursor(10,1);
lcd.print(temp03);
delay(4000);
}