This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC2640R2: Reading ADC value without pressing button, and sending via Bluetooth to TI SimpleLink Connect

Part Number: LAUNCHXL-CC2640R2
Other Parts Discussed in Thread: CC2640R2F

Hi, First of all, I should start by saying that I am really beginner about embedded systems. I want to make a project that sends the voltage value read from the ADC to the mobile phone via bluetooth. When I browsed the sample projects in the resource explorer section, I saw that the sample project made in the link I will add does the project I want to do. Link of the project is 

https://dev.ti.com/tirex/explore/node?devtools=LAUNCHXL-CC2640R2&node=A__AHyUOcWiO1qGZkv7m9HraA__com.ti.SIMPLELINK_ACADEMY_CC2640R2SDK__7unKOT8__LATEST

When I wanted to do this example as NON-POSIX and using the development board's own ADC pin without using a booster pack, I realized that the best way would be to use task 4,5 and 6. Then I started to follow the steps. When I completed all steps I can send ADC value to mobile phone altough values are not same that I see Putty and SimpleLink. But it is not the main problem.

To reduce power consumption and using button is not logical for my project, it needs  periodic measurement (period can be up to 5 minutes). To do so, I put the lines to comment line which are about pressing button in myThread page and then after debugging the program it does not measure the ADC value.  I expect that using sleep function in while loop in myThread page can solve this problem (Correct me if I am wrong). Then  I add sleep function inside of the while loop and also #include <unistd.h> top of the myThread. Before adding ${COM_TI_SIMPLELINK_CC2640R2_SDK_INSTALL_DIR}\source\ti\posix\ccs to the  include path in project properties, #1965 cannot open source file "unistd.h" error is shown( I also checked that unistd.h folder is in the correct pathway).  After adding  ${COM_TI_SIMPLELINK_CC2640R2_SDK_INSTALL_DIR}\source\ti\posix\ccs  to the  include path in project properties, #10010 errors encountered during linking; "ble5_simple_peripheral_cc2640r2lp_app_sleep_withoutbutton.out" not built , error is shown. I also add the screenshot of the error. 

I also try to insert the sleep function in the variable projects but same problem appears in each one. But in the adcbufcontinous example ( it is in the resource explorer) it uses sleep function and it works properly. I directly import the adcbufcontinous project and build, debug. I can easily adjust ADC sampling frequency and sleep time.

In short, I need a program that measure the ADC like in the adcbufcontinous project and sending data like in the link I mentioned before.

Version of the SDK that I use is 5.30.0.03, I have been used it for 1 months ( I write this becasue many of the similar questions is asked to update the version of SDK.) CCS version is 12.3.0.

I also add the project folder, it might help.

 

