4 Replies Latest reply on May 7, 2020 2:40 PM by ToMo_3736886

    Communication between two psoc 5lp by bluetooth

    ToMo_3736886

      Hello, I'm new to the community.. I have a query ... my project uses 2 psoc 5lp, A) a temperature sensor that is distant with a psoc and B) another psoc with a 16x2 lcd plus LEDs that indicate an action ... my problem is how I can receive the data that A) sends to process it and perform actions to turn LEDs on and off with the psoc B) additional data: the bluetooth modules are perfectly linked and I receive the data in char format which I print on the screen. But I do not know how to process it and perform actions such as turning on and off the led when exceeding a temperature.

       

      Thank you in advance and sorry for my bad English

        • 1. Re: Communication between two psoc 5lp by bluetooth
          GaneshD_41

          Hi,

           

          For your application, you need two BLE modules and those two modules should be connected to PSoC 5LP devices one each.

           

          The sensor data from one PSoC 5LP device should be transferred to BLE module 1. You can use the I2C communication between PSoC 5LP and BLE module for this.

           

          Similarly, for the second BLE module which receives the data from the first BLE module, should be connected to second PSoC 5LP throuh I2C/SPI interface.

           

          Are you doing like the same mentioned above?

           

          If yes, please go through attached code examples SERVER and CLIENT which can be referred to establish BLE communication between two devices.

           

          For establishing communication between PSoC 5LP and BLE module, you can go through code examples in PSoC Creator for PSoC5LP I2C and SPI.

           

          Hope this helps ! Please update if we are not clear or if you need some other information.

           

          Also, please note that you can use only BLE modules for your application. There is no need for PSoC 5LP devices because PSoC BLE supports ADC as well as LCD. Please have a look at PSoC 4 BLE datasheet.

           

          https://www.cypress.com/file/416486/download

           

          Thanks

          Ganesh

          • 2. Re: Communication between two psoc 5lp by bluetooth
            ToMo_3736886

            Hello, thank you very much for responding.

            I am going to attach my project to see if you can help me finish it.

            plus the photos of it ...

            what I would like is that when the temperature of sensor A> = 70 the red led turns on and when sensor B> = 180 the yellow led turns on

            • 3. Re: Communication between two psoc 5lp by bluetooth
              SudheeshK_26

              Hello,

               

              As per my understanding you are able to successfully communicate between the two PSoC 5LP devices using the HC-05 Bluetooth modules. The data format that you use to send the temperature from sensor A and B is as below.

               

              A<Temperature reading from sensor A>B<temperature reading from sensor B>

              e.g. A55B120

               

              You are able to print the received data on the LCD screen and you need assistance to convert the temperature data from both sensors to decimal format. Please correct me if my understanding is wrong.

               

              To convert the temperature data from ascii to decimal format the receiver should be able to detect the end of data received from the sender. Because the number of digits after the character 'B' can vary.

              e.g. A45B12, A66B120 etc

               

              One way to let the receiver know the end of data is to add a letter at the end of data format as below (new character 'E' is added at the end).

              A<Temperature reading from sensor A>B<temperature reading from sensor B>E

              Now, the data received my receiver will be A23B55E. You can modify your while loop in the receiver as below to convert the temperature data to decimal.

                  int temp_A = 0, temp_B = 0;
                  int *ptr;
                  while(1)
                  {
                      ch = UART_GetChar();
                      if(ch > 0)
                      {
                          if(ch == 'A')                   //Start of temperature data from sensor A 
                          {
                              posD = 0u; 
                              LCD_WriteControl(LCD_CLEAR_DISPLAY); 
              
                              LCD_Position(0u, posD++);
                              LCD_PutChar(ch);            //Print ch on LCD screen
                              
                              ptr = &temp_A;              //Point the ponter to the variable to store temperature from sensor A
                              continue;
                          }
                          else if(ch == 'B')              //Start of temperature data from sensor B
                          {
                              ptr = &temp_B;              //Point the pointer to the variable to store temperature data from sensor B    
                              LCD_Position(0u, posD++);
                              LCD_PutChar(ch);            //Print it on LCD screen
                              continue;
                          }
                          else if(ch == 'E')              //End of temperature data
                          {
                              if(temp_A > 71)
                              {
                                  //turn RED LED on
                              }
                              if(temp_B > 180)
                              {
                                  //turn YELLOW LED on
                              }
                              temp_A = 0;
                              temp_B = 0;
                              continue;
                          }
                          LCD_Position(0u, posD++);
                          LCD_PutChar(ch);                //End character 'E' is not yet received. Print the new character on LCD screen
                          *ptr = ((*ptr)*10) + (ch-48);   //convert the character from ascii to decimal and store
                      }
                  }
              

              I used two new variables temp_A and temp_B to store the temperature data from sensor A and B respectively.  Pointer 'ptr' is used to update store data to the correct variable. I hope this helps.

               

              Please clarify your query, if you were not looking for the above information.

               

              Thanks and Regards,

              Sudheesh

              • 4. Re: Communication between two psoc 5lp by bluetooth
                ToMo_3736886

                Hello!!! Thanks a lot!!! with your answer I was able to solve my problem! Thank you!