Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Managing Arduino RAM - Is this an effective technique? on: December 03, 2013, 05:20:19 pm
Awesome resources, thank you.  I have some nighttime reading ahead of me  smiley

I don't fully understand the idea behind fragmentation - it seems like dynamic Strings tend leave behind "trash" bits which eventually hog all your SRAM. 

How would I know how much space to reserve for my strings?  If I overcompensate the size, will I have funky data?
2  Using Arduino / Programming Questions / Managing Arduino RAM - Is this an effective technique? on: December 03, 2013, 03:51:27 pm
Hi all,

I have an Arduino Mega that I intend to use for logging data of water and air quality.  Using an ethernet shield for writing to a SD, the intent is to log data in time intervals of 5 seconds or greater.  I have four sensors connected via RX/TX, a RTC, a digital moisture sensor, and a few analog devices. 

I'm trying to keep RAM usage at a minimum so I can expand this project in the future.

My general strategy was to use as few global variables as possible and rely on local variables within functions to do my heavy lifting.  My question is:  when I tell Arduino to execute a function (for example 'getTimeDs'), does it store the String that the function was declared as?  Is this a very RAM-intensive code?

Please refer to my paraphrased code:

Code:
void loop() {
  File dataFile = SD.open(fileName, FILE_WRITE);
  if(dataFile) {
    dataFile.print(getTimeDs1307());  //calls for the RTC to get the time
    dataFile.print(", ");
    dataFile.print(getDateDs1307()); //calls for the RTC to get the date
    dataFile.print(", ");
    dataFile.print(getTemperature1()); //calls for the digital thermometer
    dataFile.print(", ");
    dataFile.print(getHumidity1()); //calls for the digital moisture sensor
    dataFile.print(", ");
    dataFile.print(getSensorPH()); //calls for pH
    dataFile.print(", ");
    dataFile.print(getSensorORP()); //calls for ORP
    dataFile.print(", ");
    dataFile.print(getSensorCond()); //calls for Conductivity
    dataFile.print(", ");
    dataFile.print(getSensorDO()); //calls for DO
    dataFile.close();
  }
  else {
    Serial.println("Error 1");
  }
  delay(interval);  //the interval between data samples
}

String getTimeDs1307()
{
//code for the RTC
}

etc etc etc...

Thank you for the help.
3  Using Arduino / Storage / Re: SD and 16x2 LCD do not work together. on: November 07, 2012, 02:10:49 pm
ElCaron, I think I'm experiencing the same problem as you, though I'm not sure what you mean by two different SPI interfaces.  Could you elaborate a bit, perhaps posting your end-result pinout?

I'm using an ethernet shield, 20x4 LCD, and Arduino Mega.  The LCD utilizes pins (7,8,9,10,11,12) and the SDCS at pin 4.  I can run each component separately, though when combined together (specifically when I add the line 'lcd.setCursor(0,0)'), I fail to write anything to the SD.

4  Using Arduino / Sensors / Re: analog sensor questions (especially why use voltage dividers ?) on: July 16, 2012, 10:24:32 pm
So, going off of the information about sensitivity and the resistor, is there an "optimum" resistance where your sensor is most accurate?

I'm using a water level sensor, which is basically a linear resistor.  With no water, it is 1500 ohm resistance, filled 8 inches and it's down to 300 ohm.  I'm using it for a fish pond and am not expecting fluctuations more than a few inches.  If I want to get the most accurate possible results, could I anticipate better measurements if I pick a resistor based on my height meter's mean resistance?   
5  Using Arduino / Sensors / Re: Atlas Scientific pH Sensor Help on: July 12, 2012, 05:51:35 pm
You mean 9600 baud?  I'm still getting blank stares from my serial monitor.

Are you able to explain how the serial input works?  As I understand it with this particular code, I should be able to type out '\r' into my serial monitor and get a reading.  Would anyone agree to this being correct?
6  Using Arduino / Sensors / Atlas Scientific pH Sensor Help on: July 12, 2012, 01:25:05 am
I am sporting an Arduino Mega 2560 with an ethernet shield and Arduino 1.0 software.  I am trying to hook up an Atlas Scientific pH probe (https://www.atlas-scientific.com/product_pages/kits/ph-kit.html) which hooks to my Arduino through a BNC plug to a breakout board to the Serial3 ports. 

I'm new to serial communication and was hoping someone could help clarify what is going on and how I can manipulate this into useful information.  Right now, I am getting nothing on my computer's serial monitor, regardless of what I type in.  Any thoughts?

My wiring can be found through this link: https://www.atlas-scientific.com/_files/code/Arduino-sample-code-EZ-COM-MEGA.pdf

My coding is also found through that link, or you can refer to it below:

String inputstring = "";
String sensorstring = "";
boolean input_stringcomplete = false;
boolean sensor_stringcomplete = false;
//a string to hold incoming data from the PC
//a string to hold the data from the Atlas Scientific product
//have we received all the data from the PC
//have we received all the data from the Atlas Scientific
//product
void setup(){
Serial.begin(38400);
Serial3.begin(38400);
inputstring.reserve(5);
sensorstring.reserve(30);
}
//set up the hardware
//set baud rate for the hardware serial port_0 to 38400
//set baud rate for software serial port_3 to 38400
//set aside some bytes for receiving data from the PC
//set aside some bytes for receiving data from Atlas Scientific
//product
void serialEvent() {
char inchar = (char)Serial.read();
inputstring += inchar;
if(inchar == '\r') {input_stringcomplete = true;}
}
//if the hardware serial port_0 receives
//a char
//get the char we just received
//add it to the inputString
//if the incoming character is a <CR>,
//set the flag
void serialEvent3(){
char inchar = (char)Serial3.read();
sensorstring += inchar;
if(inchar == '\r') {sensor_stringcomplete = true;}
}
//if the hardware serial port_3 receives
//a char
//get the char we just received
//add it to the inputString
//if the incoming character is a <CR>,
//set the flag
void loop(){
if (input_stringcomplete){
Serial3.print(inputstring);
inputstring = "";
input_stringcomplete = false;
}
//here we go...
//if a string from the PC has been received in its entierty
//send that string to the Atlas Scientific product
//clear the string:
//reset the flag used to tell if we have received a completed
//string from the PC
if (sensor_stringcomplete){
Serial.println(sensorstring);
sensorstring = "";
sensor_stringcomplete = false;
}
}
//if a string from the Atlas Scientific product has been
//received in its entierty
//send that string to to the PC's serial monitor
//clear the string:
//reset the flag used to tell if we have received a
//completed string from the Atlas Scientific product
7  Using Arduino / Motors, Mechanics, and Power / Re: Servo and power supply question - turns in one direction on: December 05, 2011, 09:16:28 pm
The breadboard itself is powered by 8 AA batteries, though the (+) leads that run out of the breadboard are divided by 1.5 volt integers.  So, I can choose from 1.5 volts, 3.0 volts... up 9.0 volts.  I'm running power out of the 4.5 volt. 

My only defense against the code not being bad is because the very same code works flawlessly when it is my arduino providing the power. 

8  Using Arduino / Motors, Mechanics, and Power / Re: Servo and power supply question - turns in one direction on: December 04, 2011, 06:34:36 pm
Alright, so I think I've hooked up my external power source.  On my breadboard, I've grounded my power source to the ground on my breadboard, as well as the ground on my arduino.  It seems to work, but there's a lot of "chatter".  The motor is never quiet, like it was when my arduino was solely powering it.  The power source that I'm using is actually a all-in-one solderless breadboard kit, powered by 8 AA batteries.  Would the qualities of the batteries (in terms of charge) at all affect this "chatter" ? 
9  Using Arduino / Motors, Mechanics, and Power / Servo and power supply question - turns in one direction on: December 04, 2011, 01:52:10 pm
For awhile now, I've been doing small arduino projects to learn the coding structure associated with it.  Recently, I ordered some small, 5 volt servos to experiment with motor control.  Using the provided "sweep" and "knob" examples provided, my main goal was to simply establish control of the servo.  Regardless of how the code was structured, however, the servo always turned as far as it could clockwise.  A lot of troubleshooting went on, and I found that the code would work if the servo was powered by the arduino, that is, the power, ground, and communication wires were all wired into the board.  I found that the servo misbehaved because I was using an external 5 volt power supply attached to the power and ground wires, with the communication wire attached to my arduino. 

This leads me to my question: why does my servo only work if all three leads are plugged into the arduino?  Why can't I use an external power supply if my communication wire is attached to the arduino?  Ultimately, I'd like to operate a few servos simultaneously, and I'm concerned that it may result in damage to my arduino. 

Any input is appreciated.  Thank you all.
Pages: [1]