Hello, I am new to CrazyFlie 2.0. Thank you everyone for the community support! I am only experimenting with what can be accomplished. I have researched the forums, but did not see a post about my topic.
I have a simple bulb light that requires 2.6-5 VDC. I have connected it to the CF expansion header, pins 1 VCC and 19 AGND. It lights as expected. It is always on, as long as CF 2.0 power is on.
Now, I would like a way to turn the light on and off with a remote button (game controller or keyboard). I currently use VJoy to pilot via keyboard. Is there an available pin on the expansion header that can be controlled from the PC client? The ideal pin would be able to put out an analog 2.6-5V DC when active, and 0 DC when de-activated (perhaps pin 7?) A substitute could be PWM 0-3V PtoP on activation (perhaps pins 2 or 4?).
Is there a way to control a simple analog switch on the CF the expansion board from the PC client? If possible, I would like to do this with no additional circuitry or hardware, and without a firmware update to the CF. I can write software to do this if that is required, but I am hoping that this capability was already built into the CF 2.0 for expansion purposes.
Thank you again.
Simple analog switch from expansion header?
-
- Beginner
- Posts: 19
- Joined: Mon Sep 28, 2015 11:59 pm
Re: Simple analog switch from expansion header?
Hi and welcome to the forum!
Recently we have started to implement an Arduino compatible Deck API. There you can use digital write to set pins on the deck expansion port. You images refers to the Crazyflie 1.0 port and not the 2.0 which can be found here.
So to set e.g. IO1 high you first need to setup the pin with
Then set the output to high
Or set it low
The deck port pins are wired directly to the MCU and will output 3.0v when high and 0 when low. They can't draw more then around 30mA current so dimension you bulb for that (LED?)
Recently we have started to implement an Arduino compatible Deck API. There you can use digital write to set pins on the deck expansion port. You images refers to the Crazyflie 1.0 port and not the 2.0 which can be found here.
So to set e.g. IO1 high you first need to setup the pin with
Code: Select all
pinMode(DECK_GPIO_IO1, OUTPUT)
Code: Select all
digitalWrite(DECK_GPIO_IO1, 1)
Code: Select all
digitalWrite(DECK_GPIO_IO1, 0)
-
- Beginner
- Posts: 19
- Joined: Mon Sep 28, 2015 11:59 pm
Re: Simple analog switch from expansion header?
Thank you for your response!
I can compile and flash firmware OK, and I added the following file to the crazyflie-firmware/deck/drivers/src directory. It compiles with no errors (I added the file to the Make), and flashing is successful.
With this code, I am hoping to achieve a "blink" effect by connecting the LED to pin 5 and Ground, with a two-second (approximate) delay for off and on. However, this does not work. My question: with the Deck API, how can I ensure that the code is called on startup? To me, it is not clear from the Deck API how to call the code that I have written.

I can compile and flash firmware OK, and I added the following file to the crazyflie-firmware/deck/drivers/src directory. It compiles with no errors (I added the file to the Make), and flashing is successful.
Code: Select all
#include <stdint.h>
#include <string.h>
#include "stm32fxxx.h"
#include "config.h"
#include "deck.h"
static void enableIO1(void);
static void disableIO1(void);
static bool digitalIOBlink(void)
{
volatile int delay;
int delayTime = 2000;
for( ; ; ) {
enableIO1();
for (delay = 0; delay < delayTime; delay++);
disableIO1();
for (delay = 0; delay < delayTime; delay++);
}
return true;
}
static void enableIO1(void) {
pinMode(DECK_GPIO_IO1, OUTPUT);
digitalWrite(DECK_GPIO_IO1, 1);
}
static void disableIO1(void) {
pinMode(DECK_GPIO_IO1, OUTPUT);
digitalWrite(DECK_GPIO_IO1, 1);
}
static void digitalIOInit(DeckInfo *info)
{
digitalIOBlink();
}
static const DeckDriver digitalio_deck = {
.vid = 0,
.pid = 0,
.name = "bcDigitalIO",
.usedGpio = DECK_USING_PA2 | DECK_USING_PA3,
.init = digitalIOInit,
};
DECK_DRIVER(digitalio_deck);
Re: Simple analog switch from expansion header?
To ensure your code is called at startup you should add this line to 'config.mk' (at the root of the project, create it if you did not already):
You can verify in the console that the code is initialised, for example on my Crazyflie I force the DWM1000 driver:
Unreleated note: I intend to use the bc prefix in the name for bitcraze boards so that we avoid collision, you can chose any other prefix you like
Code: Select all
CFLAGS += -DDECK_FORCE=bcDigitalIO
Code: Select all
(...)
DECK_DRIVERS: Found 5 drivers
DECK_DRIVERS: VID:PID 0:0 (bcBuzzer)
DECK_DRIVERS: VID:PID BC:3 (bcBigQuad)
DECK_DRIVERS: VID:PID BC:FF (bcExpTest)
DECK_DRIVERS: VID:PID BC:1 (bcLedRing)
DECK_DRIVERS: VID:PID 0:0 (bcDWM1000)
DECK_CORE: 0 deck enumerated
DECK_CORE: Initializing compile-time forced driver 'bcDWM1000'
(...)
DWM: Chip ID: DECA0130
DECK_CORE: Compile-time forced driver 'bcDWM1000' test [OK]
(...)
Unreleated note: I intend to use the bc prefix in the name for bitcraze boards so that we avoid collision, you can chose any other prefix you like

