avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64 avrdude: stk500_cmd(): programmer is out of sync

Galera boa noite.

Vê se alguém pode me ajudar.

Comprei um aplicativo no GooglePlay (EightControl) 

https://play.google.com/store/apps/details?id=at.klp.led1control#?t...

Após fazer todos os procedimentos que é solicitado(instalei na biblioteca as pastas Aes256 e Timer1 e o txt na W5100), abri o programa do Arduíno e ao tentar fazer upload do script abaixo está gerando o seguinte erro:

avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: stk500_cmd(): programmer is out of sync

Alguém pode me ajudar por favor?

Possuo um Arduíno Uno + Ethernet Shield W5100.

/********************************************************************************************
Eight Control is a universal IP based remote control system. This is the server application,
it is controlled from an Android device. Written by Klaus Pintoffl in April 2012. Feel free
to distribute and modify the code.
********************************************************************************************/

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <EEPROM.h>
#include <TimerOne.h>
#include <aes256.h>
#include <avr/wdt.h>


//network parameters
byte IpArray[4];
byte mac[6];
byte GatewayArray[4];
byte SubnetArray[4];
int Port=0;
//output pins
int outPins[] = {
9,8,7,6,5,3,2,1,0};
//delays in sec for auto-off
int Delay[] = {
-1,0,0,0,0,0,0,0,0};
//substract from delays until 0
int DelayCounter[] = {
-1,0,0,0,0,0,0,0,0};
//restore function?
boolean SaveState[] = {
true,false,false,false,false,false,false,false,false};
//setings file from SD card
File file1;
//incoming string from client
String inString;
//Random String sent to client
String RandomString;
//Encoded String generated at Server
String encServer;
//creates very first random
boolean firstRound = true;
//context for encryption
aes256_context ctx1;
//strong background key, 32 byte
uint8_t key[] = {
107,99,89,10,79,109,105,102,116,112,80,113,86,106,77,116,
112,57,105,120,97,6,103,118,7,81,107,78,76,80,67,114};

//set true for serial debugging
boolean debug = false;
//if debug, 2 pins are needed for Serial
int FnNr = 8;
//set false if Arduino with bootloader used (conflicts)
boolean watchdog = false;

