HM-16 BLE 4.1 module with picaxe

edmunds

Senior Member
Dear all,

I successfully created a simple remote control for a model car using iphone, HM-16 BLE 4.1 module and picaxe today. All in all it was pretty simple, but there is lots of time to be saved for someone trying to do this if you know that:

*AT commands should not be followed by LF nor CR on my module. Contrary to most documentation and examples one can find.
* Various bluetooth joystick apps that claim to be generic may well be generic to some extent, but most do not support HM-10 to HM-16 modules. The only one that really works for iphone with HM-10 to HM-16 I found after sipping through dozens of candidates is called Serial. If you also want to add buttons, it costs a small amount of money.

Code:
'TX pin to B.1;
'RX pin to B.0;
'CTS, RTS floating.

do                                                                  'Should not be connected to the phone, LED blinking
  serout B.0, T9600_8, ("AT")                           'Send AT to see if the module is alive
  sertxd ("Sent AT", CR, LF)                              'Tell me you sent AT
  serin [1000, nothing], B.1, T9600_8, b0, b1    'Wait max 1000ms for a response, jump to nothing if did not work
  if b0 = 79 and b1 = 75 then                           'Check if the response was "OK"
    sertxd ("OK", CR, LF)                                   'Tell me you are OK
  else
    sertxd (#b0, #b1, CR, LF)                            'Tell me you are not OK
  endif
  do                                                                'In case there was a response, go into a loop waiting for a command
    serin B.1, T9600_8, b2                                'Now it is a good time to connect your phone to HM-16 and send something
    sertxd (#b2, CR, LF)
  loop
nothing:
  sertxd ("Did not receive a thing :(", CR, LF)    'Tell me you are totally unhappy
  pause 1000
loop

Cheers,

Edmunds
 
Top