Dear users and developers,
I tested the following USB proximity sensor with Bela unit.
https://www.maxbotix.com/ultrasonic_sensors/mb1403.htm
I connected the sensor into the USB port on the BeagleBone Black board.
SuperCollider recognise it as
/dev/ttyUSB0
when inquiring the connected USB devices:
SerialPort.listDevices
However, it seems to receive only the lowest value from the device.
Is there something wrong in my code?
(
s.waitForBoot{
var readRate = 4;
SerialPort.closeAll;
2.wait;
~port = SerialPort( "/dev/ttyUSB0"/*"/dev/tty.usbserial-10"*/, baudrate: 57600, databits: 8, stopbit: 1, parity: 0 );
~x1 = { |interactive=1| SinOsc.ar(([400, 404]*interactive).lag(0.02/*readRate.reciprocal*/), 0, 0.05)};
~x2 = { |interactive=1| Decay.ar(Impulse.ar(([1, 1.1])*interactive.lag(0.02/*readRate.reciprocal*/)), 0.3, BrownNoise.ar(0.55))};
s.sync;
~y1 = ~x1.play;
~y2 = ~x2.play;
2.wait;
~r = inf.do {
var received = [];
6.do{ received = received.add (~port.read) };
if( received[0]!=82, { ~port.next; 6.do{ received = received.add (~port.read) };});
~val = received[1..4].collect(_.asAscii);
~val.post;
//~converted = (b = ""; ~val.collect{|item| b = b ++ item.asString;}; b.asInteger);
~converted = (~val.collect{ |val| val.asString.asInteger} * [1000,100,10,1]).sum;
[~converted].post;
~y1.set(\interactive, ~converted.linlin(300, 5000, 1, 2, \minmax).postln );
~y2.set(\interactive, ~converted.linlin(300, 5000, 1, 2, \minmax) );
readRate.reciprocal.wait;
}
};
)