Regards, ble5_simple_peripheral_cc2640r2lp_app_sleep_withoutbutton.zip

  • Hi Riza,

    Reading at what you now want to do I would recommend setting the adc value in the performPeriodTask function

    And change the EVT_Period to whatever time you want .

    You would have to mess with delays in threads.

    Kind Regards,

    Rogelio

  • Hi Rogelio, first of all thank you.
    I am writing what I understand based on your answer, please correct me where I am wrong. From your answer, set the value of adc in the performPeriodicTask function, I understand that I need to write the ADC related parts (myThread function I insterted the screenshot) in myThread inside the performPeriodicTask function that is in simpleperipheral.c . I understand from this answer that deleting the lines related to the pressing the button will eliminate the need to use a button when taking measurements.

    Another is, will setting the measurement period using EVT_Period make the system go into sleep mode and prevent power consumption? Otherwise, using sleep still causes error.
    Best Regards,

  • Hi Riza,

    You are correct in having to write the ADC parts inside the SimplePeriodicTask() function. However for the Initialization functions (Ex. ADC_init) you will need to write these inside of main() as you should only call them once and not every 5 minutes. The device should go to standby automatically as that is default when running a BLE example such as Simple peripheral you will not need to call the sleep function whatsover. 

    Kind Regards,

    Rogelio

  • Hi Rogelio,

    In order to proceed step by step, I started to do task 4 in the document I took as a reference. In the code snippet given for ADC measurement, I removed the parts related to the button and wrote the remaining part inside the performperiodictask function. As you said  I wrote the initilazion lines  in the main() function in the main.c file. At the same time, I added the #include lines in the myThread.c file to the simpleperipheral.c file. When I paste the piece of code that started with void myThread_create(void) in the last section of myThread.c to simpleperipheral.c, it gave an error at that stage before it came to the periodictask command. (I've attached a screenshot of the error). In this case, I no longer need to create the myThread.c file ( Correct me if I am wrong). In step 4 of Task 4, I changed the names of the functions to be added to the main file from myThread to the name of the performperiodic function SimplePeripheral_performPeriodicTask(void). When I do what I said and build, I get the errors (I've attached the screenshot of the error). I think I have made the necessary library and definitions, which are the explanation of #10234 unresolved symbols remain error. I think other errors are caused by similar reasons, but I couldn't understand where I made a mistake.
    I have uploaded the project files for easier understanding. I would like to ask you, considering that I am a beginner, if you explain the steps in a very simple level, it will make me very happy. And if you explain what should I do in the next steps,  it would be perfect.3426.ble5_simple_peripheral_cc2640r2lp_app.zip
    Best Regards,

  • I am writing this message as a reminder, in case it was overlooked.
    Best regards,

  • Hi Riza,

    I will try to help you with your project.

    Why do you need ADC to read the battery value? Is your battery volts greater that 3.3V?

    Have you tried adc driver example programs to read the battery value?

    I will assume your using the CC2640R2F Launchpad.

    -kel

  • Hi Kel,

    I use CC2640R2F Launchpad.

    I need to read the output voltage value of the sensor which is designed by me not battery value. Output voltage of the sensor does not exceed 3.3V.

    2437.ble5_simple_peripheral_cc2640r2lp_app.zipI can say that my main purpose is  program that measure the ADC like in the adcbufcontinous project in the project explorer and sending data like in ADC driver example. 

    I use adc driver example as a reference. As you know in adc driver example voltage is read by pressing button, but I want to read ADC value periodically. ( I mention about the application what I want to do in detail, it can be better for you to read these) After the last mention I did in this thread, I made some changes on the code.

    As Rogelio suggest that I write ADC reading section into PerformPeriodicTask. I remove the lines that are related to pressing button. I added the necessary include and definiton lines to main.c and simpleperipheral.c, and also to create service I create the myData.h and myData.c as mentioned in the adc driver example. When I build the program no error is shown but when I debug and resume the program SimplePeripheral is only shown for one period( that I adjust time of the period in #define SP_PERIODIC_EVT_PERIOD line ) by mobile phone on the SimpleLink Connect TI application, then SimplePeripheral disconnected. So, program works for once not periodic.

    The ADC value read in the program is written to the adc Value variable. Then the adc Value value is assigned to the myData variable created as a service. While the value of myData in Putty is correct in the program (I tested this situation by connecting various voltage values to the ADC pin), it appears differently on the phone. Instead, when I set the myData variable to a constant number like 15, I can read the myData value correctly in the phone application.

    For better understanding, I also added the project file. 

    Best Regards,

  • Hi Riza,

    First of all I suggest you use the BLE 4.2 simple peripheral as base example program. It is much simpler compared to BLE 5 simple peripheral. Also, it is not recommended to use BLE 5 using CC2640R2F because the BLE 5 stack is big.

    For your analog sensor reading, let's use adcsinglechannel driver example program as reference code to read your analog sensor.

    simple_peripheral.c

    /* Driver Header files */
    #include <ti/drivers/ADC.h>

    /* ADC conversion result variables */
    uint16_t adcValue0 = 0;

    ADC_Handle adc;
    ADC_Params params;

    static void SimplePeripheral_init(void)
    {

       ADC_init();

       ADC_Params_init(&params);
       adc = ADC_open(Board_ADC0, &params);

       if (adc == NULL) {

         while (1);
       }

       MyData_AddService( selfEntity );

       uint16_t myData_data_initVal[MYDATA_DATA_LEN] = {0};
       MyData_SetParameter(MYDATA_DATA_ID, MYDATA_DATA_LEN, myData_data_initVal);

    }

    static void SimplePeripheral_performPeriodicTask(void)
    {

       res = ADC_convert(adc, &adcValue0);

       MyData_SetParameter(MYDATA_DATA_ID, MYDATA_DATA_LEN, &adcValue0);

    }

    This will update the MYDATA_DATA_ID characteristics every 5 seconds with new adc value. To view the latest adc value using your app press the read button.

    If you want to read several samples of your adc sensor that would be a different implementation. The recommended way is to use the sensor controller.

    You can also remove the simple gatt profile. Remove all not needed code.

    -kel

  • First of all, thank you very much for your quick reply.
    While starting to implement the project, after entering the Resoruce explorer page, I import the project by following the Wireless connectivity > Embedded Software > SimpleLink CC2640R2 SDK- 5.30.00.03 > Examples > Development Tools > CC2640R2 Launchpad > BLE5-Stack > simple-peripheral path. But this is BLE5. How should I go about using BLE 4.2? Could you leave the link if possible? (Please excuse me if I misunderstood the concept.)
    I am writing to check that I understand correctly what I need to do after importing the link you will send. As I did before, I will import the Bluetooth 4.2 simple peripheral file to the CCS environment, instead of using the application I made by following the path Wireless connectivity > SimpleLink Academy for CC2640R2- 5.30.01.00 > Bluetooth 4.2 > Bluetooth Low Energy + TI Drivers. After writing the piece of code you have sent to the simple_peripheral.c file, it will be enough for me to run the code without creating new services and new files like in the Bluetooth Low Energy + TI Drivers tutorial.
    Kind regards,

  • Hi Riza,

    If you download the SDK

    www.ti.com/.../SIMPLELINK-CC2640R2-SDK

    It comes with examples with both the BLE5Stack and the BLEStack, what Markel is suggesting is you use the BLEStack and not the BLE5. Either way you should be able to accomplish what you wanted in either stack.

    Kind regards,

    Rogelio

  • Hi Rogelio,

    In that link there are two ınstaller option for windows, is there major differences between them for my application?

    Kind Regards,

  • Hi Riza,

    The first is the actual download link to the SDK, the second is an install link for Code Composer Studio

    Kind Regards,

    Rogelio

  • It was already downloaded, no problem.

  • Hi, 

    I exactly write the same code but I get errors are that #20 identifier "MY_DATA_DATA_ID" is undefined( also I added the screenshot). When I define these as an integer ( uint16_t MYDATA_DATA_ID;)I get another error. It is #146 variable "myData_data_initVal" may not be initialized( I added the screenshot of the error.)

    In case the cause of the error may be due to the lack of service, I created the service and created the myData.h and myData.c files as in task 5 in the Bluetooth Low Energy + TI Drivers tutorial from the example service manufacturer, but nothing changed.
    I have also attached the project file so that the cause of the error can be understood more easily.

    Kind Regards,     1050.ble5_simple_peripheral_cc2640r2lp_app.zip

  • Hi Riza,

    I suggest you do a fresh import of BLE 4.2 simple peripheral from here and try again. C:\ti\simplelink_cc2640r2_sdk_5_30_00_03\examples\rtos\CC2640R2_LAUNCHXL\blestack\simple_peripheral

    Modify the simple_peripheral.c as I have suggested. The MyData custom Bluetooth service implementation is correct. Just for some code organization put the MyData.h below the simple_gatt_profile.h includes

    #include <devinfoservice.h>
    #include <simple_gatt_profile.h>
    #include "myData.h"

    -kel

  • Hi Markel and Rogelio,

    Thank you for your huge support. I can take the data via bluetooth on my mobile phone. There is some value differences between on CCS and mobile phone. I am going to try to solve problem. In this period, what is your suggestion to solve problem, what is the reason of that problem?3678.simple_peripheral_cc2640r2lp_app.zip

    To better understanding I attached the project file.

    Best Regards,

  • Hi Riza,

    The MYDATA_DATA_ID characteristics will be updated every 5 seconds with new adc value. But, at your smartphone app side it will not display the latest value immediately. You need to press the READ button to get the latest value.

    -kel