Ciao ragazzi... Come da titolo una cosa mai successa in tanti anni. Ho un arduino mega con uno sketch che funzionava perfettamente fino a qualche gg fa. Da ieri, dopo un stacca e attacca dell'alimentazione, lo sketch funziona solo se apro il monitor seriale oppure dopo l'upload dello sketch stesso... Ma se stacco e riattacco l'alimentazione, NULLA!!! il vuoto più assoluto, non parte fino a che non riapro il seriale. ci tengo a riprecisare che lo sketch ha funzionato per mesi fino a qualche gg fa.Qualche suggerimento? ecco qui:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <avr/wdt.h>
#include <MegunoLink.h>
#include <CommandHandler.h>
#include <CircularBuffer.h>
#include <Filter.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <ArduinoTimer.h>
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
ArduinoTimer HeartBeatTimer;
////////////////////udp/////////////////////////
IPAddress ComputerIPAddress(192, 168, 1, 122);
int RecPort = 8889; //Port on the megunolink machine for receiving
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
IPAddress ip(192, 168, 1, 117);
unsigned int localPort = 8888; // local port to listen on
////////////////////udp/////////////////////////
#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
//SerialCommandHandler.AddVariable(F("pulsantetemp1"), tempSensor1);
DeviceAddress tempSensor5 = {0x28, 0x62, 0x17, 0x27, 0x00, 0x00, 0x80, 0xE4};
DeviceAddress tempSensor6 = {0x28, 0x72, 0xB6, 0x26, 0x00, 0x00, 0x80, 0xCE};
DeviceAddress tempSensor7 = {0x28, 0xB1, 0x10, 0x27, 0x00, 0x00, 0x80, 0x28};
CommandHandler<> SerialCommandHandler;
////////////////udp//////////////////
EthernetUDP Udp;
InterfacePanel MyInterfacePanel("controllo", Udp);
CommandHandler<> SerialCommandHandler1(Udp, '!', '\r');
//////////////////udp//////////////////
void setup() {
Serial.begin(9600);
// Using the Ethernet Shield, pin 10 (SS) should be output,
//and pin 4 and pin 10 are used for chip select. Disable both.
// pinMode( 10, OUTPUT);
//digitalWrite( 10, HIGH); // disable this chip select
//pinMode( 4, OUTPUT);
//digitalWrite( 4, HIGH); // disable this chip select
Serial.println(F( "\nStarting Ethernet..."));
// Ethernet.begin without 'ip' parameteir starts the DHCP
if ( Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while (true);
}
// print your local IP address.
Serial.println(F( "Ethernet started."));
Serial.print(F( "Local IP = "));
Serial.println( Ethernet.localIP());
delay(500);
////////////////udp//////////////////
// start the Ethernet and UDP:
Ethernet.begin(mac,ip); //Ethernet.begin(mac,ip);
Udp.begin(localPort);
////////////////udp//////////////////
///////////sensori e login////////////////////////
sensors.begin();
//////////////////////////////////////////////////
///////////lcd////////////////////////////////////
lcd.begin(16, 2);
lcd.backlight();
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
//////////////////////////////////////////////////
}
void loop() {
/////////////////////////udp/////////////////////////////
int packetSize = Udp.parsePacket(); //I think for the udp stuff to work this needs to be called
/////////////////////////udp/////////////////////////////
SerialCommandHandler.Process();
if (HeartBeatTimer.TimePassed_Milliseconds(20000))
{
///////////controllo temperature e stampa su seriale e sd///////////////////////
sensors.requestTemperatures();
float temperatura5 = sensors.getTempC(tempSensor5);
float temperatura6 = sensors.getTempC(tempSensor6);
float temperatura7 = sensors.getTempC(tempSensor7);
Serial.print("stato= ");
Serial.println(stato);
////////////////////STAMPO A VIDEO LE TEMPERATURE////////////////////
Serial.print("05 Murale Cassa=");
Serial.print(temperatura5);
Serial.println("}");
Serial.print("06 Murale Lato Salumeria=");
Serial.print(temperatura6);
Serial.println("}");
Serial.print("07 Banco Gastronomia=");
Serial.print(temperatura7);
Serial.println("}");
///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
Udp.beginPacket(ComputerIPAddress, RecPort);
Udp.print("{UI:controllo|SET|DynamicLabel5.Text=");
Udp.print(temperatura5);
Udp.println("}");
Udp.write("{TIMEPLOT|data|05 Murale Cassa|T|");
Udp.print(temperatura5);
Udp.write("}\n");
Udp.endPacket();
/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
Udp.beginPacket(ComputerIPAddress, RecPort);
Udp.print("{UI:controllo|SET|DynamicLabel6.Text=");
Udp.print(temperatura6);
Udp.println("}");
Udp.write("{TIMEPLOT|data|06 Murale Salumeria|T|");
Udp.print(temperatura6);
Udp.write("}\n");
Udp.endPacket();
/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
Udp.beginPacket(ComputerIPAddress, RecPort);
Udp.print("{UI:controllo|SET|DynamicLabel7.Text=");
Udp.print(temperatura7);
Udp.println("}");
Udp.write("{TIMEPLOT|data|07 Banco Gastronomia|T|");
Udp.print(temperatura7);
Udp.write("}\n");
Udp.endPacket();
/////////////////////////////////////////////
}
////////////////fine loop/////////////////////////////////
}