How to use HC05 with MacBook Pro m2

I am new to Mac OS, and this is my first time trying to work on an Arduino project with it.
I tried to use HC05 as the bluetooth module and connect it with my macbook.
The arduino side code is as below:

#include <SoftwareSerial.h>
#include <Wire.h>

SoftwareSerial BTSerial(8, 9);
byte btRead;
void setup() {
  BTSerial.begin(38400);
  Serial.begin(9600);
  
}

void BTPrint(unsigned int);

void loop() {
  Serial.println("aaa");
  BTPrint(40);
  delay(1000);
}

void BTPrint(unsigned int output) {
  BTSerial.write(output >> 8);
  BTSerial.write(output);
}

I tried to connect to HC05 with screen /dev/cu.HC05 38400 in my terminal, but I received nothing. When I connect to HC05 from the bluetooth setting on my Macbook, the led on HC05 turned to 'connected mode(blink slow)'.

Does anyone know what problem this is?

I assume the above is a macintosh command, about which no comment.

Here, the 38400 applies only to communication between Arduino and HC-05, and has nothing to do with whatever is going on at the othert end. Further, it is only valid if you have specifically configured HC-05 to communicate at 38400. I wonder if you have actually done that, and I bet you don't have good reason for doing so. If you have not configured HC-05 to 38400, I suggest you simply change to the default

  BTSerial.begin(9600);

If you did reconfigure to 38400, I suggest you reconfigure to 9600, and use the same line.

Your code seems overcomplicated. This may have something to do with your Macbook terminal but I doubt it. If it isn't, there must be a bazillion examples of Arduino/Bluetooth/PC terminal out there - each one a lot simpler than yours.

Also a show a clear diagramme of HC-05/Arduino connections Rx>Tx and Tx>Rx.

Thanks for the help.
I indeed configured my HC05 to 38400 as baud rate, so I guess this is not the actual problem…?
By the way, I guess if the problem comes from wrong baud rate, it should still receive some data, while those data are garbled. But in my case, no data is received.
Also, HC05 can be connected with Windows. I am just not sure how to do the same thing with MacBook.

Possibly not, but it's never a good idea with software serial, hence my comment.

probably true, hence my comment about wiring.

I understand you are using a MacOS, specifically not IOS, and therefore you should be able to connect just as easily as with Windows.

  1. make sure you can see the HC-05 in your settings
  2. make sure your terminal is kosher for classic Bluetooth rather than BLE..

How about googling?

Don’t post advertisement for installing cleanMyMac - it’s not a good recommendation.

Is there any way that I can use pyserial to connect to HC05 with my MACBook? I googled but got no answer.

have you checked if you have a /dev/tty.HC05. Did you try that?

I meant did you try screen /dev/tty.HC05 ?

does this appear in /dev at all?

I typed python3 -m serial.tools.list_ports in my terminal and it is showed in the list so I guess it exists. Is there any better way to check this?

cf answer 10 I was answering as you deleted the other post

also can you share exactly how the HC-05 has been configured?

Like the name says pyserial is for serial communication. A HC-05-modul has a serial interface towards yor microcontroller on the computer-side it is bluetooth.
So if you want something with python you would have to look for bluetooth / python

best regards Stefan

I typed ls /dev/tty.* and it is listed in the return values. But when I tried screen /dev/tty.HC05, I get a blank page and I cannot even leave the screen terminal with ctrl+a+k+y. It just freeze.

I just set the HC-05 with AT and configured it to factory default(AT+ORGL). I just tried with another Windows laptop, and it can be connected and transmit data to PC. But the same thing cannot be completed on my Macbook.

did you try ctrla and then just d. That should detach the session

may be force AT+CMODE=1 to allow all bindings - not sure it's the default


Sorry for the misleading. What I mean is that, I can connect to my HC05 with a python program using pyserial with another Windows laptop using the below code. But it does not wok on my Macbook. I wonder what should I use as the com port name as we don't have COMx on MacBook.

import serial
import serial.tools.list_ports


def listPorts():
    ports = serial.tools.list_ports.comports()
    for port in sorted(ports):
        print(port)
ser = serial.Serial('COM9', 38400, timeout=2)
listPorts()
while True:
    data = ser.read(1)
    if data:
        print(data)

what do you see on the Mac when you do

ports = serial.tools.list_ports.comports()
for port in sorted(ports):
  print(port)

to connect at 38400 bauds to /dev/cu.HC05 you would do something like

arduinoPort = '/dev/cu.HC05'
baudRate = 38400

arduino = serial.Serial(arduinoPort, baudrate=baudRate, timeout=.1)

what do you see if you run this (python3)

#!/usr/bin/python3

import sys, threading, queue, serial

# CHANGE THE PORT TO MATCH WHAT YOU NEED
arduinoPort = '/dev/cu.HC05'
baudRate = 38400

arduino = serial.Serial(arduinoPort, baudrate=baudRate, timeout=.1)
arduinoQueue = queue.Queue()


def listenToArduino(commandQueue):
    message = b''
    while True:
        incoming = arduino.read()
        if (incoming == b'\n'):
            arduinoQueue.put(message.decode("utf-8").strip().upper())
            message = b''
        else:
            if (incoming != b''):
                 message += incoming


def configure():
    arduinoThread = threading.Thread(target=listenToArduino, args=(arduinoQueue,))
    arduinoThread.daemon = True
    arduinoThread.start()


# ---- MAIN CODE -----

configure()
print("Ready to receive input from " + arduinoPort)
currentCommand = ""

while True:
    if not arduinoQueue.empty():
        currentCommand = arduinoQueue.get()
        print("Got [" + currentCommand + "]")

and run a small program on the Arduino printing to the BT software Serial line something every 5 seconds (with println)

Do I need to connect to my HC05 with Mac bluetooth setting before running this? Because in Windows, I only paired HC05 with my laptop (HC05 fast blinking), and then run the script in #18 ( HC05 turned to slow blinking). And I get the data.

/dev/cu.SoundcoreLifeP3
/dev/cu.Bluetooth-Incoming-Port
/dev/cu.BioLabG2
/dev/cu.usbmodem101

(BioLabG2 is the old name of my HC05 before factory reset)