Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Ethernet shield - missing components on: February 28, 2014, 02:46:04 pm
Does anybody know where, physically, the 4 leg chip that converts the raw 'reset to 'reset_w' is on the 2010 rev 5 version of the Ethernet  shield?
 I've got a couple of these shields that are supposedly the genuine article but for the life all I can find is 4 unused solder pads in the bottom left corner of the PCB next to the reset button itself.

2  Using Arduino / Storage / Re: Sd Card & Ethernet Problems on: January 05, 2014, 06:44:23 am
It's now looking as there is nothing wrong with the code or with the Uno or the Ethernet card or the SD card!!!

I was reading elsewhere about electrical interference and then my son mentioned that when his microwave started up  his main ADSL modem/router had a funny five minutes I started looking at interference rather than for a code bug. It turns our that the W5100 chip is particularly sensitive to magnetic spikes from adjacent curcitry .

I can now make the problem happen at my command (or not as the case might be)  but I needed a couple of Capacitor resistor snubbers across some relay contacts and ferrite sleves on the 9V supply lead to the Uno.
3  Using Arduino / Storage / Re: Sd Card & Ethernet Problems on: December 04, 2013, 12:01:04 pm
Well the smiley is in fact a '$ )' couplet, but that's not the problem I cant get Surffer-Tim's bit of code to compile once its added to my own code.

I've put

#include <w5100.h> in with the other include statements  but all I get out is:-

TimeStampedTemperatureData44f.ino: In function 'void ShowSockStatus()':
TimeStampedTemperatureData44f:452: error: 'w5100' was not declared in this scope

when it hits the

uint8_t s = w5100.readSnSR(i);

line in 'ShowSockStatus() function.

Now if I go
#include "w5100.h" then I get the following:-

TimeStampedTemperatureData44f.ino:125:19: error: w5100.h: No such file or directory
TimeStampedTemperatureData44f.ino: In function 'void ShowSockStatus()':
TimeStampedTemperatureData44f:452: error: 'w5100' was not declared in this scope

Which tells me that the use of <w5100.h> is right but the compiler/linker is loosing its ability to see the relivant files during the compile. 

As my sketch is falling over on its Ethernet connection and stops behaving as a web server it would be rally nice to know if I'm running out of sockets. 
4  Using Arduino / Storage / Re: Sd Card & Ethernet Problems on: December 03, 2013, 03:48:25 am
Hi thanks for the cod,e but I cant make it compile with my sketch!!

I get two errors

A stray smiley-money at the end of the uint8_t dip[4];  line which I presume is a typo
and ' 'w5100' was not declared in this scope' despite my putting an #include <w5100.h> at the front of the code

The actual file w5100.h is in the utility directory under the Ethernet directory on the PC which is where it always ha been .
5  Using Arduino / Storage / Sd Card & Ethernet Problems on: December 02, 2013, 02:20:10 pm
Physical hardware: Uno, Ethernet card, SanDisk Class 4 4Gbyt MicroSD card(formatted as FAT32) , IDE 1.0.4

I have a data logging sketch that records info on an SD card at 10min intervals. It also serves up a web page that allows the current info to be viewed over the Ethernet. Some times it will run for weeks and other times the Ethernet shield does not respond to a GET request from the PC after a couple of hours (The Wiz 5100 does not respond to a Ping either. Ping just tells me the device is unreachable).

I have set the SD card CS pin high at the beginning of the programme, So I'm now wondering if there is a subtly in the order of the Ethernet/SD card setups that Ive got wrong. Or is a class 4 micro SD card is too slow? (does any one know if an SD card slows down when it gets warm?)

The ambient temperature where the unit is 25-28DegC The chips do warm up but you can still touch them with out going 'ouch'

The Sketch is big (30K) and FreeRam() is telling me that I've got 450 - 500 bytes of SRAM free depending where I put it in the code. And the fact that it can run some times for months suggests that there is no memory leak.

