Advice please, got a HC-06 and HC-06, 1 slave & other is master but errors in comms!

JPU

Senior Member
Advice please, got a HC-06 and HC-06, 1 slave & other is master but errors in comms!

Hi

I have a pair of blue tooth modules, HC-06. I purchased them from Ebay. I have managed to get them to link and I have been able to share data serially between the two devices. However in a simple program which increments a variable by 1 each loop and then sends the value to the other module wirelessly which is then uploaded to the PE terminal via a AXE027 cable using the command sertxd, there are random errors occurring in the transmission.

This means I have to introduce some s/ware verification of the transmitted data. I have written tWo very simple test programs where by the data is only output if two sets of data which are received in series are the same. (well, to a degree, ie the qualifiers? are correct)

Please can you recommend and explain other ways of doing this or send links to detailed explanations on how to devise simple s/ware error checking routines.

Many Thanks for looking....


TX PROGRAM

Code:
#picaxe 08M2 

setfreq m8 
low C.1 
pause 1000 
main: 

 serout C.0, T9600_8, (#8, #b0) 
 pause 100 
 serout C.0, T9600_8, (#9, #b0)
 PAUSE 100
 
 b0 = b0 + 1 
 goto main
RX PROGRAM
Code:
#picaxe 14M2 
#terminal 9600 

setfreq m8 

main:

  
 serin B.1, T9600_8, b0,b1,b2,b3
 
 if b0="8" then 
 
 	serin B.1, T9600_8, b0,b1,b2,b3
 	
 	if b0="9" then 
 
 
 sertxd ( "value: ", b0,b1,b2,b3,cr,lf ) 
 
 endif
 endif
 
 
 goto main
This was my first uneducated attempt. It ensures to some degree that there is error checking. The next stage was to compare the two values of b1,b2,b3 from each set 8 & 9 and then if they didn't match I would disregard the data. However this potentially means data could be missed. Any help in s/ware driven error checking would be appreciated.
 

hippy

Technical Support
Staff member
Start with the simplest program and run at a reasonably slow speed. Get that working before moving onto anything else ...

Code:
#Picaxe 08M2 
SetFreq m8 
High C.0 
Do
  For b0 = "A" To "Z"
    Pause 2000 
    SerOut C.0, T9600_8, ( b0 ) 
  Next
Loop
Code:
#Picaxe 14M2 
#Terminal 9600 
SetFreq M8 
Do
  SerIn B.1, T9600_8, b0
  SerTxd ( "Value=", #b0, 9, "Char=", b0, CR,LF )
Loop
 

JPU

Senior Member
Hi Hippy
Thanks for your help, I have been able to get communication to work however there are random errors in the transmission. I think this may be due to the fact that there is limited error checking by the hardware devices although they are Blue tooth. I believe I need to improve the software side error checking and this was my attempt?

Do you have any ideas on how I could improve this?

Thanks
 
Last edited:

hippy

Technical Support
Staff member
I have been able to get communication to work however there are random errors in the transmission. I think this may be due to the fact that there is limited error checking by the hardware devices although they are Blue tooth.
Are they transmission errors or flaws in the sending / receiving code ? With your original code you likely won't see what you actually send and things will quickly get out of kilter.
 

JPU

Senior Member
I thought that I would start by sending two sets of identical data and then compare the two sets. In my code it compares the first part ie 8 or 9. I thought this would be the start of an error check and next would be to compare the whole set of data sent. If they didn't match then they can be disregarded. As I started to work out how to do this I realised the flaw that data would be lost as the TX program doesn't know what has been received correctly and carries on regardless. The current program works to a degree in that it only outputs data if the first two digits compare but there are random ASCII chrs in the the rest of the transmission, I suppose this is due to a combination of interference and bad coding. You are correct that the data does monumentality have periods of miss transmission and garbage which I suppose is due to the fact the sender doesn't know if the data has been received correctly.

My thread was posted in the hope that there may be someone who may have already devised or come across some code which may deal with this kind of problem. I could spend hrs, days weeks trying to resolve this and find that there is either a command or industry standard method of doing this?

Thanks
 

hippy

Technical Support
Staff member
I think the industry standard is similar to the building trade; make sure you have good foundations first.

It's hard to say how to make things better when the mechanism used for testing is flawed to start with, won't work with a hard-wired link let alone Bluetooth, other than to say start with something which will work with wired and should work with Bluetooth.

The best practice is to decide what the data is to be sent then build a robust hard-wired solution for that. Add packet framing, qualifiers and checksum to the data sent, make the receiver use those and modify the sender to always or sometimes throw out junk data to ensure that's working as expected.

Once that's all working as expected, force it to send consistent and valid data, check what is received is as expected and it doesn't throw up unexpected errors, then move from hard-wired to Bluetooth, assess the results, identify the types of errors and their potential causes and consider how things may need to be modified.

Make those changes, test as previously on a hard-wired set-up, switch back to Bluetooth and test again. Repeat as necessary.

For me, the most useful thing to know is not that what you have doesn't work, but what the code I suggested does. If that doesn't work there's a big "why not?" in there. If it does work that code can be extended to test other cases which should work which may reveal limitations if it does not which is better than going beyond those limitations and trying to fix things then, as it may actually be impossible to fix in any decent way.

If you want to dive in further than would perhaps be recommended you could try this, ntested but should work -

Code:
#Picaxe 08M2 
SetFreq M8 
High C.0 
Do
  Pause 2000
  BinToAscii b0, b1,b2,b3
  b4 = b1 + b2 + b3 
  SerOut C.0, T9600_8, ( $A3, b1, b2, b3, b4 ) 
  b0 = b0 + 1
Loop
Code:
#Picaxe 14M2 
#Terminal 9600 
SetFreq M8 
Do
  SerIn B.1, T9600_8, ($A3), b1, b2, b3, b4
  b0 = b1 + b2 + b3
  If b0 = b4 Then
    SerTxd ( "OKAY", 9, b1, b2, b3, CR, LF )
  Else
    SerTxd ( "FAIL", 9, b1, b2, b3, CR, LF )
  End If
Loop
 

JPU

Senior Member
Hi Hippy

Thats great advice, thank you.

I have looked at the code and although simple its a leap forward compared to what I posted and makes total sense.

I will have a play with something like that and see how it goes.

Thanks again
 

BeanieBots

Moderator
Just as an asside, I've recently been doing a lot of projects that involve both BlueTooth (HC-06) and ERF/URF modules.
Part of my testing has involved range tests and the consequences of being out of range.
In all the tests, I have NEVER received a 'wrong' character. i.e. corrupt.
The worst that has ever happened is a few missing characters but that was very rare.
In nearly all cases, it either worked flawlessly or there was no data at all.
 
Top