void setup(){


//if watchdog used, set it to 8 sec first
if (watchdog) {
MCUSR=0;
wdt_enable(WDTO_8S);
}

//if debug, use 6 functions and start Serial
if (debug) {
FnNr = 6;
Serial.begin(9600);
Serial.println("Debug true, 6 Functions used");
}

//card has to be initialized for pin 4
if (!SD.begin(4)) {
//if (debug) Serial.println("Card init failed");
return;
}

//Read the network and user config from SD Card:
file1 = SD.open("Settings.txt");

if (file1) {
char allText[file1.available()];
int length = file1.available();

//writes all bytes of text into the array
for (int x=0; x<length; x++){
allText[x] = file1.read();
};

char* parts;
parts = strtok (allText, ",=. \n");

while (parts != NULL){
//buid a String from the token
String s = String(parts);

//if IP type, then the next 4 bytes are the IP adress
if (s=="IP") {
for (int i= 0; i<4; i++){
parts = strtok(NULL,",=. \n");
String s = String(parts);
//define array of char with length of string s
char xy[s.length()];
//write s into array xy. 2nd parameter must be type int
s.toCharArray(xy, s.length()+1);
//atoi needs a char array, not a string
int param = atoi(xy);
IpArray[i] = param;
}
};

//if MAC type, then the next 6 bytes are the MAC adress
if (s=="MAC") {
for (int i= 0; i<6; i++){
parts = strtok(NULL,",=. \n-");
String s = String(parts);
char xy[s.length()];
s.toCharArray(xy, s.length()+1);
int param = atoi(xy);
mac[i] = param;
}
};

//if Gateway type, then the next 4 bytes are the Gateway adress
if (s=="Gateway") {
for (int i= 0; i<4; i++){
parts = strtok(NULL,",=. \n");
String s = String(parts);
char xy[s.length()];
s.toCharArray(xy, s.length()+1);
int param = atoi(xy);
GatewayArray[i] = param;
}
};

//if Subnet type, then the next 4 bytes are the Subnet adress
if (s=="Subnet") {
for (int i= 0; i<4; i++){
parts = strtok(NULL,",=. \n");
String s = String(parts);
char xy[s.length()];
s.toCharArray(xy, s.length()+1);
int param = atoi(xy);
SubnetArray[i] = param;
}
};

//if Port type, then the next byte is the Port
if (s=="Port") {
parts = strtok(NULL,",=. \n");
String s = String(parts);
char xy[s.length()];
s.toCharArray(xy, s.length()+1);
Port = atoi(xy);
};

//for the Delays 1 to 8:
if(s.indexOf("Delay")>-1) {
for (int x=1; x<=8; x++){
if (s=="Delay"+String(x)) {
parts = strtok(NULL,",=. \n");
String s = String(parts);
char xy[s.length()];
s.toCharArray(xy, s.length()+1);
Delay[x] = DelayCounter[x] = atoi(xy);
//only 1 possibilyty (Delay1 to Delay8)
break;
}
}
}

//If s is SaveState, than at least 1 function should be set on after reboot
if (s=="SaveState") {
parts = strtok(NULL,",=. \n");
String s = String(parts);
for (int x=1; x<=8; x++){
if (s.indexOf (String(x)) >-1) SaveState[x] = true;
}
};


//if Key, one round reads this code
if (s=="Key") {
parts = strtok(NULL,",=. \n");
String s = String(parts);
char xy[s.length()];
s.toCharArray(xy, s.length()+1);
int loops = s.length()-1;
if (loops>32)loops = 32; //max 32 digits of user key used, rest ignored

for (int x=0; x<loops; x++){
key[x] = (byte)(xy[x]);
}
};

parts = strtok(NULL,",=. \n");
}//end while (parts != NULL)

file1.close();

//Network config read from SD Card done.
}

//SaveState wins over Delay: Both at the same time does not make sense
for (int x=1; x<=8; x++){
if (SaveState[x] == true) {
Delay[x]=0;
DelayCounter[x]=0;
}
}

//set the pins as outputs. 0 is ISR indicator
for (int x=0; x<=FnNr; x++){
pinMode(outPins[x], OUTPUT);
}

//these pins are connected to USB and 0 is on by default
digitalWrite (0, LOW);
digitalWrite (1, LOW);

//Check states of EEProms and switch outputs on if needed:
for (int x=1; x<=FnNr; x++){
if ((SaveState[x])&& (EEPROM.read(x)==1)) digitalWrite (outPins[x], HIGH);
}

//Uses TimerOne Library. Every second ISR1 is called.
Timer1.initialize(1000000);
Timer1.attachInterrupt(ISR1);

Ethernet.begin(mac, IpArray,GatewayArray,SubnetArray);

//avoids mem fragmentation when appending to Strings
inString.reserve(51);
encServer.reserve(33);
RandomString.reserve(11);

}//end setup


void loop(){

//reset watchdog
if (watchdog) wdt_reset();

//has both to be done here, after Port read
EthernetServer server(Port);
server.begin();

EthernetClient client = server.available();

if (client) {

//http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {

if (client.available()) {
char c = client.read();
//50 is 8 byte more than actually needed
if (inString.length() < 50) {
inString.concat(c);
}


if (c == '\n' && current_line_is_blank) {

//if (debug) Serial.println(inString);

//send standard http response header
client.println("HTTP/1.1 200 OK");
client.println("");
client.println();

//if a AES-256 encoded String is returned
if(inString.indexOf("R")>0){

//substringmethod: start inclusive, end exclusive
String encClient = inString.substring(inString.indexOf("R")+1, inString.indexOf("S"));

//only if the 2 strings match, check and execute F-Functions, toggle pins, below
if ((encClient==encServer) && (inString.indexOf("F")>0)) {

int NumPos = inString.indexOf("F")+1;

for (int x=1; x<=FnNr; x++){
if(inString.indexOf(String(x)) == NumPos){
if (!digitalRead(outPins[x])) digitalWrite(outPins[x], HIGH);
else digitalWrite(outPins[x], LOW);
if (SaveState[x]) {
if(digitalRead(outPins[x])) EEPROM.write(x, 1);
else EEPROM.write(x, 0);
};
//one one F function possible per inString
break;
}
}
}//end if compare strings

else {
delay(3000);
} //checksum does not match

//prepare next random string to send
prepareNextRandom();
}

//S: Pin status to be returned
if(inString.indexOf("S")>0){

//do this only once after startup
if (firstRound){
prepareNextRandom();
firstRound=false;
}

//get pin status
for (int x=1; x<=FnNr; x++){
client.print("F");
client.print(x);
if(digitalRead(outPins[x])) client.print("p");
else client.print("n");
}//end for
}

//Y means client requests random number
if(inString.indexOf("Y")>0){
client.print("X");
client.print(RandomString);
}

//K means client requests temp reading. Separate all readings by "_".
if(inString.indexOf("K")>0){
client.print("U");

//delete following line when using newest version of Eight Control, if you want to transmit values to Android app
client.print(analogRead(0));

//********************************use this code (uncomment) with newest Version from Eight Control*********************

// //make any calculation you want to transmit to the Android app
// float TMP36 = (5.0 / 1024.0 * analogRead(0) - 0.5) * 100;
// float voltage = 5.0 / 1024.0 * analogRead(3);
//
// //Value 1: Set title in Android app settings
// client.print(TMP36);
// client.print("_");
//
// //Value 2: Set title in Android app settings
// client.print(voltage);
// client.print("_");
//
// //Value 3: Set title in Android app settings
// client.print(analogRead(1));
// client.print("_");
//
// //Value 4: Set title in Android app settings
// client.print(analogRead(4));
// client.print("_");
//
// //Value 5 ff: Will be automatically named Value 5
// client.print(analogRead(5));
// // not needed for last: client.print("_");

//********************************use this code with newest Version from Eight Control**********************************

}

break;
}

//starting a new line:
if (c == '\n') {
current_line_is_blank = true;
}
//a character on the current line
else if (c != '\r') {
current_line_is_blank = false;
}
}
}

//gives client time to receive the data
delay(1);
//reset the received string
inString = "";
client.stop();
}
}//end loop

void prepareNextRandom(){ //creates random, encodes it

randomSeed(millis());
//0 to highest possible long
long InitialRandom = random(2147483647);
RandomString = "";
//Sent to client upon request
RandomString+=InitialRandom;

//update data array
uint8_t data[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

for (int x=0; x<RandomString.length(); x++){
data[x] = RandomString[x];
}

//AES-256 encoding of data array
aes256_init(&ctx1, key);
aes256_encrypt_ecb(&ctx1, data);
aes256_done(&ctx1);

encServer = "";

for (int x=0; x<16; x++){
int a = data[x];
String b = String (a, HEX);
if(b.length()==1) b="0"+b;
encServer.concat(b);
}
}

//interrupt service routine to handle delays

void ISR1(){

//toggle control led
if (digitalRead(outPins[0])) digitalWrite(outPins[0], LOW);
else digitalWrite(outPins[0], HIGH);

//Check and decrement delays
for (int x=1; x<=FnNr; x++){

if (Delay[x] >0) {
if ((DelayCounter[x]>0) && (digitalRead(outPins[x])==HIGH)){
DelayCounter[x]--;
}
else {
digitalWrite(outPins[x], LOW);
DelayCounter[x]=Delay[x];
}
}
}
}

Exibições: 1684

Responder esta

Respostas a este tópico

Este erro de not in sync geralmente se refere a problemas na conexão do Arduino com o PC. Tente reiniciar, usar em outro PC, reinstalar os drivers e verifique se a ATmega está do lado certo (a parte com reentrância do CI deve estar apontando para o lado oposto do USB). Eu já consegui ligar uma ATmega errada na minha Uno e ficava dando este erro.

Boa sorte!

Este erro também pode ocorrer se voce estiver usando ou ligar algo nos pinos digitais 0 e 1 e tentar fazer o upload.

 

estou com este mesmo problema a meses, já considero um caso perdido, só outro atmega. 

George,

Comigo havia gerado um erro igual ao seu porém descobri que havia selecionado o arduíno errado no IDE. Ao informar o correto o erro mudou conforme tópico.

Dá uma verificada, quem sabe.

Abs.

Já tive esse problema de forma permanente no meu ATMEGA, pensei que estava perdido, mas consegui resolver reprogramando o firmware do Atmega 8u2, que realiza a função de conversor USB-serial, pois o problema era na comunicação usb.

Não lembro qual a sequência de ações, mas salvei estes links, e com um pouco de cada (principalmente o link 4), lembro que consegui.

http://arduino.cc/forum/index.php?topic=111.0 

Bruno, bom dia.

Vou tentar quem sabe dá certo.

Valeu pela ajuda.

esses links são muito bons mas só funcionam com o mega e o uno, infelizmente o meu é um duemilanove 

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço