Im fairly new to the arduino community, one of those guys that wouldn't ask for help unless ive come to the end of the road.
This code is for a hydroponics pH automated doser. Through the use of a pH probe, a pH shield, an Arduino UNO r3, and a peristalic pump; this code would sense the pH too high and send signal to the relay to power on the pump until the pH was back down to an acceptable range. Day 4 of this issue though has left me with the option of just timing a relay to come on every other day and run the pump for a few seconds hoping it is in the ballpark of the range that is accepted.
What is happening in the included code is that randomly, it hangs, leaving the pump on and dispensing all the ph buffer causing the whole system to be acidic.
As previously mentioned, I am fairly new to Arduino. There are most likely lots of issues with the code included, all thoughts and comments are very much welcomed.
I would say that you are almost certainly running out of memory. I suggest you do some investigation into PROGMEM. There's a whole thread on here about it. I'm sure someone will be able to give you a link to it.
Alright, I've added progmem to all of my strings that I could and added
unsigned char PROGMEM myFont [][8]={
just before the unsigned char
is there something I need to define for progmem or am I good just added the F macro to the strings a unsigned char fonts?
Also, there is a minor annoyance on the startup of this sketch. There is a signal sent to the relay for a couple seconds before the loop is started. Normally I wouldn't care, however, the solution gets a much larger dose of acidic solution. I have gone back through and edited what I could out and try a few things. Is this something that I will just need to get over?
Agh, I can't believe you chose pin 13 for your relay. It's connected to the onboard LED. This is flashed when there's any activity on the serial port and I believe this is why it gets flashed as the serial port is initialised on start up. Naturally this flashing will be setting your relay off. Could you pick another? such as 12,11,10,9,8,7,6,5,4,or 3, (don't use 2 or 1 either, they also get affected by coms)
UKHeliBob:
Is this really the case, because it does not happen to me using a Uno.
I have a mega2560 and every time I reset it I get two clear pulses of the onboard LED. Each about half a second in duration. This happens before the setup() function has even started. Furthermore, if I put an LED in pin13 this also strobes with it.
I have a mega2560 and every time I reset it I get two clear pulses of the onboard LED. Each about half a second in duration
What I was querying was the statement that the LED on pin 13 is flashed when there's any activity on the serial port. There may be reasons not to choose pin 13 but that is not one of them.
This morning I've changed the output pins from 12 and 13 to 6 and 7, with 6 being the one that is used currently. I've made the changes I thought were correct with the progmem and unsigned char. After uploading the modified sketch, a signal is sent to pin 6 and the OLED is blank. I don't think I did the progmem correctly, were as before I had something on the OLED and the relay was running only before the loop started.
I think the first order of business is to send the output to the Serial object and use the Serial.print() method to see if your functions are producing the results you want. Then I would check to make sure the OLED is properly working. Try placing the following fragment into setup():
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
delay(DISPLAYDELAY);
and supply a draw() function that looks something like:
I had to take out all the progmem code as I was in a very different mindset this morning.. One should probably not spend all day in heart surgery and come home to figure out code. My apologies to Nick Gammon for the omitting progmem out of the sketch. I am not sure where I was going with things this morning, but I am certainly unable to return. I've been given a couple more days to figure this out or dump the project and go commercially. Much thanks for those who are helping and kudos to your patience.
I have submitted the sketch without progmem, with the changes made to the pin assignments. I am still having the problems with the code freezing randomly which we have learned is associated with the lack of memory. Also, I've inlcuded yet another failure on my end. In the code below, the first "if" statement works. The second "if" will print screen but doesn't send the signal to pin 7.
if(avgMeasuredPH > 6.3) //When pH is above 6.3, pH Down is given
{
digitalWrite(relayPin,LOW);
setXY(4,0);
sendStr((unsigned char*)"pH Down Going");
}
else
{
digitalWrite(relayPin,HIGH);
setXY(4,0);
sendStr((unsigned char*)"PH Down Hold");
}
if(avgMeasuredPH < 5.8) //When pH is below 5.8, pH Up is given
{
digitalWrite(relayPin1,LOW);
setXY(5,0);
sendStr((unsigned char*)"PH Up Going");
}
else
{
digitalWrite(relayPin1,HIGH);
setXY(5,0);
sendStr((unsigned char*)"PH Up Hold");
}
I'm getting a whole lot of errors trying to compile your code:
/tmp/ccrxbuSN.s: Assembler messages:
/tmp/ccrxbuSN.s:1318777: Warning: .stabs: description field '14625' too big, try a different debug format
/tmp/ccrxbuSN.s:1318778: Warning: .stabs: description field '1469a' too big, try a different debug format
/tmp/ccrxbuSN.s:1318786: Warning: .stabs: description field '14f75' too big, try a different debug format
/tmp/ccrxbuSN.s:1318955: Warning: .stabs: description field '1018b' too big, try a different debug format
/tmp/ccrxbuSN.s:1318956: Warning: .stabs: description field '107d0' too big, try a different debug format
/tmp/ccrxbuSN.s:1318959: Warning: .stabs: description field '10003' too big, try a different debug format
/tmp/ccrxbuSN.s:1318960: Warning: .stabs: description field '105e9' too big, try a different debug format
/tmp/ccrxbuSN.s:1318961: Warning: .stabs: description field '10dc5' too big, try a different debug format
/tmp/ccrxbuSN.s:1318965: Warning: .stabs: description field '1058f' too big, try a different debug format
/tmp/ccrxbuSN.s:1318966: Warning: .stabs: description field '10d54' too big, try a different debug format
I curious too as to whether the relay is causing some of the issues with random hanging. There is a 2 channel 5v relay connecting the 12vdc pump for signal and a few times during startup, my OLED has froze or the pump just continued pumping as if the code froze.
Sketch uses 17,970 bytes (55%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,573 bytes (76%) of dynamic memory, leaving 475 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur.