Send Command from Bluetooth Serial Controller Android App

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Send Command from Bluetooth Serial Controller Android App

Post by yllumi » Fri Aug 21, 2015 10:22 am

I have successfuly connect my HC-05 bluetooth module to pyboard via UART(6). I also have tried to connect and send serial data from computer.

Now I currently trying to receive data from Bluetooth Serial Controller Android app to pyboard. The app can connect to bluetooth module and I try to send character '1' to pyboard, but there is no response. This is my program:

Code: Select all

from pyb import UART

uart = UART(6, 9600)

print(uart.read())
if uart.read():
  pyb.LED(3).on()
else:
  pyb.LED(3).off()
Is my code wrong or I've done wrong way?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Send Command from Bluetooth Serial Controller Android App

Post by dhylands » Fri Aug 21, 2015 4:26 pm

When you open the UART, there are 2 timeouts you can specify. One is simply called timeout and the second is called timeout_char
http://docs.micropython.org/en/latest/l ... #uart.init
The default timeout is 1000 which is 1000 msec or 1 second. What that means is that if you call uart.read() and no data shows up for 1 second then it will return an empty string.

So you really need to put your read in a loop.

Post Reply