-
- Beginner
- Posts: 19
- Joined: Mon Sep 28, 2015 11:59 pm
Re: Simple analog switch from expansion header?
Success!
Thank you so much for your help.
Here is my steps, for anyone else to repeat:
1. Get setup on the Oracle VirtualBox, so that you can build and flash the latest crazyflie 2.0 firmware. I won't go into detail here, you can find this on other threads.
2. Edit the config.mk file (mine is found at "crazyflie-firmware/tools/make/config.mk" ), and add the following line:
CFLAGS += -DDECK_FORCE=DigitalIO
3. Edit the Makefile (mine is found at "crazyflie-firmware/Makefile" ), and add the following line in the '#Deck API' section:
PROJ_OBJ_CF2 += digitalio.o
4. Here is my code, as file "/crazyflie-firmware/deck/drivers/src/digitalio.c" :
4. Finally, compile and flash your new firmware. My Client console appears as shown in the attachment.
5. Attach positive LED wire to Pin IO_1 / PB8, and negative wire to GND. It will light!
I love Crazyflie!!

Here is my steps, for anyone else to repeat:
1. Get setup on the Oracle VirtualBox, so that you can build and flash the latest crazyflie 2.0 firmware. I won't go into detail here, you can find this on other threads.
2. Edit the config.mk file (mine is found at "crazyflie-firmware/tools/make/config.mk" ), and add the following line:
CFLAGS += -DDECK_FORCE=DigitalIO
3. Edit the Makefile (mine is found at "crazyflie-firmware/Makefile" ), and add the following line in the '#Deck API' section:
PROJ_OBJ_CF2 += digitalio.o
4. Here is my code, as file "/crazyflie-firmware/deck/drivers/src/digitalio.c" :
Code: Select all
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include "stm32fxxx.h"
#include "config.h"
#include "deck.h"
static void enableIO1(void);
static void disableIO1(void);
static bool digitalIOBlink(void)
{
/* This will only turn on pin 5, but can be changed later to turn on and off */
enableIO1();
return true;
}
static void enableIO1(void) {
pinMode(DECK_GPIO_IO1, OUTPUT);
digitalWrite(DECK_GPIO_IO1, 1);
}
static void disableIO1(void) {
pinMode(DECK_GPIO_IO1, OUTPUT);
digitalWrite(DECK_GPIO_IO1, 0);
}
static void digitalIOInit(DeckInfo *info)
{
digitalIOBlink();
}
static const DeckDriver digitalio_deck = {
.vid = 0,
.pid = 0,
.name = "DigitalIO",
.usedGpio = DECK_USING_IO_1,
.init = digitalIOInit,
};
DECK_DRIVER(digitalio_deck);
5. Attach positive LED wire to Pin IO_1 / PB8, and negative wire to GND. It will light!
I love Crazyflie!!

- Attachments
-
- DigitalIO.png (9.11 KiB) Viewed 4127 times