# Can anyone help me with my thesis?

**URL:** <https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668>\
**Category:** General Guidance\
**Created:** [April 4, 2017, 2:51am UTC](https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668 "2017-04-04T02:51:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rheyrhey](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rheyrhey](https://forum.arduino.cc/u/Rheyrhey)\
**Post date:** [April 4, 2017, 2:51am UTC](https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668/1 "2017-04-04T02:51:54Z")

</div>

How will i send this set of codes into arduino? then arduino will try to send this commands into my gsm shield, can anyone send me some sketch? im using arduino uno

this codes are from vb:  
Try  
With SerialPort1  
.PortName = comports  
.BaudRate = 9600  
.Parity = Parity.None  
.StopBits = StopBits.One  
.DataBits = 8  
.Handshake = Handshake.RequestToSend  
.DtrEnable = True  
.RtsEnable = True  
.NewLine = vbCrLf  
.Open()  
End With  
Catch ex As Exception

End Try  
Try  
If SerialPort1.IsOpen Then  
With SerialPort1  
.Write("AT" & vbCrLf)  
.Write("AT+CMGF=1" & vbCrLf)  
.Write("AT+CMGS=" & Chr(34) & tbnumber.Text & Chr(34) & vbCrLf)  
.Write(textmessage.Text & Chr(26))  
MsgBox("Message Sent")

End With

Else  
MsgBox("Error on the Port")  
End If

Catch ex As Exception  
MsgBox(ex.Message)  
End Try

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [April 4, 2017, 3:45am UTC](https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668/2 "2017-04-04T03:45:19Z")

</div>

Please use code tags when posting code; edit your post and

type  
**`** **[code]**  **`**  
before your code  
type  
**`** **[/code]**  **`**  
after your code

It is not advisable to throw exceptions away as you do in the first try/catch as you don't know what goes wrong.

I suggest that you read [Serial Input Basics - updated](http://forum.arduino.cc/index.php?topic=396450.0) to get ideas how to receive your data and place it in a buffer. Example 2 will probably do in which case you might want to change your VB code to only send a LF and not CR and LF. Example 3 will make the communication more reliable but requires more changes in your VB code.

Once you have received one command (e.g. AT), you can send that to the GSM using SoftwareSerial (if your shield uses serial communication). Next wait for the next command to arrive (AT+CMGF=1) and send that to the GSM in the same way.

I have no experience with GSM, you might have to wait for replies from the shield after you have send a command and possibly pass that reply to your VB code.

Which shield are you using?

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [April 4, 2017, 7:00am UTC](https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668/3 "2017-04-04T07:00:55Z")

</div>

If you use my code (and please feel free to do so) I hope I get a mention in the footnotes to your Thesis. @sterretje deserves a mention also.

...R

---

<div class="post-metadata">

**Author:** ![davidrh](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@davidrh](https://forum.arduino.cc/u/davidrh)\
**Post date:** [April 5, 2017, 10:48am UTC](https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668/4 "2017-04-05T10:48:27Z")

</div>

Here is a couple of functions that I picked up along the way from somewhere for dealing with GSM modules.

```cpp
boolean sendATcommand(char* ATcommand, char* expectedAnswer, unsigned int timeout, uint8_t bufferSize) {
  char response[bufferSize];
  sendATCommandResponse(ATcommand, expectedAnswer, timeout, bufferSize, response);
  if (strlen(response) == 0) {
    return false;
  } else {
    return true;
  }
}

boolean sendATCommandResponse(char* command, char* endText, unsigned int timeout, uint8_t bufferSize, char* response) {
  memset(response, END_OF_STRING, bufferSize);
  uint8_t bufferPointer=0;
  unsigned long startMillis;
  
  clearSerialBuffer();

  sendLn(command);
  startMillis = millis();

  do {
    if (Serial1.available() != 0) {    
      response[bufferPointer++] = Serial1.read();
      bufferPointer = bufferPointer % bufferSize;
      if (strstr(response, endText) != NULL) {
        return true;
      }
    }
  } while((millis() - startMillis) < timeout);
  response[0] = END_OF_STRING;
  
  return false;
}

void send(char* text) {
  Serial1.print(text);
}

void sendLn(char* text) {
  Serial1.println(text);
}

void clearSerialBuffer() {
  while(Serial1.available() > 0) {
    Serial1.read();
  }  
}

```

And a rough idea of how you can use them:

```cpp
#define AT ("AT")
#define AT_IDENTIFY ("ATI")
#define OK ("OK")

void doSomething() {
    if (sendATcommand(AT, OK, 200, 10)) {
        // success
    } else {
        // failure
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 6:11pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-with-my-thesis/449668/5 "2021-05-05T18:11:18Z")

</div>


