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

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

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

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

Q&A

解決済

2回答

2067閲覧

setup が何度も実行されてloopにいかない

johnny-five

総合スコア12

Arduino

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

0グッド

0クリップ

投稿2018/05/10 12:01

SDカードとサーボを同時に使用したいのですがsetupが何度も実行されてloopまでいってないようです。
エラーは出てないけどサーボが震えた状態になります。
サーボ単体、SDカード単体のスケッチでは動作OKでした。
下記loop部分を省いたスケッチになります。
原因と解決方法がお分かりの方よろしくお願いします。

arduino

1 2#include <Wire.h> 3#include <Adafruit_PWMServoDriver.h> 4 5#include <SPI.h> 6#include <SD.h> 7 8 9Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); 10#define ServoCount 12 11#define FrameCount 8 12#define MotionCount 6 13 14int motion0[ServoCount] = {4, -60, -66, 0, 15, -4, 0, -60, -70, -22, 30, 55}; 15 16 17bool IsMove = false; 18int currentMotion = 0; 19 20File myFile; 21 22void setup() 23{ 24 25 26 // Open serial communications and wait for port to open: 27 28 29 Serial.begin(9600); 30while (!Serial) { 31 ; // wait for serial port to connect. Needed for native USB port only 32 } 33Serial.print("Initializing SD card..."); 34 35 if (!SD.begin(4)) { 36 Serial.println("initialization failed!"); 37 return; 38 } 39 Serial.println("initialization done."); 40 41 // open the file. note that only one file can be open at a time, 42 // so you have to close this one before opening another. 43 myFile = SD.open("test.txt", FILE_WRITE); 44 45 // if the file opened okay, write to it: 46 if (myFile) { 47 Serial.print("Writing to test.txt..."); 48 myFile.println("testing 1, 2, 3."); 49 // close the file: 50 myFile.close(); 51 Serial.println("done."); 52 } else { 53 // if the file didn't open, print an error: 54 Serial.println("error opening test.txt"); 55 } 56 57 // re-open the file for reading: 58 myFile = SD.open("test.txt"); 59 if (myFile) { 60 Serial.println("test.txt:"); 61 62 // read from the file until there's nothing else in it: 63 while (myFile.available()) { 64 Serial.write(myFile.read()); 65 } 66 // close the file: 67 myFile.close(); 68 } else { 69 // if the file didn't open, print an error: 70 Serial.println("error opening test.txt"); 71 } 72 73 74 pwm.begin(); 75 pwm.setPWMFreq(60); 76 for (int i = 0; i < 16; i++) { 77 myservo(i, 0); 78 } 79 80 81 //delay(1000); 82} 83

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

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

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

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

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

guest

回答2

0

C

1while (!Serial) { 2 ; // wait for serial port to connect. Needed for native USB port only 3 }

これなにしてる?

投稿2018/05/10 12:37

y_waiwai

総合スコア87774

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

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

johnny-five

2018/05/22 11:45

スケッチ例のSD card read/writeのものです。 シリアル接続を待機してるような?
johnny-five

2018/05/22 11:48

loop内に記述してたSDカードからテキスト読んでCSVパースして配列に入れるという処理が動いてなかったようです。 CSVの要素数を少なくしたら動いたのでメモリの問題かなと思ってます。
guest

0

自己解決

loop内容削除したら動いたのでloopに問題があったのかも・・

投稿2018/05/10 12:10

johnny-five

総合スコア12

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問