Error in sending ADC reading to MQTT broker

Dear Nordic community,

I am currently trying to send ADC sensor reading to MQTT broker(hivemq). I have successfully sent some data to the mqtt broker. However, the reading fo the data that I am sending is 0, which is not the adc sensor reading that it should be (meaning that the data_value is not updated and remains in its initial value). Below is my attached file, can anyone give me some suggestions?

 mqtt_simple_sensor (3).zip

Parents
  • Hi,

     

    I tested your program, and when connecting AIN1 to VDD (3.0V), I get this output:

    ADC raw value(s): 851
    

    calculated value: 0.6V/(1/6) * 851/2^10 = 2.992 V

     

    Please note that AIN1 is P0.14, and if you're enabling modem traces, this corresponds to uart1 RTS pin.

     

    Your timer "my_timer" is being overwritten, so that my_work_handler isn't called.

    Try issuing your workqueue from the timer (ie. adc_sample_event()) instead, and do not re-init the k_timer instance.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    I tested your program, and when connecting AIN1 to VDD (3.0V), I get this output:

    ADC raw value(s): 851
    

    calculated value: 0.6V/(1/6) * 851/2^10 = 2.992 V

     

    Please note that AIN1 is P0.14, and if you're enabling modem traces, this corresponds to uart1 RTS pin.

     

    Your timer "my_timer" is being overwritten, so that my_work_handler isn't called.

    Try issuing your workqueue from the timer (ie. adc_sample_event()) instead, and do not re-init the k_timer instance.

     

    Kind regards,

    Håkon

Children
Related