Old 01-20-2019, 02:10 PM   #1
Kaitain
Human being with feelings
 
Join Date: Nov 2016
Posts: 34
Default Recieve from serial

Hi folks. I'm stucked here and I'd appreciate some help.

I'm trying to send float values from my controller to OSCii Bot. I was thinking about using SysEx to do that, as posted here:

https://forum.cockos.com/showthread.php?t=215957

But as SysEx sends group of bytes (of which only 7 bits per byte are used) it seems more difficult than expected, specially the part of reconstructing the float value in the script using the separated bytes.

But the point is that my controller generates normalized values between 0 and 1, and as the controller can send directly over serial (meaning that is not necesary for the messages to have MIDI format), is it possible to recieve data directly from the serial port in OSCii bot? (AFAIK Oscii bot only receives messages if they have MIDI (@midimsg) or OSC(@oscmsg) format)

What would be the best way to accomplish this?

Cheers!
Kaitain is offline   Reply With Quote
Old 01-22-2019, 07:15 AM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,793
Default

OSCIIBot only can attach to Midi devices and to TCP ports (OSC).

Does your controller do "serial" data in hardware ?

If so, you need to set the port to 31250 Baud and adhere to the Midi protocol in your software. Moreover you need appropriate hardware to adhere o the midi 5-Pin hardware specs. And of course use a Midi I/O device to connct your controller to the Computer.

Or does your controller do "???" over USB ? If so you need to use a "family" Midi-USB library to make the controller be accepted as a Midi device in the computer.

-Michael

Last edited by mschnell; 01-25-2019 at 06:06 AM.
mschnell is online now   Reply With Quote
Old 01-23-2019, 09:06 AM   #3
Kaitain
Human being with feelings
 
Join Date: Nov 2016
Posts: 34
Default

Hi mschnell

My controller uses a Teensy 3.2, so it can send serial over USB, and also is recognized as a MIDI device in the computer. So maybe I could receive random serial data in OSCBot using msg1, msg2.. etc? I've never thought of that, I'll try it toda.

Thank you!
Kaitain is offline   Reply With Quote
Old 01-25-2019, 06:03 AM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,793
Default

There was a typo in my message

OSCBot can receive "random" MIDI data. It can't connect to a "COMx" device in Windows, but just to a MIDI device. But if your µC is recognized by Windows as an USB Midi device this will be fine.

Of course you need to adhere to the Midi spec and send only messages that start with a Byte with bit 7 set and the bytes with bit seven cleared (SysEx: 0xF0, ..... 0xF7)

-Michael

Last edited by mschnell; 01-25-2019 at 06:10 AM.
mschnell is online now   Reply With Quote
Old 01-27-2019, 04:26 AM   #5
Kaitain
Human being with feelings
 
Join Date: Nov 2016
Posts: 34
Default

Yes, I've checked that it can't receive random serial.
It can receive "random MIDI" = Sysex, but as you said, always addering to the MIDI protocol.

Thanks!
Kaitain is offline   Reply With Quote
Old 01-27-2019, 02:32 PM   #6
Kaitain
Human being with feelings
 
Join Date: Nov 2016
Posts: 34
Default

Some progress here.
What I'm trying to achieve is to send a float number fom my MIDI controller (Teensy) to OSCiiBot. This float number is normalized to 1024, so it has decimals and it goes from 0 to 1.
So far I've manged to pack this float into a SysEx message, like this:

for (int i = 0; i <= 3; i++) {
paramValMSB[i] = (mapped.bytes[i] >> 4) & B00001111;
paramValLSB[i] = mapped.bytes[i] & B00001111;
}

// SysEx message assemby
uint8_t buff[] = {SysExStart, paramNumMSB, paramNumLSB, paramValMSB[0], paramValLSB[0], paramValMSB[1], paramValLSB[1], paramValMSB[2], paramValLSB[2], paramValMSB[3], paramValLSB[3], SysExEnd};

// Sens SysEx
UsbMIDI.sendSysEx(sizeof(buff), buff, true);

A float has 4 bytes. And I had to split evey one of the 4 bytes of the float variable (paramVal) into 2 bytes (MSB and LSB), in order to have the bit 7 set to 0 on each byte, according to the MIDI protocol. Although this is not a very efficient solution it works.

Now, in OSCii Bot I wrote this to receive and reconstruct each byte:

valByte0 = ((str_getchar(oscstr, 3) << 4) & 0xF0) | str_getchar(oscstr, 4);
valByte1 = ((str_getchar(oscstr, 5) << 4) & 0xF0) | str_getchar(oscstr, 6);
valByte2 = ((str_getchar(oscstr, 7) << 4) & 0xF0) | str_getchar(oscstr, 8);
valByte3 = ((str_getchar(oscstr, 9) << 4) & 0xF0) | str_getchar(oscstr, 10);

Checking every one the bytes received, they match byte per byte with the ones sent from the controller. So far so good.

Now, the problem is how to construct a float number with these four bytes. I tryed this:

val = ((valByte3 << 24) & 0xFF000000) | ((valByte2 << 16) & 0xFF0000) | ((valByte1 << 8) & 0xFF00) | valByte0;

And although I get a 4 byte value with the 4 bytes in their right position and order, the value is interpreted as an integer. It doesn't follow the IEEE protocol: taking some bits for the sing, some for the exponent and some for the mantisa (which are indeed observed at the Arduino IDE on the other end). This is something I don't understand because inthe OSCii bot code reference says "Variables do not need to be declared, are by default global, and are all double-precision floating point".

So my question is this: how can I construct a float value in OSCii bot starting from 4 bytes? Is there any chance to make some casting like "float(var)" or something? (I tried, didn´t work).

Sorry for the very long post, but I couldn`t find a sorter way to explain this
Kaitain is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.