I am using this pressure sensor
https://www.amazon.com/dp/B07WR3NV3F/ref=cm_sw_r_cp_apa_i_csbSDbBGT3NZ1
for zero pressure/ room pressure, it outputs 0.5V and for 30psi it outputs 4.5V. I am trying to measure it with AIN0 (P1.19) on pocketbeagle . I am using iobb library.
This is my schematic
The ADC reads random values when sensor is connected to J4. But the multimeter reads correct voltage on Pin 3 J4 and on AIN0. Also If I try any other voltage via an additional voltage divider using +5V connected to J4 and give 0.5V to pin 3 on J4, and not use the sensor AIN0 reads correct value of 0.16V. Is this related to current ? I have also tried replacing R15 and R16 with 200K and 100K values hoping that it will reduce current leakage but that also doesn't work. Below is my example code.
float do_adc(void) { unsigned int sample, sum_of_samples,final; int i ,j; float result; unsigned int buffer_AIN_0[BUFFER_SIZE] ={0}; iolib_init(); /* using ADC_CALC toolkit to decide the ADC module argument . Example Sample rate : 10000 sample/s * * #./ADC_CALC -f 10000 -t 5 * * Suggest Solution : * Clock Divider : 160 , Open Dly : 0 , Sample Average : 1 , Sample Dly : 1 * */ // const int clk_div = 34 ; const int clk_div = 160; const int open_dly = 0; const int sample_dly = 1; BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN0, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, open_dly, sample_dly, \ BBBIO_ADC_STEP_AVG_1, buffer_AIN_0, BUFFER_SIZE); // for(i = 0 ; i < 5 ; i++) { BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN0); // while(1) { BBBIO_ADCTSC_work(SAMPLE_SIZE); for(j = 0 ; j < SAMPLE_SIZE ; j++) { sample = buffer_AIN_0[j]; sum_of_samples=+sample; } result = ((float)sample / 4095.0f) * 1.8f ; //result = voltage_divider(result); // printf("ADC result is %f", result); // printf("\t[sample : %d , %f v]\n", sample, ((float)sample / 4095.0f) * 1.8f); sleep(2); } } iolib_free(); return result; }