electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Problem using ChucK and Serial
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
minauras



Joined: Dec 19, 2016
Posts: 1
Location: Switzerland

PostPosted: Mon Dec 19, 2016 3:12 pm    Post subject: Problem using ChucK and Serial Reply with quote  Mark this post and the followings unread

Hey everybody,

I'm fairly new to ChuCk, and also to Serial (I've never used it before). Now I'm working on a project for fun where I want to operate oscillators in ChucK using an arduino. So I've got this small Arduino program:

Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(A0)/4);
  delay(100);
}

which sends the data collected from the A0 port to Serial.

And I don't know much about Serial so in ChucK I've used the program from someone else from the internet who operated ChucK with an arduino too, and I've copied/paste their method of getting data from Serial. I get a ChucK program like this:

Code:
SerialIO.list() @=> string list[];

for(int i; i < list.cap(); i++)
{
    chout <= i <= ": " <= list[i] <IO> int device;
if(me.args()) {
    me.arg(0) => Std.atoi => device;
}

if(device >= list.cap())
{
    cherr <= "serial device #" <= device <= " not available\n";
    me.exit();
}

SerialIO cereal;
if(!cereal.open(device, SerialIO.B9600, SerialIO.ASCII))
{
   chout <= "unable to open serial device '" <= list[device] <= "'\n";
   me.exit();
}

fun float map(float a, float ilow, float ihigh, float olow, float ohigh)
{
    ((a/(ihigh-ilow))*(ohigh-olow)) + olow => float temp;
    return temp;
}

SinOsc s => dac;

while(true)
{
    cereal.onLine() => now;
    cereal.getLine() => string line;
 
    if(line$Object != null) {
        StringTokenizer tok;
        tok.set(line);
        Std.atoi(tok.next()) => int pos;
        map(pos, 0, 255, 300, 400) => float frequency;
        s.freq(frequency); // Change sin wave frequency
    }
}


(sorry for the lack of comments) Now I don't exactly understand what it does but I've got a fair idea from reading it thoroughly.

Here's my problem: yesterday the program worked perfectly. And today after starting my computer and opening the programs it didn't work anymore (I only get the default frequency of my SinOsc).

I've tracked where the error would be and it seems that the program reaches this line, but never passes through it:
Code:
cereal.onLine() => now;

From what I understand, it means my SerialIO cereal is waiting to get data but doesn't get anything.

I've checked my serial output from the arduino using the serial monitor and everything seems to work fine, so there must be a problem in my ChucK code. Any idea? (I've already tried to restart my computer salut )

Thank you everyone!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use