Question regarding Serin command

JSDL

Senior Member
Hi everyone, after hours of trial and error, I finally got the HC-06 Bluetooth to serial module connected and working with a Picaxe 20M2. I have the Picaxe sending text in a loop to the module (Loop execution #1, Loop execution #2, etc), which I can then view in a terminal window when connected to the virtual bluetooth comm port. Here is my code:

Code:
Setfreq M8

init:  pause 500

symbol rx = c.2
symbol tx = c.1
symbol i=b0
let b0=0

high tx
pause 100

do
     serout tx, t9600_8,("Loop #", #i,cr,lf) 
     b0=b0+1
     pause 200
loop
My question is that when I program the following code instead,
Code:
Setfreq M8


symbol rx = c.2
symbol tx = c.1


high tx
pause 100

main:

serin rx, t9600_8,("set"),#b0

select case b0
	case "1"
	high b.1
	serout tx, t9600_8,("ON",cr,lf)
	case "0"
	low b.1
	serout tx, t9600_8,("OFF",cr,lf)
	
end select

pause 200
goto main

I get no response from the Picaxe (no LED toggling on/off). I think it must have something to do with the data format (ASCII or not) in the qualifier, or a special character missing. I feel it is something simple but cannot figure it out. Any help form the forum would be much appreciated. Thanks again
 

hippy

Technical Support
Staff member
Assuming the hardware and wiring is correct, one cause could be that nothing is being received or what is received does not match with the qualifier used.

You are also receiving using '#b0', which expects a series of ASCII digits representing the value, terminated by a non-digit character. Does whatever is sending provide that ?

Having received a number into 'b0' your CASE statements compare that to ASCII values; "1" is not the same as 1, "0" is not the same as 0.
 
Last edited:

hippy

Technical Support
Staff member
So then, if I remove the quotes from Case "1" and change it to Case 1, it should work?
I would expect so but it does depend on what you are receiving into 'b0' and what you are sending to it.

If you have a terminal connected to the transmitter, are typing in and sending out -

set1<RETURN>

Then taking the double-quotes out, CASE "1" becomes CASE 1, that should make it work.

Alternatively you could leave them in and change the '#b0' to just 'b0' and that would work if you sent -

set1

No <RETURN> key press needed.
 

JSDL

Senior Member
I've tried both methods above but unfortunately no go, I even tried a different module. It is as if I am not getting past the qualifier because I don't receive either of the two messages in the Case statement nor does b.1 ever go high. Any suggestions as to what to try next?
 

hippy

Technical Support
Staff member
You could post the updated code you now have so people can check that. You can add some SERTXD commands so you can tell exactly where the code does get to. I would also suggest getting it to work with a hard-wired serial connection before switching to Bluetooth.

It could be an issue of the Bluetooth module passing received data to the PICAXE back-to-back and the SERIN command being unable to keep up with that. It might be worth trying a test program which just receives a single byte and echoes that back, then two bytes etc.

If it is the data coming in too quickly for SERIN then you might have to switch to a higher operating speed or use an X2 and background serial receive.
 

JSDL

Senior Member
ok, here's the updated code:

Code:
Setfreq M16


symbol rx = c.2
symbol tx = c.1


high tx
pause 100

main:

serin rx, t9600_16,("set"),#b0

select case b0
case 1
	high b.1
	serout tx, t9600_16,("ON",cr,lf)
case 0
	low b.1
	serout tx, t9600_16,("OFF",cr,lf)
end select

pause 200
goto main
 

Hooter

Senior Member
I may be wrong but it appears you are using 'Loop' as your qualifier in the Serout routine and 'Set' as the qualifier in the Serin routine.
 

JSDL

Senior Member
Ok so I have confirmed serials comms with a hard-wired serial connection and all works fine, it must have something to do with the bluetooth module itself, or as Hippy suggested the operating speed of the Picaxe. I tried the above code at 32MHz 9600 baud (T9600_32) and still no luck. Has anyone had any success with this module?
 

manuka

Senior Member
Don't take it personally -those slave only HC-06 are known to be rather a challenge! The near identical HC-05 however has different firmware that allows both master and slave operation.

But since your HC-05 works OK with the 1st code sample (& not the 2nd),surely it's the code? Check for typos!

Thought: Grab an Android smartphone & download suitable BT apps to aid in monitoring. Blueterm is especially well thought of, while Bluetooth Signal allows BT detection & ID, along with very handy RSSI indication. Stan.
 
Top