- Tue Mar 17, 2015 8:19 pm
#12146
LastSamurai wrote:But now how do I use that free pin inside my program? Whats the pin number?
Untested, but this should do it:
Code: Select allPIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3)
For a full list of pins/functions see
http://esp8266.ru/esp8266-pin-register-strapping/LastSamurai wrote:What I got so far is this:
Code: Select alluint8_t* duty = 2;
pwm_init( 1000, &duty); // frequency , duty
pwm_start();
...
// change duty if needed
pwm_set_duty(&duty, 0); // duty, channel??
pwm_start();
Ok, there are quite a few things wrong here.
1) "uint8_t* duty = 2;" <-- you are assigning a integer value to a pointer address???
2) "pwm_init( 1000, &duty); " <-- pwm frequency is capped at 500Hz, see pwm.c. Also duty is supposed to be an array of size PWM_CHANNEL (see below)
3) "pwm_set_duty(&duty, 0);" <-- duty is an uint8_t value, not a pointer address
A working example would be:
Code: Select alluint8_t duty[] = {0,0,0};
pwm_init(500, duty); // already calls pwm_start()
...
pwm_set_duty(100, 0); // set pwm channel 0 to 100
pwm_start()
LastSamurai wrote:What exactly are these channels? Are channels equal to pin numbers?
There are 3 pwm channels in the IoT example, see pwm.h (PWM_0_OUT_IO_MUX/_NUM/_FUNC). Default pins are 12, 15, 13 (none if which are available on ESP-01). You need to change the defines to suit your needs.
LastSamurai wrote:Also which file do I have to include to use these functions? When I used pwm.h my compiler complained that it can't find such a file (although its part of the sdk).
The pwm stuff is part of the IoT example, not the SDK itself. If you want to use it, you need to copy pwm.c/.h to your project.