Bluetooth electronics App

r1erick2

New Member
Hi, I have a HC-06 bluetooth serial adaptor connected to picaxe 08m2+ and I using an Bluetooth App, it is working correctly in a just single command, example: push bottons or any serial out text comunicacion, but if you want to use digital joystick or any slider doesn't work correctly. Please any help. Thank you.

Setfreq m8

Start:

Serin c.2,T9600_8,b0
Pause 50
Sertxd ("Real Value", #b0,13,10)
Pause 100

Goto start



App www.keuwl.com
Only in android BlueTooth Electronics.
 

hippy

Technical Support
Staff member
When you say it doesn't work correctly; what does it do ?

I would guess that the phone app could be sending more than one byte of data and the code has to be adjusted for that but I couldn't find any documentation on what the app sends.

If you have any idea where that information would be it would be a great help if you could tell us where that is.

Looking at the RGB LED controller, it seems the app sends a character and then an number -

http://www.keuwl.com/electronics/rduino/bluet/02-pwm-leds

Using that example I would have expected to be able to read the data sent from the red fader with the following code, untested -
Code:
Setfreq m8

Start:

Serin c.2,T9600_8,b0, #w1
If b0 = "R" then
  Sertxd ("Red", #w1,13,10)
EndIf

Goto start
 
Last edited:

inglewoodpete

Senior Member
I agree with hippy. Those pause commands are resulting in the PICAXE skipping the successive characters. The pauses have no place in a program that is trying to receive serial data.
 

r1erick2

New Member
Im in the work right now but Thats true about the pauses, if i want to use more data bits i need to add something like that?

Start:

Serin c.2,T9600_8,b0, #w1
If b0 = "R" then
Sertxd ("Red", #w1,13,10)

Serin c.2,T9600_8,b0, #w2
If b0 = "B" then
Sertxd ("Blue", #w2,13,10)

Serin c.2,T9600_8,b0, #w3

If b0 = "G" then
Sertxd ("Green", #w3,13,10)

EndIf

Goto start

If I use this code in the joystick?


Start:

Serin c.2,T9600_8,b0, #w1
If b0 = "X" then
Sertxd ("X", #w1,13,10)

Serin c.2,T9600_8,b0, #w2
If b0 = "Y" then
Sertxd ("Y", #w2,13,10)

Ifend
Goto start
 

hippy

Technical Support
Staff member
Rather than consecutively read with separate SERIN commands you would probably be better off with something which does one SERIN and then determines what has been received. Something like -
Code:
#Picaxe 08M2
#Terminal 9600
#No_Data

Symbol rxdChar  = b0
Symbol rxdValue = w1
Symbol red      = w2
Symbol green    = w3
Symbol blue     = w4

SetFreq M8
Do
  SerIn C.2, T9600_8, rxdChar, #rxdValue
  Select Case rxdChar
    Case "R" : red   = rxdValue : Gosub Report
    Case "G" : green = rxdValue : Gosub Report
    Case "B" : blue  = rxdValue : Gosub Report
  End Select
Loop

Report:
  SerTxd( "R = ", #red,   TAB    )
  SerTxd( "G = ", #green, TAB    )
  SerTxd( "B = ", #blue,  CR, LF )
  Return
Or, very similar, for the joystick -
Code:
#Picaxe 08M2
#Terminal 9600
#No_Data

Symbol rxdChar  = b0
Symbol rxdValue = w1
Symbol x        = w2
Symbol y        = w3

SetFreq M8
Do
  SerIn C.2, T9600_8, rxdChar, #rxdValue
  Select Case rxdChar
    Case "X" : x = rxdValue : Gosub Report
    Case "Y" : y = rxdValue : Gosub Report
  End Select
Loop

Report:
  SerTxd( "X = ", #x, TAB    )
  SerTxd( "Y = ", #y, CR, LF )
  Return
 

Bill.b

Senior Member
Hi
This is a sample of the code I have used to control a robot using HC 06.
The Bluetooth app I am using is roboremo.
each button is assigned a LETTER ie A - I and a slider for speed control With ID "r".
The output range set to 0 to 255,
The HC 06 sends the slider data in 5 bytes - ID, space, units, 10s and 100s this requires some decoding in the program.
Hope this is of some help

Bill

Code:
#picaxe 40X2
Setfreq M16
#No_Data
#No_Table
DisableBod
Symbol M1PWM  = C.2  'Motor 1 & 2 Speed (PWM) output
symbol SpeedCount  = w21
RemoteIn:
REM Controlling with BT module HC-06 - PICAXE
do
'b12 = 0  ;clearing memory for commands
serin [2000],a.0,T9600_16,b12,b13,b14,b15,b16 ;reading from bluetooth (waits 2s for character)
  pause 50
'select b12  ;selection depending on received character
select case b12
case 65
gosub FWDFast 'FWD
case 66
gosub TurnRight 'FWD Right
case 67
gosub TurnRightR 'REV Right
case 68
gosub BackFast 'REV
case 69
gosub TurnLeftR 'Rev Left
case 70
gosub Turnleft 'FWD Left
case 71
gosub stopm 'Stop
case 72
VoiceNo = 33
GOSUB voice 'camera on
case 73
VoiceNo = 34
  GOSUB voice  'camera off
case 74
Pwmduty M1PWM,900
gosub TurnAround2
case 75
Pwmduty M1PWM,900
gosub TurnAround
case 113 'Speed
b17= b14 -48
if b15 = 10 then
b18 = 0
goto loopend
else
b18 = b15 -48
endif
if b16 = 10 then
b19 = 0
else
b19 = b16 - 48
endif
end select
loopend:
b7= b17 * 10 + b18 * 10 + b19 'Convert from ASCII to Binary
SpeedCount = b7 * 3 + 200 'Speed count for PWM = 200 to 950
Pwmduty M1PWM,speedCount
loop
return  ;end of loop
 
Last edited:
Top