Setup Blackbox in Cleanflight

Blackbox feature in Cleanflight is useful for tuning PID, and diagnose any performance related issue you might have with your multicopter.

This is part of the Cleanflight Setup Guide. Here is a guide on how to tune your PID using blackbox logs. Here is a guide on how to overlay sticks movement and blackbox data onto your FPV video.

Content index:

There are two ways of saving Blackbox data depends on what flight controller you have. For example the Naze32 Full version has 2MB of flash memory you can use for Blackbox, but the Naze32 Acro version has none. Therefore it will require an external data logger and a SD card.

Flight controller internal flash storage is very limited, for 2MB you can only record about 3 or 4 mins of flight (@2500 looptime). Some flight controller has larger memory such as the SPRacing F3 board has 8MB of memory, but still pretty limited. (the cunning thing is, it’s advertised as 64Mb – 64 Mega bit, not Mega Bytes 1Byte = 8 bits :D I got confused the first time!)

I think CC3D has 2MB onboard flash storage as well.

I like using an external data logger, because it’s relatively cheap to setup, and you can record for much longer with an micro SD card.

Cleanflight Documentation is pretty good! Hopefully some of the gaps that were missing can be filled in this tutorial.

Blackbox Example

In this video I tested how PID value changes affects the performance of the quad,


Setting Up OpenLog Device

I got my OpenLog on eBay from China, costed about $9, the cheapest I can find on the internet.
Also get a microSDHC card that has fast write speed. Sandisk Extreme 16GB Class 10 UHS-I microSDHC is recommended on Cleanflight documentation, but i found Sandisk Ultra class 10 16GB also works fine (which I use for my mobius and GoPro).

The advantage of using OpenLog is

  • It’s pretty cheap to setup and running
  • More than enough data storage
  • You can use the same hardware on all of your boards that don’t have onboard flash storage
  • It doesn’t take a long time to export the log file (on my Naze32 Full board, it takes 3 to 4 minutes to export a 40 second flight, which is annoying)

Update OpenLog Firmware

Updating the firmware on OpenLog allows you to record log data with a faster baud rate (default – 115200 to 250000). This is important if you are running looptime below 2500.

The OpenLog custom firmware for blackbox. Instruction is pretty clear.

You can either use a dedicated FTDI programmer, or an Arduino Uno.

openlog-ftdi-programmer-connection-sparkfun

Ardunio-MinimOSD

Here is how you connect the OpenLog data logger to the Arduino UNO, or Sparkfun FTDI programmer.

Arduino-openlog-flash-firmware-sparkfun-ftdi-programmer-connection

Problem: Error when Flashing firmware on OpenLog

I was getting this annoying error when i am uploading the sketch from Arduino IDE! And couldn’t figure out why when updating the firmware.

Error: avrdude: stk500_getsync(): not in sync: resp=0x31

It turns out to be the wrong bootloader! In the documentation, it says to choose “Arduino Uno” in “Tools => Board”. But no, that’s for the latest version of OpenLog, the one I got was the older version which is only compatible with the “Arduino Pro or Pro Mini 5V/16MHz w/ ATmega328”

If you’re not sure, try both, it won’t hurt anything.

Problem: Getting Gibberish in the log files

If you are getting bad log files, make sure you compile the Blackbox sketch for the Atmega328 5v 16Mhz – and not the 8Mhz.

Format your SD card

It’s recommended to format your Micro SD card with this tool.

For 2GB or more, you should use FAT32 format. Smaller cards can use FAT (aka FAT16).

OpenLog Configuration

The openlog’s configuration settings are placed on the SD card. You need to create a config file on the SD card and write config settings in it.

  1. Create a text file in SD card, call it CONFIG.TXT
  2. in the CONFIG.TXT file, put these in
    250000,26,3,0,1,1,0
    baud,escape,esc#,mode,verb,echo,ignoreRX

Settings in Cleanflight

To enable blackbox feature check this option.

blackbox-feature-in-cleanflight-configurator

Alternatively you can do it in CLI command by entering

feature BlackBox

By default external storage device is chosen, i.e.

set blackbox_device = SERIAL

Connection with Naze32

You will only need 4 connections, TX, RX, 5V and GND. I get the 5V and GND from the spare motor pins.

I strongly recommend using Radio pin3 (TX) and pin4 (RX) on the Naze32 board to connect to the OpenLog. These pins are UART2 serial ports, and they are available when you are running PPM on RX.

In fact you only need to connect the TX pin on the Naze32, because the communication is one way, data is only sent from Naze to OpenLog, and no data is required to send back to the FC.

cleanflight-port-tab-data-blackbox-uart2

I would not recommend running Openlog with UART1 (TX/RX pins in the middle of the board), because you cannot change Baud rate to 250000 i think in this case. Once you change that baud rate you won’t be able to connect to Cleanflight configurator (correct me if i am wrong!)

testing-blackbox-openlog-naze32

Start Recording

Arm your flight controller and it will start recording automatically. The Blue LED on the OpenLog should start blinking very rapidly when it’s recording.

Sampling frequency and Looptime

For example when looptime is 2400, there is 1s / 2400ms ~= 416 iterations of control loop data to record per second. The fastest looptime could jump around 1200 on a Naze32 board, and we have twice as many iterations (833 to be exact). And that’s a lot of data!

If your hardware is not good enough (e.g. low grade SD card), the logging device will struggle with writing speed, you will find missing data in your graphs like this.

blackbox-sd-card-missing-data-dot-line

If that happens to you and really affects your usage, easiest solution is to lower your sampling frequency, by default the sampling rate parameters are set to:

set blackbox_rate_num = 1
set blackbox_rate_denom = 1

You can halve the sampling rate by setting “rate_denom” to 2.

set blackbox_rate_denom = 2

Using Onboard DataFlash Memory

The advantage of using integrated flash storage is:

  • No need to worry about OpenLog and SD card
  • Doesn’t lose data due to writing error
  • Free up a serial port for something else

Simply enable blackbox in Cleanflight by checking the feature, or type in this command in CLI command.

set blackbox_device = SPIFLASH

After you have recorded some flight data, you can export it by going to DataFlash tab, and press “Save Flash to File”. The below diagram shows only 11 seconds of data on the Full Naze32 board @ 1200 looptime, and that’s 10% of the memory used!

cleanflight-dataflash-tab-blackbox-space

BlackBox Viewer

This is a quick Chrome application that you can use to overlay blackbox data on a MP4 video. There is no rendering wait, so it’s perfect for quick check.

However you can output it as a WEBM file, but cannot output it as a normal video file. WEBM isn’t supported by the majority of video editor, including Gopro Stduio, Adobe Premiere or Windows movie maker.

For rendering proper video, use the following tool.

BlackBox Tools for CSV file Conversion, and Video Render, Overlay

This blackbox convert and render tool only works in command lines, it doesn’t have an interface. Follow the instructions it’s pretty straight-forward.

blackbox-convert-render-tool-command-line-example

It basically can convert your log data into a series of PNG pictures, pretty much like time lapse photos. You can then convert these photos in your video editor into a single video that you can overlay on your flight footage.

How I mount Openlog on my mini quad

It’s fitted under the top plate of the frame with zip tie, a layer of Velcro to stop it from sliding. Note that I also put another half-cut zip tie there to prevent the SD card from accidentally popping out in hard landing or crashes.

mounting-openlog-data-logger-on-mini-quad-blackbox

49 thoughts on “Setup Blackbox in Cleanflight

  1. Yann

    I have a naze32 rev5 FC running with a SBUS receiver on UART2. Can I connect the logger on pin3 (UART2 TX) and enable both serial RX (the SBUS receiver on pin4 UART2 RX) and blackbox in UART2 ?
    I want to keep UART1 for a Micro minimOSD.
    Anybody tried this yet ?

    Reply
    1. Oscar Post author

      no you can’t… one UART can only be used for one thing…
      however you could use PPM while tuning your quad with Blackbox… after that replace PPM with SBUS again maybe?

      Reply
  2. Peter Kornum

    Can i use black box to tjek for what i think is a defektive ESC? and will it tell me witch one cuts out?
    link to video of my problem…. vimeo.com/168044887

    Reply
  3. Joshua

    HI Oscar,

    You definitely CAN run Blackbox on UART1 at 250 kBaud, with MSP at the default of 115.2 kBaud. I’m doing it, anyway.

    Reply
    1. Oscar Post author

      thanks Joshua :)
      UART1 is shared by USB connection on the Naze32, by changing baud rate of UART1, does that not disable your connection to the configurator?

      Reply
  4. Peter

    Hi,

    I got the OpenLog serial data logger you suggest from banggood:
    banggood.com/OpenLog-Serial-Data-Logger-9660bps-PPZ-Flight-Control-Record-FAT16-FAT32-MicroSD-Cards-p-993844.html

    But not the Sparkfun FTDI Programmer you suggested. I instead got it from banggood (cheaper and has a 3.3 / 5v switch instead of a soldering point):
    banggood.com/FTDI-Basic-Program-Downloader-USB-TTL-3_3-5V-FT232-For-Arduino-p-988937.html

    I hope it works (I’m pretty new to this). I’ll let you know when I receive it in a couple of weeks.

    Thanks for the tutorial.
    Cheers

    Reply
  5. Bryce

    Hello Oscar,

    I burnt up my Naze32 and all I have is a spare CC3D board to use at the moment. I have flashed the CC3D with Cleanflight, version 1.9 I believe. I’m trying to setup blackbox for use with the 2mb onboard flash memory.

    My problem is, whenever I input: “set blackbox_device = SPIFLASH” the CLI prompt returns: “blackbox_device set to 0”. I even tried to input “set blackbox_device = SERIAL” just for fun and the prompt returns the same thing. Do you possibly know how to fix this? Thanks!

    Reply
  6. Andrei

    Hi Oscar,

    Trying to upload the OpenLog custom firmware by following your instructions, but I’m a bit over my depth here. I am using a generic FTDI programmer and OpenLog I ordered recently from Banggood. I connected the 6 wires from the programmer to the OpenLog, 2 crossed over exactly as in your diagram. Chose the following options in the Arduino “Tools” menu:

    Board: Arduino/Genuino Uno
    Port: dev/cu.usbserial-BLAHBLAH
    Programmer: USBasp (you don’t mention this one. Does this matter?)

    When I click the “Upload” button, it compiles, but with 3 similar warnings in red, which include the text:
    warning: ‘__progmem__’ attribute ignored [-Wattributes]

    Then it gives some information about memory usage. Then it tries 10 times to sync something and gives a similar error to the one you mentioned above, that you fixed by choosing “Arduino Pro or Pro Mini”.

    If I try to change the board like you did, I get all the same errors, plus more that complain that Arduino can’t connect to my board.

    Any ideas as to what’s wrong? Does it matter what I choose for “Programmer”? Thanks for any help you can give!

    Reply
    1. Andrei

      Hi Oscar,

      I bought an Arduino Uno starter kit (was wanting one anyway) and tried to do it that way. I connected Tx to Tx and Rx to Rx as your diagram shows – seems weird but nobody has corrected that so I went with it.

      I had to remove the Tx/Rx connections to get the sketch to upload without error (as I remember reading was necessary elsewhere). Then I plugged them back in and reset the board. I assume it then tried to upload the custom firmware to the OpenLog.

      The CONFIG.TXT file on the SD card now has these contents:

      115200,26,3,0,1,1,0
      baud,escape,esc#,mode,verb,echo,ignoreRX

      There are also several log files with names like LOG00119.TXT that look like gibberish.

      Does that mean the update succeeded?

      (Should we be asking these things in your new forum instead?)

      Reply
      1. Andrei

        Hi Oscar, sorry to spam up your post with these annoying problems. You can delete them if you wish. Having said that… 

        I GOT IT WORKING!!! :D

        Arduino Uno worked without a hitch and I have recorded my first logs, synced the video and exported combined video. It is awesome. I discovered that my quad is moderately noisy, D term is quite active with the default PIDs on 2Khz mode, and I might have an oscillation on P, but the graphs look pretty good overall. So great to finally see what is happening. Thanks for your guide!

      2. Oscar Post author

        thanks for letting me now…
        In future i would really appreciate it if you could post your questions on the forum: http://intoFPV.com … I only check my blog comments once a week, but I use the forum everyday!

  7. Sammy

    Can I use the logger when I’m already running a SBUS receiver in UART2 (pin4)? Can I just hook up the logger in pin3 and enable both serial RX(the SBUS receiver) and blackbox in UART2? Or should I switch the SBUS to UART1?

    Still waiting for mine to arrive, meanwhile but trying to figure out how this should work.

    Reply
      1. Russell Holt

        i thought UART3 only supplied 3vdc? I also thought that SBUS uses UART3 and therefore OpenLog could not be hooked up to it?
        I’m very interested to know. i have GPS, OSD & OpenLog hooked up, but I seem to be having to use PPM, giving me only 8 channels with my FrSky XSR Receiver. i’d rather be using SBUS and have the 16 channels available.

        Russ from Coral Springs, FL.

  8. Shamsher Razzak

    Hey Oscar,

    I love your blog, your articles have been of so much help in building and setting up my quad, thanks for all the work you put in!

    i have a problem with my flip32+ v2.6, its supposed to have onboard flash 2mb, but my cleanflight configurator v1 says “your flight controller does not have a compatible dataflash chip available”. how can i identify if i have this chip or not?

    Reply
  9. Colby

    Hey Oscar,

    Thanks for this great article! I tried using the blackbox on my dodo flight controller, but it doesn’t seem to be storing any more than a couple seconds of flight time. I tried wiping the data and that did not help. Have you encountered this?

    Reply
      1. Ernie

        The DODO only has a 2mb onboard memory for the blackbox recording.

        You can try this though if you are not running and external blackbox.

        Go into CLI and enter

        set blackbox_rate_denom = 8

        That will drop the rate of data collection and should help get you some more time. Using Betaflight with a looptime of 900 I had to do this on my external blackbox to get clean data.

      2. Oscar Post author

        you need highest resolution recording to get to see all the noise in your PID and gyro traces :)

  10. mike

    Sorry, but this sentence is wrong. The ports should be reversed. Otherwise, great write up. thanks

    I strongly recommend using Radio pin3 (RX) and pin4 (TX) on the Naze32 board to connect to the OpenLog.

    Reply
    1. mike

      Ooops, should have put the Rev3 Naze32 manual extract too:

      When GPS feature is enabled, channels 3 and 4 are are used for 3.3V GPS connection.
      (3:TX, 4:RX). with CPPM receiver, these are normally unused, with standard receiver,
      connect AIL to 1, ELE to 2, THR to 5, RUD to 6, and AUX1/2 to channels 7 and 8.

      Reply
  11. Zac

    Hi Oscar

    Was the sync issue the only problem you had while uploading?
    Ive been getting ‘avrdude: verification error; content mismatch’ all day and can’t seem to figure it out.
    Ive tried pretty much everything, including switching boards, but can’t get past this point.

    Reply
    1. Oscar Post author

      Hi Zac, i didn’t have this error.. and tried on both Arduino UNO and an dedicated FTDI programmer, both worked fine…
      Not sure what Arduino IDE you are using, maybe tried the 1.0.5 version? (which was what I am using)
      also try a different FTDI programmer?

      thanks
      Oscar

      Reply
  12. SmoothFPV

    Hi Oscar. Always great to read your blog. For the Naze connection, you only really need 3 connections, RX, 5V and GND. There’s no bidirectional data flows because OpenLog only accepts data. Hence the config file on the SD card. There’s no reason for the OpenLog to talk back to the Naze (like a bad step-child) so you can omit the TX out from the logger.

    Reply
    1. Oscar Post author

      Yes good point ! :)
      I haven’t tried just 1 wire yet, when i tested it and confirm it’s working i will update the post.

      Reply
    1. Oscar Post author

      Kevin, what do you mean by “more data”?
      By default “blackbox_rate_denom” is 1, so you get full resolution of the flight data.

      Reply
  13. Geggog

    Great article Oscar, especially so the point of selecting the Arduino Pro Mini for uploading the sketch – this had me truly stumped.

    I’ve now got this up and running, albeit with one small issue. I can see that the data is being logged to the OpenLog correctly (I can eject the card and read it on my laptop via an SD card adapter), but for some reason when I attempt to read the data via CleanFlight configurator (Dataflash screen) I’m told that “Your flight controller does not have a compatible dataflash chip available.”

    Should I be able to read the data off the MicroSD card via the Dataflash screen? Or is this only available when using storage on-board the flight computer? Any assistance you could provide would be much appreciated.

    FWIW, I have wired up the OpenLog to pins 3/4 with UART2 configured to 255000 baud as you’ve recommended.

    Reply
    1. Oscar Post author

      HI Geggog,
      if you are using OpenLog and SD card, you can only read the data by taking out the SD card, and read it with a SD card adpater.
      You cannot read it via Cleanflight configurator, that’s only for onboard Dataflash memory which is only available on Naze32 full, or CC3D…

      Reply
  14. Ricardo Smits

    Hi Oscar,

    I was wondering, Is it possible to run both the micro minim osd and the black box at the same time?

    Thanks for the post btw, helps a lot!

    Reply
    1. Oscar Post author

      Hi Ricardo, yes it is, that’s what i am running on my Evo250, MinimOSD on UART1, and Blackbox on UART2.
      but you need to unplug minimOSD TX/RX from FC when connecting to cleanflight, when the quad is powered on.

      Reply
      1. Ricardo Smits

        Hi Oscar,

        Got everything working today although I have a new question: Why do you have the baud rate at 250k in the settings at Cleanflight? I saw that the baud rate was 115k in the .txt file from the blackbox and it is working fine. Any particular reason you did that?

        Now off to tuning. Quad flies ok out of the box with standard settings but has a big wobble with throttle puch outs. Wish me luck haha.

      2. Oscar Post author

        for looptime lower than 2500, 250k baud rate is recommended to avoid missing data (explained in the post)

      1. Kevin Yang

        Thank you for your help!
        BTW I got compile error in firmware.(It works Epprom clean)
        I will check the arduino book. maybe check the library but I cannot find in mac :-)
        Thank you again

  15. Ian

    Hi Oscar,
    The photo showing the connections from Arduino One board to OpenLog board shows Tx connected to Tx and Rx to Rx? Shouldn’t it be Tx to Rx and Rx to Tx? When run the Serial port HEllo World it works the latter way.

    I’m having zero success getting it to program from Aurduino board. When I compile and upload the new firmware, it just logs it as garbage to a new log file. It’s not modifying the firmware, even with Reset pin connected..

    Reply
    1. Oscar Post author

      1. did you flash the openlog firmware for blackbox?
      2. you have chosen the correct board in Arduino IDE as I pointed out?
      3. have you specified a baud rate in the config file on the SD card? are you using the correct baud rate in Cleanflight?

      Reply
  16. blackmennewstyle

    Hi Oscar,

    So bore this windows guys, they are so lazy :p If you were using GNU/Linux you could transform easily your WEBM file to MP4 file or whatever you want with FFmpeg or Avconv :p Maybe FFmpeg is available now for windows…

    Very nice tutorial by the way :)
    Thanks for sharing!

    Reply
    1. Oscar Post author

      haha yes they are, but they are doing it for free so can’t blame them!
      I will look into FFMpeg! thanks! It would make life so much easier :)

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you Robot? *

I don't look at blog comments very often (maybe once or twice a week), so if you have any questions related to multirotor please post it on this forum IntoFPV.com... You're likely to get a response from me faster on there.