質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
YouTube

YouTubeとはユーザーがビデオをアップロード・共有・閲覧できるビデオ共有ウェブサイトです。

コンパイルエラー

コンパイルのフェーズで生成されるエラーです。よく無効なシンタックスやタイプが含まれているとき発生します。

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

Q&A

解決済

2回答

2986閲覧

Arduinoのコンパイルエラーを解決したい

kaiararu

総合スコア1

YouTube

YouTubeとはユーザーがビデオをアップロード・共有・閲覧できるビデオ共有ウェブサイトです。

コンパイルエラー

コンパイルのフェーズで生成されるエラーです。よく無効なシンタックスやタイプが含まれているとき発生します。

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

0グッド

0クリップ

投稿2021/06/29 10:04

前提・実現したいこと

海外の方がyoutubeにて公開してくださっている資料をもとに、
いくつかのサーボモーターを使用し、動かそうとしています。
参照元: https://youtu.be/Ftt9e8xnKE4

ArduinoIDEにてコンパイルした際に以下のエラーメッセージが発生しました。
(一部個人情報を※にて隠しています)

どこをどう変更すればコンパイルが通るでしょうか?

発生している問題・エラーメッセージ

eye:12:26: error: expected unqualified-id before ')' token Adafruit_PWMServoDriver (); ^ C:\Users\※※※\Documents\Arduino\eye\eye\eye.ino: In function 'void setup()': eye:47:7: error: request for member 'begin' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.begin(); ^~~~~ eye:49:7: error: request for member 'setPWMFreq' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates ^~~~~~~~~~ C:\Users\※※※\Documents\Arduino\eye\eye\eye.ino: In function 'void loop()': eye:96:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(0, 0, lexpulse); ^~~~~~ eye:97:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(1, 0, leypulse); ^~~~~~ eye:101:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(2, 0, 400); ^~~~~~ eye:102:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(3, 0, 240); ^~~~~~ eye:103:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(4, 0, 240); ^~~~~~ eye:104:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(5, 0, 400); ^~~~~~ eye:107:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(2, 0, uplidpulse); ^~~~~~ eye:108:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(3, 0, lolidpulse); ^~~~~~ eye:109:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(4, 0, altuplidpulse); ^~~~~~ eye:110:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(5, 0, altlolidpulse); ^~~~~~ exit status 1 expected unqualified-id before ')' token

該当のソースコード

#include <Wire.h> #include <Adafruit_PWMServoDriver.h> Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); #define SERVOMIN 140 // this is the 'minimum' pulse length count (out of 4096) #define SERVOMAX 520 // this is the 'maximum' pulse length count (out of 4096) // our servo # counter uint8_t servonum = 0; int xval; int yval; int lexpulse; int rexpulse; int leypulse; int reypulse; int uplidpulse; int lolidpulse; int altuplidpulse; int altlolidpulse; int trimval; const int analogInPin = A0; int sensorValue = 0; int outputValue = 0; int switchval = 0; void setup() { Serial.begin(9600); Serial.println("8 channel Servo test!"); pinMode(analogInPin, INPUT); pinMode(2, INPUT); pwm.begin(); pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates delay(10); } // you can use this function if you'd like to set the pulse length in seconds // e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise! void setServoPulse(uint8_t n, double pulse) { double pulselength; pulselength = 1000000; // 1,000,000 us per second pulselength /= 60; // 60 Hz Serial.print(pulselength); Serial.println(" us per period"); pulselength /= 4096; // 12 bits of resolution Serial.print(pulselength); Serial.println(" us per bit"); pulse *= 1000000; // convert to us pulse /= pulselength; Serial.println(pulse); } void loop() { xval = analogRead(A1); lexpulse = map(xval, 0,1023, 220, 440); rexpulse = lexpulse; switchval = digitalRead(2); yval = analogRead(A0); leypulse = map(yval, 0,1023, 250, 500); reypulse = map(yval, 0,1023, 400, 280); trimval = analogRead(A2); trimval=map(trimval, 320, 580, -40, 40); uplidpulse = map(yval, 0, 1023, 400, 280); uplidpulse -= (trimval-40); uplidpulse = constrain(uplidpulse, 280, 400); altuplidpulse = 680-uplidpulse; lolidpulse = map(yval, 0, 1023, 410, 280); lolidpulse += (trimval/2); lolidpulse = constrain(lolidpulse, 280, 400); altlolidpulse = 680-lolidpulse; pwm.setPWM(0, 0, lexpulse); pwm.setPWM(1, 0, leypulse); if (switchval == HIGH) { pwm.setPWM(2, 0, 400); pwm.setPWM(3, 0, 240); pwm.setPWM(4, 0, 240); pwm.setPWM(5, 0, 400); } else if (switchval == LOW) { pwm.setPWM(2, 0, uplidpulse); pwm.setPWM(3, 0, lolidpulse); pwm.setPWM(4, 0, altuplidpulse); pwm.setPWM(5, 0, altlolidpulse); } Serial.println(trimval); delay(5); }

