Serial msg resets Arduino

edited February 2017 in Arduino

I have an Arduino Nano connected via USB to COM9. In Processing I'm sending a test message to the Arduino via this code:

import processing.serial.*;
Serial myPort;
void setup() {
myPort = new Serial(this, Serial.list()[2], 9600) ;
noLoop() ;
}

void draw() {
  myPort.write(0x02) ; // STX
  myPort.write(0x00) ; // all addressees
  myPort.write(0x11) ; // temperature, outside
  myPort.write(0x00) ; // high byte
  myPort.write(0x07) ; // low byte
  myPort.write(0x55) ; // fill
  myPort.write(0x03) ; // end msg   
}

The Nano resets when the message is sent. This is not what I intend. What's going on? Thanks.

Answers

  • Please format your code.Edit your post, select your code and hit ctrl+o and leave an empty line above and below your code.

    Remove the noLoop() in your setup() function. How do you know the device is being reset?

    I would add a delay(1000) in your last line of setup. Also, in setup, add frameRate(2); just to slow things down for testing purposes.

    Kf

  • Thanks on the formatting. This site works a little bit differently than other forums. Nevertheless, I should have thought of doing it that way.

    I can see that the Arduino is reset because it has an LED 4x20 display and it immediately shows the initialization text. I'm wondering if there is something in the serial comm protocol that works similar to when the Arduino IDE uploads code. When the IDE is programming via a serial-to-TTL converter, the reset is done via the DTL line. But the USB doesn't have that kind of handshake. I just need to avoid whatever it is that is similar to when the IDE resets the Arduino.

    Removing noloop() won't help. I only want to send the message once. Ditto the frame rate.

  • Did you try adding the delay() at the end of setup. They have mention this in past forums and in Arduino examples.

    Kf

  • The delay() didn't solve the problem. The Nano runs its installed sketch just fine. until the serial stream starts.

    I'm an old Forth programmer, so I always wonder if I'm screwing up the stack, but with the Arduino IDE you pretty much have to be missadressing an array to get into uncharted memory.

  • It might be helpful if you could post your Arduino code also.

  • Answer ✓

    I tried your code on an Arduino UNO and it does indeed reset the board when Processing opens the serial port. If you could eliminate the 'noLoop()' in your setup() it would reset only once. Otherwise you can take a look at the link below on ways to disable Arduino's auto reset:

    http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection

  • edited February 2017

    I removed noloop() and added some code to use the keyboard to trigger several different serial messages. Opening the port still resets the Nano, but now I can send whatever serial string I want and it works fine.

    Do you know what is going on when the serial port opens? The fact that my serial messages don't reset the Nano indicates that opening the port does something special that doesn't happen in normal serial communications, eg, some kind of command that causes the 340/FTDI USB-TTL chip to issue a DTR low signal?

    Dr Quark

  • When Processing connects to the chosen serial port the 'DTR' signal is pulsed low. This is hidden from the user by the USB connection. If you absolutely need your Processing sketch to not reset your Nano the first time it connects then using the information from the link I provided is probably the way to proceed.

Sign In or Register to comment.