Posts

Showing posts from 2016

A few teething problems

Image
A couple of teething problems in my board design. Lessons learnt and problems solved! Design philosophy Because you get 3 boards from OSHPark, and really I only needed one for this project, I wanted to 'future-proof' my board so that I could use the other two effectively as an Aruduino-type board for other future projects.  Therefore I have broken out every pin that I can and added convenient sockets for the following peripherals, which are likely to be useful in future projects (as well as in this one): - Bluetooth module (HR-04) - nRF240l radio - GY-86 10-DOF module (MPU6050 + MC5883l + MS5611) - Onboard EEPROM 4Mbits/500kbytes (a25l040-f AMIC) - ISP: Programming chip and flashing with bootloader for Arduino GUI use. - FT232RL for convenient serial USB communication. It's always a bit of a pain to wire up the nRF2401 radios and with this board design I can very easily drop on into the correct socket, and also add a bluetooth module and not having to worry

PCBs have arrived!

Image
Totally board A flurry of excitement this morning... The PCBs arrived from OSH Park!  I have to say they look gorgeous! I am in no way biased. As a quick sanity check of the custom USB part, I dropped in a USB socket and it fitted like a dream.  I can't wait to break out the soldering iron! Fingers crossed there aren't any absolute clangers in the board design!

DMP 6-axis processing

Image
Rock, Roll and Yaw... and Barometric pressure! A change to the Quadcopter design!  Previously I had MPU6050 on a GY-521 board (acc+gyro) and the magnetometer HMC5883L on a GY-271.  I decided I wanted to have a barometer on the flight board for height control.  A bit of research revealed the MS5611 was a pretty sensitive standard barometer.  There wasn't room to add a separate barometer module to the flight control board and in fact it was cheaper to replace the GY-521 and GY-271 board with a single board, GY-86, that contained the accelerometer, gyroscope, magnetometer and barometer!  On this single board we have the MPU6050 accelerometer and gyroscope, magnetometer HMC5883L and barometer MS5611. Calculating quadcopter orientation So I'm using the GY-86 10 DOF board to calculate the orientation of the quadcopter.  We have the MPU6050 processing chip on board, and although we can read off the various sensors readings, a technology/software known as Digital Motion Process

Clone wars

Image
Cloning Arduino core ... using TIMER0 in Arduino Sometimes you want to use TIMER0 in the Arduino IDE but default inclusion of Arduino libraries means that you can't have control over TIMER0 (it is used by millis() and delay() functions).  In a recent project, I wanted to use all the Atmega328 timers, and for various reasons, still use the Arduino IDE. The solution is simple .  Rather than hacking the core library, we'll clone the Arduino core library, define a board that uses the core library and then hack it to our specifications.  Steps: (1)  Clone the Arduino core Copy the Arduino core (C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores) as "arduinohacked" -  the new core directory mustn't have an underscore in it! (2) Define a new board to use the cloned core library Open "C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt" and put the following text at the bottom.  This will define a new board in the Arduino IDE.  I&#

Flashing SimonK Hex to ESCs

Image
After some experiments applying PWM signals to an ESC controller for the Quadcopter, it rapidly became clear that the response was sluggish.  The "SimonK hex" firmware for ESC controllers appears to be the community's standard for rapidly responding ESCs.  I'm using the "MultiStar LBEC 2A 15A" ESCs from Turnigy.  After slipping off the ESC's cover slip with a razor the chip to flash becomes apparent - Atmel ATMega8A. This video on Youtube was very useful: Firstly the correct hex has to be chosen for these specific ESCs from a firmware archive .  These ESC appear to be discontinued on HobbyKing so I had to chose something that appeared very closely related - "kda.hex". The flashing software, KKMulticopter tool , is a convenient way of doing things (though avrdude from the command line manually is of course possible).  From the KKMulticopter tool, choose (1) Programmer = USBtiny simple USB programmer (or whatever yours is) (2) Port

4 x 16 bit servo control on Atmega328p

Image
Controlling four motors with Atmega328 Timer1 One of the challenges in a quadcopter project is to correctly control the four thrust motors, via ESCs.  The control is effected by a pulse between 1-2 ms.  In ESC controllers, the refresh rate can be as low as 8 Hz or 20 Hz.  In quadcopters this refresh rate is far too slow - I have seen 100-200 Hz suggested as a suitable update frequency.  The "SimonK" hex is often reflashed to ESC controllers, as it has a refresh rate of approximately 488 Hz, very close to the theoretical refresh limit of just below 500 Hz. Algorithm idea Using the Atmega328 chip, we have only one 16-bit timer available, Timer 1.  Of course there are two other timers, but they are 8 bit timers, and I really want to stick to the resolution of the 16-bit timers.  We could consider using an AVR with four 16-bit hardware timers and use the four timer output pins, but it is interesting to see what can be done with just one.  So we are having to do the job

