Skip to content

Latest commit



157 lines (131 loc) · 9 KB

File metadata and controls

157 lines (131 loc) · 9 KB

c't-Bot ATmega framework

This is a very basic framework for the c't-Bot with an ATmega1284P controller. It is licensed under the terms of the GPLv3 license.


This code was created for testing a new and simplified design of the c't-Bot software framework. The basic idea is to have a modular structured framework implemented in C++ built on modern language features. Although it doesn't use the Arduino software framework for some reasons (see below), there are many similarities to an Arduino program, such as the usage of external libraries, etc.


Consider this as experimental code. If it breaks, you get to keep both pieces.

Differences against the original c't-Bot software framework

  • Programming language: using C++ instead of C to have

    • object oriented programming,
    • a strict modular structure,
    • banishment of macros, #define, #ifdef and other unsafe stuff of the last century.
  • PlatformIO build system, because of:

    • independence of IDE and environment, just use what you like for editing and building the code.
    • works on common Linux distributions, macOS, Windows.
    • simple and minimalistic tool setup, you just have to install PlatformIO Core (see below).
    • it is an open source project.
    • ...
  • Consistently reduced functionality

    • No behaviors available
    • Support for basic components only
      • UART console command interface (115200 Baud with 8N1 configuration)
        • connect with USB-2-Bot adapter and terminal program like minicom or WiPort and telnet
        • type help + [ENTER] the get a list of supported commands
      • LEDs: Leds::on(), Leds::off(), Leds::set() implemented, see leds.h
      • LCD: Display::print() and Display::printf() implemented, see display.h
      • Standard sensors (excluding mouse sensor), raw sensor values are reported on LC display or via console
      • Remote control (HQ RC Univers 29 only in standard setup, see RemoteControl::RemoteControl() in remote_control.cpp for mapped keys)
      • Motors with speed control
        • use set speed [LEFT] [RIGHT] to set speed of left / right wheel as percentage values (negative values to drive backwards)
        • alternatively use remote control to increase / decrease speed of wheels, see Usage
        • ToDo: PID calibration has to be done / fine tuned
      • 2 servos
    • ATmega1284P support only
    • Simple test cases implemented (see tests.h for details)
      • LedTest: chaser lights
      • LcdTest: prints some nice stuff on the LC display
      • EnaTest: activates ENAs one by one in an endless loop
      • SensorLcdTest: displays all sensor information like the 'sensor display screen' of the original c't-Bot software (see SensorLcdTest::run() in tests.cpp for details)


Note for Atom IDE users: When installed via Atom package, Bash (Shell) used in the terminal currently does not seem to recognise the command platformio; use pio instead. (State as of May 2019)

  1. Install PlatformIO core as described here
  2. Clone this git repository: git clone
  3. Change to cloned repo: cd ctbot-atmega
  4. Initialize build system for...
    • Commandline build: platformio init
    • VS Code project: platformio init --ide vscode
    • Eclipse CDT project: platformio init --ide eclipse
    • any other environment supported by PlatformIO


  1. Build project

    • Commandline: platformio run
    • VS Code: use “Build” button on the PlatformIO toolbar or shortcut (ctrl/cmd+alt+b)
    • Eclipse CDT: Project -> Build Project or shortcut (ctrl/cmd+b)
    • Atom: Select project folder in sidebar -> Menu PlatformIO -> Build or shortcut (Alt+Ctrl+B)
  2. Upload firmware image

    • Flash firmware.hex (located in folder .pioenvs/1284p16m/) using avrdude as described here.
      • todo: update for use of platformio upload target
  3. Use a terminal program (e.g. minicom) or telnet to connect

    • If you use minicom:
      • goto Serial port setup settings and set Serial Device to your serial device, Bps/Par/Bits to 115200 8N1 and Hardware Flow Control to No as well as Software Flow Control to No
      • goto Screen and keyboard settings and set Add carriage return to Yes
    • If you use a WiPort: telnet [IP_ADDRESS] 10002
      • to switch to line mode echo press CTRL + ] and enter mode line
      • to disable local character press CTRL + ] and enter mode -litecho
  4. Have fun with the command line interface

    • type help to get a list and description of available commands
  5. Cruise around with the c't-Bot using

    • your remote control: arrow keys for forward, backward, left, right and power button for stop
    • the command line interface: set speed 30 30 for 30% of max speed on both wheels, set speed 0 0 (or just set speed) to stop
  6. Press play on remote control get a little easter egg on the command line interface :) or I/II to shutdown the bot :(

Why it doesn't use the Arduino software framework

  • Hard coded usage of timer0
  • Uart buffer space not adjustable
  • ...


Manual Build

  1. This is currently untested
  2. Install a C++ compiler for the avr architecture, e.g. avr-g++ with avr-libc. It has to be capable to compile at least C++14 (no further libraries are needed).
  3. Compile the following files from these subdirectories of the project:
    • src/*.cpp
    • lib/cpputils_avr/src/*.cpp
    • lib/pid/*.cpp
    • lib/rc5/*.cpp
    • lib/ulibcpp/src/*.cpp
    • lib/ulibcpp/src/abi/abi.cpp
  4. Add the following subdirectories to your compiler include path:
    • src/
    • lib/cpputils_avr/src/
    • lib/pid/
    • lib/rc5/
    • lib/ulibcpp/src/
  5. Further necessary compiler flags: -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++14 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega1284p -Wextra -DF_CPU=16000000UL (at least these are tested and known to work)
  6. Necessary linker flags: -mmcu=atmega1284p -Wl,--gc-sections -flto -fuse-linker-plugin -lm (if you link with avr-g++)
  7. Create an intel-hex file for avrdude with: avr-objcopy -O ihex -R .eeprom YOUR_OUTPUT.elf YOUR_OUTPUT.hex

Continuous integration tests

Branch Build status
master PlatformIO CI