Arduino PINs not behaving equally -


i have burned code on arduino:

#include <spi.h> #include <ethernet.h> #include <stdlib.h>  using namespace std;  #define buffsize        16 #define pin0            0 #define pin1            1 #define pin2            2 #define pin3            3 #define pin4            4 #define pin5            5 #define pin6            6 #define pin7            7 #define pin8            8 #define pin9            9 #define pin10           10 #define pin11           11 #define pin12           12 #define pin13           13  // mac address please view ethernet shield. byte mac[] = {0x90, 0xa2, 0xda, 0x0d, 0x85, 0xd5};  ipaddress server(192, 168, 0, 61); // ip address of raas server  // set static ip address use if dhcp fails assign ipaddress ip(192, 168, 0, 62);   // initialize ethernet client library // ip address , port of server  // want connect (port 8 selected raas): ethernetclient client;  string getnextcommand() {     int count,i;     int temp;     string command;         serial.println("waiting next command.");     while((count = client.available()) < 1 );     for(i = 0; < count ; i++)         command += (char) client.read();         command.replace("\r","");         command.replace("\n","");         serial.println(command);         return command; }  bool connectserver() {     int rescount,i;     string response;     serial.println("trying connect...");     // if connection, report via serial:     if (client.connect(server, 8)) {         serial.println("connected");         // make handshake request:         client.println("ehlo");         response = getnextcommand();         if (response == "ehlo" ) {             serial.println("server response okay");             return true;         }     } else {         // kf didn't connection server:         serial.println("connection failed");     }     return false; }  void initializeboard() {     pinmode(pin1, output);     pinmode(pin2, output);     pinmode(pin3, output);     pinmode(pin4, output);     pinmode(pin5, output);     pinmode(pin6, output);     pinmode(pin7, output);     pinmode(pin8, output);     pinmode(pin9, output);     pinmode(pin10, output);     pinmode(pin11, output);     pinmode(pin12, output);     pinmode(pin13, output);     digitalwrite(pin1, low);     digitalwrite(pin2, low);     digitalwrite(pin3, low);     digitalwrite(pin4, low);     digitalwrite(pin5, low);     digitalwrite(pin6, low);     digitalwrite(pin7, low);     digitalwrite(pin8, low);     digitalwrite(pin9, low);     digitalwrite(pin10, low);     digitalwrite(pin11, low);     digitalwrite(pin12, low);     digitalwrite(pin13, low); }  void parsecommand(string str) {      int pinnum;     int pinstate = low;      string switchno,operation;     int temp;         temp=0;     temp = str.indexof(':',temp);     switchno = str.substring(0,temp);     operation = str.substring(temp+1);//,str.length()-temp-2);     serial.println("port: " + switchno);     serial.println("operation: " + operation);       if(operation == "off;")         pinstate = low;     else if(operation == "on;")         pinstate = high;     else serial.println("invalid command server!");      pinnum = str.toint();      serial.print("setting ");     serial.print( pinnum);     serial.print(  " ");     serial.println( pinstate);      switch (pinnum){         case pin1:                 digitalwrite(pin1, pinstate);                 break;         case pin2:                 digitalwrite(pin2, pinstate);                 break;         case pin3:                 digitalwrite(pin3, pinstate);                 break;         case pin4:                 digitalwrite(pin4, pinstate);                 break;         case pin5:                 digitalwrite(pin5, pinstate);                 break;         case pin6:                 digitalwrite(pin6, pinstate);                 break;         case pin7:                 digitalwrite(pin7, pinstate);                 break;         case pin8:                 digitalwrite(pin8, pinstate);                 break;         case pin9:                 digitalwrite(pin9, pinstate);                 break;         case pin10:                 digitalwrite(pin10, pinstate);                 break;         case pin11:                 digitalwrite(pin11, pinstate);                 break;         case pin12:                 digitalwrite(pin12, pinstate);                 break;         case pin13:                 digitalwrite(pin13, pinstate);                 break;         default:             serial.println("invalid pin address!");     } }  void setup() {      // open serial communications , wait port open:     serial.begin(9600);     // start ethernet connection:     if (ethernet.begin(mac) == 0) {         serial.println("failed configure ethernet using dhcp");         // no point in carrying on, nothing forevermore:         // try congifure using ip address instead of dhcp:         ethernet.begin(mac, ip);     } else {       serial.println("bound on given mac");     }     // give ethernet shield second initialize:     delay(1000);  }  void loop() {     //keep trying connect server until server response okay!     while (!connectserver());      //while server connected, keep listening incoming commands server.     while (client.connected()) {         string command;         command = getnextcommand();         parsecommand(command);     }      // if server's disconnected, stop client:     if (!client.connected()) {         serial.println();         serial.println("server disconnected.");         client.stop();     } } 

now have connect relays on pins 1-13. pins not behaving properly. when send command 13:on; or 13:off; pins on ethernet shield not change state in each case. when send 03:on; or 03:off; changes state w.r.t command. pins responding pin 3 , other pins not (like pin13). thing code?

the issue ethernet shield uses pins 13, 12, 11, spi . 10 , 4, select sd or ethernet.

pinnum = str.toint();

and have switch statement mach pinnum correct operation.

i see how value of str looks before "parsecommand()" function. can show me prints in "getnextcommand()"


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -