How can I pass data in real time to my PC running a python script via Bluetooth?

I have a force sensitive resistor(FSR) in my circuit and I would like my Arduino to pass this data to my PC, running a python script, via bluetooth.

Here is the bluetooth shield I am using for this project: (Bluetooth Shield)

I've attempted to mimic the examples on here but neither scenario involved a situation where the Arduino Bluetooth interacts with a PC's bluetooth and the code wouldn't even upload when I used their sketch.

Here is the code for my FSR:

   const int fsrAnalogPin = A0;
    int fsrReading;
    
    void setup(void) {
      // put your setup code here, to run once:
      Serial.begin(9600);
    }
    
    void loop(void) {
      // put your main code here, to run repeatedly:
      fsrReading = analogRead(fsrAnalogPin);
      int num = fsrReading/3;
      Serial.print("Analog reading = ");
      Serial.println(num);
      delay(50);
    }

Here is my code for the Python code(Bluetooth not implemented yet):

    import serial
    
    serialArduino = serial.Serial('COM4', 9600)
    
    while True:
        while (serialArduino.inWaiting() == 0):
            pass
        valueRead =(serialArduino.readline())
        print(valueRead)

What can I change in my FSR code and Python code to send and receive the data via bluetooth?

There are a number things that might be going on.

the code wouldn't even upload when I used their sketch.

I assume you mean the Arduino sketch. There is some nonsense in the link. Your code is using hardware serial. This is fine but it is shared with the USB cable and the fact that you have this problem more or less confirms this - and that you have the right port configured, but you cannot upload with bluetooth connected. Solution: disconnect. You can do this by taking out the port selection jumpers.

No comment on Python per se, but does it work with cable connect? If so, it is probably just a matter of changing the COM port. Your bluetooth sniffer or Control panel should advise you of the correct port for PC's Bluetooth.

If Arduino code works via cable, there is no need to change it.

The python code works just fine if I am connected via USB cable. I'd like to go into the next step and implement bluetooth functionality, but i'm not even sure of how to go about this...

Your biggest mistake is using big words like "implement bluetooth functionality". As far as Arduino is concerned, there is no functionality other than connecting the bluetooth module, in your case the shield. As I said before, if Arduino code works via cable, there is no need to change it. Same port, and Arduino neither knows nor cares what is connected to it..

The other end is a slightly different matter, PC's bluetooth will be on a different port than the cable. I'm sure Python is no more interested in the mode of transmission than Arduino is, it just needs to know which COM port to listen to in order to get the serial data. Change the COM port code as required.

Do you have the HC05 paired with the PC's Bluetooth? You may not be able to see it on a COM port unless it is first paired. This is between the HC05 and the PC. No Python involved yet.

I assume that when Python opens the COM port, with serialArduino = serial.Serial('COM4', 9600)it is the same as "connecting" with the Microsoft Bluetooth terminal app. The fast blinking light on the HC05 should then change to the blink every two seocnds. As Nick Pyner says, it the Bluetooth COM port is not not likely to be COM4.

cattledog:
Do you have the HC05 paired with the PC's Bluetooth? You may not be able to see it on a COM port unless it is first paired.

I don't think that is right. Surely, PC needs to know what port Bluetooth is on in order to pair with it. Also note that Bluetooth can sometimes be seen on two ports. This has never happened to me, but I guess they are for transmit and receive. Things can get rather messy with Bluetooth on a PC. I think using Android is a much better option.

I don't think that is right. Surely, PC needs to know what port Bluetooth is on in order to pair with it. Also note that Bluetooth can sometimes be seen on two ports. This has never happened to me, but I guess they are for transmit and receive. Things can get rather messy with Bluetooth on a PC. I think using Android is a much better option.

I'm not sure that "pairing" is the corrrect terminology for the PC. I connected an HC05 to a Bluetooth terminal app on a Windows 10 PC last night to check the process out, and through the Action Center there was a procedure to scan for the device and link to it. This was independent of any communications with the HC05 through the terminal app, which had a separate connect button.

Things can get rather messy with Bluetooth on a PC. I think using Android is a much better option.

I certainly agree with that. If things weren't messy on the PC we wouldn't be having this conversation :slight_smile:

cattledog:
I'm not sure that "pairing" is the corrrect terminology for the PC. I connected an HC05 to a Bluetooth terminal app on a Windows 10 PC last night to check the process out, and through the Action Center there was a procedure to scan for the device and link to it. This was independent of any communications with the HC05 through the terminal app

That's what everybody but Windows 10 calls pairing - getting on the dance card. PC terminal and Arduino programme are not involved.

I certainly agree with that. If things weren't messy on the PC we wouldn't be having this conversation :slight_smile:

I think I should have said Desktop PC. which don't normally have bluetooth built-in. I never got my XP desktop to run a bluetooth dongle - not enough motivation to overcome the tedium. With Win 7 it was OK. My Dell 430 laptop came with on-board bluetooth and a Toshiba Bluetooth interface, which is as good as a phone.