Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: openFrameworks serial communicaton

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Location
    Paris
    Posts
    13

    openFrameworks serial communicaton

    Hello

    My teensy project is a simple 16 by 16 analog pressure sensor matrix.
    I'm using openFrameworks C++ library to graph teensy analogue sensors values.

    I have an weird issue with the openFrameworks serial library. I'm using Teensyduino 1.28 on linux.
    The Teensy is programmed in Serial Mode - 72 MHz

    If I run my openframeworks programme I don't receive any teensy serial data. If I open the arduino serial monitor after that my openframeworks programme start to read correctly all the teensy serial data.

    Arduino partial code
    Code:
    void UsbTransmit() {
    
      if ( ( millis() - lastFrameTime ) >= FRAME_RATE ) {
    
        lastFrameTime = millis();
    
        for ( int row = 0; row < ROW; row++ ) {
          // Set row pin as output +3V
          pinMode( rowPins[row], OUTPUT );
          digitalWrite( rowPins[row], HIGH );
    
          for ( int column = 0; column < COL; column++ ) {
    
            int value = analogRead( columnPins[column] ); // Read the sensor value
    
            Serial.write( value & B01111111 );            // Write lowByte
            Serial.write( (value >> 7) & B00000111 );     // Write highByte
          }
          Serial.send_now(); // Send 32 bytes now
    
          // Set row pin in high-impedance state
          pinMode( rowPins[row], INPUT );
        }
        Serial.write( 255 ); // Write the footer
        Serial.send_now();      // Send the footer now
      }
    }
    openframeworks partial code
    Code:
    void ofApp::setup(){
      serial.setup( "dev/ttyACM0" , 230400 ){
    }
    
    void ofApp::update() {
    if( serial.available() ) {
        inputValue = serial.readByte();
        if ( inputValue == FOOTER ) {
            index = 0;
        }else {
            serialData[index] = inputValue;
            index++;
        }
    }

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    Try running: lsusb -v in a terminal before and after you load the serial monitor.
    It sounds like openframeworks isn't setting up the serial communication correctly

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Location
    Paris
    Posts
    13
    Quote Originally Posted by Xenoamor View Post
    Try running: lsusb -v in a terminal before and after you load the serial monitor.
    It sounds like openframeworks isn't setting up the serial communication correctly
    I restart my laptop
    I do : lsusb -v > ~/Bureau/lsusb1

    I plug the teensy to my laptop
    I do : lsusb -v > ~/Bureau/lsusb2

    I do : diff ~/Bureau/lsusb1 ~/Bureau/lsusb2

    Code:
    1a2,93
    > Bus 002 Device 008: ID 16c0:0483 Van Ooijen Technische Informatica Teensyduino Serial
    > Device Descriptor:
    >   bLength                18
    >   bDescriptorType         1
    >   bcdUSB               2.00
    >   bDeviceClass            2 Communications
    >   bDeviceSubClass         0 
    >   bDeviceProtocol         0 
    >   bMaxPacketSize0        64
    >   idVendor           0x16c0 Van Ooijen Technische Informatica
    >   idProduct          0x0483 Teensyduino Serial
    >   bcdDevice            1.00
    >   iManufacturer           1 Teensyduino
    >   iProduct                2 USB Serial
    >   iSerial                 3 559180
    >   bNumConfigurations      1
    >   Configuration Descriptor:
    >     bLength                 9
    >     bDescriptorType         2
    >     wTotalLength           67
    >     bNumInterfaces          2
    >     bConfigurationValue     1
    >     iConfiguration          0 
    >     bmAttributes         0xc0
    >       Self Powered
    >     MaxPower              100mA
    >     Interface Descriptor:
    >       bLength                 9
    >       bDescriptorType         4
    >       bInterfaceNumber        0
    >       bAlternateSetting       0
    >       bNumEndpoints           1
    >       bInterfaceClass         2 Communications
    >       bInterfaceSubClass      2 Abstract (modem)
    >       bInterfaceProtocol      1 AT-commands (v.25ter)
    >       iInterface              0 
    >       CDC Header:
    >         bcdCDC               1.10
    >       CDC Call Management:
    >         bmCapabilities       0x01
    >           call management
    >         bDataInterface          1
    >       CDC ACM:
    >         bmCapabilities       0x06
    >           sends break
    >           line coding and serial state
    >       CDC Union:
    >         bMasterInterface        0
    >         bSlaveInterface         1 
    >       Endpoint Descriptor:
    >         bLength                 7
    >         bDescriptorType         5
    >         bEndpointAddress     0x82  EP 2 IN
    >         bmAttributes            3
    >           Transfer Type            Interrupt
    >           Synch Type               None
    >           Usage Type               Data
    >         wMaxPacketSize     0x0010  1x 16 bytes
    >         bInterval              64
    >     Interface Descriptor:
    >       bLength                 9
    >       bDescriptorType         4
    >       bInterfaceNumber        1
    >       bAlternateSetting       0
    >       bNumEndpoints           2
    >       bInterfaceClass        10 CDC Data
    >       bInterfaceSubClass      0 Unused
    >       bInterfaceProtocol      0 
    >       iInterface              0 
    >       Endpoint Descriptor:
    >         bLength                 7
    >         bDescriptorType         5
    >         bEndpointAddress     0x03  EP 3 OUT
    >         bmAttributes            2
    >           Transfer Type            Bulk
    >           Synch Type               None
    >           Usage Type               Data
    >         wMaxPacketSize     0x0040  1x 64 bytes
    >         bInterval               0
    >       Endpoint Descriptor:
    >         bLength                 7
    >         bDescriptorType         5
    >         bEndpointAddress     0x84  EP 4 IN
    >         bmAttributes            2
    >           Transfer Type            Bulk
    >           Synch Type               None
    >           Usage Type               Data
    >         wMaxPacketSize     0x0040  1x 64 bytes
    >         bInterval               0
    > Device Status:     0x0000
    >   (Bus Powered)
    > 
    63c155
    <    Port 2: 0000.0100 power
    ---
    >    Port 2: 0000.0103 power enable connect
    I launch my openframework application that read incoming data.
    I do : lsusb -v > ~/Bureau/lsusb3

    I do : diff ~/Bureau/lsusb2 ~/Bureau/lsusb3
    Nothing different
    Last edited by Maurin; 04-19-2016 at 02:20 PM.

  4. #4
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    Sorry! I got mixed up between that and another configuration. At least we can confirm the enumeration is happening correctly
    Try the same with: stty -F /dev/ttyXX
    Where ttyXX is your device

  5. #5
    Junior Member
    Join Date
    Oct 2014
    Location
    Paris
    Posts
    13
    I launch my openframework application that read incoming data.
    I do : stty -F /dev/ttyACM0
    Code:
    speed 230400 baud; line = 0;
    -brkint -icrnl -imaxbel
    -opost
    I launch Arduino serial monitor see incoming data
    then I do : stty -F /dev/ttyACM0
    Code:
    speed 230400 baud; line = 0;
    min = 0; time = 0;
    -brkint -icrnl -imaxbel
    -opost
    -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

  6. #6
    Junior Member
    Join Date
    Oct 2014
    Location
    Paris
    Posts
    13
    The mistake seems to be in the serial configuration file.
    How can I modify it to have the same config than Arduino serial monitor?

    https://github.com/openframeworks/op...n/ofSerial.cpp

  7. #7
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    It seems the settings are set here
    I'll see if I can figure this out for you without you having to use a system(""); command


    EDIT -
    Right so <termios.h> holds all the settings for the serial communication.
    What you want to do is add a line near 137 to modify the c_lflag.
    See here for details
    So I believe you want:
    Code:
    options.c_lflag &= (tcflag_t) ~(ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK |  ECHONL);
    It may just be this actually, I'm really not familiar with it I must admit
    Code:
    options.c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK |  ECHONL;
    Last edited by Xenoamor; 04-20-2016 at 01:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •