0

My goal is to send a string from an Arduino via an HM-10 bluetooth module to a Rasperry Pi. I do this today by connecting the HM-10 on the Arduino to another HM-10 module (master/slave) and then from that module to the Raspberry Pi via USB Serial adapter which gives me a /dev/ttyUSB0 that I can read. I would like to just have the Arduino's HM-10 connect up directly to the Bluetooth of the Raspberry Pi without any extra modules at all.

I found the app "Arduino Bluetooth Controller" (Android) that can connect to the module and serial communication is working.

I also have the HC-05 module and there I can solve it by using rfcomm bind 2 , but that doesn't work on the HM-10.

I'm open to any solution that can do this. Either bind the serial communication using rfcomm (or alternative) like on the HC-05, or try to build an app that is doing the same thing the Android app does, only on the Raspberry Pi.

1 Answer 1

1

HM-10 is a BLE device. You'll need to understand BLE programming, which is quite different than classic Bluetooth. There is no standard BLE service for serial communication. The best way on a Pi to use BLE is with the

If you are fit in Phyton: The HM-10 style device will send notifications that the Pi's BLE device can read. Basically you need to attach a 'delegate' call-back function to the Peripheral object, and then wait for notifications. The call-back can then process the received data. You'll have to install the bluepy lib on the PI. This sample code writes to an Arduino HC-10 device

import bluepy.btle as btle

p = btle.Peripheral("AA:BB:CC:DD:EE:FF")
s = p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb")
c = s.getCharacteristics()[0]

c.write(bytes("Hello world\n", "utf-8"))
p.disconnect()   

Here is some code for reading from an Arduino HC-10 device

import bluepy.btle as btle

class ReadDelegate(btle.DefaultDelegate):
    def handleNotification(self, cHandle, data):
        print(data.decode("utf-8"))

p = btle.Peripheral("AA:BB:CC:DD:EE:FF")
p.withDelegate(ReadDelegate())

while True:
    while p.waitForNotifications(1):
        pass

p.disconnect()
1
  • I ended up using bluepy like in your example and with some chunking of the incoming data (seems to be a 20 byte limit) it all works great! Thank you!
    – miccet
    Apr 15, 2020 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.