Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / problem in while language on: March 16, 2013, 12:01:43 pm
hello...may i ask, is it valid to use while and if in the loop?
2  Using Arduino / Programming Questions / I HAVE a problem in repeating the task inside the loop on: March 15, 2013, 11:29:09 am
Code:
#include <SoftwareSerial.h>
#define SOP '<'
#define EOP '>'
SoftwareSerial RFID(10,11);

bool started = false;
bool ended = false;

char inData[80];
byte index;



 
 


char Rx_data[50];
unsigned char Rx_index = 0;
int i = 0;
char msg[160];
int sig;
char c;

void setup() {
  Serial.begin(38400);
  Serial1.begin(9600);
  RFID.begin(9600);
 
 
}

void loop() {
  if (RFID.available()){
     c=RFID.read();
    Serial1.write(c); //it will echo the rfid code
     // Read all serial data available, as fast as possible
  while(Serial1.available() > 0)
  {//Serial1.write(c);
    char inChar = Serial1.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }
   

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    // The end of packet marker arrived. Process the packet
    char *num = strtok(inData, ",");
    if(num)
    {
       char *mesg = strtok(NULL, ",");
       if(mesg)
       {
         initGSM(); //send a mesage depending to the receive msg and cp number
  send_msg(num, mesg);
       

       }
    }
   
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
 
   
     
   
  }
}
void send_msg(char *number, char *msg)
{
  char at_cmgs_cmd[30] = {'\0'};
  char msg1[160] = {'\0'};
  char ctl_z = 0x1A;

  sprintf(msg1, "%s%c", msg, ctl_z);
  sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
 
  sendGSM(at_cmgs_cmd);
  delay(100);
  delay(100);
  delay(100);
  sendGSM(msg1);
  delay(100);
}

void sendGSM(char *string){
  Serial.write(string);
  delay(90);
}

void clearString(char *strArray) {
  int j;
  for (j = 100; j > 0; j--)
    strArray[j] = 0x00;
}

void send_cmd(char *at_cmd, char clr){
  char *stat = '\0';
  while(!stat){
    sendGSM(at_cmd);
    delay(90);
    readSerialString(Rx_data);
   
    stat = strstr(Rx_data, "OK");
  }
  if (clr){
    clearString(Rx_data);
    delay(200);
    stat = '\0';
  }
}

void initGSM(){
 
  send_cmd("AT\r\n",1);
//  send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module

  send_cmd("AT+CMGF=1\r\n",1); // Set message format to text mode
  //Sucess
 
  Serial.println("Success");

  delay(1000);
  delay(1000);
  delay(1000);
}

void readSerialString (char *strArray) {
 
  if(!Serial.available()) {
    return;
  }
 
  while(Serial.available()) {
    strArray[i] = Serial.read();
    i++;
  }
}

the problem is,,in the first tym it operate normally...but in a second tym did'nt..you need to reupload the program before it function correctly...please help me to solve this prob..tnx
3  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 06:51:15 pm
i got it...thank you very much
4  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 11:57:54 am
is it functional if the computer will send two type of  data for example <jvvmv>{fff},is it posible to use two start and end maker...
5  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 11:49:27 am
THANK YOU very much...is it functional of what i want to do as what i said in my first post?
6  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 11:42:59 am
im sory....it works it print but the problem is it auto scroll...
7  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 09:52:53 am
please give me the very specific examples in IDE pls???
8  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 09:36:10 am
plz...give me a specfic examples
9  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 09:09:41 am
how can i do this?any advice?
10  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 08:59:47 am
i'm so sorry for that....im unfamiliar with this,,,
ahm..is it possible to use the switch case function??plz help me
11  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 08:46:55 am
one key??i want to store it in a buffer...this character will be send by the computer to the arduino,if ahm..for example the original data is a099999bTYYYYU, IF character 'a' is detected the 099999 will be store to a buffer and if character 'b' is detected the TYYYYU will be store to another buffer....please help me to do this...
12  Using Arduino / Interfacing w/ Software on the Computer / Re: how to interpret the serial data on: March 14, 2013, 08:02:42 am
ah...i know that it is incomplete i just want to know if it is applicable to what i want to do?tnx
13  Using Arduino / Interfacing w/ Software on the Computer / how to interpret the serial data on: March 14, 2013, 03:44:16 am
can u please give me a sample that are receiving a serial data,that f the mcu receive a charater 'a' the corresponding data will store in a buffer and when the character 'b' is detected d corresponding character will store to other buffer..can u please give me a related sample
14  Using Arduino / Programming Questions / Re: i have a problem in separating the data on: March 02, 2013, 02:26:03 am
how can i convert the Serial.read to a string?
15  Using Arduino / Programming Questions / i have a problem in separating the data on: March 02, 2013, 02:12:36 am
i have a problem in receiving the data from pc  and separate ..here's my code
Code:

String c;

String getValue(String data, char separator, int index);

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

void loop(){
  if (Serial.available()){
    c=Serial.read();
String cpNum = getValue(c, ' ', 0);
String logTime = getValue(c,' ',1);

Serial.println(cpNum);
Serial.println(logTime);
}
}

String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
hers my error
Code:
split_string_2.ino: In function 'void loop()':
split_string_2:14: error: invalid conversion from 'int' to 'const char*'
split_string_2:14: error: initializing argument 1 of 'String& String::operator=(const char*)'
pls help me
Pages: [1] 2