Hi Everyone,

I am looking for a way to log readings from an external custom sensor circuit with the APM logs. For hardware, I can use either the APM unit or an external Arduino to wire the sensor circuits and then read this value out into the APM. Once figuring this out, there is the additional challenge of getting this data into the APM logs in order to have precise location information for each sensor sample.

Does anyone know how I could do this???

Cheers,

Adam

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

Join diydrones

Email me when people reply –

Replies

  • I am also doing the same project can anyone help me.
  • Hi Adam, &  Everyone!

    Nice post.  I am trying something similar. but the connection is from pixhawk to an odroid xu4, mounted on a 3dr x8.  The connection is using the USB-UART cable. The odroid successfully displays voltage readings based on gas sensing..I have a CO2 sensor.

    Is there any sample code that I could refer to,  to have the drone navigate to the source of a leak (in this case CO2).

    I need to do path planning and eventual localization of a source of the gas leak.

    Any ideas ? Thank you in advance

    Thanks

  • I made it work with an i2c splitter, so you keep the magnetometer installed.

    •  Did you have to do some kind of fault checking code because there were two devices on i2c bus?

      • Now I prefer to output some APM data to my external electronic device handling sensors rather than logging sensors data to the APM logs.

        Anyway, it is the same about i2c protocol. You have to use AP_HAL::Semaphore to avoid errors.

        What is working for me is to do something like this in the user code:

         AP_HAL::Semaphore* _i2c_sem = hal.i2c->get_semaphore();

        if (!_i2c_sem->take(5))

        {
        //error check
         }

        if(hal.i2c->write(2,sizeof(DataToSend), DataToSend) !=0)
        {//gcs_send_text_P(SEVERITY_LOW,PSTR("writing error"));
        }

        _i2c_sem->give();

        The function gcs_send_text_P is nice for debugging (text only), you get the message in Mission planner last tab.

        One last thing when playing with user code before flying your copter: arm it without props, and play with it. Download dataflash logs and check PM messages about slow loops. I had an issue which was making the APM running very slow which was not good when flying...

        • Excuse me, Can data from external sensors incorporated into other applications , while flight mission took place to collect the data which is stored in the log APM ?  for example I have a program that can automatically realtime plotting external sensor data and geo tagging of logs apm
  • Hi Adam, a lot is possible if you don't mind coding it yourself. What sort of signal are you looking to monitor? What frequency do you need to record at? If you are just after a 'quick fix' then perhaps you could substitute your signal for either the voltage or current inputs currently monitored by the apm? Obviously you would have to disable any battery failsafes. If you do want to custom code a solution then you'll have to get familiar with the development tools/environment. I added the ability to log rssi to a version of arducopter, logging one of the inputs shouldn't to big a deal.
    • Hi James, I'm looking to monitor environmental conditions from small sensors wired to an Arduino. I would have about 6 different sensors outputs, so maybe PWM is the way to go? The frequency should be minimally 5 Hz. It sounds like custom code will be the way to go and I may even need a Pixhawk for the added memory space. What is everyone using currently to develop on Pixhawk's STM32F4?

      • If you are already using an Arduino to read the sensors then you could look at connecting it to the APM as an i2c slave device. The i2c port on the APM is where you attach the external magnetometer so you would need to get or make a 'Y' cable if you already use one of these (the i2c port supports connecting multiple devices in parallel, each individually addressable) There are plenty of Arduino i2c examples around on the net to follow but you can start here: http://arduino.cc/en/Tutorial/MasterReader The APM is already configured as the i2c master so you will have to code your Arduino as the slave device as in this example.

        There are already 'user hooks' set up in the APM code to allow you to run your custom code at specified intervals (1, 3.3, 10, 50 and 100 Hz loops) If you strictly need 5Hz then you will have to use the 10Hz loop and perform your operations every 2nd call. It will be up to you to decide how you are going to format the data that is transferred to the APM and how you will format it in the log.

        If you have not done so already, you should download and get familiar with the ArduXXX code and the development tools for your platform. Check out http://dev.ardupilot.com/. Once you can compile and run your own code on the APM, you will be a big step along the path to your goal. 

        If you have any further questions along the way, I am happy to help as best I can.

        • Excellent, thank you James!

This reply was deleted.

Activity