EInitialized never fired with ofArduino

hi everyone, I’m facing a problem with OF 0.8.1 and ofArduino (using standardFirmata sketch).
Basically, it never fires the EInitialized event. The only way to make it work…is to open the Arduino IDE, and connect with the console, then it seems to “unlock” the port and it works fine.

I’m on Linux Debian Wheezy 64bit

Here is the classic code

void Arduino::setup(){
  arduino.connect(ARDUINO_PORT, ARDUINO_BAUDRATE);
  ofAddListener(arduino.EInitialized, this, &Arduino::setupArduino);
}

void Arduino::update(){
    arduino.update();
}

void Arduino::setupArduino(const int & version){
    cout << "Setup Arduino OK!" << endl;
    ofRemoveListener(arduino.EInitialized, this, &Arduino::setupArduino);
    // this is where you setup all the pins and pin modes, etc
    for (int i = 0; i < PINS_COUNT ; i++){
        arduino.sendDigitalPinMode(arduinoPins[i], ARD_INPUT);
    }
    ofAddListener(arduino.EDigitalPinChanged, this, &Arduino::digitalPinChanged);
}

I’ve solved using the workaround for the Raspberry Pi, reported here.

stty raw crtscts -F /dev/ttyACM0

…or much better, editing ofSerial.cpp, adding these lines in row 375

options.c_cflag |= CRTSCTS;
options.c_lflag &= ~(ICANON | ECHO | ISIG);

Thanks a lot.
That helped me very much.
:smile:

That solved my problem with connecting Arduino to Raspberry Pi via a Serial-to-USB cable (Raspbian Wheezy). Thank you!

I understood, that the CRTSCTS line enables the RTS/CTS handshake in the serial protocol. Can you please explain what the second line does?

It enables raw mode, to reproduce the “raw” parameter in stty.

Wow, fast answer, thank you!

opening IDE and monitor, closing monitor, this workaround helps me .
thanks!.

it also fire the event when i I pressed the reset button on the arduino,

But its impossible for me to press the button everytime i turn on the program… does anyone know a workaround in code?

Patching ofSerial.cpp works for me too! Thanks @vcuculo!

I’m using: oF 0.9.3 and Arduino 1.6.7 StandardFirmata.
Do mind that the line numbers have changed in oF 0.9.3.
I’ve added these lines after line 363.

So, in total:
options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_iflag &= (tcflag_t) ~(INLCR | IGNCR | ICRNL | IGNBRK); options.c_oflag &= (tcflag_t) ~(OPOST); options.c_cflag |= CS8; options.c_cflag |= CRTSCTS; options.c_lflag &= ~(ICANON | ECHO | ISIG); tcsetattr(fd, TCSANOW, &options);

1 Like

There are still some bug…
If I put usb direct to arduno.It works fine.
But if i use a usb-ttl device.Now the port is /dev/ttyUSB0
Then it only can receive data.But can not send data…

1 Like