zondag 25 december 2011

ISP programming with arduino

Looking for an alternative to get my kkmulticopter blackboard v5.5 flashed with the latest firmware I stumbled upon this arduinoISP project. It's basically a sketch that turns you arduino board into an ISP programmer. The guide that holds most if the information is here. Some information on how I got this working.

The Arduino I used for this is a Duemilanove. Arduin Uno doesn't work with this code yet. With a mini solderless breadboard (I really love these things for prototyping!) I linked all the correct pins together. Check the arduino ISP link in the beginning for more details. You have to link digital pins 10, 11, 12 and 13 like this to the ISP programming interface:


  • digital10:ResetTarget Pull this low to reset the target and prepare for programming.
  • digital11:MOSI Master Out/Slave In
  • digital12:MISO
  • digital13:SCK Serial clock to target.

The kkmulticopter blackboard v5.5 has the 6 pin header, first one in this picture:



If you want to have some visual feedback from the programmer you can also add leds to the pins 7, 8 and 9. Check the sketch for info on what these leds do. Don't forget to add some resistor to these leds so you don't burn them out right away. You can use an online calculator to get the correct resistor value for your led. When in doubt a 1k Ohm will work in most cases.

Now for this arduino you need to disable the auto reset option. For this link the 5v pin with the reset pin using a 120 ohm resistor. Color code for this resistor is brown, red, brown.

That's about it for the physical connections. Go ahead and flash your arduino with the arduinoISP sketch from the examples section and you'll be able to see the heartbeat led when everything works.

I tried this first with the kkflashtool but that didn't work out of the box. No matter what programmer I selected. I got it working using avrdude directly. Since I'm on OS X I installed crosspack package. It's a simple disc image (dmg) that holds a package (pkg) to be installed by double clicking it.

The command for flashing looks like this:

$ avrdude -P /dev/cu.usbserial-A800eFOW  -b 19200 -c arduino -p atmega168ap -v -e -U flash:w:/Users/userX/Downloads/QuadControllerV4_5/QuadControllerV4_5_M168_M328.hex

Make sure to adapt the red parameters to match your configuration. By default the atmega168ap programmer doesn't exist in config. I created that myself by making a copy form atmega168 changing only the programmer name and the device signature. In order to know the device signature you can run the above command with any existing programmer id that isn't valid for your programmer connected to that port. You then will get a message that looks like this telling you what the ID is you need to put in the usr/local/CrossPack-AVR/etc/avrdude.conf file.

avrdude: Device signature = 0x1e940b
avrdude: Expected signature for ATMEGA168ap is 1E 94 6B
         Double check chip, or use -F to override this check.

And you're done. This should let you program your kkmulticopter board with an Arduino (or any other programmer supported by AVR).

zaterdag 24 december 2011

New Redmine project website now live

I'll be collecting project specific information on my new project website from now on. This project website is available at http://redmine.hcpl.be.



woensdag 14 december 2011

KK Quad X issue solving

All the hardware is in and everything is mounted and I got a few test flights. But it needs to be tweaked since for now it's hard to control. I believe it should be easier.

Basically this is the URL you're looking for on how to set up your KK quad in X configuration.

What I'm going to fix for now on my quad:

I already changed the way my motors were mounted. This is how it looks now. This way I can properly mount the propellers (no more prop savers) and the motors are better protected in case of crashes. You will break more props though. Don't forget to kill throttle on impact!


I would like to find better booms also. These are 13mm booms while the holders are all molded to fit 12mm booms like used on HK 450 copters. They work but I believe real 12mm booms will fit better and give me a stronger frame. For now all shops either don't sell these in 12mm or they're out of stock. Looks like many multicopters are created these days.

I need to fix that battery properly. It's influencing the center of gravity (it even shifts in flight) the way it's mounted on this picture. Like with any aircraft you want a good balance in the air. The best option to change the balance is by moving the battery around.


And if I review the mounting of the lipo I can as well review the mounting of the controller board. I have some adhesive foam pad in that I can use to tape it to the top of this frame. These plastic screws might still pass too much vibrations on to the controller.


Besides that I will calibrate the ESCs again (I did it at some time but I'm not sure it really worked). And I'll play with the gain of the gyro's. You never know it might just need some more gain to be easier to control. Too windy these days to get it in the air though.

Oh and don't forget to upload the latest firmware. With each firmware upgrade the platform gets better and better. My board came preloaded with the Quadrocopter 2.2 firmware while 4.5 was already out. 

vrijdag 9 december 2011

Arduino thermostat project

Probably one of the most popular Arduino projects :). I just needed a thermostat controlled infrared (heat) lamp to keep the water installation free from frost.

