HELP I cant get the arduino to stay on the serial port

I'm running Arduino 1.0.5 on OS 10.6.8 Is there a patch? could the sketch i uploaded knock the arduino off the serial list? Can anyone help me?? My project depends on serial communication and this is frustrating.

THank you for your time.

Keith

What do you mean "stay on the serial port"?

What happens when it drops off?

Patch for what and why do you think you need one? And why do you think that's the faulty bit?.

The odds are the problem is YOU, in your code and in your diagnosis of the problem.

Post your code and make sure that it has been auto formatted before posting.

Mark

holmes4:
What do you mean "stay on the serial port"?

What happens when it drops off?

Patch for what and why do you think you need one? And why do you think that's the faulty bit?.

The odds are the problem is YOU, in your code and in your diagnosis of the problem.

Post your code and make sure that it has been auto formatted before posting.

Mark

It just isnt listed in the serial port list and when i tried to upload the sketch or view the serial monitor its not there...

my sketch is below:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 

union comPack{
  int positions[16];
  int servo[8];
};

comPack rf_out;

int ail_led = 4;
int ele_led = 5;
int rud_led = 6;
int thr_led = 7;
int serial_led = 8;
int trigger_led = 12;

int pinState = LOW;

// User input for servo and position
long userInput[3];    // raw input from serial buffer, 3 bytes
long posArray[4];
int startbyte;       // start byte, begin reading input
int servo;           // which servo to pulse?
int pos;             // servo angle 0-180
int con;              // servo 
int i;               // iterator

long previousMillis = 0;
long interval = 25;

LiquidCrystal_I2C lcd(0x20, 6, 5, 4, 0, 1, 2, 3, 7, POSITIVE);

 
RF24 radio(9,10);
 
const uint64_t pipe = 0xE8E8F0F0E1LL;
 
 
 
void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  
  setDisplay();
  
  pinMode(ail_led, OUTPUT);
  pinMode(ele_led, OUTPUT);
  pinMode(rud_led, OUTPUT);
  pinMode(thr_led, OUTPUT);
  pinMode(serial_led, OUTPUT);
  pinMode(trigger_led, OUTPUT);
}

void setDisplay(){
  lcd.begin(16,2); // initialize the lcd
  //lcd.backlight();
  lcd.setCursor(0,0);
  //lcd.print("Ail=");
  lcd.print("s01=");
  lcd.setCursor(8,0);
  //lcd.print("Ele=");
  lcd.print("s02=");
  lcd.setCursor(0,1);
  //lcd.print("Rud=");
  lcd.print("s03=");
  lcd.setCursor(8,1);
  //lcd.print("Thr=");
  lcd.print("s04=");
}
 
void loop(void)
{
  
  // Wait for serial input (min 6 bytes in buffer)
  if (Serial.available() > 5) {
    digitalWrite(serial_led, HIGH);
    // Read the first byte
    startbyte = Serial.read();
    // If it's really the startbyte (255) ...
    if (startbyte == 255) {
      // ... then get the next two bytes
      for (i=0;i<2;i++) {
        userInput[i] = Serial.read();
      }
      // First byte = servo to move?
      servo = userInput[0];
      // Second byte = which position?
      pos = userInput[1];
      
      // Packet error checking and recovery
      if (pos == 255) { servo = 255; }
      
      switch (servo) {
        case 1:
       if(pos > 92 || pos < 90){
            digitalWrite(ail_led, HIGH);
          }else{
            digitalWrite(ail_led, LOW);
          }
          rf_out.positions[0] = pos;
          
          lcd.setCursor(4,0);
          lcd.print("    ");
          lcd.setCursor(4,0);
          lcd.print(pos);
          
          break;
        case 2:
             
          if(pos > 92 || pos < 90){
            digitalWrite(ele_led, HIGH);
          }else{
            digitalWrite(ele_led, LOW);
          }
          rf_out.positions[1] = pos;
          
          lcd.setCursor(12,0);
          lcd.print("    ");
          lcd.setCursor(12,0);
          lcd.print(pos);
          
          break;
        case 3:
         if(pos > 92 || pos < 90){
            digitalWrite(rud_led, HIGH);
          }else{
            digitalWrite(rud_led, LOW);
          }
          rf_out.positions[2] = pos;
          
          lcd.setCursor(4,1);
          lcd.print("    ");
          lcd.setCursor(4,1);
          lcd.print(pos);
          
          break;
        case 4:
        if(pos < 145){
            digitalWrite(thr_led, HIGH);
          }else{
            digitalWrite(thr_led, LOW);
          }
         rf_out.positions[3] = pos;
         
          lcd.setCursor(12,1);
          lcd.print("    ");
          lcd.setCursor(12,1);
          lcd.print(pos);
          
          break;
          
          case 99:
          if (pos == 180) {
            Serial.println("pos = 180");
             pinState = HIGH; 
          }
          if (pos == 0) {
            Serial.println("pos = 0");
            pinState = LOW;
          }
          digitalWrite(trigger_led, pinState);
          break;
      }       
       
    }
  }else{
    digitalWrite(serial_led, LOW);
  }
  
 
  Serial.println("Transmitting Servo positions");
  radio.write( &rf_out, sizeof(rf_out) );
 
}

