Sysex messages issue/question

About Forums Forum Troubleshooting Sysex messages issue/question

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #568
    kalanda
    Participant

    Hi,

    First, thanks a lot for this great project. It’s a piece of art 😉

    My question/issue is about Sysex messages from arduino to breakoutjs. I don’t know if the behaviour is correct or not. I hope to explain correctly in english.

    When I send Sysex commands from the browser to arduino, with a line as below:

    // Javascript
    arduino.sendSysex(0x01,[9,8,7,6,5,4,3,2,1]);

    In the arduino side I have this code:

    // Arduino
    void sysexCallback(byte command, byte argc, byte*argv)
    for (byte i=0;i<argc; i++){
    lcd.print(argv[i], DEC);
    }
    }

    I get the exact values in the LCD. ('987654321')

    Right, my issue is when I send a Sysex message from Arduino to the browser. For example, if I send as below:

    // Arduino
    byte values[3] = {1,2,3};
    Firmata.sendSysex(55, 3, values); // 55 is my custom command

    In the browser I have this code:

    // Javascript
    function onSysexMessage(event) {

    console.log("sysex received: " + event.message);

    }

    And I get in the console log:
    [55, 1, 0, 2, 0, 3, 0]

    MY QUESTION IS: Why I get that "0" between each value of the array? Is it normal?

    Thank a lot in advance for your support.

    #569

    This is because Firmata.sendSysex splits each byte in the array into 2 bytes because Firmata is based on midi which sends data in 7-bit pieces. You need to assemble each pair of 7 bit values when you receive them in onSysexMessage() using the following method:

    arduino.getValueFromTwo7bitBytes(LSB, MSB]);

    This helps keep data in sync. Another way people do this with other protocols is to use a checksum but I think using either method uses roughly the same number of clock cycles.

    I see you’ve also discovered the more advanced use of Breakout (writing your own firmware rather than using StandardFirmata). I plan to write a tutorial on this approach in the near future. Also refer to the examples in custom_examples if you have not already.

    #570
    kalanda
    Participant

    Great!

    Thanks for the quick answer.

    Yes, I need my own protocol because I’m developing a desktop control for my hardware project “Photoduino”. If you want to know more about visit http://www.photoduino.com

    Currently, Photoduino is using a buttons/LCD based interface but in some situations is a bit hard to configure when you are testing values to take photos. Before I discover Breakoutjs, I did some test using P5websocket library (also based in webbit) to make the serial bridge using a modified version of https://github.com/kalanda/serial2socket-proxy for use websockets instead tcp sockets, but with some problems with charset encoding with values over the standard 127 ASCII chars.

    BreakoutJS lets me a better framework to do what I want.

    Thanks again,

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.