如何使用 C++ 对 Arduino 进行编程 [英] How to program an Arduino with C++

查看:163
本文介绍了如何使用 C++ 对 Arduino 进行编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在玩我的 Arduino,我想知道是否有某种方法可以用 C++ 对 Arduino 进行编程.我一直在使用 Vim 中的 C++/Processing 语言对其进行编程,并使用makefile 编译并上传到 Arduino.

So lately I've been playing around with my Arduino and I was wondering if there was some way I could program the Arduino in C++. I've been programming it using the C++/Processing language in Vim and using a makefile to compile and upload to the Arduino.

但我的目标是能够使用类和所有出色的 C++ 特性(或至少是 sum)来对其进行编程.最终,我什至很想用原始 C 语言对其进行编程,但我也很难找到如何去做.如果有人能指出我正确的方向或帮助我,那就太好了.

But my goal is to be able to use classes and all the great C++ features (or at least sum) to program it. Eventually I would even love to program it in raw C and I'm just having troubles finding out how to do either. It would be great if someone could point me in the right direction or help me out.

推荐答案

这是我的经验:我正在使用 Arduino、传感器、电机、LED 和蓝牙为自闭症儿童构建机器人智能玩具.我使用 C++ 编写了自己的库来完成我需要的工作.但是我发现 Arduino IDE Compiler 是一个旧版本,不支持新的 C++11 特性.

Here is my experience: I'm building a robotic smart toy for autistic children using Arduino, sensors, motors, led and bluetooth. I wrote my own libraries to do exactly what I needed using C++. But I found out that the Arduino IDE Compiler is an older version that does not support the new C++11 features.

所以我必须找到一种方法来编译 C++11 代码并将其上传到我的 Arduino.结果证明它是非常"基本的:我需要一个 Makefile、avr-gcc 4.8 工具链和瞧!makefile 工作由 Sudar 完成(https://github.com/sudar/Arduino-Makefile)而且效果很好.不过,我必须对其进行一些自定义才能使其适用于我的项目.

So I had to find myself a way to compile C++11 code and upload it to my Arduino. It turns out to be "pretty" basic: I needed a Makefile, the avr-gcc 4.8 toolchain and voilà! The makefile job is done by Sudar (https://github.com/sudar/Arduino-Makefile) and it works great. I had to customise it a bit to make it work for my project though.

这是我为我的项目编写的一些文档.你应该看看,它可能对你有用.https://github.com/WeAreLeka/moti/blob/master/INSTALL.md

Here is some documentation I've written for my project. You should take a look, it might be useful for you. https://github.com/WeAreLeka/moti/blob/master/INSTALL.md

希望有帮助!干杯:)

编辑 2014 年 8 月 16 日:

因为我从朋友和其他开发人员那里收到了很多与此类似的请求,所以我决定建立某种框架来快速轻松地启动和运行您的 Arduino 项目.

Because I got a lot a requests similar to this one from friends and other devs, I decided to set up some kind of framework to get up and running with your Arduino projects quickly and easily.

这是裸Arduino项目

希望对大家有帮助!如果您发现错误或我可以改进的东西,请随时填写和发布.:)

Hope it could be of any help! If you find bugs or stuff that I could make better, feel free to fill and issue. :)

这篇关于如何使用 C++ 对 Arduino 进行编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