Arduino Communiction

This works great for sending values to the board through USB, or with Bluetooth (for the Metabot).

There is however an issue when receiving data:
score reports that the data is received in the message window:
Debug: “1\n” (serial_protocol:49)
similarly as when data is sent out witch shows on the message window as follows:
Debug: “1\n” (serial_protocol:90)

The problem is to allocate the value to an address in the Serial Device tree.
The “function onMessage(message)” does not seem to return anything.
I tried adding a “console.log(message)” inside but it had no effect on the message window.

here is the little qml code:

import QtQuick 2.0
import Ossia 1.0 as Ossia

QtObject {

function openListening(address) {}
function closeListening(address) {}

function onMessage(message) {
console.log(message);
return [{address: recieve, value: message}];
}

function createTree() {
return [ {
name: “led”,
type: Ossia.Type.Int,
request: “$val”,
access: Ossia.Access.Set
},
{
name: “recieve”,
type: Ossia.Type.Int,
access: Ossia.Access.Get
} ];
}
}

The problem could be that the function “onMessage()” dosen’t recognise “\n” as the end of a message and still waits. Just a wild gess.

Hi @thibaudk and welcome !

Thanks for the post. I have no idea about the answer, but at least that’s a good intro for people wanting to use QML/serial protocol.

Oh, and a little welcome hint:

You can use those funny little quotes: ` (3 of them) to have your code nicely laid out, with its indentation kept, and all…

Something like this:


import QtQuick 2.0
import Ossia 1.0 as Ossia

QtObject {

     function openListening(address) {}
     function closeListening(address) {}

     function onMessage(message) {
     console.log(message);
     return [{address: recieve, value: message}];
}

function createTree() {
     return [ {
          name: “led”,
          type: Ossia.Type.Int,
          request: “$val”,
          access: Ossia.Access.Set
          },
          {
          name: “recieve”,
          type: Ossia.Type.Int,
          access: Ossia.Access.Get
          } ];
     }
}

I think that it should be

     return [{address: "/recieve", value: message}];

instead (also it should be “receive” in place of “recieve” :p)

Thanks @bltzr!
It does look a lot better.

Thanks @jcelerier ! I updated the code but so far, the values still aren’t updated.
I also added the “access”, “bounding” and “repetition filter” parameters.
“bounding” and “repetition filter” are shown to be updated on the bottom part of the Device explorer but “min”, “max” and “Access” aren’t.
Could the addresses be stuck in “set” mode, although they look to remain in “bi” mode?

import QtQuick 2.0
import Ossia 1.0 as Ossia

QtObject {

     function openListening(address) {}
     function closeListening(address) {}

     function onMessage(message) {
     console.log(message);
     return [{address: "/receive", value: message}];
}

      function createTree() {
        return [ {
                     name: "led",
                      type:  Ossia.Type.Int,
	              min : 0,
	              max : 1,
	              request: "$val",
                      access: Ossia.Access.Set,
                      bounding: Ossia.Bounding.Clip,
                      repetition_filter: Ossia.Repetitions.Filtered
                        },
                       	{
                            name: "receive",
                            type:  Ossia.Type.Int,
                            access: Ossia.Access.Get
          } ];
     }
}

To match the syntax of messages that score sends out, I made sure the values i receive appear in the message window as “1\n” for exemple.
adding the “\n” I assume finishes the message.
Is the function onMessage(message) bufferized and expecting a certain character of command to consider the end of a message (presumably “\n”)?
Similar to what is done around the 9 min mark in this video:

i’d like to be able to verify this for myself but the “console.log(message)” dosen’t output anything either.

it now works, just use

 return [{address: "/receive", value: parseInt(message.split(',')[0])}];

to get the first int for instance

1 Like

Perfect!
Will start working on a few examples to go with the metabot one!

Chears!