The basic idea was to have an Arduino checking temperature with a thermistor. Based on some MIN and MAX temperature setting a relay (with an infrared light bulb) would be activated. With 3 leds I can indicate the state of the Arduino (LOW, MID and HIGH temp).



It took me some time to get a reasonable reading out of the thermistor. A thermistor is basically a resistor that reacts on temperature changes. That way we can read the resistance with our arduin (use AREF) and calculate a temperature. The first results were way too low, around -21 C. After some debugging I discovered I picked the wrong resistor for reference. Replaced that one and got an acceptable reading.



By far the best tutorial I found on using a thermistor with Arduino. It promotes a specific thermistor wrapped in some black plastic protection. Don't mind that, just make sure you get the right Beta value (datasheet) and measure your resistor to double check the value. Update these in the code (take last code snippet form tutorial for best measurement) and you're ready to go.

You can find my source code for this project here.

The thermistor isn't perfect. Even with the smoothing (using average of multiple readings) I still get 1 C difference between successive reads. Also it seems to be a bit positive starting from around 10 C. In a later version I replaced the thermistor with a DS18B20 chip and finally got consistent read outs.

A tutorial on using the DS18B20 chip I liked. And another DS18B20 tutorial using the updated library. Note that the link metioned in that second tutorial doesn't point to the correct updated library. I just installed one of the 2 libraries and used one of the included examples to get everything working.

And that resulted in an updated Arduino script file.

So far for input. Output is limited to 3 status leds. Check the standard Arduino samples if you don't know how to use leds.



And a relay. The relay interrupts the 230V wire. Using a 5V power input and a signal wire to activate (high) or deactivate (low) the relay. All the information you ever wanted to know on using relays with Arduino is here. Make sure the relay can handle the power you're going to put through it. BE CAREFUL SINCE THIS IS HIGH VOLTAGE!!

So far for what you really need. You'll notice that my prototype board also has a bluetooth adapter. That one is used to communicate with an Android app for monitoring, logging and (some time) internet access. If you don't need the Android connection but want to have some internet connection you can get the ethernet shield instead.

donderdag 8 december 2011

Arduino performance with digitalWrite alternative

Arduino language is no more than a high level, java like wrap around the C language. Still you can simply include C libraries or use even C code in your arduino sketch. For some operations this is very useful!. 


Ever checked how much cycles digitalWrites actually take? You would be surprised!

digitalWrite(9,HIGH); // 57 clock cycles
digitalWrite(9,LOW); // 57 clock cycles
digitalWrite(8,value); // 57 clock cycles

Solution is to write these instructions in C code directly. It's the exact same result but about 25 times as fast. An example:

bitSet(PORTB,1); // 2 clock cycles
bitClear(PORTB,1); // 2 clock cycle
bitWrite(PORTB,0,value); // 3 clock cycles

Improved Arduino OneWire lib

Original Arduino OneWire lib had some bugs. Too bad it's still all over the web. For better performance and support for more sensors you can check this project for download:

http://www.pjrc.com/teensy/td_libs_OneWire.html



Basic Usage

OneWire myWire(pin)
Create the OneWire object, using a specific pin. Even though you can connect many 1 wire devices to the same pin, if you have a large number, smaller groups each on their own pin can help isolate wiring problems. You can create multiple OneWire objects, one for each pin.
myWire.search(addrArray)
Search for the next device. The addrArray is an 8 byte array. If a device is found, addrArray is filled with the device's address and true is returned. If no more devices are found, false is returned.
myWire.reset_search()
Begin a new search. The next use of search will begin at the first device.
myWire.reset()
Reset the 1-wire bus. Usually this is needed before communicating with any device.
myWire.select(addrArray)
Select a device based on its address. After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.
myWire.skip()
Skip the device selection. This only works if you have a single device, but you can avoid searching and use this to immediatly access your device.
myWire.write(num);
Write a byte.
myWire.write(num, 1);
Write a byte, and leave power applied to the 1 wire bus.
myWire.read()
Read a byte.
myWire.crc8(dataArray, length)
Compute a CRC check on an array of data.

Arduino use analog inputs as digital pin


Many people don't realise that the Arduino analog pins can be used as regular digital I/O lines simply by addressing them using a different pin number.

analog 0 = digital 14
analog 1 = digital 15
analog 2 = digital 16
analog 3 = digital 17
analog 4 = digital 18
analog 5 = digital 19

So to use, for example, analog input pin 2 as a digital pin, you can simply use a regular digital command such as:
digitalWrite( 16, HIGH );