Go Down

Topic: Arduino uno with ethernet shield problems (Read 457 times) previous topic - next topic

Not sure if it is the program or if it is the router but I can not get the arduino uno with ethernet shield to send data to another pc wirelessly.
Can you view the program and tell me if there is anything that will help it work better. time is running out and I need to finish this before next week. please help    Michael Albert
Here is the code>    Thank you.

/*
*    The purpose of this program is too monitor the voltage of a battery and depending on the voltage generator.
*     The controller needs to handle a wide voltage range and a wide current range if connected to a turbine
*    of varying speed. The speed can vary greatly and therefore the out will have to be carefully monitored.
*
*    The controller will have the following states:
*        - Battery voltage below 14.0v       :    charge the battery
*        - Battery voltage 14.0v or above    :    dump the turbine generator power to a dummy load
*
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>

byte mac[] = { 0x90, 0xA2, 0XDA, 0X0D, 0X8B, 0X11 };  //mac address for Arduino//
byte ip[] = { 192, 168, 3, 178 }; //ip address//
byte gateway[] = { 192, 168, 1, 1 }; //internet access via router//
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(23); // server port

// Voltage divider constants (ohms)
const int    VD_R3                    =    10000;
const int    VD_R4                    =    1000;

// Manual buttons
const int    CHARGE_BUTTON            =    2; // DIN
const int    DUMP_BUTTON              =    3; // DIN

// LED displays
const int    STATUS_LED               =    13; // DOUT

// Battery charging
const int    BATTERY_MONITOR_PIN      =    0; // AIN
const int    INSTRUCTION_PIN          =    6; // DOUT
const float  BAT_VMIN                 =    11.9;
const float  BAT_VMAX                 =    14.0;

// Turbine RPM monitoring
const int    RPM_MONITOR_PIN          =    1; // AIN

// Other
const int    DELAY_TIME               =    32; // 32 default

// Program variables
bool manual = false;
bool charging = false;
EthernetClient client;
void setup()
{
    pinMode(STATUS_LED, OUTPUT);
    pinMode(CHARGE_BUTTON, INPUT);
    pinMode(DUMP_BUTTON, INPUT);
    pinMode(INSTRUCTION_PIN, OUTPUT);
   
    digitalWrite(STATUS_LED, HIGH);
   
    Serial.begin(9600);
    if (Ethernet.begin(mac) == 0){
      Serial.println("Failed to configure Ethernet using DHCP");
      for(;;)
        ;
    }
    Serial.println(Ethernet.localIP());
}

void loop()
{
    int vin = analogRead(BATTERY_MONITOR_PIN);
    float voltage = calculateBatteryVoltage(vin);
   
    int rin = analogRead(RPM_MONITOR_PIN);
    int rpm = calculateRPM(rin);
   
    if (chargeButtonDown())
    {
        manual = true;
        charge();
    }
    else if (dumpButtonDown())
    {
        manual = true;
        dump();
    }
   
    if (!manual)
    {
        if (voltage < BAT_VMAX)
            charge();
        else
            dump();
    }   
   
    manual = false;
   
    delay(DELAY_TIME);
}

float calculateBatteryVoltage(int vin)
{
    float resconst;
   
    if (VD_R3 == 0 || VD_R4 == 0)
        resconst = 1.0;
    else
        resconst = ((VD_R3 + VD_R4) / VD_R4);
   
    return (5.0 / 1023.0) * resconst * vin;
}

int calculateRPM(int rin)
{
    // this function will determine the rpm from an analog value
    // for now just return value passed
    return rin;
}

inline bool chargeButtonDown() { return (digitalRead(CHARGE_BUTTON) == HIGH) ? true : false; }

inline bool dumpButtonDown() { return (digitalRead(DUMP_BUTTON) == HIGH) ? true : false; }

inline void charge() { digitalWrite(INSTRUCTION_PIN, HIGH); charging = true; }

inline void dump() { digitalWrite(INSTRUCTION_PIN, LOW); charging = false; }

inline bool getState() { return (charging) ? true : false; }

void SerialWriteData(float voltage, int rpm)
{
    Serial.print("Voltage: ");
    Serial.print(voltage);
    Serial.print("V");
    Serial.print("RPM: ");
    Serial.print(rpm);
    // TO DO: show whether charging or not
}

Also can not find a proper arduino ip address maybe that is the problem  again help and thanks

billroy

The IP address may indeed be the problem, as you suspect.  The one in the program is on a different network from the gateway, which doesn't work.  Change the 3 in the third octet to a 1 to match the gateway:
Code: [Select]

//byte ip[] = { 192, 168, 3, 178 }; //ip address -- wrong network
byte ip[] = { 192, 168, 1, 178 }; //ip address -- maybe right network

I say maybe because your actual network might be set up differently.  If this doesn't work, it will next help to tell us the IP address of your PC.

-br

NickPyner

#2
Nov 30, 2012, 03:22 am Last Edit: Nov 30, 2012, 03:28 am by NickPyner Reason: 1
I have had an on-line thermometer setup. This used the sketch from Freetronics. The vital difference between mine and yours is that mine uses three libraries

SPI
Ethernet
Webserver

Yours uses three libraries

SPI
Ethernet
Servo

My webserver library surely does what it sounds like it does. You don't have this library and, while I guess your Servo library is vital for your project, it doesn't sound like it is a substitute for Webserver.  If my supposition is correct, therein may lie your problem.

I did not need to use subnet or gateway, but this may be due to using just cable connect to the router.

Cybernetician

#3
Nov 30, 2012, 06:33 am Last Edit: Nov 30, 2012, 06:35 am by Cybernetician Reason: 1
What do you mean by wireless?

Quote

I can not get the arduino uno with ethernet shield to send data to another pc wirelessly.


Did you post your exact code?

Code: [Select]

if (Ethernet.begin(mac) == 0){
     Serial.println("Failed to configure Ethernet using DHCP");
     for(;
       ;
   }


what is this?

Code: [Select]
for(;
       ;


if this comment use // for comment

Use # to post your code
From Idea To Invention

Cybernetician

Use ping in cmd to check response of ethernet device on your network e.g. ping 192.168.3.178
From Idea To Invention

Go Up