Page 1 of 1

gpio_set_level() can not set the output value of the PIN

Posted: Mon Nov 05, 2018 12:20 pm
by Natsu_Kawa
I write a callback func like this to deive my peripheral , it runs when a specific key is down:
void DrainWater(void)
{
gpio_set_level(GPIO_NUM_x,1);//set the pin as high level to drive the peripheral
printf("The Value Of The GPIO_NUM_x now is %d",gpio_get_level(GPIO_NUM_x));
}
this func is included in a Task created in main.h
build and no error or warring...
but when I open my port assisstant , screan print
The Value Of The GPIO_NUM_x now is 0
can anybody help me ...?
thanks in advance...its so strange a question isn it ..??

Re: gpio_set_level() can not set the output value of the PIN

Posted: Tue Nov 06, 2018 1:32 am
by Natsu_Kawa
Ok guys ... there actually has not such a question here .. bucause when I use avometer to check the value of the pin , the pin was actually on the high value while the the msg printf by gpio_get_level(); is "0" , so there is also sth wrong on API..?

Re: gpio_set_level() can not set the output value of the PIN

Posted: Tue Nov 06, 2018 5:00 am
by WiFive

Re: gpio_set_level() can not set the output value of the PIN

Posted: Tue Nov 06, 2018 6:55 am
by Adham Aboud
You can't read the value of a GPIO if you didn't declare it as input....

Natsu_Kawa wrote:I write a callback func like this to deive my peripheral , it runs when a specific key is down:
void DrainWater(void)
{
gpio_set_level(GPIO_NUM_x,1);//set the pin as high level to drive the peripheral
printf("The Value Of The GPIO_NUM_x now is %d",gpio_get_level(GPIO_NUM_x));
}
this func is included in a Task created in main.h
build and no error or warring...
but when I open my port assisstant , screan print
The Value Of The GPIO_NUM_x now is 0
can anybody help me ...?
thanks in advance...its so strange a question isn it ..??

Re: gpio_set_level() can not set the output value of the PIN

Posted: Tue Nov 13, 2018 2:12 am
by Natsu_Kawa
Adham Aboud wrote:
Tue Nov 06, 2018 6:55 am
You can't read the value of a GPIO if you didn't declare it as input....
well , i actually had decleared the pin as input mode before I call the func gpio_get_level(),but I cannot see the change of the pin on my screan still... but when I use avometer to check the level of the pin ,it does changed while it just didn't show on my screan...its so strange isn't it..?

Re: gpio_set_level() can not set the output value of the PIN

Posted: Tue Nov 13, 2018 8:40 am
by loboris
Think about which mode you have to set to use the pin as output and be able to read its value back.
https://docs.espressif.com/projects/esp ... pio_mode_t