Reading Sensor Value and Sending It

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi ,

I am an absolute newbie in this area(coming from Arduino), and I am trying to do just 1 thing: read value from a temperature sensor and send it to the lightblue app on my iPhone.

I have two questions about this :

1. how do I use the GPIO to read the sensor value?? (or should I use the gpio at all)

Currently, I first added the pins to hello_sensor_gpio_cfg

const BLE_PROFILE_GPIO_CFG hello_sensor_gpio_cfg =

{

    /*.gpio_pin =*/

    {

    GPIO_PIN_WP,      // This need to be used to enable/disable NVRAM write protect

    GPIO_PIN_BUTTON,  // Button GPIO is configured to trigger either direction of interrupt

    GPIO_PIN_LED,     // LED GPIO, optional to provide visual effects

    GPIO_PIN_BATTERY, // Battery monitoring GPIO. When it is lower than particular level, it will give notification to the application

    GPIO_PIN_BUZZER,  // Buzzer GPIO, optional to provide audio effects

    7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // other GPIOs are not used

    },

    /*.gpio_flag =*/

    {

    GPIO_SETTINGS_WP,

    GPIO_SETTINGS_BUTTON,

    GPIO_SETTINGS_LED,

    GPIO_SETTINGS_BATTERY,

    GPIO_SETTINGS_BUZZER,

    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    }

};

Then, in hello_sensor_create(), I added just one line after bleprofile_GPIOInit(bleprofile_gpio_p_cfg);

:

    /******* added by ME*/

    gpio_configurePin(0, 7, GPIO_INPUT_ENABLE, 1);

And then, in hello_sensor_send_message(),

I used gpio_getPinInput(0,7) to try to read in the sensor's value. However this function returns a BYTE, so I casted it to char and assigned it to the dereferenced pointer *db_pdu.pdu

I don't know what went wrong, but the message does not seem to be sending.

Do you know what I should do with this?? I am just trying to do one simple thing: read a sensor value and send it.

I would appreciate any suggestions from you guys.


Thanks a lot

0 Likes
1 Solution
Anonymous
Not applicable

You should use 0 as gpio_flag. 1 means GPIO_OUTPUT defined in bleprofile.h.

When I read GPIO value as input, I use code like below.

----------

gpio_configurePin(p >> 0x04, p & 0x0f, GPIO_INPUT_ENABLE, GPIO_PIN_OUTPUT_LOW);

...

BLEPROFILE_DB_PDU p_pdu;

p_pdu.len = 0x01;

if (gpio_getPinInput(p >> 0x04, p & 0x0f)) {

p_pdu.pdu[0x00] = 1; // High

} else {

p_pdu.pdu[0x00] = 0; // Low

}

bleprofile_WriteHandle(HANDLE_SAMPLE, &p_pdu);

View solution in original post

4 Replies
Anonymous
Not applicable

You should use 0 as gpio_flag. 1 means GPIO_OUTPUT defined in bleprofile.h.

When I read GPIO value as input, I use code like below.

----------

gpio_configurePin(p >> 0x04, p & 0x0f, GPIO_INPUT_ENABLE, GPIO_PIN_OUTPUT_LOW);

...

BLEPROFILE_DB_PDU p_pdu;

p_pdu.len = 0x01;

if (gpio_getPinInput(p >> 0x04, p & 0x0f)) {

p_pdu.pdu[0x00] = 1; // High

} else {

p_pdu.pdu[0x00] = 0; // Low

}

bleprofile_WriteHandle(HANDLE_SAMPLE, &p_pdu);

Anonymous
Not applicable

Thank you very much for the very helpful reply!!!! I shall try it out!!!

Just another quick related questions though:

Is there a way for the tag chip to read analog input instead of digital input??

Thanks a lot!

0 Likes

Maybe the ADC is what you want to use?

Re: BCM20732S ADC Configuration

Anonymous
Not applicable

Thank you so much for your reply. I shall look into the analog to digital converter. Thank you so much again.

0 Likes