Comments (6)
@weilie91 , please check this function in App.c which is the callback. You can add your hardware logic there. ESP32-DevKit-C, which is our most common boar,d does not have in-built user controllable LED, and so the example too does not have any hardware control.
from esp-apple-homekit-adk.
Is there a simple GPIO blinking led example? I am familiar with Arduino (and C) but I have no idea how to start to control the GPIOs for this board from the App.c function.
As far as I understood the callbacks are HandleLightBulbOnWrite
to change status and HandleLightBulbOnRead
to get the status, but how can I switch on and off a pin? Could you please point me to a documentation to understand what I am suppose to write there?
Many thanks and sorry for the dumb question.
from esp-apple-homekit-adk.
Ok I find what to add, I report here because it can be useful for other beginners with ESP32 like me. Maybe you could add this (commented?) in the App.c as example of how to turn on the GPIO.
Everything goes in App.c
.
First thing is to include the header for GPIOs, I also added a define for the name of the GPIO to switch:
#include "driver/gpio.h"
#define LED_GPIO 2
then you need to setup at the startup the GPIO as output. I am not sure where is the better place to put this code, but I setup it in the AppAccessoryServerStart
function that runs before starting the app, maybe it can be done in a better place. At the end of the function I added:
gpio_reset_pin(LED_GPIO);
gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
finally the logic to turn it on on off stays in the HandleLightBulbOnWrite
and has to change the value of the led as function of the value
:
if (value) {
gpio_set_level(LED_GPIO, 1);
} else {
gpio_set_level(LED_GPIO, 0);
}
That's all. This will turn on and off the GPIO pin with the number 2 on the board (on some board where the red led is connected to number 2 you will see that one blinking as well, mine is not connected to any GPIO).
from esp-apple-homekit-adk.
@emanuelelaface it is better to use this example to setup the output:
https://github.com/espressif/esp-idf/tree/master/examples/peripherals/gpio/generic_gpio
In this way you can avoid possible unwanted behavior of the I/O peripherals.
from esp-apple-homekit-adk.
Thanks, I see that it may be safer to initialize it in the proper way. Where would you put the init part in the homekit example? I sued the AppAccessoryServerStart
but it doesn't sound as the correct place (it should be used for the server) but on the other hand there is no initializer there for the peripherals.
from esp-apple-homekit-adk.
For me the proper place would be in the InitializePlatform function inside app_main.c
from esp-apple-homekit-adk.
Related Issues (20)
- LightBulb example does not work reliably HOT 1
- Where to generate your own example? HOT 3
- Sample with GPIO interrupt HOT 2
- How to serve multiple accessories? HOT 3
- Stops working after a while HOT 10
- LightDemo can't be discoverd by iphone HOT 5
- Set up MbedTLS HOT 3
- Make it easier to add component to project HOT 2
- homekit adk not compiling HOT 1
- error while compiling LightBulb Example HOT 3
- New MbedTLS issue HOT 4
- Controlling Multiple pins from single accessory HOT 2
- Error on setup HOT 1
- Getting Uncertified Accessory message when adding device HOT 3
- Lightbulb example is not working HOT 6
- Update apple ADK version HOT 1
- this project support esp32s3 ?
- use esp32s3 report error Pair Verify M3: Pairing not found.
- I am unable to successfully compile the Light example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-apple-homekit-adk.