###前提・実現したいこと
Arduinoで、水温などの情報を得るプログラムを作っていますが、マイコンボードに書き込む際にエラーが出てしまいます
###発生している問題・エラーメッセージ
エラーメッセージ
timeout communicating with programmer
###該当のソースコード
言語 Arduino
#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>
#include <Wire.h>
#define I2C_addr 0x5C
#define ACK 0x00
#define NACK 0x01
byte I2cbuff[ 8 ];
const byte LPS25H_ADDR = B1011101; // SA0 = GND
int RTC8564_ADDRESS=0x51;
int a=0;
byte command;
int i;
long hex_pre;
long hex_aft;
byte trash;
long water[2];
long address[5];
const byte LPS25H_WHOAMI = 0x0f;
const byte LPS25H_CTRL1 = 0x20;
const byte LPS25H_CTRL2 = 0x21;
const byte LPS25H_CTRL3 = 0x22;
const byte LPS25H_P_LL = 0x28;
const byte LPS25H_P_L = 0x29;
const byte LPS25H_P_H = 0x2A;
const byte LPS25H_T_L = 0x2B;
const byte LPS25H_T_H = 0x2C;
void setup()
{
Serial.begin(9600);
acc.powerOn();
Wire.begin();
Wire.begin();
Wire.beginTransmission(RTC8564_ADDRESS);//時間取得
Wire.write(0x00);
Wire.write(0x00);
Wire.endTransmission();
while (!Serial) { }
Wire.begin();
Serial.println(LPS25H_read(LPS25H_WHOAMI), HEX);
LPS25H_write(LPS25H_CTRL1, B10010000);
}
void loop()
{
if(Serial.available() > 20){
if(Serial.read() == 0x7E){
delay(10);
for( i = 1; i < 21; i++){
if (i == 8) {
address[0] = Serial.read();
} else if (i == 9) {
address[1] = Serial.read();
} else if (i == 10) {
address[2] = Serial.read();
} else if (i == 11) {
address[3] = Serial.read();
} else if (i == 19) {
hex_pre = Serial.read();
} else if (i == 20) {
hex_aft = Serial.read();
} else {
trash = Serial.read();
}
}
address[4] = (address[0]256256*256) + (address[1]256256) + (address[2]*256) + address[3];
if (address[4] == 1081786034) {
//407ABEB2
water[0] = (((hex_pre * 256 + hex_aft) + 135) - 600);
} else if (address[4] == 1080782062) {
//406B6CEE
water[1] = (((hex_pre * 256 + hex_aft) + 135) - 600);
}
}
}
byte receive_msg[1]; int i = 0; if (acc.isConnected()) { // メッセージを読み込む int len = acc.read(receive_msg, sizeof(receive_msg), 1); // メッセージがaであれば if (len > 0 && receive_msg[0] == 'a') { // シリアルポート出力 Serial.println("Get message from Android!"); // Androidに応答メッセージを送る unsigned short dat_sdh; unsigned short dat_sdt; dat_sdh = getsdh(); dat_sdt = getsdt(); long ppxl,pol,poh; short tl,th; float p, t; poh = LPS25H_read(LPS25H_P_H); pol = LPS25H_read(LPS25H_P_L); ppxl =LPS25H_read(LPS25H_P_LL); th = LPS25H_read(LPS25H_T_H); tl = LPS25H_read(LPS25H_T_L); Serial.print("poh -> "); Serial.print(poh); Serial.print(" pol -> "); Serial.print(pol); Serial.print(" ppxl -> "); Serial.print(ppxl); p = (poh*16.0*16.0*16.0*16.0)+(pol*16.0*16.0)+ppxl; Serial.print(" p -> "); Serial.print(p); p = p/4096.0; Serial.print(" p -> "); Serial.println(p); t = (th*16*16)+tl; t = 42.5 + t/480.0; if(a==0){ setDay(); setTime(); a=1; } Wire.beginTransmission(RTC8564_ADDRESS); Wire.write(0x00); Wire.endTransmission(); Wire.requestFrom(RTC8564_ADDRESS,9); Wire.read(); Wire.read(); byte r_sec=Wire.read(); byte r_minute=Wire.read() & 0x7F; byte r_hour=Wire.read() & 0x03F; byte r_date=Wire.read() & 0x03F; Wire.read(); byte r_month=Wire.read() & 0x1F; byte r_year=Wire.read(); byte send_msg[27]; send_msg[0] = 'b'; send_msg[1] = ','; send_msg[2] = ((dat_sdt / 10)/10)+48; send_msg[3] = ((dat_sdt / 10)%10)+48; send_msg[4] = '.'; send_msg[5] = (dat_sdt % 10)+48; send_msg[6] = ','; send_msg[7] = ((dat_sdh / 10)/10)+48; send_msg[8] = ((dat_sdh / 10)%10)+48; send_msg[9] = '.'; send_msg[10] = (dat_sdh % 10)+48; send_msg[11] = ','; int atom = (int)p; send_msg[12] = (atom / 1000)+48; send_msg[13] = ((atom / 100) % 10)+48; send_msg[14] = ((atom / 10) % 10)+48; send_msg[15] = (atom % 10)+48; send_msg[16] = ','; send_msg[17] = (water[0]/100)+48; send_msg[18] = ((water[0]/10)%10)+48; send_msg[19] = '.'; send_msg[20] = (water[0]%10)+48; send_msg[21] = ','; send_msg[22] = (water[1]/100)+48; send_msg[23] = ((water[1]/10)%10)+48; send_msg[24] = '.'; send_msg[25] = (water[1]%10)+48; send_msg[25] = '\n'; Serial.print("RTC "); Serial.print(r_year,HEX); Serial.print("/"); Serial.print(r_month,HEX); Serial.print("/"); Serial.print(r_date,HEX); Serial.print("_"); Serial.print(r_hour,HEX); Serial.print(":"); Serial.print(r_minute,HEX); Serial.print(":"); Serial.println(r_sec,HEX); Serial.print("LPS25H "); Serial.print((int)p); Serial.print("hPa "); Serial.print(t); Serial.println("T"); Serial.print("AM2321 "); Serial.print( dat_sdt / 10 ); Serial.print( "." ); Serial.print( dat_sdt % 10); Serial.print( "T " ); Serial.print( dat_sdh / 10 ); Serial.print( "." ); Serial.print( dat_sdh % 10 ); Serial.println( "%" ); Serial.print( water[0] ); Serial.println( "w" ); Serial.print( water[1] ); Serial.println( "w" ); Serial.println(""); acc.write(send_msg, sizeof(send_msg)); } } delay(10);
}
###試したこと
ボードを変えてみたりはしたのですが、どうしても書き込みができません
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー