Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 26 to 50 of 60

Thread: how many serial tx rx inputs

  1. #26
    Thanks Paul, as Headroom said this above my skill level. but thats ok i'll keep pushing ahead.
    The plan is to have each imu device( this includes a 9dof sensor with its microcontroller to do fusion)
    that kit will eventually be wireless. getting it started I was planning on using serial because it is still
    in testing.

    By going RS485 would I be able to easily go wireless or would I have to rebuild and recode?
    Going wireless means each kit( imu plus microcontroller) would be bluetooth or some other form for a total
    of 15 kits wireless

    By going to dedicated serial ports my plan would be to use 3 kits(imu with its mcu for fusion) per teensy
    being that the teensy has 3 serial hardware ports. With 4 limbs and another for head shoulder and chest it would be
    5 kits and of course 5 teensy 3.1 recieving the information.
    All the teensy data would be sent through i2c. being that they would be in a very close range maybe even in the
    same case. That 6th teensy would collect all the data and send it to the pc.

  2. #27
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    ypur motivation should not be to avoid having to rewrite code. You'll be doing that anyway ;-)

    Start with a simple prototype to gain confidence. One IMU and one MCU and see what you can get to work. When you have that completed to some degree you'll see clearer what a path forward is.

    If you really think you won't have to rewrite code going from any wired solution to completely wireless then that is highly unlikely ;-)

  3. #28
    Thanks headroom for the reply.
    I dont want to make it sound like I wouldnt want to rewrite the project, im just putting out the questions
    to see what yourself and other more advanced technicians think from your experiences.

    Ive been working on this for 2 years and I know it has time still.

    I am actually taking your advice on working on one first. As you can see on the potentiometer version i
    went first with simple data input and now i'm moving up from single axes sensors to these triple axes sensors.

    In theory it would be just a matter of changing out one type of sensor to another. but this is a larger picture look

  4. #29
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    Using Bluetooth for your application would rather expensive,

    How about using a RFM69 RF module as described here

    Whatever wired solution you use I2C, RS485, serial you will likely be rewriting larger portions of code.

  5. #30
    Quote Originally Posted by Headroom View Post
    Using Bluetooth for your application would rather expensive,

    How about using a RFM69 RF module as described here

    Whatever wired solution you use I2C, RS485, serial you will likely be rewriting larger portions of code.

    Well Ive been able to find bluetooth for as low as $5
    All in all it is going to be in investment because being able to do motion capture really
    pushes the ability to produce more animation.
    even with my first version ( the small scale skeleton) is a great production tool.

  6. #31
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    I doubt that ;-)

    You've found a piece of electronics that states Bluetooth capability and you like the price.
    Does it have a well written spec sheet in English and not some Chinglish mambo jumbo ?
    Are there other support documents such as application notes avaliable form the reputable manufacturer and is there technical customer support ?
    Most importantly for you to get anything done with your current skills at hand, is there a currently maintained Arduino library available ?

    A mistake many newcomers make ( I stepped onto that trap as well ) is that they only look at the cool hardware but forget to look at the software side. The Arduino libraries very often shield a user from having to deal with register settings and protocol specifications etc. the best hardware can be rendered useless if its functionality it's not accessible to the user because he lacks the skills.

    The Tutorial on the RFM69 modules was written by one of the most knowledgable folks here on the forum. You have questions, you'll likely get very specific answers that'll help you find a solution for your problem. If you but come cheap piece of hardware on Dealextreme that's not likely to happen.

  7. #32
    I actually havent bought one yet but I have seen it
    and have seen it working.
    Whether it works and works well would have to come by testing.
    But even if I have to go with acouple wireless products that cost $100 each if its needed because of stability then I am definitely going to buy them, but testing a couple 5 10 dollar isnt bad.
    and ive seen on sparkfun wireless and bluetooth for $30 -$99 bucks.

  8. #33
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    921
    Quote Originally Posted by ben10teensy View Post
    I actually havent bought one yet but I have seen it
    and have seen it working.
    Whether it works and works well would have to come by testing.
    But even if I have to go with acouple wireless products that cost $100 each if its needed because of stability then I am definitely going to buy them, but testing a couple 5 10 dollar isnt bad.
    and ive seen on sparkfun wireless and bluetooth for $30 -$99 bucks.
    There are some 'good' cheap bluetooth modules - i use the HC07, works robustly with android phone controlling the Teensy Led array. HOWEVER, as far as I know, pairing for bluetooth is still for single device, and not multiple simultaneously, where radio devices can be multiple. That is, you can pair/recognise more than one bt device, but not use simultaneously. I guess that this would entail rapid polling between the series of bt devices paired, but in essence one conversation at a time.

  9. #34
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    921
    as an update, I just did a quick test for running two HC07 bluetooth devices at the same time on a single teensy 3.1, using serial1 and serial3 to receive data from two different bluetooth transmitting devices (android phone and macbook). The received data was text based and output to the serial terminal on the arduino IDE. it worked just fine with serials 1 and 3, but not serials 1 and 2. Have not checked the acquisition/polling rate. the setup was along the lines of:
    Code:
      Serial1.begin(9600); //using teensy3.1 rx1=pin0 and tx1=pin1
      delay(500);
      Serial3.begin(9600);// using teensy3.1 rx3=pin7 and tx3=pin8
      delay(500);
    and the loop was:
    Code:
        if (Serial.available()) {Serial1.write(Serial.read()); Serial3.write(Serial.read());  }
        
      while(Serial1.available() > 0) { // While there is more to be read, keep reading.
        command += (char)Serial1.read();
        delay(10);
      }
      
      while(Serial3.available() > 0) { // While there is more to be read, keep reading.
        command += (char)Serial3.read();
        delay(10);
      }
    where "command" was the text send from either device
    Code:
    String command = "";

  10. #35
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,851
    IIRC, Serial1 (0/1) and Serial2 (9/10) have hardware FIFO queues of 8 bytes, while Serial3 does not have a FIFO queue, but at 9600 baud, the Teensy should have enough cpu cycles that it should not matter on the above script. If you were running long strings of ws2812's (i.e. neopixels) that turn off interrupts for an extended period of time, then perhaps it would matter.

    In other embedded environments, the String library is problematical, in that with limited memory, the dynamic allocation eventually fails. You might consider using fixed sized buffers and explicit pointers/indexes within the buffer.
    Last edited by MichaelMeissner; 11-13-2014 at 12:28 PM.

  11. #36
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    921
    Thanks Michael. A bad habit of mine is to test comms and code using string / char values as a lazy way to check connectivity.
    And, of course, just tested with byte, and serials 1 and 2 receive bluetooth data at the same time (as you already knew they would )
    Last edited by mortonkopf; 11-13-2014 at 12:59 PM.

  12. #37
    Hey all an update on the project
    I have the teensy receiving data on HWSERIAL lines
    And I'm able to print what's coming in and my data is coming in correctly
    90.1,55.6,125.9
    This is an example of what is coming in the rx line.
    Now I'm looking at different examples on how to separate this incoming data to be used
    My question is how would I grab the first set and turn it into an int or whatever would be needed to convert it
    To midi data ?

  13. #38
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    Quote Originally Posted by ben10teensy View Post
    90.1,55.6,125.9
    This is an example of what is coming in the rx line.
    Is it always formatted like this, e.g.

    <float number><comma><float number><comma><float number><newline>

    If so, you could store the serial chars into an appropriately-sized char buffer until you see the newline, then use something like

    sscanf(serialBuffer, "%f,%f,%f", &var1, &var2, &var3);

    to parse out the numbers.

  14. #39
    Yes sir
    It's coming in fast. But it maintains it's format of float,float,float
    Then it has a return or a new line
    So it comes in
    90.8,89.8,120.5
    91.6,88.6,116.8
    And so on...
    ...
    ..
    ..

  15. #40
    how would I setup the buffer?
    Ive seen examples of Serial.readBytesUntil(character, buffer, length)
    but not sure how to mix what you have with this

  16. #41
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    Sorry I'm not in front of a Teensy so I can't give you actual working code but hopefully this is enough to get you started

    Code:
    #define BUFFER_SIZE 64
    
    char buffer[BUFFER_SIZE];
    int bufferIndex = 0;
    float val1, val2, val3;
    
    for (;;) {
        if (Serial1.available() > 0) {
            buffer[bufferIndex] = Serial1.read();
            if (buffer[bufferIndex]=='\n') {
                buffer[bufferIndex]='\0';
                break;
                }
            if (bufferIndex<(BUFFER_SIZE-1)) {
                bufferIndex++;
                }
            }
        }
    
    sscanf(buffer, "%f,%f,%f", &val1, &val2, &val3);

  17. #42
    OK thanks
    I will try it
    Are there any variables I need to switch out?
    Also can i add print(val1);
    to see its value?

  18. #43
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    You might need to adjust BUFFER_SIZE for your implementation, although if it's 3 floats with a single digit in the fraction part you should be fine with a 64 char buffer.

    You can absolutely use prints to see the values you're getting out, in fact I'd probably have prints all over the place while I'm testing & debugging, e.g. after

    buffer[bufferIndex] = Serial1.read();

    I'd put

    Serial.print("Read character '");
    Serial.println(buffer[bufferIndex]);

    until I knew it was working, then I'd comment them out or delete them.

    Good luck!

  19. #44
    ok so i cleaned up the code a little since im not using the button functions
    how does it look. remember I am just replacing what was a analog potentiometer with the values coming in from the
    tx rx of the IMU. Hopefully I can replace the variables and make it work.


    /////////////////////////////////////////////////////////////////////////////////

    /* USB MIDI AnalogControlChange Example

    You must select MIDI from the "Tools > USB Type" menu
    http://www.pjrc.com/teensy/td_midi.html

    This example code is in the public domain.
    */

    #define BUFFER_SIZE 64
    #include <Bounce.h>

    char buffer[BUFFER_SIZE];
    int bufferIndex = 0;
    float val1, val2, val3;


    // the MIDI channel number to send messages
    const int channel1 = 1;
    const int channel2 = 2;
    const int channel3 = 3;
    const int channel4 = 4;
    const int channel5 = 5;
    const int channel6 = 6;
    const int channel7 = 7;
    const int channel8 = 8;
    const int channel9 = 9;
    const int channel15 = 15;
    const int channel16 = 16;


    // the MIDI continuous controller for each analog input
    const int controllerA0 = 11; // 10 = pan position
    const int val1 = 11; // 11 = volume/expression
    const int controllerA2 = 11; // 91 = reverb level
    const int controllerA3 = 11; // 93 = chorus level
    const int controllerA4 = 11; // 93 = chorus level
    const int controllerA5 = 11; // 93 = chorus level
    const int controllerA6 = 11; // 93 = chorus level
    const int controllerA7 = 11; // 93 = chorus level
    const int controllerA8 = 11; // 93 = chorus level
    const int controllerA9 = 11; // 93 = chorus level
    const int controllerA10 = 11; // 93 = chorus level
    const int controllerA11 = 11; // 93 = chorus level
    const int controllerA12 = 11; // 93 = chorus level
    const int controllerA13 = 11; // 93 = chorus level
    const int controllerA14 = 11; // 93 = chorus level

    void setup() {


    }

    // store previously sent values, to detect changes

    int previousA0 = -1;
    int previousA1 = -1;
    int previousA2 = -1;
    int previousA3 = -1;
    int previousA4 = -1;
    int previousA5 = -1;
    int previousA6 = -1;
    int previousA7 = -1;
    int previousA8 = -1;
    int previousA9 = -1;

    //

    elapsedMillis msec = 0;

    void loop()
    {

    for (;; {
    if (Serial1.available() > 0) {
    buffer[bufferIndex] = Serial1.read();
    if (buffer[bufferIndex]=='\n') {
    buffer[bufferIndex]='\0';
    break;
    }
    if (bufferIndex<(BUFFER_SIZE-1)) {
    bufferIndex++;
    }
    }
    }

    //
    //
    if (msec >= 20) {
    msec = 0;
    int n15 = analogRead(A0) / 8;
    int n1 = val1;
    int n2 = analogRead(A2) / 8;
    int n3 = analogRead(A3) / 8;
    int n4 = analogRead(A4) / 8;
    int n5 = analogRead(A5) / 8;
    int n6 = analogRead(A6) / 8;
    int n7 = analogRead(A7) / 8;
    int n8 = analogRead(A8) / 8;
    int n9 = analogRead(A9) / 8;



    // int n7 = analogRead(A7) / 8;
    // only transmit MIDI messages if analog input changed
    if (n1 != previousA1) {
    usbMIDI.sendControlChange(controllerA1, n1, channel1);
    previousA1 = n1;
    }


    //delay(50);
    //

    }

    // MIDI Controllers should discard incoming MIDI messages.
    // http://forum.pjrc.com/threads/24179-...ses-midi-crash
    while (usbMIDI.read()) {
    // ignore incoming messages
    }
    }
    sscanf(buffer, "%f,%f,%f", &val1, &val2, &val3);

  20. #45
    I was just trying the code and I get an error.

    c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-writer.o): In function `_write_r':
    writer.c.text+0x16): undefined reference to `_write'
    collect2.exe: error: ld returned 1 exit status

  21. #46
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    Quote Originally Posted by ben10teensy View Post
    I was just trying the code and I get an error.

    c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-writer.o): In function `_write_r':
    writer.c.text+0x16): undefined reference to `_write'
    collect2.exe: error: ld returned 1 exit status
    Is post #44 your complete code? When I cut & paste it into the Arduino editor and try to verify I get

    Arduino: 1.0.5 (Windows XP), Board: "Teensy 3.1"
    sketch_nov25a:35: error: conflicting declaration 'const int val1'
    sketch_nov25a:16: error: 'val1' has a previous declaration as 'float val1'
    sketch_nov25a.ino: In function 'void loop()':
    sketch_nov25a:75: error: expected primary-expression before '{' token
    sketch_nov25a:75: error: expected ')' before '{' token
    sketch_nov25a:108: error: 'usbMIDI' was not declared in this scope
    sketch_nov25a:108: error: 'controllerA1' was not declared in this scope
    sketch_nov25a:120: error: 'usbMIDI' was not declared in this scope
    sketch_nov25a.ino: At global scope:
    sketch_nov25a:124: error: expected constructor, destructor, or type conversion before '(' token
    and I don't see any reference to "write" at all.

  22. #47
    OK so I got the sscanf working
    I needed to add the #include <string.h>

    But not as I print the data it is not updating
    here is the code im using on the teensy 3.1

    #define BUFFER_SIZE 64
    #define HWSERIAL Serial1
    #include <string.h>
    char buffer[BUFFER_SIZE];
    int bufferIndex = 0;
    float val1, val2, val3;

    String incoming1;
    String Xrot;
    String Yrot;
    String Zrot;
    //String myString;
    // Search for the next comma just after the first

    //char pch;
    int led = 13;

    //int j = ',';
    //int i;
    //int x;
    //int var1 = 0;

    void setup() {
    Serial.begin(57600);
    HWSERIAL.begin(57600);
    pinMode(led, OUTPUT);


    }


    void loop() {
    for (; {
    if (Serial1.available() > 0) {
    buffer[bufferIndex] = Serial1.read();
    if (buffer[bufferIndex]=='\n') {
    buffer[bufferIndex]='\0';
    break;
    }
    if (bufferIndex<(BUFFER_SIZE-1)) {
    bufferIndex++;
    }
    }

    }

    //Recieving value and Seperating

    sscanf(buffer, "%f,%f,%f", &val1, &val2, &val3);
    Serial.print("Xrot = ");
    Serial.print(val1);
    Serial.print('\t');
    Serial.print("Yrot = ");
    Serial.print(val2);
    Serial.print('\t');
    Serial.print("Zrot = ");
    Serial.println(val3);


    }

  23. #48
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    If you add this

    Serial.print("Got data from serial: \"");
    Serial.print(buffer);
    Serial.println("\"");

    right before the sscanf() line, do you see output?

    If not, try adding some debugging prints inside the for() loop and make sure you're receiving the serial data.

  24. #49
    Yes it outputs
    but the same number repeats even if i move the sensor

  25. #50
    I added these lines and it updates
    so I guess the buffer receives one message and doesn't refresh

    Xrot = HWSERIAL.readStringUntil(',');
    Serial.print(Xrot);
    Serial.println("\"");

Tags for this Thread

Posting Permissions

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