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:
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)'.
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.
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
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.
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)
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.