3 Replies Latest reply on Sep 28, 2015 4:01 PM by CMata_Intel

    How to get bluetooth HC-05 working on system level?

    julianak

      Hello,

      I have a Galileo Gen 2 and I managed to read some data I've sent via bluetooth using HC-05 from one of the serial ports (not sure which).

      I use an android app called Bluetooth Terminal, it connects to the module and open a terminal windows to send and receive data.

      Some time ago I was messing with the module and I figured out that when I cat a serial port in Galileo (not sure if it was  /dev/ttyS0 or /dev/ttyS1) I could see all the data coming from the app. But now I can't anymore, when I cat /dev/ttyS0 or /dev/ttyS1 I get nothing.

      Since the module is connected via TX/RX, according to this post Re: Serial ports it shouId work when I cat /dev/ttyS1.

      What am I missing?

       

       

      I'm trying to get the incoming data from the module in the system side, not using the arduino IDE thing, so I can get data from the cellphone and use a script in python to read it and change the state of the GPIO. Is there a better way of doing this?

       

      Any help is appreciated!

        • 1. Re: How to get bluetooth HC-05 working on system level?
          CMata_Intel

          Hi julianak,

           

          If you are connecting the HC-05 to pins 0 and 1 of the board. You must set the multiplexers to be able to read and write in the UART. Fortunately there is post from Peter with this information step by step: Re: How to program UART serial from Linux on Galileo Gen 2?

          You have to do the following:

          cd /sys/class/gpio                                                                        

          echo -n "28" > export

          echo -n "32" > export

          echo -n "45" > export

          cd gpio28

          echo -n "out" > direction

          echo -n "0" > value

          cd gpio32

          echo -n "out" > direction

          echo -n "1" > value

          cd gpio45

          echo -n "out" > direction

          echo -n "1" > value

          stty -F /dev/ttyS0 9600                    //change to the baud rate you want to use

          echo -n "value" > dev/ttyS0             //change value for what you want to write

          cat /dev/ttyS0                                //read from UART

               

          You can find the pin configuration of the Galileo Gen2 in this link: EmutexLabs

          I hope this helps.

           

           

          Regards,

          Charlie

          • 2. Re: How to get bluetooth HC-05 working on system level?
            julianak

            Hello Charlie,

             

            Thanks for your help, I was able to get it working again using this setup.

            I have two questions now:

            Do I have to set it like this every time?

            And what exacty does the command stty -F /dev/ttyS0 9600 do?

            Because if I have to reset it every time I'd do it using mraa in python, so I'd need to replace this command for something else...

             

            Thanks again!

            • 3. Re: How to get bluetooth HC-05 working on system level?
              CMata_Intel

              Hi julianak,

               

              Yes, you have to set it every time you are going to use it.

              About stty -F /dev/ttyS0 9600 is the command that sets the device (/dev/ttyS0) to work with a specific baud rate (9600).

              You can check the full configuration of the device(/dev/ttyS0) with stty -F /dev/ttyS0 -a

              More info about this command: stty(1): change/print terminal line settings - Linux man page

               

              If you don't want to this manually all the times, you can create a script that runs at boot with this configuration so it will be loaded every time you power the board.

              If you want to set all this configuration with python, you can use system calls so you would be able to run the same command from the python environment.

               

              Kind regards,

              Charlie