Problem of comunication via bluetooth

Alex68

Member
Licensed User
Longtime User
Hi

sorry for my bad english

I have a problem with comunication between smartphone e microcontroller via bluetooth.

I try to explain

Some years ago I did a program in VB6 that comunicate with a microcotroller for drive 5 servo RC through RS232
Belove a part of program that send then comand to the microcontroller
The command is divided into three parts like you see below
1) value of sinconization. evere 255
2) value of number of servo to drive ( 0 to 4)
3) value of position of servo ( 0 to 254) this valus is obtained by a slide

Part of program VB6

For ritardo = 1 To (Slider2.Value * 1)
MSComm1.Output = Chr(255) ' costant for sincronization of comunication
MSComm1.Output = Chr(u) ' number of servo
MSComm1.Output = Chr(Label20(u).Caption) ' slide’s value of servo postion ( 0 to 254 )
Next

Now I bought a little transciver bluetooth-RS232

I used the code by Erel for comunication between smartphone via bluetooh and use AsyncStreams to send messages.
If I try to comuincate with PC it work fine but when I connect with the microcontroller the servo don’t work.
The progam use e seekbar and take the value to send to the microcontroller.
Belove the part of program in B4A that send the comand to the microcontroler

Sub Vbar_ValueChanged(Value As Int, UserChanged As Boolean)
Dim valore() As Byte
Dim BC As ByteConverter
Dim a() As Byte
Dim b() As Byte
Dim c As Int

If UserChanged Then
label1.Text=Chr(Value)
c=255
a=BC.ShortsToBytes(Array As Short (c))
c=1
b=BC.ShortsToBytes(Array As Short (c))
valore=BC.ShortsToBytes(Array As Short ( Value))
AStream.Write(a)
AStream.Write(b)
AStream.Write(valore)

End If

End Sub

Where am I wrong?:BangHead:

Thank you in advance
 

Beja

Expert
Licensed User
Longtime User
Hi Alex68,

I am also working in interfacing Android to the outside world and will post my work here when finish.
My design practice is first design a test project. a breadboard with only 1 LED. and try to switch that LED on and off. if it worked then designing more complex I/O projects is easy (right?)
So my suggestion to you is to test the I/O functions (not your project).
I am now able to communicate using HC-05 BT <> RS232 module and RF radio.
I could extend the xmision distance to 800 meters.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Bluetooth and Microcontroller

Hello guys, i just posted the source code for a project i have been working on for a while, if you guys are interested you guys can check it out here
http://www.b4x.com/forum/basic4android-share-your-creations/24604-bluetooth-microcontroller-communication.html#post142525
So far the projects works very good, i can transmit the DC Voltage measured by the Atmega168 over to my android phone, and turn on and off a few LEDs as well as dim up and down one of the leds, check it out and hopefully it helps you guys out!

Cheers,
Walter
 
Upvote 0

Alex68

Member
Licensed User
Longtime User
thanks to all

The codce suggested by Erel worked on the first try:sign0098:

Now I have anoter question.

in the code of the chat program posted by Erel. is necessary to paring with th bluetooth device avry time.

The quastion is:
how I can to choose from a list ( for example by spiner) when pairing has already been done the first time. In effect now is necessary to paring te device avery time

thank
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
in the code of the chat program posted by Erel. is necessary to paring with th bluetooth device avry time.
Not necessary... you only need to remember the MAC address of the bluetooth device you are using as slave, then call the "connect" function and pass the MAC address to it, as Erel explained it in another thread.
serial.connect
 
Upvote 0
Top