Go Down

Topic: Character limit? (Read 2003 times) previous topic - next topic

Graynomad

Quote
Maybe this simple example can help you:


Which is essentially what I posted a while back, I don't know if Jassper tried it or not.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Jassper


Why don't you just check one character each time?


That won't give me what I Need. If the first number in is 234 I need Data[0] to be 234, so after reading the 2, I must wait until the 3 and then the 4 come in as well.

The main loop is then going to do something with all this data so it all has to be in, then the rest of the loop. Also, the data will be coming in every second. so I need to repeat the data and do something with it before the next line comes in.

This program is only so I can verify that I am reading the data correctly.

I think I have it working now, thanks to everyone. I never realized that the Serial port was that slow.

dxw00d

Quote
I never realized that the Serial port was that slow.


Code: [Select]
  Serial.begin(9600);

You could make it a lot faster.

Jassper


Quote
I never realized that the Serial port was that slow.


Code: [Select]
 Serial.begin(9600);

You could make it a lot faster.


I realize that, but the data set is coming from something that is sending it at 9600. I will however look into if I can speed that up, but the distance is about 50 feet unshielded so not sure how much faster I want/can push it without possible corruption.

This is what I have now,
Code: [Select]

// ****************************************************************
// File Name:
// Version:
// Created By:
// Comments:
// ****************************************************************

// ********************** Version x.xx ****************************
// 03.11.12

// ********************** Consants ********************************
#define EOP        ';'
#define SERSIZ     25

// ********************** Included Libraries **********************
//#include <SoftwareSerial.h>

// ********************** Defaults ********************************
// ********************** Analog Input Pins ***********************
// ********************** PWM Output Pins *************************
// ********************** Digital Input Pins **********************
// ********************** Digital Output Pins *********************
// ********************** Output Pins *****************************
// ********************** Sensor Pins *****************************

// ********************** Variables *******************************
int i;
int c;
int Percent[4];
int iData[SERSIZ];
int iTemp = 0;

boolean PrintFlag = false;

int index = 0;

unsigned long startTime;

// ********************** Other Information ***********************

// ********************** Declorations ****************************
//SoftwareSerial LCDserial(7,8);

// ********************** SET UP **********************************
void setup()
{
 Serial.begin(9600);
}

void loop()
{
 ///////////////////////// TO READ SERIAL ////////////////////////
 if(Serial.available())
   {
   ReadData();
   }
 
 if(PrintFlag)
   {
   for(i=0; i < SERSIZ; i++)
     {
     Serial.println(iData[i]);
     }
   PrintFlag = false;  
   }
}

// *********************** FUNCTIONS *******************************
// Read Incoming Data from Tank monitor
void ReadData()
{
 index = 0;
 iTemp = 0;
 c = 0;
 startTime = millis();
 
 while(c != EOP && millis() - startTime < 600) // Exit if EOP is not seen in less than 0.6 sec
   {
   c = Serial.read();
   if(c >= '0' && c <= '9')
     {
     iTemp = iTemp * 10 + (c - '0');
     }
   else if(c == ',') // Record Data and move to next index
     {
     iData[index] = iTemp;
     index++;
     iTemp = 0;
     }
   else if(c == EOP) // Record data and exit loop
     {
     iData[index] = iTemp;
     PrintFlag = true;
     break;
     }
   }
}
// End ReadData()



And it appears to be working correctly. It will take incoming data like this;
244,23.5,100,23.6,456,345; (actual string is 24 numbers separated by commas ending in ; )
and record them as
iData[0] 244
iData[1] 235
iData[2] 100
iData[3] 236
etc

Now I can go back to work on what I am doing with this data in the main loop - which isn't much so a lot of time spent just trying to understand what the heck was going on. Gerrr. All well, what doesn't cause me to kill myself makes me stronger right? lol

Thanks everyone and if anyone sees anything else I can improve on - please feel free to point it out.


Go Up