Diavolino serial timeout

Hi,

I’m trying to implement a serial connection in my project, but appear to have run into a small problem.

I am talking to the board through a USB serial connection with PuTTY.
When I first plug the arduino (diavolino) in, everything works fine. About an hour later, I notice that the serial connection has quit, and I cannot re-connect until I unplug the arduino, leave it, and then plug it back in.

I’ve completed the loop-back test, and it does print out the characters back to me (which appears instead to simply “write” the words as I type them, only one copy appears on PuTTY).

The search function on the forum has changed since the last time I visited, and I find it quite a bit harder to navigate when one entry takes up several heights of my monitor… But Google searching hasn’t revealed anything as well, none of the posts I found with my problem have a solution that is pertinent to me.

If someone more knowledgeable with arduino programming could lend a hand, I’d be grateful.

Thanks,
-BBX

//
// SuiteLock v.2.a
// By: Chris Bero (bigbero@gmail.com)
// Last Updated: 10.21.2012
//

#include <Servo.h>
#include <avr/wdt.h>

// Pin Constants:
const int servoPin = 9;
const int doorbtn = 3;

// Not sure if I'm still going to use these...
const int ledGND = 4;
const int ledVCC = 5;
const int servDelay = 600; // The delay allowing for the servo to complete an action.

//Variables:
int doorState = 0;  // The value returned by the door button (0 or 1).
int servState = 90;  // The position of the servo in degrees.
int serialByte = 0;
int smallBlink = 0;
bool debug = false;
Servo serv;

// Set up the pin environment.
void setup() 
{
  wdt_enable(WDTO_4S);
  pinMode(doorbtn, INPUT);
  pinMode(ledGND, OUTPUT);
  pinMode(ledVCC, OUTPUT);
  pinMode(servoPin, OUTPUT);
  digitalWrite(ledGND, LOW);
  serv.attach(servoPin);
  Serial.begin(9600);
}

/////////////////////////////////////////////
// Debugging function, still kinda beta.
//////////////////////////////////////////
int debugger ()
{
  wdt_reset();
  Serial.println("Debugging: ");
  refresh();
  Serial.print("DoorState: ");
  Serial.println(doorState);
  Serial.print("Servo Position: ");
  Serial.println(servState);
  return(0);
}

////////////////////////
// Lock the door.
/////////////////////
int locker()
{ 
  wdt_reset();
  
  // Check the button states.
  refresh();
  
  // Make sure the door is closed.
  do
  {
    wdt_reset();
    delay(500);
    refresh();
  }while(doorState == LOW);
  
  // Call the debugging function, still a WiP right now.
  if(debug == true)
  {
    debugger();
  }
  
  // Turn on the locking LED during the servo movement.
  digitalWrite(ledVCC, HIGH);
  
  wdt_reset();
  
  // Here we set the motor pins to draw current through in a direction the locks the door.
  serv.write(20);
  
  // Keep the motor turning for another fraction of a second to complete the locking motion.
  delay(servDelay);
  
  wdt_reset();
  
  // Turn the servo motor opp direction to reset.
  serv.write(90);
  
  
  // Wait for the servo to reach it's reset point.
  delay(servDelay);
  
  // Turn off the cool little LED.
  digitalWrite(ledVCC, LOW);
  
  return(0);
  
}

/////////////////////////
// Unlock the door.
//////////////////////
int unlocker ()
{
  wdt_reset();
  
  // Check the pin states.
  refresh();
  
  // Turn on the status LED.
  digitalWrite(ledVCC, HIGH);
  
  // Debug
  if(debug == true)
  {
    debugger();
  }
  
  wdt_reset();
  
  serv.write(170);
  
  // Complete the motion to unlock the door.
  delay(servDelay);  
  
  wdt_reset();
  
  serv.write(90);
  
  // Wait for reset motion to complete.
  delay(servDelay);
  
  // Turn off LED.
  digitalWrite(ledVCC, LOW);
  
  return(0);
}

///////////////////////////////
// Refresh button states.
/////////////////////////////
void refresh ()
{
  wdt_reset();
  doorState = digitalRead(doorbtn);
  servState = serv.read();
}

///////////////////////
// Main function.
////////////////////
void loop() 
{
  
  wdt_reset();
  
  // Blink the LED every so many turn overs of the function.
  if (smallBlink == 5)
  {
    smallBlink = 0;
    digitalWrite(ledVCC, HIGH);
    delay(300);
    digitalWrite(ledVCC, LOW);
  }
  
  // Debug.
  if(debug == true)
  {
    debugger();
  }
  
  // Refresh button states.
  refresh();
  
  // Is the door closed and not locked? *Gasp*
  if ((doorState == LOW))
  {
    // Fix it.
    while (doorState == LOW)
    {
      wdt_reset();
      delay(500);
      refresh();
    }
    locker();
  }
  
  // Check for available communications.
if (Serial.available() > 0)
  {
    // Reset the serialByte, done for debugging.
    serialByte = 0;
    wdt_reset();
    // Read the serialByte.
    serialByte = Serial.read();
  }
  
  // Act on the byte data.
  if (serialByte == 'U')
  {
    // Let someone in.
    unlocker();
    // Wait for the door to change states.
    delay(1000);
  }
  if (serialByte == 'L')
  {
    locker();
    delay(1000);
  }
  
  // Clean serialByte for debugging.
  serialByte = 0;
  
  // Count through program cycles.
  smallBlink++;

}

SuiteLock.ino (3.97 KB)

Code seems fine to me. Are you sure it isn't an error with PuTTy? You can in fact talk to the arduino through the serial montior. Also you could easily make an interactive sketch with processing. Processing is extremely similar to what you code in for the Arduino IDE

Thanks funkyguy4000,

I am planning to convert my serial tool over to a dedicated program soon. I've checked and made sure that PuTTY is using settings that should work with the arduino. Once the connection has timed out, I cannot access the device (COM10) from the arduino serial monitor either.

-BBX

What is the Diavolino based off of? If it is similar to a Arduino Leonardo, your OS may be resetting the connection. When the 32U4 resets, it can sometimes come in on a different COM or come in unresponsive on the same COM.

Otherwise I got nothin

I am under the impression that the Diavolino is based off of the Duemilanove, it is the same size and uses a 328. Furthermore, I think I bought it before the Leonardo came out (and the UNO for that matter), I haven't actually seen one of the Leonardos before.

I've locked the arduino to COM10, and even when neither serial tool can connect to it, both can "see" it, and it is recognized in Device Manager in Windows.

I'm going to try some more trouble shooting. This has been a problem for about a week now, but I've overlooked actually trying to build a workaround. I've just enabled the "debug" switch in the .ino, which allows the arduino to print a heartbeat to the serial connection several times a second. If the connection still resets after a while even when the arduino is interacting, is the possibility of this being a timeout eliminated? Or does the computer need to be exchanging data back to the arduino?

Thanks, -BBX

Do you know what regulator you used? I know that they are shipped without said regulator. I use 100mA 5v0 regulators and they work all day long.

Ah, that has been a problematic topic for me.

I am using a 7805 chip and two 10uF caps, following the first part of this page: http://www.arduino.cc/en/Main/Standalone

The 7805 is fed from a 6V, 500mA DC adapter.

I have connected both ground and 5v+ between the regulator and the Diavolino. I also installed the EvilMadScience voltage regulator on the Diavolino itself.

Earlier, I only connected the grounds, as was suggested in a playground article. For some reason unknown to me, that would cause the servo to pick up "phantom" pwms and occasionally turn randomly. I could only fix this by also connecting the 5V between the board and power regulator.

I've measured the temperature on the 7805 while running the board and servo; it does not even get warm to the touch.

Thanks, -BBX

With that big old 7805, you are going to need more than 6V, more like 9V for the voltage drop on that regulator. Since you are playing with servos you probably need to stay with the 1500mA device.

Have you tried hooking the USBV and just power from the USB?

Sorry, all I really know how to use is the 7805 :cold_sweat:
I’m looking around for a higher voltage, 1A power supply to cannibalize and hook up to the 7805.

I tested the voltage coming out of the 7805, and it does seem to supply 5V, but I haven’t tested it under load yet…

Do you mean pulling 5V through the Arudino? I was told it barely supplies 40mA… And whenever I try pulling power directly from the laptop’s USB, it crashes (I’m probably doing something wrong).

Also, it looks like the debugging system fixed the serial issue. Apparently, all I have to do is use the COM port every once in a while to keep the serial connection open. I updated the debug system this morning to only write to the serial line every four seconds.

Thanks,
-BBX

About 100mA, but with a motor driver or MOSFET it should be more than enough. If you are connecting to USB with a servo larger than the toy servo, then sure, it will trip if not fry the USB port.

Glad you found something that works.