Help getting Codrone to work with PlatformIO

Hello, I have a CoDrone from Robolink and want to use VS and PlatformIO to program the Controller. The Controller is Atmel32 processor. Here is the info on installing Codrone:

I’ve have installed the extension and have a small piece of code:

//#include <Arduino.h>
#include <CoDrone.h>
//#include <EEPROM.h>

void setup() {

  CoDrone.begin(115200);
  CoDrone.pair(Nearest);

  CoDrone.takeoff(); //goes up and hovers for 3 seconds
  CoDrone.hover(10); //hovers for an additional 2 seconds
  CoDrone.land(); //lands the CoDrone
  

}

void loop()
 {
 byte bt8 = digitalRead(18);
 byte bt4 = digitalRead( 14);
 byte bt1 = digitalRead(11);

 if(bt1 && bt4 &&!bt8)
  {
    CoDrone.emergencyStop();
  }
 }

Here is my platform.ini

[env:ATmega32]
board = ATmega32
platform = atmelavr
framework = arduino

lib_deps =
  # Using a library name
  CoDrone
    
  # ... or using library Id
  909
      
  # ... or depend on a specific version
  CoDrone@2.1.1

I’m not sure what to select for the board so I chose Arduino/Genuino Uno

Here is my output of the compilation:

Processing ATmega32 (board: ATmega32; framework: arduino; platform: atmelavr)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega32.html
PLATFORM: Atmel AVR 1.15.0 > ATmega32
HARDWARE: ATMEGA32 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), tool-avrdude 1.60300.190424 (6.3.0), framework-arduinoavr 4.1.1
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CoDrone> 2.1.1
Checking size .pio\build\ATmega32\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=====     ]  45.7% (used 935 bytes from 2048 bytes)
PROGRAM: [==        ]  21.7% (used 6986 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: COM9
Uploading .pio\build\ATmega32\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502 (probably m32)
avrdude: reading input file ".pio\build\ATmega32\firmware.hex"
avrdude: writing flash (6986 bytes):

Writing | ################################################## | 100% 1.21s

avrdude: 6986 bytes of flash written
avrdude: verifying flash memory against .pio\build\ATmega32\firmware.hex:
avrdude: load data flash data from input file .pio\build\ATmega32\firmware.hex:
avrdude: input file .pio\build\ATmega32\firmware.hex contains 6986 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.73s

avrdude: verifying ...
avrdude: 6986 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:00, L:00)

avrdude done.  Thank you.

======================================================================== [SUCCESS] Took 5.88 seconds ========================================================================

Terminal will be reused by tasks, press any key to close it.

It look like I’m able to upload the code to the Controller, but when I try to run the code, that is, unplug the USB to the Controller, flip the switch on the dip switch, power on the Drone and then connect the Controller with the USB to start the program, which for some reason does not work. The Controller never finishes paring with the Drone.

What could be the problem?

Thank you very much,
Joe

I haven’t heard of CoDrone before but it seems that all examples change to flight mode after pairing. Could it be that you are missing:

CoDrone.DroneModeChange(Flight);
1 Like

Hello, thank you for responding to my message. I use the same code on the Arduino IDE and it paired and did a Hover.

Here is the Arduino Upload:

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\ProgramData\MATLAB\SupportPackages\R2017b\3P.instrset\arduinoide.instrset\idepkgs\packages\arduino\tools\avrdude\6.0.1-arduino5/etc/avrdude.conf"

         Using Port                    : COM9
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega32
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.16
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502
avrdude: reading input file "C:\Users\DDS\AppData\Local\Temp\ArduinoServer\MW/Hover.ino.hex"
avrdude: writing flash (10304 bytes):

Writing | ################################################## | 100% 1.79s

avrdude: 10304 bytes of flash written
avrdude: verifying flash memory against C:\Users\DDS\AppData\Local\Temp\ArduinoServer\MW/Hover.ino.hex:
avrdude: load data flash data from input file C:\Users\DDS\AppData\Local\Temp\ArduinoServer\MW/Hover.ino.hex:
avrdude: input file C:\Users\DDS\AppData\Local\Temp\ArduinoServer\MW/Hover.ino.hex contains 10304 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.09s

avrdude: verifying ...
avrdude: 10304 bytes of flash verified

avrdude done.  Thank you.

Here is the PlatformIO Upload:

> Executing task: platformio.exe run --target upload <

Processing ATmega32 (board: ATmega32; framework: arduino; platform: atmelavr)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega32.html
PLATFORM: Atmel AVR 1.15.0 > ATmega32
HARDWARE: ATMEGA32 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), tool-avrdude 1.60300.190424 (6.3.0), framework-arduinoavr 4.1.1
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CoDrone> 2.1.1
Checking size .pio\build\ATmega32\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=====     ]  45.7% (used 935 bytes from 2048 bytes)
PROGRAM: [==        ]  21.7% (used 6986 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: COM9
Uploading .pio\build\ATmega32\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502 (probably m32)
avrdude: reading input file ".pio\build\ATmega32\firmware.hex"
avrdude: writing flash (6986 bytes):

Writing | ################################################## | 100% 1.21s

avrdude: 6986 bytes of flash written
avrdude: verifying flash memory against .pio\build\ATmega32\firmware.hex:
avrdude: load data flash data from input file .pio\build\ATmega32\firmware.hex:
avrdude: input file .pio\build\ATmega32\firmware.hex contains 6986 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.73s

avrdude: verifying ...
avrdude: 6986 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:00, L:00)

avrdude done.  Thank you.

======================================================================== [SUCCESS] Took 5.88 seconds ========================================================================

Terminal will be reused by tasks, press any key to close it.

I’ll keep working on it tomorrow.

Thank you very much,
Joe

I did try adding the line of code you suggested but that didn’t solve the problem. There must be something different in the Arduino upload and the the Platformio upload.

Thank you for helping me.,

Joe

Could be something wrong with the upload, or the compile itself. Can you add the Arduino IDE compile summary also - sketch size and memory usage - for both Arduino IDE and PlatformIO if the code isn’t exactly the same… as any variance there could point to something different.

Also, for your platformio.ini, you only need to have the following - you had copied in the example of three of the different ways in which the library could be referenced.

[env:ATmega32]
board = ATmega32
platform = atmelavr
framework = arduino
lib_deps =
  CoDrone

Edit: Having had a closer look at the avrdude output, I do think there is something completely wrong/different with the compile… the PlatformIO compile seems a lot smaller… perhaps the bootloader wasn’t included?

Arduino IDE : avrdude: writing flash (10304 bytes)

PlatformIO : avrdude: writing flash (6986 bytes)

Am I right in thinking that to work with the CoDrone in the Arduino IDE, you need to have installed the board support package they provide by adding this URL? https://raw.githubusercontent.com/RobolinkInc/Robolink/master/package_rokit_index.json

1 Like

It looks as if CoDrone is using a custom Arduino core. See package that’s downloaded as part of the Arduino board installation: http://www.robolink.com/wp-content/uploads/2016/07/RokitSmartInventor_1.0.3.zip

1 Like

Indeed, as @manuelbl and @pfeerick noted, a different Arduino core seems to be used, right? You also installed this Arduino core and selected the “SmartInventor” board for compilation?

Anyway, try the following:

  • Download the RokitSmartInventor ZIP file for above and extract it
  • Copy the “cores\atmega32” folder as “Rokit” into C:\Users\<user>\.platformio\packages\framework-arduinoavr\cores
  • copy all folders from “variants” into C:\Users\<user>\.platformio\packages\framework-arduinoavr\variants
  • use the following platformio.ini
[env:ATmega32]
board = ATmega32
platform = atmelavr
board_build.core = Rokit
board_build.variant = SmartInventor
framework = arduino
lib_deps =
  CoDrone
  • compile and observe
DATA:    [=====     ]  47.0% (used 963 bytes from 2048 bytes)
PROGRAM: [==        ]  24.4% (used 7868 bytes from 32256 bytes)

With that the new Arduino core is successfully hacked in PlatformIO’s framework-arduinoavr package, and we can also see that the compiled binary size has increased, though it’s still not at the level of the Arduino IDE. But now we are at least using the correct core and variant, which might help…

Edit: I also notice that SmartInventor-mega32_v2.build.f_cpu=7372800L line in the boards.txt, so if you are using that variant, you need to additionally add

board_build.f_cpu = 7372800L
1 Like

Hello, thank you very much for helping me get this working. I really appreciate it.

Here is my code:

//#include <Arduino.h>
#include <CoDrone.h>
//#include <EEPROM.h>

void setup() {

  CoDrone.begin(115200);
  CoDrone.pair(Nearest);  
  CoDrone.takeoff(); //goes up and hovers for 3 seconds
  CoDrone.hover(10); //hovers for an additional 2 seconds
  CoDrone.land(); //lands the CoDrone
}

void loop()
 {
 byte bt8 = digitalRead(18);
 byte bt4 = digitalRead( 14);
 byte bt1 = digitalRead(11);

 if(bt1 && bt4 &&!bt8)
  {
    CoDrone.emergencyStop();
  }
 }

Do I need to include the “Arduino.h”. I don’t think so.

Here is my compilation output:

Processing ATmega32 (platform: atmelavr; framework: arduino; board: ATmega32)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega32.html
PLATFORM: Atmel AVR 1.15.0 > ATmega32
HARDWARE: ATMEGA32 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduinoavr 4.1.1
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CoDrone> 2.1.1
Compiling .pio\build\ATmega32\src\main.cpp.o
Compiling .pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone.cpp.o
Compiling .pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_led.cpp.o
Compiling .pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_request.cpp.o
In file included from src\main.cpp:2:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909/CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\src\main.cpp.o] Error 1
In file included from C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.cpp:7:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone.cpp.o] Error 1
In file included from C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone_request.cpp:1:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_request.cpp.o] Error 1
In file included from C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone_led.cpp:1:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_led.cpp.o] Error 1
========================================================================= [ERROR] Took 1.81 seconds =========================================================================
The terminal process terminated with exit code: 1

In directory I have:

C:\Users\DDS\.platformio\packages\framework-arduinoavr\cores\Rokit
atmega16
atmega32
atmega128
In directory I have:
C:\Users\DDS\.platformio\packages\framework-arduinoavr\variants
SmartInventor
Ardu-X100
Ardu-X200

Hopefully this can help use find what we are missing.

How do I “add” board_build.f_cpu _ 7372800L line?

Thank you very much.
Joe

Here is my platformio.ini file:

[env:ATmega32]
board = ATmega32
platform = atmelavr
board_build.core = Rokit
board_build.variant = SmartInventor
framework = arduino
lib_deps =
   CoDrone

Literally just add

board_build.f_cpu = 7372800L

to your platformio.ini … just like the core and variant parameters.

1 Like

Yes… as soon as you use setup() and loop() (among other things) you need to #include <Arduino.h> I’m not sure why it’s not being found when CoDrone.h etc. try to include it as well though.

No, your Arduino core is not installed properly, you must not have the three atmegaX folders there, but the contents of atmega32 must be inside the cores\Rokit folder, as I have written above. It can’t find the Arduino.h (and the entire core) this way.

1 Like

Hello, thanks to everyone helping me get this working.

How does this look?

[env:ATmega32]
board = ATmega32
platform = atmelavr
board_build.core = Rokit
board_build.variant = SmartInventor
framework = arduino
lib_deps =
   CoDrone
board_build.f_cpu = 7372800L

Will give it a try.

Joe

Processing ATmega32 (framework: arduino; board: ATmega32; platform: atmelavr)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega32.html
PLATFORM: Atmel AVR 1.15.0 > ATmega32
HARDWARE: ATMEGA32 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduinoavr 4.1.1
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Looking for board_build.f_cpu  library in registry
Warning! Library `{'requirements': None, 'name': 'board_build.f_cpu '}` has not been found in PlatformIO Registry.
You can ignore this message, if `{'requirements': None, 'name': 'board_build.f_cpu '}` is a built-in library (included in framework, SDK). E.g., SPI, Wire, etc.
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CoDrone> 2.1.1
Compiling .pio\build\ATmega32\src\main.cpp.o
Compiling .pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone.cpp.o
Compiling .pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_led.cpp.o
Compiling .pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_request.cpp.o
In file included from C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.cpp:7:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
src\main.cpp:1:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\src\main.cpp.o] Error 1
In file included from C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone_led.cpp:1:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_led.cpp.o] Error 1
*** [.pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone.cpp.o] Error 1
In file included from C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone_request.cpp:1:0:
C:\Users\DDS\.platformio\lib\CoDrone_ID909\CoDrone.h:9:21: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

compilation terminated.
*** [.pio\build\ATmega32\lib871\CoDrone_ID909\CoDrone_request.cpp.o] Error 1
========================================================================= [ERROR] Took 1.74 seconds =========================================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Hello, I’ve made the suggested changes and unable to get a good path to the header files. Any ideas?
I’ll keep trying.
Thank you very much.