試したこと

ネット上で検索や翻訳をしてみましたが、お手上げ状態となります。

補足情報

ArduinoIDE 1.8.14を使用。
書き込み先は Miuzei Board Model R3 です。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

問題無くコンパイル出来るようだけど。

ライブラリは入れた?
https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library

投稿2021/06/29 17:13

nac_tnk

総合スコア463

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kaiararu

2021/06/30 11:11

こんばんは、回答誠に有難う御座います! ライブラリマネージャーを確認しましたが、 Adafruit PWM Servo Driver Libraryのバージョン2.4.0はinstalledとなっていました…
nac_tnk

2021/06/30 12:32

それはおかしいね。 そのスケッチをそのままコピペして、同じ2.4.0のライブラリバージョンでコンパイル出来たよ。 「Miuzei Board Model R3」っていうのは単にUNO互換機だよね? フォルダが C:\Users\※※※\Documents\Arduino\eye\eye\eye.ino と2重になっているのがちょっと気になるかな。
kaiararu

2021/06/30 13:40

お返事有難う御座います! こちらUNO互換機で間違いありません。 フォルダを確認してみたところ、以下のような内容のinoファイルも同梱されておりました。 こちらが何か悪さを働いていますでしょうか? /*! * @file Adafruit_PWMServoDriver.h * * This is a library for our Adafruit 16-channel PWM & Servo driver. * * Designed specifically to work with the Adafruit 16-channel PWM & Servo * driver. * * Pick one up today in the adafruit shop! * ------> https://www.adafruit.com/product/815 * * These driver use I2C to communicate, 2 pins are required to interface. * For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4. * * Adafruit invests time and resources providing this open source code, * please support Adafruit andopen-source hardware by purchasing products * from Adafruit! * * Limor Fried/Ladyada (Adafruit Industries). * * BSD license, all text above must be included in any redistribution */ #ifndef _ADAFRUIT_PWMServoDriver_H #define _ADAFRUIT_PWMServoDriver_H #include <Arduino.h> #include <Wire.h> // REGISTER ADDRESSES #define PCA9685_MODE1 0x00 /**< Mode Register 1 */ #define PCA9685_MODE2 0x01 /**< Mode Register 2 */ #define PCA9685_SUBADR1 0x02 /**< I2C-bus subaddress 1 */ #define PCA9685_SUBADR2 0x03 /**< I2C-bus subaddress 2 */ #define PCA9685_SUBADR3 0x04 /**< I2C-bus subaddress 3 */ #define PCA9685_ALLCALLADR 0x05 /**< LED All Call I2C-bus address */ #define PCA9685_LED0_ON_L 0x06 /**< LED0 on tick, low byte*/ #define PCA9685_LED0_ON_H 0x07 /**< LED0 on tick, high byte*/ #define PCA9685_LED0_OFF_L 0x08 /**< LED0 off tick, low byte */ #define PCA9685_LED0_OFF_H 0x09 /**< LED0 off tick, high byte */ // etc all 16: LED15_OFF_H 0x45 #define PCA9685_ALLLED_ON_L 0xFA /**< load all the LEDn_ON registers, low */ #define PCA9685_ALLLED_ON_H 0xFB /**< load all the LEDn_ON registers, high */ #define PCA9685_ALLLED_OFF_L 0xFC /**< load all the LEDn_OFF registers, low */ #define PCA9685_ALLLED_OFF_H 0xFD /**< load all the LEDn_OFF registers,high */ #define PCA9685_PRESCALE 0xFE /**< Prescaler for PWM output frequency */ #define PCA9685_TESTMODE 0xFF /**< defines the test mode to be entered */ // MODE1 bits #define MODE1_ALLCAL 0x01 /**< respond to LED All Call I2C-bus address */ #define MODE1_SUB3 0x02 /**< respond to I2C-bus subaddress 3 */ #define MODE1_SUB2 0x04 /**< respond to I2C-bus subaddress 2 */ #define MODE1_SUB1 0x08 /**< respond to I2C-bus subaddress 1 */ #define MODE1_SLEEP 0x10 /**< Low power mode. Oscillator off */ #define MODE1_AI 0x20 /**< Auto-Increment enabled */ #define MODE1_EXTCLK 0x40 /**< Use EXTCLK pin clock */ #define MODE1_RESTART 0x80 /**< Restart enabled */ // MODE2 bits #define MODE2_OUTNE_0 0x01 /**< Active LOW output enable input */ #define MODE2_OUTNE_1 \ 0x02 /**< Active LOW output enable input - high impedience */ #define MODE2_OUTDRV 0x04 /**< totem pole structure vs open-drain */ #define MODE2_OCH 0x08 /**< Outputs change on ACK vs STOP */ #define MODE2_INVRT 0x10 /**< Output logic state inverted */ #define PCA9685_I2C_ADDRESS 0x40 /**< Default PCA9685 I2C Slave Address */ #define FREQUENCY_OSCILLATOR 25000000 /**< Int. osc. frequency in datasheet */ #define PCA9685_PRESCALE_MIN 3 /**< minimum prescale value */ #define PCA9685_PRESCALE_MAX 255 /**< maximum prescale value */ /*! * @brief Class that stores state and functions for interacting with PCA9685 * PWM chip */ class Adafruit_PWMServoDriver { public: Adafruit_PWMServoDriver(); Adafruit_PWMServoDriver(const uint8_t addr); Adafruit_PWMServoDriver(const uint8_t addr, TwoWire &i2c); void begin(uint8_t prescale = 0); void reset(); void sleep(); void wakeup(); void setExtClk(uint8_t prescale); void setPWMFreq(float freq); void setOutputMode(bool totempole); uint8_t getPWM(uint8_t num); void setPWM(uint8_t num, uint16_t on, uint16_t off); void setPin(uint8_t num, uint16_t val, bool invert = false); uint8_t readPrescale(void); void writeMicroseconds(uint8_t num, uint16_t Microseconds); void setOscillatorFrequency(uint32_t freq); uint32_t getOscillatorFrequency(void); private: uint8_t _i2caddr; TwoWire *_i2c; uint32_t _oscillator_freq; uint8_t read8(uint8_t addr); void write8(uint8_t addr, uint8_t d); }; #endif
nac_tnk

