Using 08M2 with Sparkfun Blue smirf Gold

Samuel43

New member
Hi,
So I am trying to use a 08M2 with a Sparkfun Blue smirf gold, https://www.sparkfun.com/products/retired/12582, so that I can control a project of mine over bluetooth. I have had success with the 08M2 sending text to the serial terminal app on my phone, but when I send the characters "0" or "1" from the terminal app to the 08M2, they are never received correctly. Instead of getting ASCII 48 or 49, I almost always get 248, 230, 152, 24, or 6. Does anybody have any idea what might be going on? Attached is a simplified schematic of my test setup and my code

Thanks


Schematic.jpg

Code:
let b0 = 0 ; Fog machine ready input
let b1 = "0" ;Recieving serial buffer
HSERSETUP OFF
Mainloop:
if pinc.3 = 0 AND b0 = 1 then ;Check if fog machine has gone into the not ready state from previous
    let b0 = 0            ;ready state and notify user if so
    LOW c.4
    serout c.2, T4800_4, ("Fog not ready")
    serout c.2, T4800_4, (13)
    pause 250
    serout c.2, T4800_4, ("Fog off")
    serout c.2, T4800_4, (13)
    HSERSETUP OFF
endif

if pin3 = 1 AND b0 = 0 then ;Check if fog machine has gone into ready state from previous not ready
    let b0 = 1            ;state and notify user if so
    serout c.2, T4800_4, ("Fog ready")
    serout c.2, T4800_4, (13)
    HSERSETUP B4800_4, 8
endif

if b0 = 1 then ;If fog machine is ready then read serial buffer
    hserin b1
    if b1 = "0" then ;If "0" is received then turn off fog
        LOW c.4
        serout c.2, T4800_4, ("Fog off")
        serout c.2, T4800_4, (13)
        let b1 = 0
    endif
    
    if b1 = "1" then ;If "1" is received then turn on fog
        HIGH c.4
        serout c.2, T4800_4, ("Fog on")
        serout c.2, T4800_4, (13)
        let b1 = 0
    endif
        
endif
debug
goto Mainloop
 
Last edited:

hippy

Technical Support
Staff member
It might be worth running a simpler test program to see what the PICAXE receives over Bluetooth. Something like ...
Code:
HSerSetup B4800_4, 8

Do
  w0 = 256
  HSerIn w0
  If w0 < 256 Then
    SerTxd("Got ", #w0, " - ", w0, CR, LF)
  End If
Loop
Updated : Now takes into account AlleyCat's comments below - Seems I am still a bit rusty in some places !
 
Last edited:

AllyCat

Senior Member
Hi,

You're not really using the HSERIN command "correctly" for M2 PICaxes. See Example 2 in the HSERIN command syntax.

It's important to ensure that the buffer has received a byte, but only one. There appears to be a timing "issue" with the handling of any (closely following) subsequent byte(s), so in my experience it's much safer (with M2s) to read the buffer directly, using PEEKSFR commands.

Cheers, Alan.
 

Samuel43

New member
Okay,
So instead of using hserin I used peeksfr $79, w1. This produced similar results compared to before. I also turned off local echo in the terminal app and made sure that it wasn't sending any additional CR, LF, STX, ETX, or NUL characters, didn't make a difference.
 

hippy

Technical Support
Staff member
One thing I note with your "HSEROUT B4800_4, 8" is you are disabling the TX to the module. If that is putting a low into the module that may be causing it to misbehave. Using ",0" would be worth a try.

Three common reasons for serial not being received correctly is wiring error, wrong baud rate or wrong signal polarity.

The hard part with diagnosing any serial receive issue is not knowing what is actually being sent to the PICAXE, what may be causing it to report what it does. Inverting the module's output and looking at what is received using the Serial Terminal is where I would start with trying to diagnose what is going on.
 

Samuel43

New member
Okay, the reason I disabled the TX pin for HSER is because that line is shared between HSER and the AXE027 programming cable and I didn't want interference between the two. So I decided to use just the HSERIN connection to receive the data from the terminal app on my phone and then use serout on pinc.2 to send data to the terminal, which does work, I am able to get status messages from the 08M2. The wiring I used for the bluetooth module was just the standard download circuit required for the AXE027 programming cable, see schematic in my original post. I will look through the documentation of the bluetooth module a bit later when I have time to see if there is some obscure setting that may be causing the issue. I know the baud rate is fine because I did connect to the modlue with the Arduino terminal and set it to 4800 previously.
 

Samuel43

New member
Okay I figured it out. Turns out that having debug enabled messed everything up. Here is my final code:

Code:
let b0 = 0 ; Fog machine ready input
HSERSETUP OFF
Mainloop:
if pinc.3 = 0 AND b0 = 1 then ;Check if fog machine has gone into the not ready state from previous
    let b0 = 0            ;ready state and notify user if so
    LOW c.4
    serout c.2, T4800_4, ("Fog not ready")
    serout c.2, T4800_4, (13)
    pause 250
    serout c.2, T4800_4, ("Fog off")
    serout c.2, T4800_4, (13)
    HSERSETUP OFF
endif

if pin3 = 1 AND b0 = 0 then ;Check if fog machine has gone into ready state from previous not ready
    let b0 = 1            ;state and notify user if so
    serout c.2, T4800_4, ("Fog ready")
    serout c.2, T4800_4, (13)
    HSERSETUP B4800_4, 8
endif

if b0 = 1 then ;If fog machine is ready then read serial buffer
    HSERIN b1
    if b1 = "0" then ;If "0" is received then turn off fog
        LOW c.4
        serout c.2, T4800_4, ("Fog off")
        serout c.2, T4800_4, (13)
        let b1 = 0
    endif
    
    if b1 = "1" then ;If "1" is received then turn on fog
        HIGH c.4
        serout c.2, T4800_4, ("Fog on")
        serout c.2, T4800_4, (13)
        let b1 = 0
    endif
        
endif
goto Mainloop
 
Top