Get bad values with serialRead/ Arduino

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Get bad values with serialRead/ Arduino

obaudouin
(csd below)

Hello!

I am trying an Arduino Uno. I get correct values with the arduino software (~ from 330 to 340)
In Csound, I get correct values with serialPrint (~ from 330 to 340) but not with serialRead:

i1    -1.00000
 i1    13.00000
 i1    56.00000
 i1    13.00000
 i1    10.00000
 i1    51.00000
 i1    50.00000
 i1    56.00000
 i1    13.00000
 i1    10.00000
 i1    51.00000
 i1    50.00000
 i1    56.00000
 i1    13.00000
 i1    10.00000
 i1    51.00000
 i1    50.00000
 i1    56.00000
 i1    13.00000
 i1    10.00000
 i1    51.00000
 i1    50.00000
 i1    56.00000
...

An idea?


--------------

<CsoundSynthesizer>

<CsOptions>

;AUDIO
-+rtaudio=jack
-odac
; -iadc
-B2048
-b256
</CsOptions>

<CsInstruments>
sr = 44100
ksmps = 500
nchnls = 2

    instr MyInstr
iPort serialBegin "/dev/ttyACM0"
kByte serialRead iPort
printk2 kByte
    endin

</CsInstruments>

<CsScore>
i "MyInstr" 0 3600
</CsScore>

</CsoundSynthesizer> 

Olivier Baudouin, PhD
http://olivierbaudouin.com
MINT-OMF
Paris-Sorbonne
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

jpff
I assume this is Linux?

What values were you expecting?

All it is doing is
    unsigned byte b;
    bytes = read((int)*p->port, &b, 1);
    if (bytes > 0)
      *p->rChar = b;
    else
      *p->rChar = -1;

    return OK;


> (csd below)
>
> Hello!
>
> I am trying an Arduino Uno. I get correct values with the arduino software
> (~ from 330 to 340)
> In Csound, I get correct values with serialPrint (~ from 330 to 340) but
> not
> with serialRead:
>
> i1    -1.00000
>  i1    13.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
> ...
>
> An idea?
>
>
> --------------
>
> <CsoundSynthesizer>
>
> <CsOptions>
>
> ;AUDIO
> -+rtaudio=jack
> -odac
> ; -iadc
> -B2048
> -b256
> </CsOptions>
>
> <CsInstruments>
> sr = 44100
> ksmps = 500
> nchnls = 2
>
>     instr MyInstr
> iPort serialBegin "/dev/ttyACM0"
> kByte serialRead iPort
> printk2 kByte
>     endin
>
> </CsInstruments>
>
> <CsScore>
> i "MyInstr" 0 3600
> </CsScore>
>
> </CsoundSynthesizer>
>
> -----
>
> Olivier Baudouin, PhD
> http://olivierbaudouin.com
> MINT-OMF
> Paris-Sorbonne
>
> --
> View this message in context:
> http://csound.1045644.n5.nabble.com/Get-bad-values-with-serialRead-Arduino-tp5445222p5445222.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email [hidden email] with body "unsubscribe
> csound"
>
>
>
>




Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email [hidden email] with body "unsubscribe csound"

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

obaudouin
Yes, it is on Linux.
Expected values: from 330 to 340 (OK with serialPrint, but not with serialRead).

Olivier Baudouin, PhD
http://olivierbaudouin.com
MINT-OMF
Paris-Sorbonne
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

Tarmo Johannes
In reply to this post by obaudouin
hello,

I have very small experience with arduino and I don't havew now one, but from my knowledge:

doesn't it depend, what kind of info is the arduino sending? Do you know what sketch is uploaded to arduino?

The difference is that if arduino is sending the information wit Serial.print it is sent to serial port as string (or text), so you can do
cat /dev/ttyUSB0
in terminal and see readable output

if it is sent with Serial.write , inf is sent as binary bytes.

I assume, similarly csound's  serialPrint assumes that string is coming in and serialRead reads the stream as binary bytes.
If Arduino sends '300' with print, bytes '3','0','0' etc are read with serialRead. That's why the porridge.

In short: if you get expected result with serialPrint, stick to it!
(although Serial.write in arduino and serialRead in csd should be faster),

hope it helps.

tarmo

On Tuesday 31 January 2012 19:39:23 obaudouin wrote:

> (csd below)
>
> Hello!
>
> I am trying an Arduino Uno. I get correct values with the arduino software
> (~ from 330 to 340)
> In Csound, I get correct values with serialPrint (~ from 330 to 340) but not
> with serialRead:
>
> i1    -1.00000
>  i1    13.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
>  i1    13.00000
>  i1    10.00000
>  i1    51.00000
>  i1    50.00000
>  i1    56.00000
> ...
>
> An idea?
>
>
> --------------
>
> <CsoundSynthesizer>
>
> <CsOptions>
>
> ;AUDIO
> -+rtaudio=jack
> -odac
> ; -iadc
> -B2048
> -b256
> </CsOptions>
>
> <CsInstruments>
> sr = 44100
> ksmps = 500
> nchnls = 2
>
>     instr MyInstr
> iPort serialBegin "/dev/ttyACM0"
> kByte serialRead iPort
> printk2 kByte
>     endin
>
> </CsInstruments>
>
> <CsScore>
> i "MyInstr" 0 3600
> </CsScore>
>
> </CsoundSynthesizer>
>
> -----
>
> Olivier Baudouin, PhD
> http://olivierbaudouin.com 
> MINT-OMF
> Paris-Sorbonne
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Get-bad-values-with-serialRead-Arduino-tp5445222p5445222.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email [hidden email] with body "unsubscribe csound"
>
>


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email [hidden email] with body "unsubscribe csound"

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

jpff
In reply to this post by obaudouin
I remain confused, as 300 > 255 which is the largest value readable


> Yes, it is on Linux.
> Expected values: from 330 to 340 (OK with serialPrint, but not with
> serialRead).
>
> -----
>
> Olivier Baudouin, PhD
> http://olivierbaudouin.com
> MINT-OMF
> Paris-Sorbonne
>
> --
> View this message in context:
> http://csound.1045644.n5.nabble.com/Get-bad-values-with-serialRead-Arduino-tp5445222p5445466.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email [hidden email] with body "unsubscribe
> csound"
>
>
>
>




Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email [hidden email] with body "unsubscribe csound"

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

obaudouin
jpff wrote
I remain confused, as 300 > 255 which is the largest value readable
But Arduino analog outputs send values from 0 to 1023...

Olivier Baudouin, PhD
http://olivierbaudouin.com
MINT-OMF
Paris-Sorbonne
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

jpff
but the csound opcode reads 1 byte at a time, so yu need to reconstruct a
10bit number

>
> jpff wrote
>>
>> I remain confused, as 300 > 255 which is the largest value readable
>>
>
> But Arduino analog outputs send values from 0 to 1023...
>
>
> -----
>




Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email [hidden email] with body "unsubscribe csound"

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino

obaudouin
How would you do that?

Olivier Baudouin, PhD
http://olivierbaudouin.com
MINT-OMF
Paris-Sorbonne
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Get bad values with serialRead/ Arduino (SOLVED)

obaudouin
I have mapped the analog Arduino output to send values from 0 to 255. Thats OK now.

Thanks!

Olivier Baudouin, PhD
http://olivierbaudouin.com
MINT-OMF
Paris-Sorbonne
Loading...