at_program.jpgToday i succeeded in completing a small Visual basic program that can send instructions via bluetooth to a Nokia (or other AT-commands) cell phones. AT commands where used to communicate directly to the Nokia cell phones. I was struggling for a long time to make a proper connection, i have tried some different Nokia protocols, in fact there are three. The standard At commands, the Mbus and the newer Fbus. There are many sites where you can lookup the supported format.

Although to make a connection with the PC i buy a serial data cable, yes the old serial ones, because we want to connect it lateron to a microcontroller.
To connect it to the pc i must use a usb to serial adapter, because i don’t have a serial port anymore. Like the most of us, i hope ;) . Like i said before, i can’t get a proper connection through the cable for a long time, i have tried almost everything. So i came up the idea of using bluetooth instead. It was in fact really easy by then. All the ’simple’ AT commands worked properly. So why didn’t the cable work? I think its about the usb- serial adapter, that have its on drivers. The strange thing is a demo application called: Lylix worked good with (only) the Fbus protocol.

On the other hand, using bluetooth is easier then connecting a cable again and again..

So now the solution or rather called, tutorial:
First check of you (Nokia) phone supports AT commands and have bluetooth. We use a nokia 6021
Second get yourself a bluetooth connection, for example buy a bluetooth dongle.


1) Now we need to setup a COM port connection.
We use IVT BlueSoleil found here: http://www.bluesoleil.com/

We briefly discuss how to setup a connection. For more info, look at the original site bluesoleil.com
- When you don’t see a phone, make sure the bluetooth is anabled on the phone itselfs. Then hit the Orange button.
- The phone should appear.
- Next step is to right click on the phone and choose something like “link” (i have a dutch version).
- If needed you must enter a code on both phone and pc.
- Hit the serial cable icon to make a COM port connection
- A good connected phone looks like the image below…
- Final right click on the phone and select ’status’ Now write down your virtual comport! In our case its COM port 4

blusoleil_nokia.jpg

2)Testing in the hyperterminal.

Before using the Visual basic program it’s recommend to test first the connection in the Hyperterminal program!
- open hyperterminal, START -> All programs -> Bureau accessories -> communicate -> hyperterminal
- choose file – New connction
- Select right COM port, in our case COM 4
- Change the settings to: 9600, 8, parity No, stop bit 1, flow: None

To test a connection Type “AT” (without the quotes) then hit enter

  • NOTE: if the connection is good, the phone returns OK.

hyperterminal.jpg

You can now check some AT commands for a good understanding an check if all AT commands are supported. In case, not all AT are supported usually!

AT+CSQ
returns Signal strength

AT+CBC
returns Battery Charge

AT+CGMM
returns model number

and so on… A lot of information about AT commands can be found here: http://www.developershome.com/sms/atCommandsIntro.asp

3) Visual basic program

First off all we explain al little about what for the program is designed.. If you have read the other articles on Labcoding you probably should have read something about gps tracking. The main goal of this PC to phone connection is to setup a 2 way connection on two mobile phones, one connected to the PC and one Connected at a microcontroller / gps module.

The basic idea is to send a ‘request’ sms to the phone connected to the microcontroller / gps module, this phone sends back the gps location data..

The visual basic program must therefor send a request sms and read incoming sms, then the sms data must be saved in a xml or kml file.
See also our earlier article: real-time-gps-tracking-through-a-simple-txt-file

The Visual Basic 2008 test or better called beta program is just a simple explanation on how to send a SMS trough AT commands.

  • Note: Again this is just a real simple (buggy) code for testing the basics. Feel free to use the code and to adjust it.

at_prog_big.jpg

Basicaly You just have to reset the COM port and Phone number. Then Hit the sms button And the text in the field: GetPosition will be sent to that number. For testing you can use your own number, sent yourself an sms! :P

The debuggin section can be used to just

Here’s the beta code:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
TextBox1.Text = “open”
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

TextBox1.Text = SerialPort1.ReadExisting()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SerialPort1.Close()
TextBox1.Text = “closed”
End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

SerialPort1.Write(TextBox2.Text + Chr(+13))

End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
‘change settings

SerialPort1.PortName() = PortBox.Text
SerialPort1.BaudRate() = BaudBox.Text
SerialPort1.DataBits() = DatabitBox.Text
‘ for now hardcoded…
SerialPort1.Parity() = IO.Ports.Parity.None

Const quote As String = “”"”
If SerialPort1.IsOpen = False Then SerialPort1.Open()
SerialPort1.Write(“AT+CMGS=” & quote & NummerBox.Text & quote & Chr(+13))
SerialPort1.Write(TextBox3.Text + Chr(+26) + Chr(+13))
TextBox3.Text = “Sms sended”
If SerialPort1.IsOpen = True Then SerialPort1.Close()
End Sub

Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub NummerBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NummerBox.TextChanged

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

End Sub

Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

End Sub

Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Settings.Enter

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Dim gpsdata As String = _
My.Computer.FileSystem.SpecialDirectories.MyDocuments _
& “\gpsdata.txt”

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

If TextBox1.Text <> “” Then

‘ Add the selected picture to the favorites text file.
My.Computer.FileSystem.WriteAllText(gpsdata, _
Me.TextBox1.Text, False)

End If

TextBox1.Text = “Data saved in :My documents\gpsdata.txt”

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub ParityBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParityBox.TextChanged

End Sub
End Class

The real sending part is:

  • SerialPort1.Write(“AT+CMGS=” & quote & NummerBox.Text & quote & Chr(+13))
  • SerialPort1.Write(TextBox3.Text + Chr(+26) + Chr(+13))
  • TextBox3.Text = “Sms sended”

NummerBox.Text contains the number you typed into the box.
Chr(+13) is used for ’saying’ this is the end of the command.
Chr(+26) is only to say, this is the end of the sms message. Otherwise use
Chr(+13) …

Download the example code:

Nokia_at_communicator.zip

Keep checking our site, more codes and updates are posted frequently!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Furl
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati