Eclipse 来编译Arduino程序,并烧写Arduino程序

2023-11-14

If you want to build some electronic stuff that needs some programming, then Arduino is certainly the best choice. It just works, you only need to plug it in, write your code and press on the deploy button to have your board flashed and working.
And this is great, it saves you from tons of troubles, if you worked with microchip PICs in the past you probably know what I’m talking about.

The only thing that I don’t like about Arduino is it’s IDE, which is a very simple code editor written in Java with very few features and many annoying problems. The default IDE is very good to start learning Arduino programming, but the more you use it, the more you hate it, at least I do.

However until now I always used the default IDE, but for my last project (Sir Biss, an Arduino based snake robot) I figured out how to setup Eclipse for Arduino, and, after a bit of headache, it works great.

If you Google something like “Arduino development with eclipse” you’ll find some tutorials, some of them are very inaccurate and incomplete, others are pretty well explained but they simply don’t work, because some fundamental step is missing.

These tutorials, however, gave me the start to setup my own Eclipse, here they are:

So first of all, thanks to the people who wrote these tutorials.

What follows is a step by step guide of my personal way on how to setup a development environment for Arduino, I’ve done it on a Windows 7 32 bit PC, and my Arduino hardware is the Arduino Duemilanoveboard.
I do not own other boards so I cannot test this guide for other types of Arduino (Arduino Mega, Arduino Mini, …) if someone reading this guide is able to test it on different boards, please tell me if and what changes must be done I’ll be glad to update this tutorial, thank you!

Install Eclipse

First thing to do is download the latest Eclipse IDE for C/C++ developers from the Eclipse website, as I’m writing this the latest Eclipse version is Indigo.

To run Eclipse you need the Java Runtime Environment (not the JDK, because we are not going to develop in Java, so the JRE is fine), you can download the latest JRE from the Oracle website, click on the “Download”button under JRE, then choose the right JRE for your system, I downloaded the Win 32 x86 version, for offline installation (jre-7u3-windows-i586.exe).

Start Eclipse and choose a workspace, where all your Arduino projects will be saved.

Install the Eclipse AVR Plugin

From Eclipse, go to “Help” and then “Install New Software”.

In the “Work with:” box write this url:

http://avr-eclipse.sourceforge.net/updatesite

Then click “Add”.
Set the “Name:” to “Eclipse AVR Plugin”, leave the “Location” as is.

Click “OK” and wait until the installable components are loaded, then select all and click “Next”, a dependencies check will start for the selected components and it should take some minutes.

After the depencencies check completes you will be asked to review the selected components, click “Next”, then accept the license terms and hit “Finish”. The components installation will start. An alert dialog will appear saying that you are installing unsigned software, say “OK”.

When the installation completes you will be asked to restart Eclipse.

Download the Arduino SDK

Download the latest Arduino SDK, at the time I am writing this the latest available SDK is marked as Arduino 1.0. Nedless to say, download the right one for your machine, I downloaded arduino-1.0-windows.zip.

Choose a place on your file system for the Arduino SDK and then unzip the downloaded file, I unzipped mine inD:\arduino so from now on remember to replace this base path with the one you choose.

Setup the Eclipse AVR Plugin

From Eclipse go to “Window” and then “Preferences”, open the “AVR” section on the left, then select “Paths”

Select AVR-GCC, click “Edit”, in the window that appears set “Path source:” to “Custom”, click “Browse” and point it to this path <arduino_base_path>\hardware\tools\avr\bin which is the path to the AVR compiler (avr-gcc.exe) inside the arduino SDK directory. I pointed mine to D:\arduino\hardware\tools\avr\bin.

Select GNU Make, click “Edit”, in the window that appears set “Path source:” to “Custom”, click “Browse” and point it to this path <arduino_base_path>\hardware\tools\avr\utils\bin which is the path to the makeexecutable inside the arduino SDK directory. I pointed mine to D:\arduino\hardware\tools\avr\bin.

Select AVR Header Files, click “Edit”, in the window that appears set “Path source:” to “Custom”, click “Browse” and point it to this path <arduino_base_path>\hardware\tools\avr\avr\include which is the path to the AVR toolchain headers files inside the arduino SDK directory. I pointed mine toD:\arduino\hardware\tools\avr\avr\include.

Select AVRDude, click “Edit”, in the window that appears set “Path source:” to “Custom”, click “Browse” and point it to this path <arduino_base_path>\hardware\tools\avr\bin which is the path to the AVRDude executable (used to deploy the binary on the Arduino board) inside the arduino SDK directory. I pointed mine toD:\arduino\hardware\tools\avr\bin.

Now the AVR plugin knows where to find the toolchain to build and deply code for the Arduino board.
Click “Apply” and then “OK”

Create the ArduinoCore library

The ArduinoCore library will contain all the basic functionalities to deal with the Arduino board, this library can be seen as the standard c library equivalent for Arduino. If you write some code for Arduino in the Arduino IDE, this library is silently linked to your code, but if you plan to use Eclipse you have to manually link the library to each of our projects before deploying them on the Arduino board.
Here are the steps to create the ArduinoCore library (which is just the name I gave it):

From Eclipse go to “New” then “C++ Project” then “AVR Cross Target Static Library” and select “Empty Project”.

Set the “Project Name:” to “ArduinoCore” and click “Next”.
This library will contain code distributed with the Arduino SDK which is considered to be stable, so deselect the“Debug” configuration and click “Next”.
Set the “MCU Type” and “MCU Frequency”, this depends on the specific board, my Arduino Duemilanove is equipped with an ATmega328P chip clocked at 16MHz (16000000 Hz). If you are not sure which values to use here, go to the arduino website in the “Hardware” section and click on your specific board to see the tech specs, here’s the link.
Once done hit “Finish”.

Now you have an empty library project, what we are going to do now is import the Arduino core files from the Arduino SDK folder.

In Eclipse right click on the “ArduinoCore” project, select “Properties” and then “C/C++ Build”.
Open the “AVR Compiler” section and select “Directories”.
Add the include path to the arduino core header files in the Arduino SDK, they are located inside“<arduino_base_path>\hardware\arduino\cores\arduino”
Add the include path to the pins_arduino.h header file, this again depends on the specific board you are working with.
Many version of the pins_arduino.h header file can be found, they are located inside specific folders under“<arduino_base_path>\hardware\arduino\variants\”:

  • <arduino_base_path>\hardware\arduino\variants\standard: I used this one for my Arduino Duemilanove
  • <arduino_base_path>\hardware\arduino\variants\mega: I guess you should use this one if you are working on an Arduino Mega board
  • <arduino_base_path>\hardware\arduino\variants\leonardo: maybe to be used with the new Arduino Leonardo board
  • <arduino_base_path>\hardware\arduino\variants\micro: absolutely dunno

Do the same for the “AVR C++ Compiler” section, then click “OK”.

From Eclipse right click on the “ArduinoCore” project, select “Import” and then “File System”. Point the file browser to the arduino core files directory inside the Arduino SDK which are located in“<arduino_base_path>\hardware\arduino\cores\arduino”.

Select all the files except main.cpp.

Click on “Advanced” and select “Create links in workspace” so the files are not copied into the library but only weak-referenced. It’s better to only reference these files so if you download a newer version of the Arduino SDK you can simply overwrite the existing one and the ArduinoCore library is automatically updated.
Click “Finish”.

If everything went well you should now be able to build the ArduinoCore library, right click on the “ArduinoCore”project and do a “Build Project”.

Create a test project

Let’s now create a test project to check that everything’s fine.
Remember that these steps must be done with every new project that you create.

In Eclipse go to “New” then “C++ Project” and then “AVR Cross Target Application” and select “Empty Project”.
Set the “Project Name:” to “TestProject” and click “Next”.
Deselect the “Debug” configuration and click “Next”.
Set the “MCU Type” and “MCU Frequency” to the same values you set in the ArduinoCore library project and hit “Finish”.

Right click on the “ArduinoCore” project, go to “Properties” and then “C/C++ Build” and in both “AVR Compiler” and “AVR C++ Compiler” add the same include paths that were added in the ArduinoCore library project plus the include path for the test project itself which is not added by default and can be added with this magic string: “${workspace_loc:/${ProjName}}” which simply expands to your workspace directory followed by the test project directory.

From the “C/C++ Build” section in the “Properties” window go to “AVR C++ Linker”.
Set the command line pattern to:

${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}

Now click on the “Libraries” subsection.

In the “Libraries path” box add the path to the ArduinoCore library by clicking on the “Add” button on the top right corner of the box, then select “Workspace” and point it to the “Release” folder inside the ArduinoCore project. You can also directly insert this magic string: “${workspace_loc:/ArduinoCore/Release}” which is the same thing.

In the “Libraries” box add the ArduinoCore library by clicking on the “Add” button on the top right corner of the box and simply type “ArduinoCore”, this instructs the linker to link against “libArduinoCore.a” when linking the final executable.

In the project properties window, click on “Project references” in the left menu and check “ArduinoCore”, so the library will be automatically built (and re-built if needed) when building the test project.