What I think is happening is that your code is jumping to a random location from your switch statement.

What are are out sending to the arduino. For example typing a 1 into the serial monitor and then sending it does not get you 1 from serial.read() it gets you the numeric value of the ascii char "1" which is the number (dec) 49!.

You could try using a default: statement in the switch.

Mark

holmes4:
What I think is happening is that your code is jumping to a random location from your switch statement.

What are are out sending to the arduino. For example typing a 1 into the serial monitor and then sending it does not get you 1 from serial.read() it gets you the numeric value of the ascii char "1" which is the number (dec) 49!.

You could try using a default: statement in the switch.

Mark

Thank you, I will try adding the default statement asap.

adding the default statement didnt seem to help:

(thank you for your help so far ...btw)

 case 99:
          if (pos == 180) {
            Serial.println("pos = 180");
             pinState = HIGH; 
          }
          if (pos == 0) {
            Serial.println("pos = 0");
            pinState = LOW;
          }
          digitalWrite(trigger_led, pinState);
          break;
          
          default:
          Serial.println("Nothing matches the switch case");
      }

Hmmmm... any other suggertions? :\

What/how are you sending data?

Mark

Are you plugging it into the same USB port each time? My experience with Windows 7, is that it assigns different com ports to each USB port.

holmes4:
What/how are you sending data?

Mark

Serial data comes from a joystick through a python code.

Are you plugging it into the same USB port each time?

Yes, but I'm using a Mac

Ah, can you find out what your really sending to the arduino?

Mark

Simple serial test code for use with the IDE serial monitor.

// zoomkat 7-30-11 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);

    readString="";
  } 
}

holmes4:
Ah, can you find out what your really sending to the arduino?

Mark

Everything works great if I get the Arduino "working" (ie visible). If I load the Example "Blink", the arduino becomes visible on the port, but as soon as I upload my sketch, it disappears! :frowning:

I dont know whats going on...

Simple serial test code for use with the IDE serial monitor.

I think there has to be something "wrong" with my sketch...

Could there be a conflict with any of the Includes?

I think there has to be something "wrong" with my sketch...

What draws you to that conclusion?

zoomkat:
What draws you to that conclusion?

What else could it be?

It's either the hardware or the software, and at this stage the software looks far more likely.

Does the problem occur when you just run the Arduino, or only when you send it input via the serial port?

If it is caused by input then you need to know what the input is and what the Arduino is doing with that input leading up to the problem.

If it's not caused by input then I suggest that you start by isolating sections of your sketch until you can prevent the problem from occurring. Don't worry too much about whether the sketch still does anything useful - the objective is just to keep the Arduino running. Once you have achieved that, add in some code to measure and display the amount of free memory. You will find example code for this in the playground. No special reason to suppose you're running out of memory, but it would be good to exclude it from consideration. Then reinstate sections of your code until the problem occurs. Try to work with logically sensible chunks of functionality such as dealing with serial input or dealing with other attached devices. Once you can identify a region of the code which causes the problem you can gradually narrow the problem down.

Instead of

 radio.write( &rf_out, sizeof(rf_out) );

The last line of your code.

Use radio.write( rf_out, sizeof(rf_out) ); or radio.write( &rf_out[0], sizeof(rf_out) );

You do understand what on startup there will be nothing in the serial buffer and that your code will go straight to the call to radio.write()

Take a look at this thread Address of array vs. address of array[0] - C language - Stack Overflow

Mark

Mark