1 2 Previous Next 16 Replies Latest reply on Mar 3, 2015 1:47 PM by user_78878863

    Connecting ADC to BLE

    user_469915547

       Hi 

         

      I'm trying to get a analog signal converted in a single ended ADC, and then i want to transmit the converted value over the BLE. For this i trying to create a custom profile. How do i transmit my converted value? 

         

      Thanks in advance. 

        • 1. Re: Connecting ADC to BLE
          rohit.kumar

           Can you give this post a look? It is related to something similar.

             

           

             

          http://www.cypress.com/?app=forum&id=5283&rID=107084

          • 2. Re: Connecting ADC to BLE
            user_469915547

            Not exactly: 

               

            My code in main.c is: 

               

            #include <project.h>

               

            int main()

               

            {

               

                /* Place your initialization/startup code here (e.g. MyInst_Start()) */

               

                ADC_Start();

               

                ADC_StartConvert();

               

                int EMGval = 0; 

               

             

               

                /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */

               

                for(;;)

               

                {

               

                    EMGval = ADC_GetResult16(0); 

               

                   //Transmit EMGval with BLE 

               

                }

               

            }

               

             

               

            Could i use CyBle_GattcReadCharacteristicValue() here? And if, which parameters should this be given? 

            • 3. Re: Connecting ADC to BLE
              user_78878863

              Just a short intro (assuming you know how to read the ADC data and get it into a variable):

                 
                    
              • BLE doesn't do 'data transfer' in the sense of a data stream (like in a serial port)
              •     
              • BLE uses the notion of 'Attributes'
              •     
              • the side that provides the attribute data is the 'GATT server', the reading side is the 'GATT client'
              •     
              • attribute data is either transferred when the GATT client wants to read it, or via a notification
              •     
              • so when you have defined your custom service, your client just needs to set the attribute value, and fire the notification when they are enabled
              •     
              • don't forget to handle the notification settings that might come in from the GATT client
              •    
              • 4. Re: Connecting ADC to BLE
                user_78878863

                Take this example project as a starting point: http://www.cypress.com/?rID=107617&cache=0 . Instead of the proximity data you need to send your ADC value.

                1 of 1 people found this helpful
                • 5. Re: Connecting ADC to BLE
                  user_469915547

                   Thanks you very much! 

                  • 6. Re: Connecting ADC to BLE
                    rohit.kumar

                    Project provided by hli is the best way to start.

                       

                    Just make following changes in the project:
                    1) Open BLE Component configuration by double clicking on it-> Profiles tab -> CapSense Proximity (characteristic) -> Change the type to sint16 (2 bytes) (marked red in attached image).

                       

                    2) In BLEApplication.c file -> SendDataOverCapSenseNotification(), make the following change to notificationHandle.value.len

                       

                    notificationHandle.value.len = 2;

                       

                     

                       

                    3) Change the definition of the function SendDataOverCapSenseNotification(uint8) to SendDataOverCapSenseNotification(int16). This way, you can pass your 2 bytes of ADC data to it.

                       

                     

                       

                    4) Redefine the function HandleCapSenseProximity()in main.c to obtain your ADC data and pass to the SendDataOverCapSenseNotification() function.

                       

                     

                       

                    I would also advise you to change the value of UUID of the service and characteristic in BLE component to a different value (marked in purple in attached image). This way, the CySmart App will not recognize it as CapSense proximity.

                       

                     

                       

                    -Rohit

                    • 7. Re: Connecting ADC to BLE
                      user_469915547

                       I tried to make the changes on the project that you recommended. But is still have some issues. 

                         

                      I have change the settings in the CapSense Characteristics, and I modified the functions as followed: 

                         

                      void HandleCapSenseProximity(void) {

                         

                      int16 EMGval;

                         

                              EMGval = ADC_GetResult16(0);

                         

                      SendDataOverCapSenseNotification(EMGval);    

                         

                      }

                         

                       

                         

                      and 

                         

                      void SendDataOverCapSenseNotification(int16 EMGval)

                         

                      {

                         

                      CYBLE_GATTS_HANDLE_VALUE_NTF_T notificationHandle; 

                         

                      if(busyStatus == CYBLE_STACK_STATE_FREE)

                         

                      {

                         

                      notificationHandle.attrHandle = CYBLE_CAPSENSE_CAPSENSE_PROXIMITY_CHAR_HANDLE;

                         

                      notificationHandle.value.val = &EMGval;

                         

                      notificationHandle.value.len = 2;

                         

                       

                         

                      CyBle_GattsNotification(connectionHandle,&notificationHandle);

                         

                      }

                         

                      }

                         

                       

                         

                      I've also given the characteristics and services a unique UUID 

                         

                       

                         

                      But the value i get is just constant 14337, and the actual value I'm sending is a DC that can vari from 0 to 5 volt. 

                      • 8. Re: Connecting ADC to BLE
                        user_1377889

                        You did not wati for a conversion cycle ready before reading channel 0.

                           

                        I cannot se whether you issued a ADC_StartConvert().

                           

                        The BLE is sent to sleep, did you care for that sending the ADC to sleep, and wakeup or did you remove the

                           

                        #define ENABLE_LOW_POWER_MODE in BLEApplications.h

                           

                         

                           

                        Bob

                        • 9. Re: Connecting ADC to BLE
                          user_469915547

                          Thanks. I though when called ADC_StartConvert() it was constantly converty until i called a method to stop it. 

                             

                          But i works now! 

                             

                          Thanks alot!

                          • 10. Re: Connecting ADC to BLE
                            user_78878863

                            The ADC can actually do that, when you configure it that way (just look at the configuration dialog). But even then you should for the finished conversion to be sure you get a valid result.

                            • 11. Re: Connecting ADC to BLE
                              manuel.martinez.lb13505

                               Hello,

                                 

                              I don't know if it's a correct place to post my issue! But I'm doing similar thing..

                                 

                               

                                 

                              I have modified the CapSense Proximity Project to send data stream. I have succeeded but I have some questions.

                                 

                               

                                 
                              /*This is only a example, for the future in this part I going to use the ADC to take data of analog sensor and put data in the DataSend vector*/ 
                                 
                              void HandleCapSenseProximity(void)
                                 
                              {
                                 
                                  uint8 DataSend[MAX_INDEX];  //Data stream to send
                                 
                                  uint8 index;
                                 
                                  static uint16 cont = 0;
                                 
                                 /*Increment data*/
                                 
                                  for(index=0;index < MAX_INDEX; index++) 
                                 
                                  {
                                 
                                      DataSend[index] = 0x00+cont; 
                                 
                                      cont++;
                                 
                                  }
                                 
                              SendDataOverCapSenseNotification(DataSend); 
                                 
                              }
                                 
                               
                                 
                              /*-------------------------------------------------------------------------------------------------------------------------------------------*/
                                 
                              void SendDataOverCapSenseNotification(uint8 DataSend[])
                              {
                              /* 'notificationHandle' is handle to store notification data parameters */
                              CYBLE_GATTS_HANDLE_VALUE_NTF_T notificationHandle; 
                              /* If stack is not busy, then send the notification */
                              if(busyStatus == CYBLE_STACK_STATE_FREE)
                              {
                              /* Update Notification handle with proximity data*/
                              notificationHandle.attrHandle = CYBLE_CAPSENSE_CAPSENSE_PROXIMITY_CHAR_HANDLE; notificationHandle.value.val = DataSend;
                              notificationHandle.value.len = NOTIFICATION_DATA_LEN; //max size of vector:15
                              /* Report data to BLE component for sending data by notifications*/
                              CyBle_GattsNotification(connectionHandle,&notificationHandle);
                              }
                              }
                                  

                               

                                 

                              I'm using the CySmart1.0 tools to the Client. When I enable to receive notification, I receive some times 2 or 3 data stream in the same time.

                                 

                               

                                 

                              [11:29:36:746] : 'Characteristic Value Notification' event received

                                 

                              [11:29:36:746] : Attribute Handle: 0x000E

                                 

                              [11:29:36:746] : Value: [0D:0E:0F:10:11:12:13:14:15:16:17:18:19:1A:1B]

                                 

                              [11:29:36:746] : 'Characteristic Value Notification' event received

                                 

                              [11:29:36:746] : Attribute Handle: 0x000E

                                 

                              [11:29:36:746] : Value: [1C:1D:1E:1F:20:21:22:23:24:25:26:27:28:29:2A]

                                 

                              [11:29:36:761] : 'Characteristic Value Notification' event received

                                 

                              [11:29:36:761] : Attribute Handle: 0x000E

                                 

                              [11:29:36:761] : Value: [2B:2C:2D:2E:2F:30:31:32:33:34:35:36:37:38:39]

                                 

                               

                                 

                              Does this function control the data sent? CyBle_GattsNotification(connectionHandle,&notificationHandle); 

                                 

                               How can I control to send only a one stream data for each interval connection?

                              • 12. Re: Connecting ADC to BLE
                                user_78878863

                                There is no "data stream" in BLE. It uses the notion of attributes (that form in the end kind of a tree). Typically the other end of the connection (the GATT client) queries the values of the attributes its interested in. A notification changes this into a push whenever the attribute value changes. But its only the current value thats pushed.

                                   

                                What might happen in your case: the payload length is limited, so maybe the notification is split into multiple packages.

                                • 13. Re: Connecting ADC to BLE
                                  david.stamper_1542706

                                  can you update link to this project?

                                  • 14. Re: Connecting ADC to BLE
                                    rawnak.hamid

                                    Hi,

                                       

                                    Can you please update the link? 

                                       

                                    Thanks 

                                    1 2 Previous Next