In the test project create a new main.cpp file and paste the following code into it.
This is the classic Blink code sample that blinks the led linked on pin 13 of the Arduino board once every second:

 
#include <Arduino.h>
 
int ledPin =  13;    // LED connected to digital pin 13
 
// The setup() method runs once, when the sketch starts
void setup()   {
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);
}
 
// the loop() method runs over and over again,
// as long as the Arduino has power
 
void loop()
{
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
}
 
 
int main(void) {
 
  init();
  setup();
 
  while(true) {
    loop();
  }
}

You’ll notice that there are some difference between this code and the usual code that you write for Arduino, the next post will focus on these differences, for now just take it as it comes. No questions. Or this post will never end.

Deploy on the Arduino board

After compiling and linking the binary a tool named AVRDude will deploy it on the Arduino board.
AVRDude must be configured to work with Arduino.
What we are going to do now is stealing the AVRDude configuration from the Arduino SDK.

From Eclipse go to “Window” then “Preferences” and select the “AVR” section on the left, then select“AVRDude”.
Check “Use custom configuration file for AVRDude” and set “AVRDude config file” to the one provided with the Arduino SDK: it can be found under <arduino_base_path>\hardware\tools\avr\etc\avrdude.conf.
Click “Apply” and then “OK”.

From Eclipse select the test project and open the project properties once more (right click->“Properties”).
Select the “AVR” section and the click on “AVRDude”
You now have to create a new programmer configuration for your board, this must be done only once.
Click “New”, in the window that appears insert these data:

  • “Configuration Name” : “Arduino”
  • “Programmer Hardware” : “Arduino”
  • “Override default baudrate” : 57600

And set “Override default port” to the COM port that you use to work with the Arduino board. If you do not know what this value is, plug your Arduino board in and start the Default IDE, the COM port is showed at the bottom of the IDE window, my Arduino IDE says:

Arduino Duemilanove w/ ATMega328 on COM10

My COM port is COM10 so my “Override default port” field is set to:

//./COM10

Don’t ask me what the “//./” prefix means, I don’t know.
Click “OK”

Back in the “AVRDude” window select the “Advanced” tab.
Check “Disable Device signature check” and click “OK”.

加一点:要选择avr-gcc编译,默认的上avr-g++,properties->C/C++ build->settings->AVR C++ Linker中的command改为avr-gcc

First deploy

It’s time. Plug your Arduino board in.

