Установка Arduino IDE
Для установки Arduino IDE качаем архив с IDE, устанавливаем дополнение для компилятора gcc и java для запуска Arduino IDE. Список всех версий Arduino IDE на google code. На момент написания статьи максимальная версия 1.0.5
Ubuntu i386 (32 разрядная):
$ sudo apt-get install gcc-avr avr-libc openjdk-6-jre
$ wget https://arduino.googlecode.com/files/arduino-1.0.5-linux32.tgz
$ tar -xzvf arduino-1.0.5-linux32.tgz
$ cd arduino-1.0.5/
$ ./arduino
Ubuntu amd64 (64 разрядная):
$ sudo apt-get install gcc-avr avr-libc openjdk-6-jre
$ wget https://arduino.googlecode.com/files/arduino-1.0.5-linux64.tgz
$ tar -xzvf arduino-1.0.5-linux64.tgz
$ cd arduino-1.0.5/
$ ./arduino
Не активен пункт "Сервис - Последовательный порт"
В Arduino IDE (в Ubuntu 12.04) при подключенной Arduino не активен пункт главного меню Сервис - Последовательный порт (Tools - Serial Port). Чтобы его активировать не выгружая IDE нужно определить на каком последовательном порту находится Arduino и добавить права всем на чтение и запись в этот порт.
Определяем на каком порту Arduino:
$ dmesg
В выводе команды находим похожие строки:
...
[3183.646743] usb 3-2: new full-speed USB device number 5 using uhci_hcd
[3389.146517] cdc_acm 3-2:1.0: ttyACM0: USB ACM device
...
Понятно, что Arduino находится на порту ttyACM0. Изменим режим доступа этого порта:
$ sudo chmod a+rw /dev/ttyACM0
После запуска Arduino IDE пункт главного меню Сервис - Последовательный порт становится активным.
Ошибка компилирования программы
Print.cpp: In member function ‘size_t Print::print(const __FlashStringHelper*)
Эта ошибка связана с устаревшим определением типа в avr-libc v1.8.0.
/**
\ingroup avr_pgmspace
\typedef prog_char
\note DEPRECATED
This typedef is now deprecated because the usage of the __progmem__
attribute on a type is not supported in GCC. However, the use of the
__progmem__ attribute on a variable declaration is supported, and this is
now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__
has been defined before including <avr/pgmspace.h> (either by a
#define directive, or by a -D compiler option.)
Type of a "char" object located in flash ROM.
*/
typedef char PROGMEM prog_char;
Ошибка возникает в Arduino IDE 1.0 в Ubuntu 12.04. Есть два варианта решения проблемы (одно или второе):
- заменить тип данных в файле Print.cpp с "prog_char" на "char PROGMEM" в методе print(const _FlashStringHelper*) Важно! Это объявление переменной работает в версии Andorid IDE V1.0 и avr-libc v1.7.1 в Print.cpp
- определить константу для компилятора __PROG_TYPES_COMPAT__ перед импортом pgmspace.h в файле Arduino.h
Изменям Print.cpp
$ cd arduino 1.0
$ nano +57 hardware/arduino/cores/arduino/Print.cpp
Находим метод, комментируем его
size_t Print::print(const __FlashStringHelper *ifsh)
{
const prog_char *p = (const prog_char *)ifsh;
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
if (c == 0) break;
n += write(c);
}
return n;
}
Пишем другой метод:
// New code
size_t Print::print(const __FlashStringHelper *ifsh)
{
const char PROGMEM *p = (const char PROGMEM *)ifsh;
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
if (c == 0) break;
n += write(c);
}
return n;
}
/* Old code
size_t Print::print(const __FlashStringHelper *ifsh)
{
const prog_char *p = (const prog_char *)ifsh;
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
if (c == 0) break;
n += write(c);
}
return n;
}/**/
Сохраняем.
Изменяем Arduino.h
$ cd arduino 1.0
$ nano +8 hardware/arduino/cores/arduino/Arduino.h
#ifndef Arduino_h
#define Arduino_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
...
Перед #include <avr/pgmspace.h> пишем #define __PROG_TYPES_COMPAT__
#ifndef Arduino_h
#define Arduino_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define __PROG_TYPES_COMPAT__
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
Сохраняем.