Arduino ethernet Problems

Hi, I have been working on this code for some time now.
The Xivley online upload and the SD card writing don’t work together.
They work fine separately, not not together. I have commented out one of them and the other works.
I’ve tried a bunch of stuff to fix it.
What the program does is, it reads values from 4 sensors and acquires 6 variables to store.
These 6 variables just need to be uploaded to xivley live, and be writen on the SD card.
Here is the code that i have so far. Please help me out if there is anything that can be done to resolve this issue.
Thanks.

`/*
SD card datalogger

This example shows how to log data from three analog sensors
to an SD card using the SD library.

The circuit:

  • analog sensors on analog ins 0, 1, and 2
  • SD card attached to SPI bus as follows:
    ** MOSI - pin 11
    ** MISO - pin 12
    ** CLK - pin 13
    ** CS - pin 4

created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it’s not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;
// MAC address for your Ethernet shield
byte mac[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90};
char xivelyKey[] = “XxxxxxxxxxxxxxxxxxxxXXXXXXXXXX”;

// Analog pin which we’re monitoring (0 and 1 are used by the Ethernet shield)
int sensorPin0 = 0;
int sensorPin1 = 2;
int sensorPin2 = 1;
int sensorPin3 = 5;
const int numReadings = 10;
const int chipselect = 4;
const int echipselect = 10;
double Voltreadings[numReadings]; // the readings from the analog input
double Currentreadings[numReadings];
double Volt2readings[numReadings];
double Current2readings[numReadings];
int index = 0; // the index of the current reading
double total = 0; // the running total
double total1 = 0;
double total2 = 0;
double total3 = 0;
int voltaverage = 0; // the average
int currentaverage = 0;
int volt2average = 0;
int current2average = 0;
int powern=0;
int powers =0;

// Define the strings for our datastream IDs
char Voltage_north[] = “Voltage_north”;
char Voltage_south[] = “Voltage_south”;
char Current_north[] = “Current_north”;
char Current_south[] = “Current_south”;
char Power_north[] = “Power_north”;
char Power_south[] = “Power_south”;

void setup()
{
// Open serial communications and wait for port to open:

//Serial.begin(9600);

//Serial.print(“Initializing SD card…”);
// make sure that the default chip select pin is set to
// output, even if you don’t use it:
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
digitalWrite(4, LOW);

// see if the card is present and can be initialized:
/if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
// don’t do anything more:
return;
}
/
digitalWrite(4, HIGH);
//Serial.println(“card initialized.”);
for (int voltReading = 0; voltReading < numReadings; voltReading++)
Voltreadings[voltReading] = 0;
for (int currentReading = 0; currentReading < numReadings; currentReading++)
Currentreadings[currentReading] = 0;
for (int volt2Reading = 0; volt2Reading < numReadings; volt2Reading++)
Volt2readings[volt2Reading] = 0;
for (int current2Reading = 0; current2Reading < numReadings; current2Reading++)
Current2readings[current2Reading] = 0;
}

void loop()
{
double sensorReading = analogRead(sensorPin0);
double outvolt = sensorReading*5/1024;
double voltageread= (100.03)*outvolt + 0.1436;
double sensorcurrent = analogRead(sensorPin2);
double outcurrent = sensorcurrent *5/1024 ;
double currentread = (3.3727)outcurrent - .0025;
double sensorReading2 = analogRead(sensorPin1);
double outvolt2 = sensorReading2
5/1024;
double voltageread2= (99.653)*outvolt2 + 1.8825;
double sensorcurrent2 = analogRead(sensorPin3);
double outcurrent2 = sensorcurrent2 *5/1024 ;
double currentread2 = (3.3649)*outcurrent2 - .002;

Voltreadings[index] = voltageread;
total= total + Voltreadings[index];
Currentreadings[index] = currentread;
total1= total1 + Currentreadings[index];
Volt2readings[index] = voltageread2;
total2= total2 + Volt2readings[index];
Current2readings[index] = currentread2;
total3= total3 + Current2readings[index];
index = index + 1;

if (index >= numReadings)
{
voltaverage = total / numReadings;
currentaverage = total1/numReadings;
volt2average = total2 /numReadings;
current2average = total3 / numReadings;
powern = voltaverage * currentaverage;
powers = volt2average * current2average;
digitalWrite(10, LOW);
XivelyDatastream datastreams[] = {
XivelyDatastream(Voltage_north, strlen(Voltage_north), DATASTREAM_FLOAT),
XivelyDatastream(Current_north, strlen(Current_north), DATASTREAM_FLOAT),
XivelyDatastream(Power_north, strlen(Power_north), DATASTREAM_FLOAT),
XivelyDatastream(Voltage_south, strlen(Voltage_south), DATASTREAM_FLOAT),
XivelyDatastream(Current_south, strlen(Current_south), DATASTREAM_FLOAT),
XivelyDatastream(Power_south, strlen(Power_south), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(55555555555, datastreams, 6 /* number of datastreams */);

EthernetClient client;
XivelyClient xivelyclient(client);

datastreams[0].setFloat(voltaverage);
datastreams[1].setFloat(currentaverage);
datastreams[2].setFloat(powern);
datastreams[3].setFloat(volt2average);
datastreams[4].setFloat(current2average);
datastreams[5].setFloat(powers);

index = 0, total = 0, total1 = 0, total2 = 0, total3 = 0;

int ret = xivelyclient.put(feed, xivelyKey);
digitalWrite(10,HIGH);

// make a string for assembling the data to log:
String dataString = String(voltaverage)+","+String(currentaverage)+","+String(powern)+","+String(volt2average)+","+String(current2average)+","+String(powers);

// read three sensors and append to the string:

digitalWrite(4, LOW);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open(“SDwE2.csv”, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
//Serial.println(dataString);
digitalWrite(4,HIGH);
}
// if the file isn’t open, pop up an error:
else {
//Serial.println(“error opening SDwE2.csv”);
}
}
delay(4000);
}`

wrong forum???

Yeah, sorry @rjthomas, but this is the Electric Imp forum - we can’t help you with Arduino queries unless you’re converting Arduino code to run on the imp. We like Arduino, but it’s a completely different platform from ours.