I'm trying to communicate with a HM-10 over bluetooth, however, when I connect to the device using the third party app ''LightBlue', I can't see any COM port open when I type ' ls /dev/tty.* ' into my terminal. Is there anything I can do to fix this? Thanks.
Try ls /dev/tty*
Yeah, a bunch. more ports come up now, but how do I know which one is the right one? Thanks
Disconnect the HM-10, note the list of ports. Connect the HM-10, check for the differences.
I do not know what your setup is. Did you connect the HM-10 to the PC through a serial-to-usb converter? Or do you have another setup?
I'll try that. I connected it through a soft serial via the Arduino
If that means that you connect your HM-10 to an Arduino and use a sketch with SoftwareSerial, you will never see you HM-10 in you operating system; you will only see the Arduino.
Which Arduino are you using?
Are you following specific instructions that you found somewhere? Please provide a link.
Should I not see a COM port open when I connect to the HM-10 via bluetooth?
I'm using an arduino nano.
For the HM-10 connection to the arduino, I'm following this: https://www.youtube.com/watch?v=itGgUTPLkz8 instructions. The HM-10 is working fine though. My only problem is I can't find a COM port open when I connect to it using LightBlue. Id it possibly to do witht the fact that I'm connecting to blueooth via a third party app? Thanks
Sorry, can't do youtubes. If your HM-10 is connected to software serial pins on the Arduino, you will not see a com port on the PC.
But isn't it to do with the bluetooth connection that I want to see the COM port? If not, how can I connect it such that I can see the COM port when I connect via bluetooth? Thanks.
Connect a USB-serial converter directly to the Bluetooth module (make sure to obey the 3.3V logic level) and a COM port will appear on the PC.
It is not clear what you are actually trying to do. For better advice, take the time to describe your project.
If you want to use an Arduino in between the HM-10 and the PC you can use the below sketch as the basics.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(19200);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop()
{
if(mySerial.available())
{
Serial.write(mySerial.read());
}
}
Code not tested or compiled. Whatever is received by the Arduino will be send by the Arduino to the PC. This is basically what your link does but a different way.
If you want to connect the PC to the HM-10, either use an adapter as described by @jremington or use the Arduino as an adapter. For the latter
- Connect the reset of the Arduino to GND. This will keep the main processor in reset and whatever you did upload will not run.
- Connect HM-10 TX to Arduino TX and HM10 RX to Arduino RX.
- HM-10 Vcc and GND as you had it.
You can now use the serial monitor (or other terminal program) to see what is received by the HM-10; the port will be the port of the Arduino.
Note:
You will never see a HM-10 anywhere in your operating system; it will always be the converter between the HM-10 and the PC.
Ok thank you. I'm already using similar code. I then use this code:
import serial
serialcomm = serial.Serial('......', 9600)
print(serialcomm)
serialcomm.write(bytes(str(1), 'utf_8'))
serialcomm.close()
to communicat to the HM-10 in Python once I've connected using LightBlue. However, I require a COM port to communicate with it, however, no COM port appears once I connect using LightBlue (I've put ...
where the COM port name should be).
Based on the info that you provided in post #5, the serial port will be the port of the Arduino.
That is irrelevant, it's the serial port of the Arduino.
Which Arduino are you using?
I'm using an Arduino Nano.
So how sould I be communicating with the HM-10 over bluetooth?
You talk to the Nano that is running a appropriate sketch that forwards data received from the PC to the HM-10 and that forwards data received from the HM-10 to the PC. The below can act as a framework.
#include <SoftwareSerial.h>
const byte rxPin = 2;
const byte txPin = 3;
// Set up a new SoftwareSerial object
SoftwareSerial hm10Serial (rxPin, txPin);
void setup()
{
Serial.begin(115200);
hm10Serial.begin(9600);
}
void loop()
{
if(Serial.available())
{
hm10Serial.write(Serial.read());
}
if(hm10Serial.available())
{
Serial.write(hm10Serial.read());
}
}
It compiles but is not tested. You will need to adjust the wiring between the Nano and the HM-10 so it uses pins 2 and 3 or you need to adjust the sketch (rxPin and txPin) to reflect the connections between the Nano and the HM-10. You will need to adjust your python script to use a baud rate of 115200.
Be aware that SoftwareSerial can not transmit and receive at the same time.
So what code do I use to connect to the HM-10 in Python? I know this isn't a Python forum, but would you be able to help me with that by any chance?
You talk to the Nano from your python script. You can not use your python script while your IDE has an other terminal program (e.g. serial monitor) open so you have to close that.
Be aware that when you open the serial port, the Nano goes through a reset cycle and you can not immediately send something from the PC; you'll have to wait a while (few seconds).
I suggest that you start by using serial monitor to test; once you're comfortable that it works as expected, you can concentrate on the python side of things.
I'm not a python programmer. Here are some tutorials regarding the subject of python communication
Thank you. I've already set up the Arduino and HM-10 so that I can communicate with it (i.e, using AT commands). I then close the serial monitor to try to communicate with it using Python (after I connected to it via LightBlue), but I just dont know how. Thats my problem.
I've written a small tutorial on interfacing with Python. See Two ways communication between Python3 and Arduino
can you try that?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.