arduinoReadF — Read data from an arduino port using the Csound-Arduino protocol.
Plugin opcode in serial.
Read integer data from an arduino port with CsoundArduino protocol.
iPort -- port number obtained from a arduinoStart opcode.
iStream1, iStream2, iStream3 -- Numbers of the three data streams in the range 0 to 30. Each stream carries 10 bits of the 30 bits floating point result. The division is created in the Arduino sketch encapsulated in the put_float function.
kval -- floating point value read.
Note | |
---|---|
The value transmitted is two bits shorter in the mantissa than produced on the Arduino so there is a little error introduced. |
Here is an example of the arduinoReadF opcode. Play arduinoReadF.csd
Example 64. Example of the arduinoReadF opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
Arduino-Joystick2Csound1g-fm1-port (version with smoothing) - Push Joystick button to turn on note - Use JoystickX to offset and control the modulation index of the foscil opcode from 0-40 via the scale opcode - Use JoystickY to offset and control the Frequency of the foscil opcode up/down two octaves via the scale opcode <CsoundSynthesizer> <CsInstruments> sr = 44100 ksmps = 441 nchnls = 2 0dbfs = 1 giport init 0 // NOTE: change USB port "/dev/cu.usbmodem1414301" to correspond // with USB port used by Arduino on your system giport arduinoStart "//dev/ttyACM0", 9600 // for GNULinux instr 1 kk arduinoReadF giport, 1, 2, 3 printks "kk=%f\n", 0.5, kk endin </CsInstruments> <CsScore> f 1 0 16384 10 1 i 1 0 1 e </CsScore> </CsoundSynthesizer> <arduinoSketch> // Float Example // John ffitch & Richard Boulanger // December 7, 2020 // BreadBoard & Arduino Setup void setup() { // NOTE: Digital pins can be either inputs or outputs. Serial.begin(9600); } // put_val( ) - a function to send data values to the Csound // "arduinoRead" opcode // The first argument of the put_val function "int senChan" sets // the software channel number that Csound reads // NOTE: "senChan" does "not" define the input pin that is used on // the Arduino for a specific sensor // The specific Arduino input pin used by any sensor is assigned // and set elsewhere in the Arduino sketch and mapped to a // user-defined put_val "senChan" channel void put_val(int senChan, int senVal) // Set the Csound receive channel "senChan", and read from // the sensor data stream "senVal" { // The packing of the data is sssssvvv 0vvvvvvv where s is a // senChan bit, v a senVal bit and 0 is zero` bit int low = senVal&0x7f; int hi = ((senVal>>7)&0x0f) | ((senChan&0x0f)<<4); Serial.write(low); Serial.write(hi); } void put_float(int senChan1, int senChan2, int senChan3, float senVal) { typedef union { float f; long i; } JOINT; JOINT x; x.f = senVal; put_val(senChan1, (x.i>> 2)& 0x3ff); put_val(senChan2, (x.i>>12)& 0x3ff); put_val(senChan3, (x.i>>22)& 0x3ff); } void loop() { Serial.write(0xf8); // Synchronization Byte - (essential!) marks beginning of new serial frame put_float(1,2,3,1.23456789); delay(10); } </arduinoSketch>