2021/06/30 14:58

Adafruit_PWMServoDriver.h と書いてありますから、ライブラリのヘッダファイルを持ってきて、何らかの修正をしたのかもしれません。 それがエラーの原因の可能性が高いでしょうけど、単に削除して良いものかどうか?は判断付きません。
kaiararu

2021/06/30 15:33

ご確認有難う御座います! 一度このinoファイルを無くして(別端末に移動させて)から、本来扱いたいファイルをコンパイルしようとしましたが、最初と同様のエラー文が表示されてしまいました。 やはりライブラリがうまく入れられていないのでしょうか… やり方は「スケッチ」→「ライブラリをインクルード」→「.zip形式のライブラリをインストール」→「GitHubよりダウンロードした.zipファイルを選択」で間違いありませんか?
nac_tnk

2021/06/30 18:11

入れたのはかなり昔なので覚えていませんけど、2つ入っていたので、ZIPとライブラリマネージャの2通りで入れたのかも。因みにバージョンは2.3.?でも試しましたけど問題無かったです。 ※warningは出ますけど、使われていない引数がある、という問題ないものです。 ※多分、私と同じように、新規作成で、提示した上記のスケッチのみをコピペしてコンパイルすれば出来るのでは?と推測しますけど。
guest

0

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

実行文は関数の中に書く必要があります
ここは変数定義だけにしといて、Setup関数の中ででも代入文を書いておけばいいのでは

投稿2021/06/29 10:12

y_waiwai

総合スコア87774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kaiararu

2021/06/30 11:20

こんばんは、回答誠に有難う御座います! この行 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); を Setup関数の中に移動させるにあたり、代わりにここに書くべき変数定義はどのようなものになるでしょうか? 当方プログラミング初心者のため、詳しくご教示いただけますと幸いです…
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問