Roll telemetry dataI'd like to get telemetry from my RC Yachts beyond Rx voltage and RSSI info. For instance, the "optimal heel angle" seems to vary depending on who you listen to, so getting heel angle would be a nice start.
There are lots of cheap sensors that can report this, but none are targeted at yachts. So I'm going to build a simple one. Since I can't find rc radio gear that supports such telemetry, I'm going to hijack flight pack voltage on an aircraft system. Just read the roll angle from the gyro sensor (an MPU650 in a GY-521 board), convert that to a number between 0 and 255, then output that as a PWM value via a D->A circuit to get a voltage. The advantage of using an analog voltage sensor is that any radio system with flight pack telemetry can do this.
I'm using a FrSky Rx which incorporates the flight pack voltage sensor in the Rx, and a Walkera Devo 10 running deviationTx, since that lets me adjust the gain on the voltage sensor across a wide range. This means I can get a reading in 10 degree increments, which works well. 1 degree increments would be better, but the display won't scale to 90 volts of input.
The hardwareYou'll need some form of Arduino. The test build uses a Uno, but my goto Arduino for final installs is the Pro Mini. Another interesting possibility would be the Teensy 3.1. This includes a DAC, which would simplify the build a bit and make the value sent to your transmitter more accurate.
The other major component is an MPU6050, or possibly a later MPU9150 which adds a compass. I ordered mine from Amazon.
The connections for the MPU650 breakout are:
- VCC to either 3.3 or 5 volts on the Arduino
- GND to GND on the Arduino.
- SDA to A4 (aka SDA) on the Arduino.
- SCL to A5 (aka SCL) on the Arduino.
- INT to D2 on the Arduino.
Calibrate/Calibrate.inoto calibrate MPU650. After calibrating, you can use the
FloatController.inosketch to see the Y roll values, both as degrees and in the 0→255 PWM values. Read the MPU Calibration section below for more information on this.
The extra hardware is a capacitor and resistor to turn the PMW value into a flat voltage. The actual values don't seem to matter much, as the voltage to degrees map will deal with things. Personally, I used a 100µF cap and a 330Ω resistor. The resistor connects to Pin D5 on the Arudino, then the sensor and cap to the other end of the resistor, and finally the other end of the cap to ground. Sorry if this is hard to follow - see the details for information on how this works, circuit diagrams, and calculations.
The CodeThe code is a very simple modification of the MPU6050 demo code that comes with Jeff Rowberg's MPU6050 library. You will of course also need the library. The demo outputs the various sensor readings to the serial port. Instead of calculating the degrees, the actual code (in the
Arduino/FloatControllerdirectory of the blog repository) takes the absolute value of the appropriate sensor, and scales that to our 0→255 range before outputting it as a PWM value.
To install the production version after you've calibrated the MPU as described in the MPU Calibration section, comment out the line that says
#define SERIAL_DEBUGat the top of
FloatController.ino, and upload that version.
MPU CalibrationLike most sensors, the MPU6050 needs to be calibrated before it can be used. All the code is in the
Arduino/FloatControllersubdirectory of my blog repository. In the
Calibratesubdirectory, there's a sketch that will calibrate the MPU, and save the calibration values to EEPROM.
Compile and upload this sketch, and the calibration process will start whenever the Arduino resets. It will wait for a serial connection to the Arduino at 115,200 baud, and the prompt for a character before starting the actual calibration. Calibration takes about a minute, and your MPU650 needs to be in the position it'll be in in the yacht and still for this period, so get that set before you start it.
While the calibration is running, the LED will blink irregularly, and you'll get output as the process goes through each of it's three states. At the end, the acceleration and roll values with the given calibration are printed, along with their expected values (0s except for Y acceleration, which is about 1g). The 0's should be a single digit off. The g value will be a bit further off as you never really get 1g.
After some more inputs are added to the Arduino, the calibration should move into the FloatController sketch and be triggered by the user.
Radio calibrationThe next step will depend on your radio equipment. Connect the voltage sensor to the resistor as described. If your sensor needs configuration, set it up for a 2S battery. Unless you're using a 3.3V Arduino, in which case set it up for a 1S battery.
If your radio allows adjusting the gain on the telemetry voltage, turn the sensor on edge, and note the value. Then try and adjust the gain so that will read about 9 volts. Or - if your radio allows it - 90 volts. If you're adjusting the FrSky AD2 gain on deviation, don't forget to reboot the transmitter after changing it.
Hopefully, you can now set your heel alarms if you desire. I've set mine for 80°.
WorkingAnd here's a video showing the protototype build running an an Arduino Uno with the MPU6050 mounted on a breadboard shield.
The next step will be moving this to a Pro Mini on a more permanent board and putting it in a yacht!