How to get the port for HC-05 Module on macOS

77 views Asked by At

I am trying to make a simple led on/off circuit and controlled via hc-05 on your laptop(in my case a Mac) but I can't find the port and when I run

ls /dev/cu.*
ls /dev/tty.*

here in the terminal (I can't embed images yet) I get 2 instances of cu.HC-05 or tty.HC-05 but neither of them work

this is the Arduino code I am using

#include <SoftwareSerial.h>


const int RxD = 3;
const int TxD = 2;

SoftwareSerial HC05(RxD, TxD);  // RX, TX

void setup() {
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  pinMode(6, OUTPUT);
  HC05.begin(9600);
}

void loop() {
  while (1) {
    HC05.print("bluetooth connected!\n");
    Serial.println(HC05.read());
    delay(2000);
    HC05.flush();
  }
  if (HC05.available()) {
      String cmd = HC05.readStringUntil('\n');
      if (cmd == "on"){
        HC05.println("LED is on");
        digitalWrite(6, HIGH);
      }
      else if (cmd == "off") {
        HC05.println("LED is off");
        digitalWrite(6, LOW);
      }
      else {
        HC05.println("Command not found");
      }
  }
}

this is the PySerial code I want to use:

import serial
import time

ser = serial.Serial()


ser.port = 'port' #i want to repace this with my port
ser.baudrate = 9600
ser.timeout = 1


ser.open()

time.sleep(5) #give serial time to load

if ser.isOpen():
    print("Serial is open")
    while True:
        user_inp = input("LED is ")
        ser.write(b'user_inp\n')
        data = ser.readline() # read the data from the serial port
        print("Received data:", data)

# Close the serial connection
ser.close()

I want to replace the ser.port = 'port' with my hc-05 port but I don't know how to get it

0

There are 0 answers