Go Down

Topic: Lockup at Boot: ---> Udp.begin(localPort); (Read 848 times) previous topic - next topic

Hi, I'm new to this forum and have a problem when trying to merge two network formats into one program.   There are probably alot of improvements to be had here overall... but my main problem is when adding the second example sketch.. it wont boot.  

I have both working separately, one is a web server that posts sensor info in a browser, and has one Digital Output controllable by a button.  This uses these network protocols:
EthernetClient client;
EthernetServer server(80);

The other that I am trying to merge into this web server sketch is the Ardumote example code...  each work fine separately, but merging the two causes the Mega2560 to lock up unless I comment out this line - the first line in Setup ():   Udp.begin(localPort);    //Ardumote  Setup UDP socket on port defined earlier.  THIS LOCKS UP UPON BOOT

Here's the code... there's allot I have a few things connected... all working ok though.  

If there's anything you can recommend... please do!  Thank you!

#define aref_voltage 3.3         // FOR temp36 temp sensor - we tie 3.3V to ARef and measure it with a multimeter!

#include <SPI.h>
#include <Ethernet.h>

// define settings for the SHT21 temp/hum sensor on pins 20(SDA) /21(SCL) (SCL and SDA)
#include <Wire.h>
#include <SHT2x.h>
// end of define for SHT21 sensor

