T3

Using analogRead with ArduIMU v3

Hello,

I'm running arduIMU v.D and I cannot get the code to compile if I use either analogRead/Write features. I get the following:

core.a(wiring_analog.c.o):(.data.analog_reference+0x0): multiple definition of `analog_reference'
arduimu.cpp.o:(.data.analog_reference+0x0): first defined here

Something about the way arduimu works seems to break the analog features.It looks like I need to do some direct port manipulation to read analog pin 0-4 (the pins I desire to read). Does someone have some advice on an equivalent piece of code to directly replace:

         analogRead(A0);

The reason for me doing this is that I am attempting to make a motion-based transmitter for multicopters, pitch and roll controlled by motion, but I would still need to poll some pots for yaw and throttle.

Thanks,

Ted 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • This reply was deleted.
    • T3

      are you also running arduimu code along with that? I can do it standalone, but not while arduimu code is running. I would assume the normal SDA and SCL pins (A4 and A5) are used up, but for some reason any call to analogwrite/read results in the above. There most be something buried in the code that I do not understand. 

      • This reply was deleted.
        • T3

          Got it, Thanks! I went through and commented out all references to boards < 3 AND I commented out this section.

          /*
          volatile uint8_t MuxSel=0;
          volatile uint8_t analog_reference = DEFAULT;
          volatile uint16_t analog_buffer[8];
          volatile uint8_t analog_count[8];
          */

          I am now able to use analogRead/Write in my code. So I decided to go back to stock code and then just comment out what I show above and NOT comment out any of the defines for < board 3 and it compiles, which I suppose is expected. 

          I tried just wrapping that snippet of code up like this

          #if BOARD_VERSION < 3
          volatile uint8_t MuxSel=0;
          volatile uint8_t analog_reference = DEFAULT;
          volatile uint16_t analog_buffer[8];
          volatile uint8_t analog_count[8];
          #endif

          but when I set the board type 1 or 2 I get issues about declaring variables on compile (even without analogRead/Write in there). I suppose that is because it still compiles the "void Read_adc_raw(void)" despite not needing to. 

          So I have a very workable solution now considering I have board ver 3. Thank you very much Al Toma. You rock. 

  • T3

    Hmm, I am guessing that there is a fundamental issue I am not grasping. Are the analog pins already being used to read the onboard sensors? 

This reply was deleted.

Activity

Jose Araujo liked Jose Araujo's profile
Aug 29
spencer harvey liked spencer harvey's profile
Jul 9
More…