Show Posts
Pages: [1] 2 3
1  Using Arduino / Project Guidance / Serial.event question with software serial on: December 06, 2013, 10:40:46 pm
Quick question guys... I have a attiny85 project that I am using software serial with. My question is if I am sending a message via software serial, but waiting for a specific message back from the device before I send the next message etc, etc, etc....

I have not coded anything yet, and this is my second attiny85 project (I mean not having a hardware UART lines)... but was just trying to get some pointers on how to proceed.... from a general concept I wish I could use a serial.event type of command to pull each character out of buffer into a string and check it against my "known reply" that I am looking for. the thing is that I don't think serial.event does not apply to Software Serial.... My concern is I will slow/stop the main loop if i try and check for messages repeatedly...

Soooooo, ideas smiley

Thanks
2  Using Arduino / Project Guidance / Re: Software Serial Question on: December 01, 2013, 07:58:59 pm
Peter,
Thanks for the suggestion - that makes much more sense. The one caveat I would mention is I am 100% certain that once the original transmitter sends the trigger, it will be silent until the event is over. there is no change that two drivers will fight each other in that sense. My other issue is that I was hoping to do this with a attiny85.... so hardware uart lines are out. I understand the limitations of software serial, so if its not possible - that's the deal smiley I will have to go back to the drawing board.... but if you can see any other way please let me know your thoughts...
3  Using Arduino / Project Guidance / Re: Software Serial Question on: December 01, 2013, 07:45:27 pm
sorry for delay in reply - thanks for the help.

Quote
Is the Arduino intercepting the message (i.e. it receives it on one interface and transmits it on another - there is no direct path past it), or just listening to the message (i.e. the original message is also received at the ultimate destination)?

yes, the arduino is intercepting/ aka listening to the "transmit" line of one of the uart modules. when it hears something that it is listening for, it then connects "its" transmit line to the uart bus and sends its message to the same uart device that was being talked to. after it is done it "releases" the line by turning the pin into an input so as to allow normal non-arduino communication to occur.

Quote
Why have you two separate instances of softwareSerial with the same name and different pins?
again, this is so that I can listen on one pin without having the tx pin hold the line "mute". when I acutally want to send something after an event is triggered, that is when I change the pin assignments...

Quote
I wondered about that, but more about why use software serial at all.
using this on an attiny, no hardware uart lines....

thansk for all the help guys - and sorry for all the """""" uses smiley smiley
4  Using Arduino / Project Guidance / Re: Software Serial Question on: December 01, 2013, 12:22:34 am
That is 100% right. ... The software serial example uses 11 and 12. Changing them did not alter the issue though. ....any other ideas? ????
5  Using Arduino / Project Guidance / Software Serial Question on: November 30, 2013, 10:53:37 pm
Hi all,

I am trying to listen into a uart line between two devices. When a particular set of characters is sent, I want my Arduino to transmit a specific message. My issue is that it seams some characters that should be sent are getting lost... and also once I trigger one event, the remaining events do not send any characters, just line feed.... not sure why. I have attached my code, not sure if this was adequate explanation but please feel free to comment and suggest any solution. Thanks,
 
Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(11, 12); // RX, TX

const unsigned int MAX_INPUT = 50;
static unsigned int input_pos = 0;

void setup() 
{
  mySerial.begin(38400);
  pinMode(13, OUTPUT);
}

void(* resetFunc) (void) = 0;//declare reset function at address 0

void SendMessage(const char * data)
{
  digitalWrite(13, HIGH);
  boolean fourZero = false;



      SoftwareSerial mySerial(11, 10);     
      mySerial.begin(38400);
      mySerial.println();
      delay(1500);
 
      if(strcmp(data,"!01")==0) {mySerial.print("%50155%"); }
      if(strcmp(data,"!02")==0) {mySerial.print("%50154%"); }
      if(strcmp(data,"!03")==0) {mySerial.print("%50153%"); }   

 //     input_pos = 0; 

    mySerial.println(" ");
 
    mySerial.println("");
    pinMode(10, INPUT);



}

void loop()
{
  if (mySerial.available () > 0)
  {
    processIncomingByte (mySerial.read ());
  }   
}

void processIncomingByte (const byte inByte)
  {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

 
   if (inByte == 35)                    // # is the key
       {
         SendMessage(input_line);

          SoftwareSerial mySerial(11, 12); // RX, TX
          mySerial.begin(38400);
 
 
//       input_pos = 0;     

        resetFunc(); //call reset
           }
           else
           {

            if (input_pos < (MAX_INPUT - 1))
            input_line [input_pos++] = inByte;
            }
  }
6  Using Arduino / Project Guidance / Re: String help please on: October 08, 2013, 05:53:58 pm
I am sorry - I did not mean to seam like I was ignoring the advice - I very much appreciate and value all the input. The problem I have is that my knowledge is limited and the only way I know how to "print" something is as a string. I also am not sure how to pull and join only two characters stored in an array. I did the below and it does work, but I am sure there is a better/correct way to do this. Thanks again for all the help  smiley

Code:
if(strncmp(&inData[2],"A6",2)==0) {mySerial1.print("part1- "); mySerial1.print(String(inData[4]));mySerial1.println(String(inData[5]));}
7  Using Arduino / Project Guidance / Re: String help please on: October 07, 2013, 07:39:24 pm
Guys - that worked perfect! Thanks. My only issue is this:
Code:
            if(strncmp(&inData[2],"A6",2)==0) {mySerial1.print("part1-"); mySerial1.println((String(inData)).substring(4,7));}   

If i send a message for example like "!5A620" I would expect the output via the myserial1 to be "part1-20". The issue is that all I get is "part1-". what am I missing?

Thanks,
8  Using Arduino / Project Guidance / String help please on: October 07, 2013, 12:00:01 am
Guys - this is killing me. the amount of time I have spent of this is insane!!! please tell me what I am missing. I want to send commands via serial in the format "!541gg" and be able to trigger a software serial event based on it being a "!5" message, option "41" and now send software serial "test" and "gg"....

I cannot attach all my code right now as I am still working on it, but what I am attaching has the same issue. The "!5" filter does not work, and as soon as index = 6 all the options/if statements in the networkmessage1 & 2 get run???

Please let me know what I am doing wrong...