This is the 'Setup' part of the code
// Chip Select Pins
#define sdChipSelectPin 4
#define ethernetChipSelectPin 10
// Relay Output Pins
#define RelayPinDifferential 8        //limit stat defaults to 60C
#define RelayPinVariable 9            //variable stat with calculated temperature
// Define Clock Variables
volatile boolean TickTock [8];         //Used as a set of flags to control interupt output and timed events
volatile unsigned long systime = 1385798455UL; //946684800UL; //default time at start of year 2000;
long timeError;                       //error in systime when getting ntpEpoch

char dateTime [12] = "01 12:59:59";       //to hold dateTime

char fileName [13];                   //to hold file on SD card nb the date (year&month) is overwritten each month
char fileRequest[13];                 //File Client requests
const byte MAX_PAGE_NAME_LEN = 12;    //max characters in page name
byte fileBufferLen = 0;

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

#include <EEPROM.h>

// MAC address for controller below.
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //was ED!

const unsigned int localPort = 8888;           // local port to listen for UDP packets
// list of NTP servers so we don't have to look them up again
//ntp_servers[0] timeServer(213,123,26,170);   // time at BT
//ntp_servers[1] timeServer(94,44,157,90);     // Europe pool
//ntp_servers[2] timeServer(192,43,244,18);    // NTP server US

const IPAddress ntp_server (213,123,26,170);   // use BT
const IPAddress ip (192,168,1,62);             //62 Fixed IP for server DCHP takes up too much space
const IPAddress localdns (192,168,1,254);
const IPAddress gateway (192,168,1,254);
const IPAddress subnet (255,255,255,0);

// setup for ethernet
// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
// Initialize the Ethernet server library
// HTTP defaults to port 80
EthernetServer server(80);
EthernetClient client;

const byte BUFFER_LEN = 48;           //TC/IP Output buffer
byte Buffer[BUFFER_LEN];
//setup for temperature measurement N.B. arrays are zero indexed
unsigned int readings[6];       // accumulates the readings from the analog inputs
                                // NB these numbers are 16 times A/D conversion figures
boolean temperatureRising[6];   // HIGH indicates thermostat has switched OFF on temperature rise

int TCTemps[24];               // set points for transfer curve 0-5 for used figures,6-11 default,
                                // 12-17 for max 18- 23 for min
int SetPoints [24];            // Temeratures which will always cause a switch OFF
                                // resistors in measurement bridge
const long Pullup = 4700;       // 4700 measured value
const long VoltDiv1 = 4690;     // 4700 measured value
const long VoltDiv2 = 1426;     // 1436 measured value in parallel with internal resistor
int counter;
//DEFINITION for bottom of 'convert2temp' just so it does not have to be calulated every time and we dont have to divide the toals either
const long VoltDivider = (VoltDiv1+VoltDiv2)*1024*16/VoltDiv2;

void setup()
  // flip the relays so we know its all connected
  pinMode(RelayPinDifferential, OUTPUT);   //Set relay driver pins to OUTPUT
  pinMode(RelayPinVariable, OUTPUT);       //ie Digital pins 8 & 9
  digitalWrite(RelayPinDifferential, HIGH);//Set them HIGH so inital state of relays
  digitalWrite(RelayPinVariable, HIGH);    //is power off

  // Set up CS pins for SD card and Ethernet
  pinMode (ethernetChipSelectPin,OUTPUT);   // make sure its OUTPUT
  pinMode (sdChipSelectPin,OUTPUT);         // make sure its OUTPUT
  digitalWrite(sdChipSelectPin, HIGH);      // make sure its off
  digitalWrite(ethernetChipSelectPin,HIGH); // make sure its off