Programming Atmega328p chip wirelessly with nRF24L01+ module - Part II

Image
Fitting nRF24L01+ code into a bootloader A brief follow up to an earlier  post .  I previously had a system working whereby I was able to program an Atmega328p chip, using a connected Arduino Nano, but crucially using an nRF24L01+ module rather than a wired UART/PC connection.  What I really wanted however was to remove the Arduino Nano, and to program the MCU chip 'directly' by use of a bootloader with nRF24L01+ code to replace with the usual UART functionality.  I thought initially that I wouldn't be able to cram the radio module code into a bootloader, but in fact it wasn't too difficult.  I used Optiboot as a starting point and implemented bi-directional radio control within the bootloader.  I think it ended up being less than 1024 words (2048 bytes). I'm not an expert here - but I had to modify the compiler and linker parameters to get things to work: Compiler flags: -g -Wall -Os -fno-split-wide-types -mrelax Linker flags: -Wl,-section-start=.tex

Disassembling Arduino generated code

Image
Johnny Five... No disassemble! I recently had need to work out how many clock cycles certain functions in my code took to execute, so it was time to find the HEX file and disassemble back to the ASM instructions.  In the Arduino environment you are shielded from getting your hands dirty with the generated compiler files, but they can be located in a temporary directory in Windows, found under: C:\Users\ USERNAME \AppData\Local\Temp\build XYZ .tmp where " USERNAME " is your ... user name and XYZ is some long integer that Arduino comes up with.  Make sure you have recently compiled your code in Arduino - the folders are deleted or wiped when you exit Arduino.  In this folder you'll find some interesting files, among them the .HEX file and .ELF files are of particular interest.  Either make a .BAT file or use the CMD prompt to execute the following commands. Disassemble from HEX We'll use avr-objdump, but we need to specify the architecture.  Find the ne

HC-05 troubleshooting

Image
Some HC-05 modules are more equal than others I've been playing with some cheap HC-05 bluetooth modules I picked up off Amazon.  They are a very convenient and easy way to add remote control to a project, using two wire UART (RX/TX) in the usual way, so can replace an existing serial connection to a PC for example.  They work pretty much out the box and there are loads of guides to using them.  I thought I would share a few thoughts on using these modules though as I've come to realise that all HC-05s are not created equal... There are some visual clues.  On the back of my modules I have an "EN" pin whereas some other HC-05 modules have a "KEY" pin.  The KEY pin is used to place the module into "AT command mode", by putting it high (3.3V) before powering up the module.  I initially thought that the EN pin was analogous to the KEY pin (a different name perhaps), but the EN pin can be used to disable the bluetooth module , which I guess is

Recovering ATMEGA328p chip from external clock fuse set

Image
A quick post of tragedy and triumph! Whilst breadboarding a new project with an Atmega328p chip (the heart of some of the Arduino ecosystem), I wanted to configure the AVR "fuses" (a desperately misleading term!) in order to use an external 16 MHz crystal, rather than the default internal 8 MHz oscillator.  This is straight forward and something I've done before.  Using the excellent fuse calculator , I wanted to get cracking and rushed in without double checking my fuse selection.  Big mistake!  I saw the option "external clock" (CKSEL=0000 SUT=00), and thought "great, that's it", also unselecting the CKDIV8 option (bit 7), generates the LOW fuse = 0xC0 and the HIGH fuse = 0xD9.  Two right mistakes here!  First of all the small one:  Selecting a box corresponds to setting the bit to '0', rather than '1', i.e. *unselecting/unticking* the CKDIV8 boxes will SET this bit as true (and divide the clock signal by 8).  It can't be

Quadcopter control board - part 1

Image
Quadcopters and custom Eagle parts So I finally started my quadcopter project!  I want it to do certain things - for simplicity, I wanted to use cheap modules that you can find on Ebay or Amazon for the accelerometer, gyroscope and magnetometer.  I decided to add a micro USB port as a convenient 5 V power source, but quickly reasoned that full USB support with a FT232RL chip would be an easy way interact with the board and to spit out debug information.  So I picked up a bunch of micro USB with through-hole female ports from Ebay for next to nothing... then promptly realised they were completely non-standard and I would have to create my own custom Eagle part .  This turned out to be really quite simple.  With digital vernier calipers in hand the footprint part I created (inset) in a prototype design turned out to be near perfect - result! For the accelerometer and gyroscope I'm using a MPU-6050, and for the magnetometer, a HMC5883L module.  Essentially the design is clo