RC Groups

RC Groups
    Multirotor Talk
        Mini-HowTo Arduino and HobbyKing Multi-Rotor Control Board V3.0 or KKmulticontroller v5.5

#1 pprioverde Jun 05, 2012 03:39 PM

Arduino and HobbyKing Multi-Rotor Control Board V3.0 or KKmulticontroller v5.5
 
2 Attachment(s)
My first post. Hello everyone. :)

This should be interesting to those who are into Arduino and have either the HobbyKing Multi-Rotor Control Board V3.0 or KKmulticontroller v5.5.

Once set up (and with a usbasp programmer) you can use the Arduino IDE to code and upload directly to the controller board.

Great for those who want to roll their own controller software.

Instructions, example and pin mapping below:

More detailed instructions here : http://www.rchacker.com/diy/arduino-...v3-0-atmega328

Code:


/*

  Configuring arduino dev environment for the HobbyKing Multi-Rotor Control Board V3.0 (Atmega328 PA)
  or KKmulticontroller v.5.5 “Blackboard”
 
  using arduino 1.01
 
  and a usbasp programmer, www.fischl.de  from hobbyking
  if you are running windows you will have to install the drivers for the usbasp programmer.
 

In osx, show package contents on arduino.app. Windows I'm not sure program files or such.
add the new board to Contents/Resources/Java/hardware/arduino/boards.txt


##############################################################

hobbyking_v3.name=Hobbyking v3.0 ATmega328

hobbyking_v3.upload.protocol=arduino
hobbyking_v3.upload.maximum_size=30720
hobbyking_v3.upload.speed=57600

#hobbyking_v3.bootloader.low_fuses=0xFF
#hobbyking_v3.bootloader.high_fuses=0xDA
#hobbyking_v3.bootloader.extended_fuses=0x05
#hobbyking_v3.bootloader.path=atmega
#hobbyking_v3.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
#hobbyking_v3.bootloader.unlock_bits=0x3F
#hobbyking_v3.bootloader.lock_bits=0x0F

hobbyking_v3.build.mcu=atmega328p
hobbyking_v3.build.f_cpu=8000000L
hobbyking_v3.build.core=arduino
hobbyking_v3.build.variant=hobbyking_v3
##############################################################



 nagivate to Contents/Resources/Java/hardware/arduino/cores/arduino/variants/standard/pins_arduino.h
 make a new variant based on the above.  hobbyking_v3/pins_arduino.h
 add the following.
 
  const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  // .....
  // added the below lines
  PB,
  PB,
 
  const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  // .....
  // added the below lines
  _BV(6),
  _BV(7),
 

  now we have digital pins 20 and 21
 
  To program select your programmer and then use upload using programmer in the file menu.
 
  Marc Griffith, 2012
 
 */
 
//spare analog pads on back should just work.
const unsigned int PAD_A6 = A6;
const unsigned int PAD_A7 = A7;

//spare digital pads on back.
const unsigned int PAD_RX = 0;  //PD0
const unsigned int PAD_D4 = 4;  //PD4  (PCINT20/XCK/T0)

//we could also use digital 11,12,13 (MOSI,MISO,SCK) as long as no low impedence loads
const unsigned int PIN_MOSI_D11 = 11; //PB3
const unsigned int PIN_MISO_D12 = 12; //PB4
const unsigned int PIN_SCK_D13 = 13; //PB5

//and the rest...

const unsigned int PIN_LED = 20;  //PB6
const unsigned int PIN_AIL = 1;  //PD1 (TXD)
const unsigned int PIN_ELE = 2;  //PD2
const unsigned int PIN_THR = 3;  //PD3
const unsigned int PIN_RUD = 21;  //PB7
const unsigned int PIN_M6 = 5;  //PD5
const unsigned int PIN_M5 = 6;  //PD6
const unsigned int PIN_M4 = 7;  //PD7
const unsigned int PIN_M3 = 8;  //PB0
const unsigned int PIN_M2 = 9;  //PB1
const unsigned int PIN_M1 = 10;  //PB2
const unsigned int GYR_ROL = A2;  //PC2
const unsigned int GYR_PIT = A1;  //PC1
const unsigned int GYR_YAW = A0;  //PC0
const unsigned int POT_YAW = A5;  //PC5
const unsigned int POT_PIT = A4;  //PC4
const unsigned int POT_ROL = A3;  //PC3

//some example code:
#include <Servo.h>

Servo servoOne;
Servo servoTwo;
Servo servoThree;

int temp = 0;

void setup() {               
  servoOne.attach(PIN_M1);
  servoTwo.attach(PIN_M2); 
 
  pinMode(PIN_LED,OUTPUT);

  digitalWrite(PIN_LED,HIGH);  //I am alive
  delay(10);
  digitalWrite(PIN_LED,LOW); 
 
}

void loop() {
  temp = analogRead(GYR_ROL); 
  temp = map(temp,0,1023,0,179);
  servoOne.write(temp);
 
  temp = analogRead(POT_YAW);
  temp = map(temp,0,1023,0,179);
  servoTwo.write(temp);
     
}


