Allen Pan
Published © LGPL

Flying Drone Mjolnir With Hacked RC Transmitter

Files for laser cutting a foam Mjolnir that fits around a micro racing drone, and how to hack an RC transmitter for Arduino control!

AdvancedWork in progress13,005

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Adafruit LIS3DH Accelerometer
×1
AD5206 10K digital potentiometer
×1

Story

Read more

Custom parts and enclosures

Mjolnir Parts

These are the parts I started with, but they had to modified on the fly to make sure it...flew. Think of this as a rough draft!

Schematics

Arduino Transmitter Hack

Arduino control an RC transmitter via digital Potentiometer. Check your datasheet and the above code for wiring Pot to Transmitter.

Code

Flying Mjolnir

C/C++
Used on Arduino Uno with AD5206 potentiometer and LIS3DH accelerometer to control a DX6i Spektrum transmitter
// include the SPI library:
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
// set pin 10 as the slave select for the AD5206 digital pot:
const int slaveSelectPin = 10;
int accelValue = 0;
int rollValue = 0;
int rollValuePrev = 0;
int throttleValue = 0;
int pitchValue = 0;
// two buttons for pitch and throttle
const int pitchPin = 7;
const int throtPin = 6;

int throttle = 0;
int roll = 1;
int pitch = 2;

int flag = 0;
int pitchFlag = 0;
//value must be determined empirically:
int maxThrottle = 120;

// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH();

void setup() {
  // set the slaveSelectPin as an output:
  pinMode(slaveSelectPin, OUTPUT);
  pinMode(pitchPin, INPUT_PULLUP);
  pinMode(throtPin, INPUT);
  // initialize SPI:
  SPI.begin();
  Serial.begin(9600);
  Serial.println("LIS3DH test!");  
  if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start");
    while (1);
  }
  Serial.println("LIS3DH found!"); 
  lis.setRange(LIS3DH_RANGE_2_G);   // 2, 4, 8 or 16 G!  
  Serial.print("Range = "); Serial.print(2 << lis.getRange());  
  Serial.println("G");
  //initialize the pots at reasonable values
  digitalPotWrite(pitch, 60);
  digitalPotWrite(throttle, 51);
}

void loop() {
  lis.read();
  accelValue = lis.z;
  //values must be determined empirically:
  accelValue = constrain(accelValue, -16383, 16383);
  rollValue = map(accelValue, -16383, 16383, 51, 204);
  //hand tilt controls roll
  digitalPotWrite(roll, rollValue);  
  
  pitchValue = digitalRead(pitchPin);
  throttleValue = digitalRead(throtPin);

  //"throttle" button is connected to the "arm" switch of transmitter and state
  //is read by Arduino. Pressing the button arms the drone and the Arduino can
  //then gradually raise the throttle
  if (!throttleValue) {
    if (flag == 0) {
      flag = 1;//throttle button is pressed
      for (int level = 51;level<maxThrottle;level++) {
        digitalPotWrite(throttle, level);
        delay(2);
      }
    } else {
      digitalPotWrite(throttle,maxThrottle);
    }
  } else {
    if (flag == 1) {
      flag = 0;
      for (int level = maxThrottle;level<52;level--) {
        digitalPotWrite(throttle, level);
        delay(2);
      }
    } else {
      digitalPotWrite(throttle,51);
    }
  }
  
  //the pitch button is a single bit, so whened pressed the pitch is
  //gradually raised, and when not pressed the pitch is gradually
  //lowered. So just forwards and backwards, good luck!
    //values must be determined empirically:
  if(pitchValue) {
    if(pitchFlag==0){
      pitchFlag=1;    
      for (int level = 94; level<160; level++){
        digitalPotWrite(pitch, 255-level);
        delay(2);
      }
    } else {
      digitalPotWrite(pitch, 94);
    }
  } else{
      if(pitchFlag==1)  {
        pitchFlag=0;
        for (int level = 94; level<160; level++){
          digitalPotWrite(pitch, level);
          delay(2);
        }
      } else {
          digitalPotWrite(pitch, 160);
      }
    }
}

void digitalPotWrite(int address, int value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin, LOW);
  //  send in the address and value via SPI:
  SPI.transfer(address);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin, HIGH);
}

Credits

Allen Pan

Allen Pan

1 project • 662 followers
My name's Allen, I make pretend things into real things! Watch me do a thing on Youtube!

Comments