Problem: when I turn on one of the relays using either the Centipede or Adafruit libraries the DS1307 sends garbage time by time which messes up the execution (it's a reef tank controller). I believe it is a hardware issue.
I have a DS1307 in use in a comparable setup (the device with other on the I2C bus) and it's working correctly. You didn't post the circuitry you use, so I'm guessing wrong pull-ups for the I2C bus (or even no externals with just the internal). If this is the case the communication gets shaky and often you loose communication completely. Post the wiring you use as well as the code you use.
Pylon, thank you very much. I have tried no pull ups as well as 1Kohm pull ups with the same results. I have tried also two different libraries for DS1307 with same results. Moved the load around on different ports on the two relay boxes with same results.
It does look like the update from DS1307 on I2C gets corrupted randomely.
Pyton, once again many thanks.
No, I do not own an oscilloscope so I can not see the signal shape.
Do I have to pull up each individual MCP23017 ? The DS1307 has by design pull ups of 1KOhm on SCL and SDA. Should I replace them with 3K3 and keep them as the only pull ups on I2C ?
Thank you Pylon.
... found 10k on the DS1307 board for pull up on SCL, SDA and SQW/OUT. Replaced all with 2K7 though I was not sure if on SQW/OUT 2k7 is the appropriate value. What is the recommended value ?
Connected all the clients on the relay boxes (pumps and lights) and everything works well. Bummer ! When I connect the ballast for metal halide light I get random resets on the DS1307 !?! It happens only on this client regardless of which port and relay box is connected.
All the SSR are identical and they were used before without any problem directly from Arduino digital pins.
The 2k7 is not necessary for the SQW/OUT, it's just an output signal you probably don't use anyway. You could have left the 10k there but just leave there what you currently have.
As for the resets. Sounds strange. Does the Arduino reset too or just the DS1307? How do you realise that the DS1307 did reset? But to be able to give any comment there you have to give more details about your whole setup. What power do the halides use? What type of SSR are you using (best would be a link to the datasheet). Do you have a schematic how the SSRs and the MCP23017 are connected? Is the DS1307 already battery backed?
*** disclaimer *** - i am by NO means an expert but i ran into similar issues with the same chips ....
You only need one set of pullup resistors on SDA and SCL. if you are not using the square wave output of the DS1307 for anything i would leave that pin floating - i have never connected anything to that pin.
Can you provide a diagram of how you are interfacing your SSR's to the MCP23018? Also, is the length of your i2c bus unusually long? I do not believe it should be more than a few feet, but optimally the bus should all be on the circuit board.
What kind of SSR's are you using? i had trouble switching ballasts with SSR's and use regular relays for this. I believe this is because my MH ballasts are actually an inductive load (seems counter-intuitive being that its ultimately a light). I had this issue with an IceCap MH ballast, and my Phillips T5 ballasts.
For the garbage response you are getting back from the DS1307 - is it gibberish, or just an incorrect time?
If you are getting a time back, but not the correct time, i would replace the crystal and make sure its placed as close to the pins as possible. I have run into this issue, i have found that when using a DS1307 on a breadboard, an easy solution is to put the DS1307 in a dip socket with the leads from the crystal carefully inserted into the same 2 holes the pins from the chip go in. Then cutoff the 2 pins at the bottom of the socket.
I have a DS3234 (SPI) and a DS3231 (I2C) and had random resets with them. It was fixed once I put a 10uF electrolytic capacitor across +5 and Gnd at/near the RTC chip.
Neither chip seems to like power glitches.
I agree with El Supremo, especially if there are relays in the same room !
Decouple the 5 volt supply with capacitors ( 100nF near any chip, and 47 mFd nearby ) and definately at least 470mFd on any relay supply ( plus a diode across the relay coil - reversed polarity )
thank you very much. The I2C from Arduino gets radially distributed. I have on a shield two rows of four pins (+, -, SCL, SDA) paralleled. One row goes to LCD, the second one to the first power box and from there further to the second. The LCD cable is about 5 feet, LCD works well anytime. The second line to the first power box is of the same length 5 feet and between boxes around 2 feet.
When I turn the MH ballast on, after a short time I can see on display the time going to 00:00 for a brief (one or two seconds) and recover after that. This will be enough to make the logic think is night and turn MH off. If I let the ballast recover it will turn on again and again the time will get reseted leading to an off sequence.
The ballast is the only one doing this.
In the power box I have a small pcb with MCP23017. /RESET is connected to +V through a 1K resistor (positive reference), outputs are connected directly to SSR (+). All the (-) are collected in one point.
If I'm reading correctly, that's a 7 foot I2C cable which would naturally be very sensitive to noise at the standard Arduino 100KHz speeds.
Not guaranteeing this will work, but slowing down the I2C may help. Obviously then I2C operations will be slower.
If you want to try 10KHz instead of 100KHz, put the following in your setup() function immediately after the Wire.begin();
TWSR |= (1 << TWPS0);
TWBR = 198;
The formula for calculating new TWBR values:
TWBR = ((FCPU/FSCL) - 16) / (2 * 4 ^ TWPS)
TWPS is the value of the TWPS0 and TWPS1 bits in the TWSR register (0, 1, 2, or 3). If your calculated TWBR is more than 255, increase the TWPS value by one.
Greetings father of the Centipede library and many thanks. Noise is one of the reasons I suspect. Not finding anything on the max length of the I2C bus I went ahead (since my last post) and trimmed all the cables to their fit in the aquarium stand. I am using RJ45 connectors phone line cable and is not that difficult.
Does it matter if the feed for the bus is in the middle of the line with I2C clients both sides ?
... I am replying to my own post (isn't this something ) I've learned that even with the I2C clock lowered more than 4 feet per bus length is not working. At this stage I suspect that the clone DS1307 is not working properly.
Try attaching it directly (max a few inches of wire) to the Arduino and nothing else (the DS1307 solely). If it doesn't work in this situation I'd also assume it's broken.
Strange things happen sometimes !
I have replace the entire setup with a new Arduino and a different shield for DS1307 this time a Duemilanove. Same thing: when the metal halide lamp came on in a matter of a few minutes the time went briefly to 00:00 and the light turned off. The next second the time was displayed correctly.
Next, I disconnected the metal halide SSR from the MCP23017 and fed it directly with a digital pin from Arduino. Same thing: when the metal halide lamp came on in a matter of a few minutes the time went briefly to 00:00 and the light turned off. The next second the time was displayed correctly.
The last thing that I can do is to replace the SSR with a mechanical relay. Let's hope this will work because I run out of hardware ideas =(
Another way will be to control the metal halide ballast in a different way in software. Some thing like check for start time and if the answer is true start a timer in a countdown fashion. Is there any library that can do this ?
Total failure so far ! Everything I tried did not work. I went ahead and removed the MCP23017 from the relay boxes and wired everything directly to Mega digital pins (reduce I2C need). Still when the metal halide ballast comes on the time values read from DS1307 becomes unstable. Without, everything works perfect.
I went ahead and bought a DS3231 which is suppose to be less sensitive to EMI since the oscillator is incorporated. We will see.
Meanwhile, does anyone know how to reduce the noise coming from this ballast and make Arduino less sensitive ?