B4R Question Change analog input resolution from 10 bit to 12 bit "MKR1010"

Discussion in 'B4R Questions' started by Åke Artklo Bravida, May 3, 2019.

  1. Åke Artklo Bravida

    Åke Artklo Bravida Member Licensed User

    The Due, Zero and MKR Family boards have 12-bit ADC capabilities that can be accessed by changing the resolution to 12.
    This will return values from analogRead between 0 and 4095.
    How do I enable this in B4R?

    Thank you
    Åke Artklo
     
  2. thetahsk

    thetahsk Active Member Licensed User

    Use inline c code and call analogReadResolution(12) to set 12 bit adc resolution.

    https://www.b4x.com/android/forum/threads/inline-c-c.65714/
     
  3. Åke Artklo Bravida

    Åke Artklo Bravida Member Licensed User

    Ok I try that.

    Thank you
     
  4. Åke Artklo Bravida

    Åke Artklo Bravida Member Licensed User

    Hello again I try to use this code:
    But I do something wrong i get error

    b4r_main.cpp:35:23: error: expected constructor, destructor, or type conversion before '(' token
    analogReadResolution(12);



    Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("analogReadResolution", Null)
    analog_A0.Initialize(analog_A0.A0,analog_A0.MODE_INPUT) 'Tempsensor
    End Sub


    #if C
    analogReadResolution(12);

    #End if
     
  5. thetahsk

    thetahsk Active Member Licensed User

    Try this
    Code:
    Private Sub AppStart
       
       ...
       RunNative(
    "Set_ADC_12bit"Null)
       ...
    End Sub

    #if C
    void Set_ADC_12bit(B4R::Object* o) 
    {
      analogReadResolution(12);
    }
    #End if
     
  6. Åke Artklo Bravida

    Åke Artklo Bravida Member Licensed User

    No, I got this error.

    C:\project\B4R\TJMQTT~1\Objects\bin\sketch\b4r_main.cpp: In function 'void Set_ADC_12bit(B4R::Object*)':
    b4r_main.cpp:37:26: error: 'analogReadResolution' was not declared in this scope
    analogReadResolution(12);
    ^
    exit status 1

    Any suggestion?
     
  7. thetahsk

    thetahsk Active Member Licensed User

    Do you have installed all lib's in the Arduino IDE for your MKR1010 ?
    Write a short programm in the Arduino IDE which call's the analogReadResolution(12) function.
     
  8. Åke Artklo Bravida

    Åke Artklo Bravida Member Licensed User

    Yes I made this test in Arduino IDE for mkr 1010.

    void loop() {

    analogReadResolution(12);
    Serial.print(", 12-bit : ");
    Serial.print(analogRead(A0));

    }

    Sketch compiled no error.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    This code compiles fine when I set the board type to Arduino Due:
    Code:
    Private Sub AppStart
       Serial1.Initialize(
    115200)
       
    Log("AppStart")
       RunNative(
    "Set_ADC_12bit"0)
    End Sub

    #if C
    void Set_ADC_12bit(B4R::Object* o)
    {
      analogReadResolution(12);
    }
    #End if
     
  10. Åke Artklo Bravida

    Åke Artklo Bravida Member Licensed User

    Ok first i can´t find board type Arduino DUE in my boardlist is there an update to my boardlist?
    I tested with MKR1000 and that compiled without any error.
    So I changed back to MKR1010 and now it actually compiled without any error ??????? very strange??
    Now it´s running.

    Problem solved Thank you.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice