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

          • have you done your project ?

          • Adam,

            I actually found this quite interesting as I potentially have an application for this myself. I have had a bit of a play and I have managed to connect an Arduino Nano running 6 (virtual) sensors and transmitting the data to an APM2.5 via i2c.

            The APM (running my modified Arducopter 3.2dev) is logging the data from the Nano at 10Hz and you can display the results in the MP log browser. I have included the files you need here including the sketch I used for the Nano emulating 6 attached sensors (putting out various waveforms with random amplitude and period). Currently it is set up to transfer 6 floating point numbers (float) which amounts to 6x4=24 bytes per read. Depending on your sensors, you could probably get away with two bytes per sample which will help reduce the load. As it is, at 10Hz there does not seem to be any problems.

            3702818217?profile=original

            3702818437?profile=originalTo get the code to work, copy the contents on the attached zip file into the same folder your Ardupilot directory is in. It will overwrite the UserCode.pde and UserVariables.h files but if you haven't already added any customised the code, this is OK. You will need to alter APM_Config.h and uncomment the following lines:

            #define USERHOOK_VARIABLES "UserVariables.h"
            #define USERHOOK_INIT userhook_init(); // for code to be run once at startup

            #define USERHOOK_MEDIUMLOOP userhook_MediumLoop();        // for code to be run at 10hz

            Depending on what platform/compiler you are using, you may also have to disable various modules in this file so that the code fits on the APM.

            You will also have to add the following two lines to the LogStructure definition in log.pde:

            { LOG_SENSORS_MSG, sizeof(log_Sensors),
            "SENS", "ffffff", "Sine,Tri,SawR,SawF,Rand,Square" },

            This is at line 694 in Arducopter 3.2dev

            That should be it. Compile and upload to check it out!

            Ardupilo-I2C_Sensors.zip

            2014-03-20 14-26-01 3.log

            • Hi, James, 

              I am actually have a project that is similar to what you did. So I bascially followed what you did in this post. However, I did not know how you registered for the libraries (i2c sensor) in the file. And what file do you change and add path in order to register? 

              Also I have a question about the git submodule, is there any other way to add the nuttx and firmware files without using the git submodule command? Or is it possible to compile the firmware without the github repository?

              Thanks a lot! 

            • James, I am on a very similar project. I wonder if it's such a good idea to use a 5V arduino nano, because I believe that the i2c bus from the magnetometer port is running 3.3V logic level. What do you think about this?

              • Hi Manu, yes this is a very good point and I was somewhat remiss in not covering this as the photo I have posted is obviously misleading... In my defence, the attached Arduino was there purely to facilitate a demonstration of the APM code :) The Nano you see in the pic has been modified to run off 3.3v . Quite a few of my Nanos end up this way as 3.3v is much more common now (I have not had any trouble at 16MHz but you may want to be careful if your application is mission critical). Other options would include disabling the internal pull ups and applying external pull ups to 3.3v (from APM as the 3.3v pin on Nano is supplied from the FTDI chip and is not available when not powered by USB), using a level shifter or using a 3.3v Arduino Pro Mini. 
                • Thanks for this answer. Now I am starting the funny part with handling i2c semaphore and checking that nothing goes wrong with the magnetometer + slave arduino. Did you try to send sensors data not only to the APM log, but to ground station with MAV message?

                  • Did you get this working with magnetometer?

This reply was deleted.

Activity