Go Down

Topic: is there a difference in sending a serial command at setup and during loop? (Read 1 time) previous topic - next topic

Loren


Quote
Again the arduino mega is externally powered.


The power source usually has nothing to do with resetting an arduino. Activity on the serial port causes the arduino to reset. When a pc opens a serial port it sends signals on the rts/dtr setial lines which cause the arduino reset (unless defeated).


Even if the mega is connected to the pc via two pins tx & rx on Serial1 via the GPIO?

zoomkat

Quote
Even if the mega is connected to the pc via two pins tx & rx on Serial1 via the GPIO?


You would need to check your mega schematic for that answer. As far as I know the reset is associated with the USB serial input to facilitate the arduino programming from the pc.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Loren

I added this to the main sketch in the loop to see if see if that would work any differently:

Code: [Select]
  if ((!connection) && (!attempted)){
    comms.isAnyone();
    attempted = true;
    Serial.println("attempted to connect");
  }


Here is comms:

Code: [Select]
#include "Arduino.h"
#include "Comms.h"



void Comms::piInit(){
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;
  if (Serial1.available () > 0)
  {
    char inByte = Serial1.read ();

    switch (inByte)
    {

    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte

      // terminator reached! process input_line here ...
      process_data (input_line);

      // reset buffer for next time
      input_pos = 0; 
      break;

    case '\r':   // discard carriage return
      break;

    default:
      // keep adding if not full ... allow for terminating null byte
      if (input_pos < (MAX_INPUT - 1))
        input_line [input_pos++] = inByte;
      break;

    }  // end of switch

  }  // end of incoming data

}

void Comms::process_data (char * data)
{
  byte index = 0;

  // for now just display it
  Serial.println("here comes what was read:  ");
  Serial.println(data);
  int i;

  for (i = 0; i < strlen(data); i++){
    //Looks for the ^ Char
    if(data[i] == 94){
      incoming = true;
    }// end of if i = ^
    else{

      //Looks for the & Char
      if(data[i] == 38){

      }// end of if i = &

      if((data[i] != 38) && (incoming)){
        inChar = data[i]; // Read a character
        inData[index] = inChar; // Store it
        index++; // Increment where to write next
      }
    }// end of else



  }// end of for
  char tinData[20]; // Allocate some space for the string
  char tinChar; // Where to store the character read
  byte tindex = 0; // Index into array; where to store the character

  String lantemp = String (inData[0]);
  if(lantemp.equals("$")){
    //need to read through inData here to get the IP
    for (i = 0; i < strlen(inData); i++){
      if(i>3){
        tinChar = inData[i]; // Read a character

        tinData[tindex] = tinChar; // Store it
        //Serial.println(tinData[index
        tindex++; // Increment where to write next
      }// end i>3   
    }
    String IP(tinData);
    piIp = IP;
    Serial.print("IP:  ");
    Serial.println(IP);
    myGLCD.print("Pi IP:  " + IP, LEFT,42);
    menus.homeScrn();
  }// end if = $

  String temp = inData;
  Serial.print("String Temp:  ");
  Serial.println(temp);
  if(temp.equals("Power")){
    piStatus = "Ready";
    delay (50);
    Serial1.println("ip");
    menus.homeScrn();
    connection = true;

    //myGLCD.print("PI Status:  "+piStatus, LEFT, 28);
  }//end if inData.equals



  inData[0] = '\0';
  temp = "";
}  // end of process_data


void Comms::serialGack(int port){
  switch(port){
  case 1:

    if (Serial1.available () > 0) {
      char inByte = Serial1.read ();

    }  // end of incoming data

    break;
  case 3:

    if (Serial3.available () > 0) {
      char inByte = Serial3.read ();
    }
    break;
  }
}

void Comms::isAnyone(){
Serial1.println("VN");
delay(75);
}



What baffles me now is that in the Menus library this works:

Code: [Select]
if ((x>=150) && (x<=210)){
        if (mnu == 1){
          Serial1.println("RB");
          Serial.println("Restart");
          piStatus = "Restarting";
          piIp = NULL;
          mnu = 0;
          homeScrn();


but Serial1.println("ST"); is still not working correctly.

Go Up