Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: using integer type to define pins, why? on: February 03, 2013, 12:39:51 am
Just awesome! you guys are very helpful
2  Using Arduino / Programming Questions / Re: Concatenate Float w/ a String on: February 03, 2013, 12:32:26 am
I had some trouble with floats and strings but I got it working. Nick Gammon pointed out that there are some issues with the current string library, it may not be your immediate issue but its worth noteing .
check this out maybe it will help. http://arduino.cc/forum/index.php/topic,146586.0.html

if you look in my code I put a few floats into Strings just after the loop()
3  Using Arduino / Programming Questions / Re: using integer type to define pins, why? on: February 03, 2013, 12:20:37 am
Code:
Note, in your example, using pin 0 is wrong, since that is a digital pin.

you sure ? I pulled that from the Knob example under the servo menu. Im not 100% sure but I think A0 is the first pin on my mega

so should i

const int potpin = A0;
or
#define int potpin = A0;

dose in not really mater?

I thought this had been covered before, im not keen on the way searching works here it returns so many false leads   
4  Using Arduino / Programming Questions / using integer type to define pins, why? on: February 02, 2013, 11:48:55 pm
why do all the examples use variables to define pins? Is this a wast of RAM? isn't it slower than a constant?
My thinking is if you use the later the code wont have to GET the value from ram, guess its a compromise between ram and program memory? 

Code:
int potpin = 0;  // analog pin used to connect the potentiometer
val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)


vs

Code:
val = analogRead(0);            // reads the value of the potentiometer (value between 0 and 1023)
5  Using Arduino / Programming Questions / Re: Saving Time as String on: February 02, 2013, 07:18:01 pm
Quote
Please note that, at present, the String library has bugs as discussed here and here.

In particular, the dynamic memory allocation used by the String class may fail and cause random crashes.

I recommend reworking your code to manage without String. Use C-style strings instead (strcpy, strcat, strcmp, etc.).

Alternatively, install the fix described here:
  http://arduino.cc/forum/index.php/topic,145765

I did not know that, you may have saved me a big headache Thank you

Quote
To me that suggests there's something wrong with the PC software.
Your probably rite but its a third party.  I think the software should wait for the end of line character before trying to process the string but the string must be written very fast if not in a single write command.   
6  Using Arduino / Programming Questions / Re: Saving Time as String on: February 02, 2013, 04:44:28 pm
OK guess i just needed to take a break, I got it working. I just modified the popular digitalClockDisplay() and printDigits() functions to append to a string instead of printing.

Code:
#include <Time.h>
#include <SPI.h>
#include <Ethernet.h>
#include <stdlib.h>

// mac and ip
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0xC6, 0x10 };
IPAddress ip(10,0,16,3);


// initilaze servers
EthernetServer server1(4001);
EthernetServer server2(4002);

// String variables
String Sblender, Schemadd, stamp ;

// data feilds - clean,drv disch,drv clean,pass disch,pass clean,auger1,auger2,auger3,auger4,meas dens, target,calculated
float blender[] = {
  50.2, 48.5, 24.1, 1.7, 26.0,
  25, 15, 0, 25, 0.27, 0.25, 0.25};
int chemadd[] = {
  1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};

// buffers counters and junk
char tmp[4];
int i = 0;

void setup() {
  Serial.begin(9600);

  // start connection and server:
  Ethernet.begin(mac, ip);
  server1.begin();
  server2.begin();
}

void loop() {
  timeStamp();
  // append data feilds to string
  Sblender = stamp ;          // constant for now NEED TO FIX
  for(int i = 0; i < 12; i++){
    Sblender += (",");
    dtostrf(blender[i],1,2,tmp);
    Sblender += tmp;
  }

  Schemadd = stamp ;
  for(int i = 0; i < 7; i++);
  {
    Schemadd += (",");
    dtostrf(chemadd[i],1,2,tmp);
    Schemadd += tmp;
  }

  // Transmit no more than once a second
  delay(1000);
  // talk to me !
  server1.println(Sblender);
  server2.println(Schemadd);
}

void timeStamp(){
  // set time to something
  stamp = ("");
  //get hours and format
  if (hour() < 10){
    stamp += ("0");
  }
  stamp += (hour());
  printDigits(minute());
  printDigits(second());
}

void printDigits(int digits){
  stamp += (":");
  //leading 0's
  if (digits <10){
    stamp += ("0");
  }
  stamp +=(digits);
}
7  Using Arduino / Programming Questions / Saving Time as String on: February 02, 2013, 03:36:37 pm
I'am trying to write a program that simulates a device that communicates via Serial over TCP/IP.

I figured out I need to save everything in a single String before transmitting or the data gets fragmented and the PC software cant interpret it. Got that working. Now I need a working time stamp... it doesn't have to be correct time... I don't even car if its 24 or 12 hr format

It has to be formatted as hours:minutes:seconds

I'm getting frustrated and need help lol the time librarys seem so complicated     

here is what I have working

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <stdlib.h>

// mac and ip
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0xC6, 0x10 };
IPAddress ip(10,0,16,3);


// initilaze servers
EthernetServer server1(4001);
EthernetServer server2(4002);

// String variables
String Sblender, Schemadd;

// data feilds - clean,drv disch,drv clean,pass disch,pass clean,
//               auger1,auger2,auger3,auger4,meas dens, target,
//               calculated
float blender[] = {
  50.2, 48.5, 24.1, 1.7, 26.0,
  25, 15, 0, 25, 0.27, 0.25, 0.25};
int chemadd[] = {
  1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};

// buffers counters and junk
char tmp[4];


void setup() {

  // start connection and server:
  Ethernet.begin(mac, ip);
  server1.begin();
  server2.begin();
}

void loop() {
  // append data feilds to string
  Sblender = ("10:23:67");          // constant for now NEED TO FIX
  for( int i = 0; i < 12; i++){
    Sblender += (",");
    dtostrf(blender[i],1,2,tmp);
    Sblender += tmp;
  }
  // Transmit no more than once a second
  delay(1000);
  // talk to me !
  server1.println(Sblender);


}







Pages: [1]