1

I've got the JY-MCU Bluetooth module connected to the hardware serial port on my Raspberry Pi. It seems to be working except for one thing: when there is no communication for about 10 seconds or more, I have to send extra data to get it to read anything. For testing, I have the Bluetooth connected to my Windows machine and am sending strings with RealTerm. If I loop back the Receive pin straight back to the Transmit pin on the Bluetooth module I get exactly what I sent. When I connect it to the Raspberry Pi and run a Python echo script and keep sending strings within about 5 seconds of each other I get exactly what I sent. However, wait too long and I have to send the string 2-3 times before I get a response. What is happening? Is there a way to fix this?

Here is the test Python code used to echo the string back:

port = '/dev/ttyAMA0'
ser = Serial(port, 9600)
buffer = ''
while True:
    buffer += ser.read(ser.inWaiting() or 1).decode('ascii')
    while '\n' in buffer:
        var, buffer = buffer.split('\n', 1)
        print('Got {}. Echoing back.'.format(var))
        ser.write((var+'\r\n').encode('ascii'))
  • This happens also when connecting via telnet to the RPi over a WiFi connection. I think this is related to the way that these protocols (serial, or tcp) work over wireless connections, I suspect that due to the fact that there is no physical connections and you need to fill some buffers before sending a packet... but just guessing. So, in my opinion, the only way to avoid this behaviour is to do a regular ping or something like that – Roberto Nov 19 '14 at 13:59
  • So is this something the RPi is doing? I tried isolating the Bluetooth earlier by connecting it's Rx and Tx pins. I could wait 5, 10, 15 minutes and when I sent a command from the PC over Bluetooth, it would respond immediately. The problem only appears once the Bluetooth module is connected to the RPi over the serial pins. – Brickmastr Nov 19 '14 at 14:15
  • Not sure but I think the RPi has no responsibility on this, and remains an "issue" of the wireless protocol – Roberto Nov 20 '14 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.