#2 mcashatt Jun 15, 2012 12:41 PM

Thanks!
 
This is JUST what I was looking for!

#3 pprioverde Jun 16, 2012 09:17 AM

Updated.
 
Got it working with Arduino 1.01. Much cleaner and has its own entry in boards.txt. See changes above. Have fun. :)

#4 OregonThew Jul 24, 2012 12:08 PM

Quote:

Originally Posted by pprioverde (Post 21912555)
Got it working with Arduino 1.01. Much cleaner and has its own entry in boards.txt. See changes above. Have fun. :)

I'm fairly new to Arduino and I'm wondering if someone can help with this.
I'm having trouble getting this in to the IDE, there has to be a simpler way to get this to work. Maybe I'm missing something in the instructions.



FYI, I'm using Ver 1.01 and Win7

Thanks...

#5 pprioverde Aug 07, 2012 11:23 PM

What have you done so far? You have to edit two text files, It does not get any simpler.
I have expanded on the instructions here,

http://www.rchacker.com/diy/arduino-on-the-hobbyking-multi-rotor-control-board-v3-0-atmega328


Let me know if you still have problems.

#6 Akcopter Sep 04, 2012 08:35 AM

wow !!!!!! are you saying ....you have written some arduino code for the existing kk board design........for a multi-rotor.......if so then this is just awesome...this is just what I was looking for...

#7 pprioverde Sep 05, 2012 02:30 AM

Not for a multirotor as such, just for using the Arduino IDE with the kk board. I have not gone much further than reading the sensors and flashing leds but I was thinking it would be useful for other projects.

#8 dart50 Sep 05, 2012 02:21 PM

subscribed

#9 Akcopter Sep 06, 2012 11:59 AM

But just a very dumb and out of the blue question..Is it possible to write a multirotor firmware using the arduino libraries and syntax..for the hk kk board...keeping in mind the strict EEPROM memory constraints..if it can be written it will at-least provide a ray of hope for newbie coders wanting to develop their own firmware ...I know the multiwii and APM firmwares have been written keeping the arduino hardware in mind..but what about the kk board...I dont know but I am just asking roughly what is coming to my mind......

#10 Akcopter Sep 06, 2012 12:02 PM

also how does the 8Mhz internal oscillator be compatible with the programs written for a 16Mhz arduino hardware..

#11 dart50 Sep 06, 2012 12:12 PM

Quote:

Originally Posted by Akcopter (Post 22658314)
But just a very dumb and out of the blue question..Is it possible to write a multirotor firmware using the arduino libraries and syntax..for the hk kk board...keeping in mind the strict EEPROM memory constraints..if it can be written it will at-least provide a ray of hope for newbie coders wanting to develop their own firmware ...I know the multiwii and APM firmwares have been written keeping the arduino hardware in mind..but what about the kk board...I dont know but I am just asking roughly what is coming to my mind......

EEPROM is not limiting factor here. For such case I'd say that the processor speed will limit you. So if MultoWii and/or APM have comparable processor it should be possible to write such firmware.

#12 Akcopter Sep 07, 2012 12:01 AM

thats right but the ocsillator frequency is also a deciding factor for the speed of calculations..all the arduino boards as stated earlier have a 16Mhz external oscillator which is more stable than the 8 Mhz internal Osc on the HK kk 3.0 board..even though the processor is the same will this work for half the operating frequency

#13 dart50 Sep 07, 2012 03:46 AM

Quote:

all the arduino boards as stated earlier have a 16Mhz external oscillator which is more stable than the 8 Mhz internal Osc on the HK kk 3.0 board
I'm writing my own software for HK kk 3.0 for last 2 months. Never saw any problems with oscillator frequency or stability (can anyone explain me how oscillator instability can harm flight characteristics?).
I think it will be able to fly even with Arduino. However that software will never be a best performer (maybe there will be not enough CPU speed to handle accelerometer/Bluetooth/GPS/etc.) but it is not needed if you just want to learn programming.
And you can always rewrite your SW without Arduino libraries if you want to make it run faster.

#14 pprioverde Sep 07, 2012 09:00 AM

Quote:

Originally Posted by Akcopter (Post 22658314)
But just a very dumb and out of the blue question..Is it possible to write a multirotor firmware using the arduino libraries and syntax..for the hk kk board..

Absolutely, ardupilot and ardupilot-mega run on the Atmega328 and 2650 respectively. They both use Arduino and do far more than just multirotor control.

As long as you avoid floats and divides your Arduino code should perform plenty fast enough. Use hardware PWM, not software PWM for the esc's and use interrupts to capture your rc data.
Ardupilot has good libraries for this, there is even a PID library with examples.

#15 pprioverde Sep 07, 2012 09:07 AM

Quote:

Originally Posted by Akcopter (Post 22658333)
also how does the 8Mhz internal oscillator be compatible with the programs written for a 16Mhz arduino hardware..

Arduino code takes care of that, original arduino's were also 8Mhz.


All times are GMT -5. The time now is 10:28 PM.