If you know any programming and have never heard of Arduino, you live under a rock. If you don't know any programming its a great place to start. A friend in Peru introduced me to it when he asked me to help him program his beer brewing controller. Since then I've decided that its the best thing to come out of Italy since girls in summer dresses on scooters.
Seriously Arduino is cool. Take a look at diydrones.com very nice stuff all built on Arduino. Trust me I'm saving for one of those Ardupilot Megas. If you want to get into it HobbyKing seem to have cornered the market on price. They have clones of the Arduino Uno, Arduino Nano and even Arduino Mega. There are also some nice 5/3.3V switchable versions of the nano pro mini on ebay for around $10. There are loads of resources on Arduino on the internet. To get started go to the Arduino website, read the language reference then follow your internet nose. A personal recommendation Tronixstuff has some great Arduino tutorials. Moving on... Arduino is a system for making it easier to program micro controllers. Arduino refers to both the programming environment (Arduino IDE) and Arduino hardware all of which is currently based on the ATMega series of micro controllers. You guessed it, the same micro controllers that you find in most of the Multi-Rotor control boards out there, a number of ESCs, and even the Turnigy 9x. The great thing about the Arduino IDE is that it is open source. Which makes it easy for us to hack and make it work with our multi-rotor control board. What you need: A USBasp programmer. The HK 3.0 Controller board. (you could also adapt this to other boards) Step 1: Install your USBasp drivers.Sorry if I am repeating myself here.No drivers are needed for Linux or OSX. Windows get your drivers from here you have to manually install the drivers. Josh on Flite Test shows how to install the drivers on Windows 7, and also how to use KKMultiTool on a HK controller board. Worth a look. Step 2: Modify the Arduino IDE.Get it first of course. Now we need to find the boards.txt file and add an entry for the HK controller board. Mac users control click on arduino.app and show package contents. Then follow the path to the boards.txt file. Contents/Resources/Java/hardware/arduino/boards.txt Windows users, its in the Arduino folder under hardware\arduino Open it with your favorite text editor and add this to the top of it: ############################################################## 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.build.mcu=atmega328p hobbyking_v3.build.f_cpu=8000000L hobbyking_v3.build.core=arduino hobbyking_v3.build.variant=hobbyking_v3 ############################################################## Save it. Now navigate to Contents/Resources/Java/hardware/arduino/variants/ (hint the variants folder is right next to the boards.txt file). We want to make a new variant based on the standard variant. Make a copy of the whole standard folder and rename it to hobbyking_v3. Again with your favorite text editor. Open the pins_arduino.h file that is inside your newly created hobbyking_v3 folder. We are going to add two entries to two arrays in order to make use of two digital pins on the Atmega that Arduino does not use. After line 152 add the following two lines. PB, PB, Also after line 175 add these two lines. _BV(6), _BV(7), You should end up with something looking like this. Thats it, save it and your done hacking the IDE. Step 3: Upload a simple Arduino sketch to the HK board.Here is some example code, paste it in. Can you figure out what it is doing?
//Pin Definitions for Hobbyking Multi-rotor control board v3.0 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 enabled above 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 enabled above 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); //10 milliseconds digitalWrite(PIN_LED,LOW); //the board is set up with a 1.65V analog reference analogReference(EXTERNAL); } void loop() { temp = analogRead(GYR_ROL); temp = map(temp,600,1023,0,179); servoOne.write(temp); temp = analogRead(POT_YAW); temp = map(temp,600,1023,0,179); servoTwo.write(temp); } I am making use of the Arduino servo library and simply taking the output from the gyros and feeding it to the servos. The reason I used consts rather than #defines is a good habit from my software engineering days. It can help to avoid hard to find bugs as the compiler processes the symbols rather than the preprocessor. Once you have the above code pasted in you can upload it to your board. Plug in your programmer to your board like this: You should have the Hobbyking V3.0 Atmega328 listed under Tools->Boards. Select it. Also select USBasp as your programmer. Tools->Programmer->USBasp Plug in your programmer to your computer and upload the code using File->Upload using programmer. Using the standard upload button will not work. Done. To play with it unplug your programmer stick a servo in M1 and M2 and provide power using 5V from a UBEC anywhere else. Now use your imagination to find something cool to do with it. Try reading the values from the pots to to make a simple servo tester. For your reference I have include the diagrams I made to figure the code out. The datasheet for the angular rate sensors is also at the bottom. Enjoy. |
www.rchacker.com Radio control model reviews, builds and DIY hacks.