Serin Qualifiers

r1erick2

New Member
Hi, I have problems using Qualifiers in serin, I have the PCA9685 16 channels servo, serial Bluetooth hc-06, and 18m2+ picaxe, the app is Bluetooth electronics and RC Bluetooth, I would like to use the 3 variables X, Y, and Z, I made a simple program but when I tried to use more qualifiers stop working.

Code:
setfreq m8

main:
'main address
HI2cSetup I2CMASTER, $84, I2CSLOW, I2CBYTE
  Hi2COut %00 ,( %00110000 )
  Hi2COut $FE,( 121 )
  Hi2COut $01,( %00000100 )
  Hi2COut $00,( %00100000 )

'set home all servos
For b3 = 0 To 15
    b4 = 150

  Next

start:

   'serin B.3,T9600_8,("X","Y","Z"),#b8,#b10,#b12       """"""I tried to use this serin""""""
      
  serin B.3,T9600_8,("X"),#b8 ' only works with one qualifier

     b9=b8+50
     b3 = 0   ' servo 0
     b4 = b9  ' position variable
      Gosub math
   
b11=b10+50
      b3 = 1   ' servo 1 to 16
      b4 = b11  ' position minimum 50
      Gosub math

b13=b12+50
      b3 = 1   ' servo 1 to 16
      b4 = b13  ' position minimum 50
      Gosub math
     

Pause 10
      'pause 40
goto start

'default servo driver math.

math:

  b2 = b3 * 4 + $06
  b4 = b4 Min 50 Max 250
  w0 = b4 * 2
  w0 = b4 ** 3112 + w0
  HI2cOut b2,(0,0,b0,b1) ' servo controller
return
 
Last edited:

hippy

Technical Support
Staff member
The qualifiers define what must be at the start of the message, not the variables themselves. If your message is -

X=12,Y=34,Z=56<CR><LF>

You should be able to capture that using -

serin B.3,T9600_8,("X"), #b8, #b10, #b12

If that doesn't work then if you can tell us what your message looks like that will help.
 

r1erick2

New Member
The qualifiers define what must be at the start of the message, not the variables themselves. If your message is -

X=12,Y=34,Z=56<CR><LF>

You should be able to capture that using -

serin B.3,T9600_8,("X"), #b8, #b10, #b12

If that doesn't work then if you can tell us what your message looks like that will help.
Hi Hippy, it's not working, servos move randomly and all 3 servos move at the same time, qualifiers in this app are T,S,G,HO,R,L.
this is the app:

 
Last edited:

AllyCat

Senior Member
Hi,
Code:
   'serin B.3,T9600_8,("X","Y","Z"),#b8,#b10,#b12       """"""I tried to use this serin""""""
PICaxe commands work almost entirely from Left to Right, so the program would look for "XYZ" before reading a value into b8. As hippy said, just looking for "X" should work and then it should skip over the other non-digit characters to load b10 and b12 (but note that the # qualifier requires a non-digit character to be sent after the digits for b12). Alternatively, use separate lines of code for X , Y and Z (or whatever qualifiers are present). But, particularly if nothing is being received, try leaving out all the qualifiers to see what is actually being transmitted.

However, there still may be problems if the ASCII characters are being transmitted with only small spaces between them (or even fully "concatonated") which a PICaxe just can't handle (except perhaps by using HSERIN, but that also has issues). You really need a logic analyser or 'scope to be sure of what is being transmitted.

As for the servos operating "randomly" and/or all at the same time, I'd suspect a power supply issue or poor earth connections. Does the power supply have a good current rating (at least several Amps) with good decoupling capacitors? Again, if problems are encountered, use a separate power supply (or batteries) for the PICaxe, but don't forget to link the Earths. ;)

Cheers, Alan.
 

Bill.b

Senior Member
This is the code I use on my robot car for the Hc-06 bluetooth receiver

Code:
RemoteIn:
REM Controlling LED with BT module HC-06 - PICAXE
do
gosub DistanceMessure

'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
'debug
'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
'debug
return  ;end of loop

b12 is the Identifier I.E Which button or slider from the bluetooth device
b13 is a null bit
b14,15 and 16 are the ascii code for the value from the speed slider
b16 = unit
b15 = tens
b14 = hundreds

Hop this may be some help

Bill
The remainder of the code converts the ascii value to decimal
 

r1erick2

New Member
This is the code I use on my robot car for the Hc-06 bluetooth receiver

Code:
RemoteIn:
REM Controlling LED with BT module HC-06 - PICAXE
do
gosub DistanceMessure

'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
'debug
'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
'debug
return  ;end of loop

b12 is the Identifier I.E Which button or slider from the bluetooth device
b13 is a null bit
b14,15 and 16 are the ascii code for the value from the speed slider
b16 = unit
b15 = tens
b14 = hundreds

Hop this may be some help

Bill
The remainder of the code converts the ascii value to decimal
thanks, I'll try it
 
Top