Hi
I want to read a adc signal from adc3.3 in pixhawk board how can I do this?
You can check the pinout here, from right to left (the last one is not sure, you should measure it):
5V, PIN14, GND, PIN13, GND
In the code, you need:
AP_HAL::AnalogSource *adc_source; uint8_t pin=14; //or 13 adc_source = hal.analogin->channel(pin); float analog_value = adc_source->voltage_latest();
You can find more functions here, but this is just an abstract class, for the detailed implementations look into the AP_HAL_PX4 library.
I do that and compile the code using make on linux and the compilation process runs succesfully without compile erros. However, when i upload the firmware onto the Pixhawk, the main led initializes, blinks yellow and then stops blinking and when I coment this line “analog_value = adc_source->voltage_latest();” and upload the led blink correctly.
If you could provide a bit more context… what code are you using, and where did you put the stuff?
I usually use the UART_test in the AP_HAL library, because it’s quite minimal, and perfect for debugging.
this my code:
-
float bbb;
-
AP_HAL::AnalogSource *analog_source;
-
#ifdef USERHOOK_INIT
-
void Copter::userhook_init()
-
{
-
// put your initialisation code here
-
// this will be called once at start-up
-
uint8_t pin=14;
-
cliSerial->printf("0");
-
analog_source = hal.analogin->channel(pin);
-
cliSerial->printf("1");
-
}
-
#endif
-
#ifdef USERHOOK_MEDIUMLOOP
-
void Copter::userhook_MediumLoop()
-
{
-
// put your 10Hz code here
-
cliSerial->printf("3");
-
bbb=analog_source->voltage_latest();
-
cliSerial->printf(“4”);
-
//hal.scheduler->delay(100);
-
}
-
#endif
in terminal I can’t see any number
i upgrade my linux and the problem solved