Thanks
Code:
/*
#include <SoftwareSerial.h>

SoftwareSerial mySerial1(10, 11); // RX, TX

String stringOne;
char inData[6];
char inChar;
byte index =0;

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }




  // set the data rate for the SoftwareSerial port
  mySerial1.begin(9600);

}

void loop() // run over and over
{
   if (Serial.available() > 0)
   {

     checkApplicationMessage();

 }
}

void checkApplicationMessage()
{

       if (index < 6)
       {
         inChar = Serial.read();
         if (inChar == '!'){
           index = 0;
         }
         
         inData[index] = inChar;
         index++;
         inData[index] = '\0';
       }
       else
       {
         index = 0;
       }

    ProcessApplicationMessage();       

  }   
 
void ProcessApplicationMessage()
{

    if (index == 6)
     {


              if((String(inData)).substring(0,2) == "!4")
              {   
              NetworkMessage1();
              }

       
              if((String(inData)).substring(0,2) == "!5")
              {   
              NetworkMessage2();
              }
          index = 0;
         

}
}

void NetworkMessage1()
{


           
            if((String(inData)).substring(2,4) == "01") {mySerial1.print("test1_1"); mySerial1.print((String(inData)).substring(4,6));}
            if((String(inData)).substring(2,4) == "02") {mySerial1.print("test2_1"); mySerial1.print((String(inData)).substring(4,6));}
            if((String(inData)).substring(2,4) == "03") {mySerial1.print("test3_1"); mySerial1.print((String(inData)).substring(4,6));}
         

}

void NetworkMessage2()
{


           
            if((String(inData)).substring(2,4) == "01") {mySerial1.print("test1_2"); mySerial1.print((String(inData)).substring(4,6));}
            if((String(inData)).substring(2,4) == "02") {mySerial1.print("test2_2"); mySerial1.print((String(inData)).substring(4,6));}
            if((String(inData)).substring(2,4) == "03") {mySerial1.print("test3_2"); mySerial1.print((String(inData)).substring(4,6));}
         

}
9  Using Arduino / Project Guidance / Re: using gsm module for access control on: August 22, 2013, 11:26:57 am
full code

Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial2(7, 8);
SoftwareSerial mySerial1(10, 11);

int SER_Pin = 6; 
int RCLK_Pin = 3; 
int SRCLK_Pin = 4;


#define number_of_74hc595s 1


#define numOfRegisterPins number_of_74hc595s * 8

String stringOne;


boolean registers[numOfRegisterPins];
char inData[6];
char inChar;
byte index =0;

char inDataModem[6];
char inCharModem;
byte indexModem =0;


void setup(void) {
  Serial.begin(9600);
  mySerial2.begin(19200);
  mySerial1.begin(9600); 

  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
 
 
  pinMode(5, OUTPUT);
  pinMode(2, OUTPUT);   
  pinMode(13, OUTPUT);
  pinMode(9, OUTPUT);

  //reset all register pins
  clearRegisters();
  writeRegisters(); 

}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
  digitalWrite(5, HIGH);
  digitalWrite(2, LOW); 
}

void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

 
void loop(){
 
   while (Serial.available() > 0) {
     {
       if (index <5)
       {
         inChar = Serial.read();
         if (inChar == '!'){
           index = 0;
         }
         
         inData[index] = inChar;
         index++;
         inData[index] = '\0';
       }
       else
       {
         index = 0;
       }
     }
     if (index == 5){
              if(strcmp(inData,"!0000")==0) {Serial.println("OK");}
              if(strcmp(inData,"!0100")==0) {mySerial2.println("AT");}


    if (indexModem <5)
       {
         inCharModem = mySerial2.read();
         if (inChar == '+'){   
           indexModem = 0;
         }
         
         inDataModem[indexModem] = inCharModem;
         indexModem++;
         inDataModem[indexModem] = '\0';
       }
       else
       {
         indexModem = 0;
       }
       if(strcmp(inDataModem,"+CMTI")==0) { indexModem = 0; mySerial2.println("AT+CMGR=6"); }

 
}
   }
}
10  Using Arduino / Project Guidance / Re: using gsm module for access control on: August 21, 2013, 11:16:42 pm
ok guys... working though and need some help. I have this code running in my loop, and my goal is to
1. when the gsm receives a text on myserial2 the code checks for the index, opens the message with cmgr  and then checks the body for a "yes" or "no" as message body.
2. based on that it runs 2 possible processes.
3. it ends by deleting all messages with at+cmdl 1,4

I know I only have the very beginning, but am hoping there may be a better way. right now this is in my main loop....

Code:
   while(mySerial2.available() > 0){
     inCharModem = mySerial2.read();
      if (indexModem < 5){
         if (inCharModem == '+'){   
           indexModem = 0;
         }
         
         inDataModem[indexModem] = inCharModem;
         indexModem++;
         inDataModem[indexModem] = '\0';
       }
     
     else
       {
         indexModem = 0;
         Serial.write(mySerial2.read());
       }
   }
       if(strcmp(inDataModem,"+CMTI")==0) { indexModem = 0; mySerial2.println("AT+CMGR=7"); }
}
11  Using Arduino / Project Guidance / Re: using gsm module for access control on: August 21, 2013, 01:38:56 pm
its a seeed studio sim900 board - could not find that much info on it from their site...

on the first topic - do you have any examples I could use as a foundation - code that continually checks for new txt messages, and then reads them and based on what it reads creates an output?
12  Using Arduino / Project Guidance / using gsm module for access control on: August 21, 2013, 01:21:54 pm
Hi all,

I have a project using a arduino micro to control some shift registers as well as communicate with a uart serial device with a software serial port. A pc based software application I developed send commands to the atmega which in turn either affects the state of a relay or sends a pre-packaged message to the serial device. currently there is no bi-directional communication between the application and arduino. adding this is not a issue and is in the near future.

I would like to use a gsm shield that I have, connected to the arduino via another software serial port to enable and disable the hardware. I would also be the same mechanism for re-enabling the hardware. my concerns and what I am looking for help on is...

how would I check the gsm modem all the time for any new messages and how to parse them for the "code" sent
how would I retain a memory even with a power cycle that the current state of the arduino is "diabled" or "enabled"
how would I trigger something in the code so that the serial port reports to the software application the hardware is "on" or "off"

any suggestions would be great! thanks
13  Using Arduino / Project Guidance / Shift Register and Software Serial Delay Issues on: July 02, 2013, 10:28:00 pm
Hello all. I am using software serial to communicate with a device attached to pin 9 and 10 on my Uno. my issue is that most all data needs to be passed to/from the software serial port.  What I need is a way to also control my shift registers as well as 4 additional digital ports that control relays via transistors... My issue is that any time I try and do this by pointing to a "trigger" character like "!" to indicate a command meant for shift register control or relay control I loose characters on the software serial communication.  Is there any way to address this delay and loss of characters....

Thanks


Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10); // RX, TX

int SER_Pin = 4;   //pin 14 on the 75HC595
int RCLK_Pin = 3;  //pin 12 on the 75HC595
int SRCLK_Pin = 2; //pin 11 on the 75HC595

//How many of the shift registers - change this
#define number_of_74hc595s 1

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8


boolean registers[numOfRegisterPins];

char inData[6];
char inChar;
byte Forward =0;
byte index =0;


void setup(){
  Serial.begin(9600);
   mySerial.begin(9600);
  
  
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(13, OUTPUT);  
  pinMode(12, OUTPUT);  
  pinMode(11, OUTPUT);  
  pinMode(5, OUTPUT);

  //reset all register pins
  clearRegisters();
  writeRegisters();
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(5, LOW);  
}              


//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}


//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}



void loop(){
 //  while (Serial.available() > 0) {

                     if (Serial.read() == '!')
                     {
                     ShiftOut();
                     Forward = 1;
                    }
                    else
                    {
                    if (mySerial.available())
                      Serial.write(mySerial.read());
                    if (Serial.available())
                      mySerial.write(Serial.read());
                     }
}





void ShiftOut(){
        if (index <5)
       {
         inChar = Serial.read();
             if (inChar == '!')
             {
               index = 0;
             }
        
         inData[index] = inChar;
         index++;
         inData[index] = '\0';
       }
       else
       {
         index = 0;
       }
    
     if (index == 5){
      
       int firstArg = atoi(inData + 3);

         // Register 1 Round Shutdown  
         if (strncmp(inData, "!8", 2) == 0)
          {
            setRegisterPin(firstArg, LOW);
            writeRegisters();
            index = 0;
            Forward = 0;
          }
         // Register 1 Round TurnOn
         if (strncmp(inData, "!9", 2) == 0)
          {
            setRegisterPin(firstArg, HIGH);
            writeRegisters();
            index = 0;
            Forward = 0;            
          }



      
       }
}
14  Using Arduino / Project Guidance / Re: serial.read string if statment on: June 30, 2013, 10:49:05 am
thanks for the quick response guys...
Quote
If there might be 80 characters, plan for that.
80 would for sure be a safe upper limit...


Quote
There are several ways to do what you describe of capturing single bytes into a useable form. What have you tried that did not work?

My issue is that while I have done some code, I am not sure how to define it.... would I use
Code:
char instring[80];
or would I use
Code:
string instring;
then I would try and add it to the end
Code:
instring = ((serial.read) + insttring)
all this in a while loop
Code:
do[
while ((serial.read) <> "/n");

I have not tried any of this... just trying to figure out my plan of attack.
15  Using Arduino / Project Guidance / serial.read string if statment on: June 30, 2013, 08:46:17 am
I have my Uno connected via software serial to a ttl device... 38400baud etc and everything seams to work. what I need help with is defining/using a string in my code that will server as the "buffer" for all received serial traffic.... it should combine all the individual characters until a LF is detected, and once it is it will execute some code which concludes with clearing the string and starting again.

I thought I had an idea on how to do it, but it would only work with fixed length strings... in this application the string could be 3 characters long or 40, no way to tell how many between LF so I know i still need to read 1 character at a time and run it though the LF check to see if its the end of a string......

thanks
Pages: [1] 2 3