Add new sensor - arduino code


Hi everyone,

I am trying to add some sensors to my OpenROV and I have some problems with
the arduino coding. So far I am trying to add a very simple analog input read and
display it to the telemetry stream.

Practically, I tried to modify the code that is already available for
controlling the lights of the ROV. However, when I add the code, I lose all
the telemetry data. Like I mess somehow with the streaming of the data.

Any advice or help would be welcome. The code is very simple, however I
think I am doing some fundamental mistake, or missing something.
The ROV is version 2.6 and running image 2.5.1.

Many thanks

** These are all the changes I did:

* In OpenROV.ino added:
     #include "Adctest.h"
     Adctest adctest;

* In AConfig.h added:
    #define HAS_STD_ADCTEST (1)

* In Device.h added:
   #define ADCTEST_CAPABLE 7

* Created a new file Adctest.cpp:

    #include "AConfig.h"
    #include "Device.h"
    #include "Pin.h"
    #include "Adctest.h"
    #include "Settings.h"
    #include <Arduino.h>
    #include "Timer.h"
    Timer update_timer;
    int sensorPin = A15;    
    float sensorValue = 0;  
    void Adctest::device_setup(){
        Settings::capability_bitarray |= (1 << ADCTEST_CAPABLE);    //not sure about this
    void Adctest::device_loop(Command command){
       if (update_timer.elapsed (100)){
            sensorValue = analogRead(sensorPin);

* And also the header file for this:
    #ifndef __ADCTEST_H_
    #define __ADCTEST_H_
    #include <Arduino.h>
    #include "Device.h"
    #include "Pin.h"
    #include "AConfig.h"
     #include "Cape.h"
      #include "controllerboard25.h"
    class Adctest : public Device {
        void device_setup();
        void device_loop(Command cmd);


Glad to see you’re figuring it out!

The ADCTEST_CAPABLE is not hurting anything, but the capabilities array is intended to signal to the rest of the system the features that are enabled on the ROV firmware. In this way we can have UI elements automatically enable or disable themselves as needed.

My initial guess is that you are hitting a limit in the number of devices that have been added. There is a fixed array and the system does not give a good error message when the number of devices is exceeded. I keep having to move that number up as I add new devices.


Thanks Brian, indeed this was the problem. Works now.

Is there any recommended way to develop (and debug) on the Arduino, without having to go through the Beaglebone and the cockpit?


That’s an area that can be better explored. Using another Arduino mega board + visual micro + atmel ice hardware debugger will let you step through the lines of code and set breakpoints.

You can get an SPI programmer and use the controller board sans the beaglebone so that you can use the Arduino IDE directly… essentially treating the controllerboard like a standard Arduino board.

I personally keep the logic simple and use plenty of print statements. For the complex logic I write unit tests that validate the logic for me. You can see the unit tests in the test folder.