Page 1 of 1

[EMW3165] ADC Readings

Posted: Tue Jan 05, 2016 7:26 pm
by kjordan2001
I'm trying to read from an ADC input but it gives me a consistent reading of around 26-28, except when starting up it gives me around 309. When reading from an unconnected ADC input it gives me the same values. Here is the code which I copied from another WICED example:

Code: Select all

void application_start( )
    uint16_t value;

    /* Initialise the WICED device */

    WPRINT_APP_INFO( ( "Analog in measurement...\n" ) );

    wiced_adc_init( WICED_ADC_5, 1000 );

    while ( 1 )
        wiced_adc_take_sample( WICED_ADC_5, &value );
        WPRINT_APP_INFO( ( "Analog in: %d\n", value ) );
        wiced_rtos_delay_milliseconds( 1000 );

I'm connected to pin 34 which should be the correct one for ADC_5.

Re: [EMW3165] ADC Readings

Posted: Fri Feb 12, 2016 6:50 pm
by petesoper
I've confirmed odd behavior from two EMW3165 modules on WiFiMCU boards purchased last October: one running the WiFIMCU bits rev "0.9.6" and the other running Loboris' January bits rev "0.9.13_LoBo".

I connected a LM35DZ temperature sensor to the first ADC line (pin "D1" on the WifiMCU) and measured the voltage seen by the EMW3165 with a Rigol DM3068 (6 1/2 digit DMM) .

With the WiFiMCU 0.9.6 bits I get readings like this with about five seconds between each function call:

Code: Select all

                              print(read.adc(1))       (reading/4096)*3.3         Rigol DMM
 after power up          2982                              2.402v                             0.198v (i.e. 19.8C/68F)
 2nd reading                 833                              0.671v                             0.198v
 3rd reading                 529                               0.129v                             0.198v                       
 4th reading                 779                               0.627v                             0.198v

With the LoBo 0.9.13 bits:

Code: Select all

                                   print(read.adc(1))       (reading/4096)*3.3         Rigol DMM
 after power up            309                              0.249v                             0.198v (i.e. 19.8C/68F)
 2nd reading                   11                              0.009v                             0.198v
 3rd reading                   12                               0.010v                             0.198v                       
 4th reading                   11                               0.009v                             0.198v

If I grab the sensor with my fingers the meter indicates the expected voltage and the ADC readings reported by the function calls go up from one unbelievable value to a higher unbelievable value.

Re: [EMW3165] ADC Readings

Posted: Fri Feb 12, 2016 10:38 pm
by petesoper
Aha, too many different boards and pin mappings. I feel silly.
The arguments to for WiFiMCU are of course the raw "Dn" pin numbers. So the five analog pins correspond to read() arguments of 1, 13, 15, 16, and 17.

I ran some quick tests on all these pins with the same input of about 200mv and got impossible values from, but very much larger than what pin one gave me earlier in the day.

The Adafruit ESP8266 Huzzah's single ADC pin (10 bits, referenced to one volt) gives reasonable numbers from my sensor. Off by a few percent from what the DMM reports, but close enough to be able to say the ADC works.

Re: [EMW3165] ADC Readings

Posted: Sat Feb 13, 2016 11:30 am
by loboris
petesoper wrote:Aha, too many different boards and pin mappings...

There was a bug in ADC mapping for D1 on WiFiMCU board which was mapped to the same pin as D17.
It will be fixed in the next release. I will also add the averaging algorithm to improve the ADC accuracy
ADC on pins D13, D15 and D16 works as expected (I've just tested them).
Pin D17 on WiFiMCU board is connected to BLUE LED and is practicaly not usable for ADC measurements.


When converting ADC value to voltage, always use the voltage measured on 3.3V pin (it is never exactly 3.3000 V).

Re: [EMW3165] ADC Readings

Posted: Sat Feb 13, 2016 3:50 pm
by petesoper
I connected a Siglent SPD3303S (precision power supply) to pins 13, 15 and 16 in turn and used Just as you said, the ADC function works fine. So there's a mystery with yesterday's measurements with the temp sensor, but that's my problem.

But for me with your .13_LoBo bits I cannot make the blue LED light. I tried this:

On a board running the WiFiMCU vendor 0.9.6 firmware the same function calls do supply a ground and light the blue LED.

I can't get back to this for a day or two, but look forward to figuring out what I did wrong yesterday and trying out your latest binaries.

Re: [EMW3165] ADC Readings

Posted: Sat Feb 13, 2016 3:53 pm
by petesoper
I forgot to ask what kind of frequency of averaging of ADC values are you planning, and will this be a simple running average?

Re: [EMW3165] ADC Readings

Posted: Sat Feb 13, 2016 7:14 pm
by loboris
petesoper wrote:.. gpio.mode(17,gpio.LOW) ...

gpio.write(17,gpio.LOW) / gpio.write(17,gpio.HIGH) turns LED ON/OFF without problem (just tested)

Updated adc module will be ready tomorrow, then you'll be able to test it. Apart from fixed D1 issue, automatic/manual calibration with internal STM32F411 Embedded reference voltage and internal MCU temperature measurement (not very usefull) are added.
For now simple average of up to 128 values is added.
As we don't have the possibility to use external voltage reference, I don't think any more complex averaging algorithm makes sense.
The results I've got are quite good.

Re: [EMW3165] ADC Readings

Posted: Mon Mar 21, 2016 6:57 pm
by kjordan2001
There's incorrect mappings for the ADC channels in the EMW3165 WICED patch. I filed a pull request for it a while back.