//  Serial.begin(9600);                         // for debuging
//Get other info from EEPROM
  for (byte i = 0; i<=23; i++){
    SetPoints[i] = Byte2Int(;   
    TCTemps[i]   = Byte2Int(; 
//Set up reference for Analog input
  analogReference (EXTERNAL);//Use External to avoid any dependancy on Vcc
  analogRead (A0);           //force the procesor to listen 

// use fixed IP address (DHCP seem to add 4k to sketch)
  digitalWrite(ethernetChipSelectPin,HIGH); // make sure its off
// line start the Ethernet server
//Check presence of SD card
  if (!SD.begin(sdChipSelectPin)) { //card initialized.
    // don't do anything more:

  // initialize timer1
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
                            // runs slow @ 15624 fast @ 15563 try 15601which is slightly too
                            // fast and causes double dipping for time stamp after 24hours
  OCR1A = 15602; //0x3CF2;  // compare match register for 1Hz output
  TCCR1B |= (1 << WGM12);   // CTC mode
  TCCR1B |= (1 << CS10);
  TCCR1B |= (1 << CS12);    // 1024 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();             // enable all interrupts

//Get start time from NTP
  TickTock[4] = true;       // Flag start up for record in data file
  sendNTPpacket();          // send an NTP packet to a time server using a range of addresses it could still come back
                            // with zero but its unlikely It will be flaged and try again on first 10min cycle
  breakTime(systime);       // So make up the file name for the current data This gets updated automatically
                            // but we might not want to wait after a restart
  //get initial fill of average temperature data from each sensor
  for (byte j = 0; j<128; j++){ //use 128 lots of readings for the first load of the array
//  Serial.print (systime);
} //end 'setup'

Interestingly the sketch continues to loop and do all the things It's supposed to even when it stops talking to the pc on the other end of the local network.

This has been bugging me for a year now, I've already tried Surfer-Tim's Timeout trick, in case it was a hardware/Ethernet wiring problem, to no avail. I've also tried to introduce several Serial.print(... statements to debug and find if any of the code stops working but usually the serial monitor overflows and crashes before the communication with the network falls over

6  Using Arduino / Programming Questions / Re: Printing what should be an ordinary integer returns a Max size unsigned long val on: November 29, 2013, 11:48:02 am
Thanks for that, As always a small Syntax error causes the problem, but the more you look at the code the less you see!!
7  Using Arduino / Programming Questions / Re: Printing what should be an ordinary integer returns a Max size unsigned long val on: November 29, 2013, 02:34:11 am
Yes I guessed that was part of the effect if the EEPROM is 0xFF then the Byte2Int(int i) function should turn it into 0xFFFF which is stored as a signed integer and is  -1 in decimal. But the number I'm getting out in the data file is 4294967295 which is a maximum size UNSIGNED LONG 0xFFFFFFFF.

The error seems to arise in the 'datafile print' part of the of the code as the rest of the arithmetic is using the correct value of -1 in the sums and Client.print works correctly when outputting the webpage
8  Using Arduino / Programming Questions / Re: Printing what should be an ordinary integer returns a Max size unsigned long val on: November 28, 2013, 02:55:18 pm
I was using 1.0.4 but I've just downloaded 1.0.5 and it does the same thing.

The whole code is attached. It compiles to just over 30K and has about a quarter of the SRAM left free. I highlighted the relivant bits of code in the first post suspecting that there is a simple answer in the way the arduino implementation handles casts or there might be a known quirk in the client.print/ datafile.print routines
9  Using Arduino / Programming Questions / Printing what should be an ordinary integer returns a Max size unsigned long val on: November 28, 2013, 11:53:59 am
     Can any one explain this phenomenon to me.

     I have a sketch where I'm storing some fixed thermostat temperature values as single bytes in the EEPROM of a Uno, they only need to be read on setup and startup. These values are in the range -20 to +100 so they are being stored  as 8 bit compliment form in  a single byte.

     On startup they are read into an integer array to avoid 'wear' on the EEPROM

     Occasionally these thermostat Break points need to be setup/changed and the values are written to the EEPROM with>

if (!k) {
        SetPoints = newvalue;
        EEPROM.write(i,SetPoints);// Set new Default or range limit value

     Another part of the programme checks if the 'newvalue' is in a valid range and different to the old value and sets 'k' to flag the need to write the new value into the integer array and EEPROM. This routine obviously discards the upper byte which would be 0 for numbers up to 100 and all 1's for the -ve values.

     When reading the EEPROM back Because of the possible -ve value I'm converting them to true 16bit integers with a little routine.

int Byte2Int(int i)
  return (bitRead(i,7) ? i|0xff00 : i);

called by

SetPoints = Byte2Int(

from a for loop

    Now when I subsequently read from an EEPROM address that I haven't written to yet and then print the value to the SD card with


 I get 4.2..E9. in the output file - ie the biggest unsigned long integer that the Uno can handle????

10  Using Arduino / Motors, Mechanics, and Power / Measuring AC Power to make best use of Solar Panel output on: October 14, 2013, 11:17:03 am
Hi, Appoligies to the moderators if this is in the wrong place, but 'High Power Controls' or 'Home Automation' appear to be the best bet for this subject.

Has anybody tried to make a power measuring system using a four quadrant analogue multiplier like the AD 633? I believe the DC output of one of these could be feed to the Arduino's analogue inputs. Using such a chip means that you are only digitizing 1 input instead of 2. By oversampling and decimation, rather than averaging, it would also be possible to improve on the 10bit accuracy of the native ADC.

I'm looking to make a system that diverts the output from my Solar Panels that I don't use during the day to batteries so that it can be used a night. (at the moment 60+%  of production is sold to the grid and I buy in at least the same again at night)

I've seen several implementations of the 'Open Energy Monitor' that use the Arduino's analogue inputs, but the sampling rate of multiple volt and current waveforms takes tens of mains cycles and several seconds to come out with the power being transmitted on the mains side. It also strikes me that there is precious little processing time left to get the Arduino to then control what one might do with the numbers obtained.
The system is also prone to accumulated errors including:-

       The problem of multiplying the instantaneous current value with the voltage value that by definition was worked out earlier.
This is a built in Power Factor error.

       The DC biasing in the circuit means only a 5bit accuracy of current or voltage. this severely limits the range of the output given that the RMS value of the Voltage will not alter very much.

        Theoretical error figures of over 15% are quoted in some places.

I don't think that the input side of the 'Open Energy Monitor' is up to simultaneously measuring the three 'power' figures that I'll be looking for. The AD633 has a probable error of 2% and some other analougue multipliers are eve n better. Has anybody seen and used anything better?

11  Using Arduino / Project Guidance / Re: Over writing Leonardo Boot loader and retaining Serial.print capability on: September 11, 2013, 01:01:41 pm
Thanks to Paul__B you've confirmed what I hoped to be the case, but I did not want to spend £ 20 only to discover that I would need to buy both a Mega and a new box to put it all in. I still don't understand why the bootloader for the Leonardo is so big Tough

Yes Peter I know programme, SRAM and EEPROM are three different things, The programme on the UNO runs to the 31K mark until I take out some debugging code. Add to that there is only about 600bytes of SRAM left when its running. However it is doing a lot of things, reading six temperature probes (which I would like to be 8 - reading the extra 2 will put 3 more lines of code in the programme), deciding which valves to open/close, which heat sources to use, dumping all the data to a log file on an SD card (the log runs up to 400K per month). It also outputs real time data to a web page, takes thermostat settings input from another Web page and allows the data files to be downloaded to a PC over the Ethernet.

By the way I started coding computers in the days of 5 hole punched tape. The luxury of moving from a computer that had just 32 flipflops to store temporary values to a computer that had 2k of magnetic core store you just could not appreciate.
12  Using Arduino / Project Guidance / Over writing Leonardo Boot loader and retaining Serial.print capability on: September 10, 2013, 01:42:40 pm
I have successfully written a solar system control sketch using a Uno but I really need a couple more analog inputs to do some extra monitoring. The existing programme only leaves 400 bytes free ram on the Uno, it has already been carefully optimised to reduce the size and I don't have room in the box to use a Mega so I was going to go down the Leonardo route until I saw that it had a 4K bootloader. 

I know I can use a programming module or even another arduino to be able to use all the 32K programme space but will I lose the ability to use  Serial.print..... for debugging if I zap the bootloader?
13  Using Arduino / Networking, Protocols, and Devices / Ethernet Shield failing? on: May 09, 2013, 11:55:32 am
Does anybody have any experience of partial failure of an Ethernet shield? The symptoms are

a) The standard Web Client code in the tutorials which looks up arduino in google works
b) The Web Server code in the tutorials never returns a client when a request is made via a browser on the PC
c) It will get an NTP time once but not repeatedly. (needs more checking)
d) It still writes additional info to an existing CSV file on the SD card.
e) the SD Card info Sketch works but the SD Dump File doesn't

I've looked at the card under a magnifying glass and bright light, would a dry joint on the MOSI line of the SPI connector on the shield cause theses sorts of faults
14  Using Arduino / Networking, Protocols, and Devices / Re: Where do I post code for help with a large (29K) NTP/UDP and TCP/ip sketch on: April 21, 2013, 06:26:41 am
If all the sockets are in use then what ever is calling for another socket, be it Server or UDP should fail to get one. What I've been showing is that once you top and bottom your code that sends and receives a NTP request with a Udp.begin()/Udp.stop(),  the UDP fails even when there are sockets available and it is allocated one.

I haven't dug deep into the library code yet but I suspect that when a socket is allocated to UDP and that was or is still being used by the server it is not recognised as still being in use.
15  Using Arduino / Networking, Protocols, and Devices / Re: Where do I post code for help with a large (29K) NTP/UDP and TCP/ip sketch on: April 21, 2013, 05:54:33 am
I've found a curious thing with my sketch and the Ethernet Library. I now believe that your original thought that I was running out of Sockets is right but not in the normal overload way. Yes I did have the last CRLF left in the buffer as well but once I cured that problem I still had a problem getting UDP time stamp updates.

As originally coded I put a Udp.begin(localPort); at the beginning of the code to get an NTP time stamp and a UDP.stop(); at the end of that segment of the code. As I was only looking to get a time stamp once a day it seemed reasonable to free up the socket that UDP was using for the rest of the time.

Now by doctoring the Server.available() and the UDP begin() to print out the socket number to the serial monitor showed that in on start up Server.available() claimed socket 0 and UDP claimed socket 1. However once running in the loop as soon as there was a browser request Server.available() hogged both sockets 0 &1, I suspect the reason for two sockets is that the browser starts asking for the Style.css file before its finished receiving the web page. If the sketch called for an updated time stamp it might get socket 0 or 1and it seems to be pure chance as to which it gets If it got socket 1 ie its original socket, the new time was returned any other socket and nothing comes back. I even tried loading the system with several browsers open on various PCs on the network. All 4 sockets were in use but UDP code was only interested in socket 1.

Going a stage further I deleted the Udp.stop() line and moved the Udp.begin() into the setup part of the code. Now on start up Server.available gets socket 0 UDP gets socket 1 and keeps it! Make a browser request for a web page and server.available uses sockets 0 and 2. With this set up the time stamps keep on coming with out any hickcups. So good coding practice of releasing resources when you don't need them creates a problem.

It is my belief that there is either something wrong with the way the server releases sockets or there is something wrong with the way UDP aquires a socket. Certainly there is a an incompatibility between the two.

The code has run for 4 days now with out a problem albeit that the UDP code is hogging one of the sockets, however I think this incompatibility between Server.available() and UDP.begin() should be treated as a bug that needs fixing.
Pages: [1] 2