/* Simple Counter
* ------------
* This is a simple counter that takes a digital input
*  http://www.toddholoubek.com/classes/pcomp/?page_id=58
//int ledPin = 13; // choose the pin for the LED
//int switchPin =2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;

// serial LCD setup Serial 2x16 LCD Backlit with speaker (1 wire connection) http://learn.parallax.com/KickStart/27977
const int TxPin = 6;  // this is the pin the serial LCD data is connected too
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
// end of serial LCD setup

const int temperaturePin = 0; //the analog pin the TMP36?s Vout (sense) pin is connected to  //TMP36 Pin Variables - this is the Temp sensing chip, look like a transistor
int LightPin1 = A7;    // MOVED TO A7 Pin A1 was taken and outputing 5v all the time -- Ambient Light Sensor Modern Device MD0505  uses a Sharp GA1A1S202WP chip - outputs 0-5v analog
int LightSensValue1 = 0; // // variable to store the value coming from the sensor - example is when adding calibration curve... 0v = 0,  5v = 1023.. use MAP to blend it in.  

// Sainsmart Eithernet controller settings
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; // Ethernet shield MAC address
byte ip[] = { 192, 168, 0, 19 };  // worked before I added this line
EthernetClient client;
EthernetServer server(80);

//  Ardumote Setup Info
unsigned int localPort = 7777;      // local port to listen on (set this the same as Port # on Ardumote Params Screen)
IPAddress iPhoneIP(192, 168, 0, 14);  //Set the iPhone/iPod/iPad's IP address to send messages back to Ardumote...
unsigned int iPhonePort = 7777;      //Set the Port # of the message table you configured in Ardumote (default is 7777)...
int LED_Pin = 7;  //Set LED_Pin to Pin 7 - Place an LED on Pin 6 of your ethernet shield for testing this code
// buffers for receiving and sending data
char packBuff[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
EthernetUDP Udp;

int MotionLED =  9;      // the number of the Sonic Sensor LED Motion output Pin
int LED1 =  22;      // the number of the LED1 Pin

String readString = String(30);  // sets the webserver strings
String state = String(3);  // sets the webserver strings

//TMP36 Pin Variables - this is the Temp sensing chip, look like a transistor
   int OutdoorT_Pin = A6;        //the analog pin the TMP36's Vout (sense) pin is connected to this analog input 6
                       //the resolution is 10 mV / degree centigrade with a
                       //500 mV offset to allow for negative temperatures
   int OutdoortempReading;        // the analog reading from the sensor

 // Temp36 SMOOTHING
  // Define the number of samples to keep track of.  The higher the number,
 // the more the readings will be smoothed, but the slower the output will
 // respond to the input.  Using a constant rather than a normal variable lets
 // use this value to determine the size of the readings array.
 const int numReadings = 120;     // the average sample length
 int readings[numReadings];      // the readings from the analog input   was int readings[numReadings];  
 int index = 0;                  // the index of the current reading
 int total = 0;                  // the running total    int total = 0;
 int Outdoor_averageTemp = 0;    // the average   was   int Outdoor_averageTemp = 0;

// END OF TMP36 Pin Variables

void setup()
     Udp.begin(localPort);    //Ardumote  Setup UDP socket on port defined earlier.  THIS LOCKS UP UPON BOOT
     pinMode(LED_Pin,OUTPUT);    //Designate pin 7 as Output Pin
     pinMode (2,OUTPUT);//attach pin 2 to vcc for Ultrasonic HC-SR04
     pinMode (5,OUTPUT);//attach pin 5 to GND for Ultrasonic HC-SR04
    Serial.begin(9600); //Start Serial terminal
 // TEMP36 Temp sensor SMOOTHING
    // initialize all the readings to 0:
     for (int thisReading = 0; thisReading < numReadings; thisReading++)
     readings[thisReading] = 0;      
    // for the LED1 output control from webpage
     pinMode(LED1, OUTPUT);  
     state = "OFF";
    // start the serial SHT21 digital temp/hum sensor on pins 20 + 21
     Wire.begin(); //brings in the SHT21
     Serial.print("RESET   ");  // I (DAN) added this to show RESET on the serial logger when the RESET button is pushed, or when the SERIAL logger is run.  
    // beginning of Serial 2x16 LCD Backlit with speaker (1 wire connection) http://learn.parallax.com/KickStart/27977
     mySerial.begin(9600); // anything with "mySerial" is Dans Serial LCD
     pinMode(TxPin, OUTPUT);
     digitalWrite(TxPin, HIGH);
     mySerial.write(12);  // Clear Screen
       mySerial.write(208);                // sets the note length to 1/4   (208-214)
       mySerial.write(231);                // A tone (G+)   (220-232)
       mySerial.write(12);                 // Clear            
       mySerial.write(17);                 // Turn backlight on
       delay(1);                           // Required delay
       mySerial.print("BOOTING UP...");    // First line
       mySerial.write(13);                 // Form feed
       mySerial.print("Server v8b!");          // Second line
       delay(1000);                        // Wait 1/4 second
        mySerial.write(18);                // Turn backlight off
        mySerial.write(12);                // Clear LCD
   // end of serial LCD setup

   //Serial.write(0xFE); //ATTN LCD

   //Serial.write(0x01); //Clear LCD
   mySerial.write(12);  // Clear  LCD (dans serial LCD)

   //Serial.write(0x7C); //ATTN

   // Serial.write(157); //Full Display Brightness
   mySerial.write(17);                 // Turn backlight on

   //Serial.write(0xFE); //Attn
   //Serial.write(128); //Mv cursor to line 1, col 1 on LCD
   delay(5);                           // Required delay

    //delay(1000); // Do not f* with this line. It ensures that the LCD is ready to receive data.
    Serial.println("Waiting for DHCP request..."); // print on serial monitor
    mySerial.print("DHCP request...");  // First line
    mySerial.write(13);                 // Form feed
    delay(1000);                        // Wait 3 seconds - keeps LCD on to read it
    mySerial.write(18);                 // Turn backlight off

    if (Ethernet.begin(mac) == 0) {
    mySerial.write(12);  // Clear Screen
    Serial.println("DHCP Address Failed - STOP");  // Print message and halt Arduino. We need an IP.
    mySerial.print("DHCP Address Failed - STOP");

    ; //Endless loop.
    server.begin(); // Start Web server.
    Serial.println("Starting Web server.");
    mySerial.print("Starting server");

    mySerial.write(12);  // Clear Screen

Nick Gammon

Read this before posting a programming question

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Please post technical questions on the forum, not by personal message. Thanks!

More info:

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131