readAnalogVoltage - does it work?
Posted: Wed May 30, 2018 10:01 pm
Hello All,
I'm having difficulty using the analog input for the CrazyFlie 2.0. I have a small circuit built which is testing the output of a pin (HELLO_LED) based on the voltage input of another pin (READ_LED). I have tested with various voltages, but the output LED never seems to trigger. Does anyone have some working code for readAnalogVoltage, or can you spot what's wrong with my code? Thank you!
I'm having difficulty using the analog input for the CrazyFlie 2.0. I have a small circuit built which is testing the output of a pin (HELLO_LED) based on the voltage input of another pin (READ_LED). I have tested with various voltages, but the output LED never seems to trigger. Does anyone have some working code for readAnalogVoltage, or can you spot what's wrong with my code? Thank you!
Code: Select all
#define DEBUG_MODULE "HelloDeck"
#include "debug.h"
#include "stm32fxxx.h"
#include "FreeRTOS.h"
#include "timers.h"
#include "deck.h"
#include "param.h"
#define HELLO_LED DECK_GPIO_RX1
#define READ_LED DECK_GPIO_IO1
#define LED_ON HIGH
#define LED_OFF LOW
#define VBAT_TEST_VOLTAGE_LOW (3.0 / ((1.0 + 69.0 + 10.0) / 10.0) * 0.95) /* 0.35625 */
#define VBAT_TEST_VOLTAGE_HIGH (3.0 / ((1.0 + 69.0 + 10.0) / 10.0) * 1.05) /* 0.39375 */
float fVoltage = 0.0F;
static xTimerHandle timer;
static void tfTimer(xTimerHandle timer)
{
digitalWrite(HELLO_LED, LED_OFF);
fVoltage=analogReadVoltage(READ_LED);
if (fVoltage>VBAT_TEST_VOLTAGE_LOW)
{
digitalWrite(HELLO_LED, LED_ON);
}
}
static bool isInit = false;
static void helloInit()
{
if (isInit) {
return;
}
DEBUG_PRINT("Hello Crazyflie 2.0!\n");
adcInit();
pinMode(HELLO_LED, OUTPUT);
//pinMode(READ_LED, INPUT);
digitalWrite(HELLO_LED, LED_OFF);
timer = xTimerCreate("tfTimer", M2T(100), pdTRUE, NULL, tfTimer);
xTimerStart(timer, 100);
isInit = true;
}
PARAM_GROUP_START(hello)
PARAM_ADD(PARAM_FLOAT, fVoltage, &fVoltage)
PARAM_GROUP_STOP(hello)
static const DeckDriver helloDriver = {
.name = "myHello",
.init = helloInit,
.usedGpio= DECK_USING_IO_1|DECK_USING_IO_4|DECK_USING_RX1,
};
DECK_DRIVER(helloDriver);