バージョン情報
Arduino IDE 1.0.6 ,windows 8.1
ArduinoのI2Cスレーブ第三弾。音声合成LSIを使ってみた。
音声合成LSI:ATP3011をArduinoとI2C接続しスレーブとして動くようにしてみた。マスター側のArduinoはPCと接続し、シリアル通信で受信した文字列をそのままI2C側に転送するようにしてみた。こうすることでPCから直接、音声合成LSIにしゃべらせることができる。
材料
Arduino
音声合成LSI:ATP3011
圧電スピーカ:SPT15
回路
ソースコード
マスター側
#include <Wire.h>
char charA_out[80];
byte len_out = 0;
void setup() {
Serial.begin(38400);
Wire.begin();
}
void loop() {
//シリアルを受信
len_out = myReadLine(charA_out);
if(len_out > 0){
myTalk_send(len_out);
}
}
//音声合成IC:送信
void myTalk_send(byte len_out){
char *p_out;
char arr_out[len_out + 1];
for(int i = 0; i <= len_out; i++){
arr_out[i] = charA_out[i];
}
arr_out[len_out] = '\r';
p_out = arr_out;
Wire.beginTransmission(0x2E);
Serial.write(p_out);
Wire.write(p_out);
Wire.endTransmission();
}
//シリアル受信
byte myReadLine(char charA[]){
byte cnt_buf = 0;
//受信したら
if(Serial.available() > 0){
delay(100);
cnt_buf = min(79,Serial.available()); //受信文字数 最大79文字
for (int iii = 0; iii < cnt_buf; iii++){
charA[iii] = Serial.read();
}
charA[cnt_buf] = '\0'; //終端文字
}
return cnt_buf;
}
動作確認
Arduino IDE のシリアルモニタで 『konnichiwa』と送信すると、、、しゃべった!!
(音が小さいのでアンプ回路があった方がよさそう。)