Select the test project and build it, then right click on it and select “AVR” and then “Upload project to target device”, the deploy will start and if everything’s fine you should have your program running on the Arduino board after a few seconds. Look at the led at PIN 13 and it should be blinking. Mine blinks.
That’s all, hope this guide is useful.
Again, let me know any problem you had so I can update the tutorial with your info.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Eclipse 来编译Arduino程序,并烧写Arduino程序 的相关文章

  • 批处理文件:从串口接收数据并将其写入txt文件

    我正在尝试通过 USB 串行端口从 Arduino 提取一些数据并将其写入 txt 文件 因此 我使用批处理文件 Windows 7 普通cmd 它发送例如 d 从 Arduino 请求所需的数据 收到 d 后 Arduino 开始向 PC
  • 读取串行端口 - 忽略在一定时间内写入串行端口的部分数据

    我想定期读取串行端口上的数据和Arduino 所以本质上是这样的 读一读 Wait 读一读 Wait Take etc 我面临的问题是端口将缓冲其信息 因此一旦我调用等待函数 串行端口上的数据就会开始缓冲 等待函数完成后 我尝试再次读取数据
  • 如何将值从 Arduino 发送到 Python,然后使用该值

    我正在构建一个使用 Python 进行远程控制的机器人 通过简单的 GUI 通过互联网发送控制消息 我的部分代码 GUI 和控制系统 运行得很好 但我陷入了困境 我正在尝试使用视差平传感器来获取与物体的距离信息Arduino Mega ht
  • Java RXTX 库不加载本机库

    基本上我想使用 Arduino 编写一个简单的通信工具java 的 RXTX 库 http rxtx qbang org wiki index php Main Page并且在加载动态库时严重失败 我的系统规格 操作系统 OS X 优胜美地
  • ESP32 Arduino-ide如何获取唯一id

    我试图自动为每个 esp32 设置一个唯一的 id 在我使用提供该方法的 ESP IDF 框架对设备进行编程之前esp efuse mac get default 这将返回一个 8 字节值 该值在我手上的所有设备上都是唯一的 在arduin
  • C++:将成员函数作为普通函数指针传递的闭包

    我正在尝试调用外部库的成员函数 该函数接受函数指针作为参数 Timer every unsigned long period void callback void 但不幸的是我想传递的参数是一个成员函数 void MyClass the m
  • Arduino - 高效地迭代 C 数组

    我有以下数组 PROGMEM prog uint16 t show hide info 4216 8900 4380 580 500 600 500 580 1620 580 500 600 500 580 500 600 480 600
  • 为什么使用 libnfc 和 PN532 SHIELD 时“找不到 NFC 设备”

    我在 ArchLinux 上安装了 libnfc 并通过我的 Adafruit PN532 arduino SHIELD 使用它 nfc list返回消息 未找到 NFC 设备 我在 etc nfc devices d pn532 conf
  • 将浮点数转换为字节数组的 C 函数

    我正在尝试创建一个函数来接受浮点变量并将其转换为字节数组 我找到了一段有效的代码片段 但如果可能的话 希望在函数中重用它 我也在使用 Arduino 环境 但我知道它接受大多数 C 语言 目前工作 float variable 1 11 b
  • 使用 Java 控制 Arduino

    我正在寻找一个LED http en wikipedia org wiki Light emitting diode用Java程序打开和关闭 我用 C 完成了这个项目大约 5 分钟 但用 Java 似乎更具挑战性 我让 Arduino 等待
  • SIM900 GSM/GPRS 未获得正确的 AT+CREG?回答

    我使用的是带有 IComsat SIM900 GSM GPRS 扩展板的 Arduino UNO 使用以下教程 Arduino 实时 GPS 追踪器 http www samaria me uk 2011 12 arduino live g
  • 使用 Ardulink 命令 Arduino Uno

    我试图在我的 JAVA 应用程序中使用 Ardulink 库来命令我的 Arduino Uno 但没有成功 我不知道我错过了什么 这是我的代码 Link link Link getDefaultInstance boolean connec
  • 如何提高 PySerial 读取速度

    我目前正在构建一台使用 Arduino Mega2560 作为主控制器的机器 Arduino 通过串口连接 获取命令 执行它并每 1ms 吐出一堆测量数据 我有一个运行 Python 的 Raspberry Pi 为用户提供一个漂亮的 GU
  • Arduino C++ 析构函数?

    我知道在Arduino中你不能使用delete 那么什么时候调用 C 类中定义的析构函数呢 同样 如果我想创建一个指向数组的指针 我必须使用malloc and free 当对象被销毁时 析构函数被调用 对于自动 堆栈上 变量 它在离开其作
  • 在链接时合并全局数组/从多个编译单元填充全局数组

    我想定义一系列的东西 比如事件处理程序 的内容 该数组在编译时是完全已知的 但定义在 多个编译单元 分布在多个库中 至少在最终 静态 链接之前是相当解耦的 我想要 也保持这种方式 因此添加或删除编译单元将 还可以自动管理事件处理程序 而无需
  • Python串口通信

    我正在开发一个 Arduino 项目 由于内存限制 我将其与 Python 脚本连接起来 在Python方面 我有一个二维矩阵 其中包含各自的x y坐标值 并且在此列表中有26000个坐标对 因此 为了向大家澄清数据结构 pathlist
  • 仅从日期计算夏令时

    我正在使用 Arduino 和实时时钟芯片 该芯片补偿了闰年等 因此它始终具有正确的日期 但我认为由于区域复杂性 它不处理夏令时 时钟可以给出日 月 年 从 1 开始 以及星期几 星期日 0 到星期六 6 因为我需要与用户输入的日期和时间进
  • 如何将 Android 应用程序正确连接到支持蓝牙的 Arduino 微控制器上的 RFCOMM 套接字?

    我正在与我大学的一些学生合作开发一个简单的蓝牙 Android 应用程序 该应用程序将用于与连接有蓝牙模块的 Arduino 微控制器进行串行通信 RFCOMM 据我所知 我正在使用正确的蓝牙地址和 UUIDRFCOMM SPP 00001
  • 是否值得为 EEPROM 实现小型文件系统

    我买了一个I2C EEPROM 我想存储传感器和电压数据 我假设该值可以大于一个字节 并且可以有很多数据 在这种情况下是否值得实现具有小文件分配表的文件系统 例如 这会让我更容易查看 EEPROM 我发现 EEPROM 上出现 FAT 有两
  • Arduino 引导加载程序

    有人可以解释一下如何Arduino引导加载程序 http code google com p arduino source browse tags 0019 hardware arduino bootloaders atmega ATmeg

随机推荐