Skip to content

A Tutorial with examples for a Python-Arduino serial communication using a HC-05 Bluetooth module.

Notifications You must be signed in to change notification settings

KarimLakra/Python_communication_Bluetooth

Repository files navigation

Bluetooth Communication - Python

1 - Transmitting data from Python to the Arduino Software (IDE) serial monitor

To test this examples (made for windows):
  • Connect the parts with the Arduino as shown in the image
  • Connect the Arduino to the PC using USB connector.
  • Transfer the .ino file located in Arduino_Bluetooth folder to the Arduino using the Arduino Software (IDE).
  • In the Arduino Software (IDE), from the menu: Tools>Port>Serial ports, choose the port where the Arduino is connected.
  • If you don't know the COM port number, double click on ActivateVirtualEnv.bat which will opens a Command Line(CLI) and activates a virtual environment for you.
  • Execute this: python -m serial.tools.list_ports -v
  • You will get a list of available ports with info, you need something like this(My Arduino is connected to COM5): USB-SERIAL CH340 (COM5)
  • If you have a paired Bluetooth to the computer, you should get results like(this is not what you need now): Standard Serial over Bluetooth link (COM3)
  • Open the Arduino Software (IDE) serial monitor.
  • Double click on ActivateVirtualEnv.bat
  • Execute in the CLI: python Transmitter.py
  • The transfer of data should be printed in both the CLI and (IDE) serial monitor.
  • The LED is turned ON in the beginning of the transfer and OFF in the end.

2 - Receiving data using a CLI instead of the IDE serial monitor

If you get the steps above done, you can start the next steps which uses a CLI to replace the (IDE) serial monitor.

This example uses the miniterm to listen to a specific port, you can explore the many useful options offered by this tool.

  • Before executing the Miniterm-listen-to-COM.bat, right click on it and choose edit(any simple editor can do the job) change the port number that you used for the serial monitor.
  • Now execute Miniterm-listen-to-COM.bat
  • Now the miniterm is listening to the COMx (where the Arduino USB is connected, mine is COM5) save the file.
  • Open a CLI using ActivateVirtualEnv.bat
  • And execute: python Transmitter.py
  • You should see the same as in the first example.

3 - Using Python to Transfer/Receive data

In this third example we will use a python class to receive data, which can be useful for developping a Python application.
  • As the step above, open a CLI using ActivateVirtualEnv.bat
  • Edit the Receiver.py and change the COMx as above(mine is COM5) save the file.
  • Open a CLI using ActivateVirtualEnv.bat
  • Execute: python Receiver.py
  • Open a CLI using ActivateVirtualEnv.bat
  • Execute: python Transmitter.py
  • You should see the same as in the first and second examples.

4 - Python GUI to communicate with the Arduino

Next update!


Links:

About

A Tutorial with examples for a Python-Arduino serial communication using a HC-05 Bluetooth module.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published