Code Monkey home page Code Monkey logo

Comments (4)

sensorium avatar sensorium commented on July 23, 2024

Hi Jaap,
are you just using Serial.read(), or another protocol? I'll have to look closer depending on how you're doing it, but it's likely that the processor is being blocked with delays or loops reading the serial. The way to fix this, which also happens with the standard Arduino analog reading and I2C communication, has been to look at the Arduino code and separate the part which initiates a read from the part which waits for a response, calling the first in Mozzi's updateControl() so it can happen behind the scenes and getting the result next time updateControl() is called.
If you want to send a bit more detail, I'll be able to be more specific.
Tim

from mozzi.

Hactari avatar Hactari commented on July 23, 2024

Hi Tim,

Thanks a lot for your quick response. I was expecting it to be something
like this indeed.

I am just using Serial.read indeed. There is a copy of my scripts below:

Cheers, Jaap

---------------------------------------------- first arduino

/*
ToDo: include encoder resolution to translate pulses to actual rotation
speed
*/

#include <PinChangeInt.h>
#define PIN1 2

uint8_t latest_interrupted_pin;
uint8_t interrupt_count[20]={0}; // 20 possible arduino pins

// the following function is called when an interrupt occurs
void quicfunc() {
latest_interrupted_pin=PCintPort::arduinoPin;
interrupt_count[latest_interrupted_pin]++;
};

void setup() {
pinMode(PIN1, INPUT); digitalWrite(PIN1, HIGH); //
PCintPort::attachInterrupt(PIN1, &quicfunc, FALLING); // add interrupt
Serial.begin(115200); // start serial
communication
}

uint8_t counts;
uint8_t old_counts;

void loop() {
old_counts = counts;
counts = interrupt_count[PIN1];

Serial.write(counts); //send speed
// Serial.print(";");
// Serial.print(counts - old_counts, DEC); // send acceleration
// Serial.println(";");

interrupt_count[PIN1] = 0;
delay(100);
}


------------------------------------- mozzi arduino

/*
first try at making a hurdy gurdy sound

next step:
make realistic drone sound
improve trumpet sound
add hardware filter or use HiFi

output pin: 9
HIFI mode: output pins 9 and 10

*/

//#define AUDIO_MODE HIFI
#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator
#include <tables/saw2048_int8.h> // saw table for oscillator
#include <MozziGuts.h>
#include <mozzi_utils.h>
#include <mozzi_analog.h>

// use: Oscil <table_size, update_rate> oscilName (wavetable)
Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> aSaw(SAW2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);

// use #define for CONTROL_RATE, not a constant
#define CONTROL_RATE 64 // powers of 2 please
//unsigned char gain = 255;
uint8_t val;

void setup(){
startMozzi(CONTROL_RATE); // set a control rate of 64 (powers of 2 please)
aSaw.setFreq(2*392); // set the frequency
aSin.setFreq(392); // set the frequency
adcEnableInterrupt();
Serial.begin(115200);
}

void updateControl(){
// put changing controls in here
//adcReadAllChannels();
//gain = adcGetResult(3)/4;
//Serial.println(gain);

       if (Serial.available()) {
            val = Serial.read();
            analogWrite(11,val);
      //      Serial.println(val);
    //   for (i=0;i<val;i++){
    //    analogWrite(11,255);
    //    delay(200);
    //    analogWrite(11,0);
    //    delay(200);
    // }

    }

val = 255; // test the sound, when arduino with encoder is not
connected

}

int updateAudio(){
return ( (aSin.next() + aSaw.next() )* val)>>8;
}

void loop(){
audioHook(); // required here
}


On Fri, Jul 19, 2013 at 7:39 AM, Mr Sensorium [email protected]:

Hi Jaap,
are you just using Serial.read(), or another protocol? I'll have to look
closer depending on how you're doing it, but it's likely that the processor
is being blocked with delays or loops reading the serial. The way to fix
this, which also happens with the standard Arduino analog reading and I2C
communication, has been to look at the Arduino code and separate the part
which initiates a read from the part which waits for a response, calling
the first in Mozzi's updateControl() so it can happen behind the scenes and
getting the result next time updateControl() is called.
If you want to send a bit more detail, I'll be able to be more specific.
Tim


Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-21232361
.

from mozzi.

sensorium avatar sensorium commented on July 23, 2024

Hi Jaap,
just had a quick search and found NBSerial library, for non-blocking serial- there's version 2.5 at the bottom of this page:
http://forum.arduino.cc/index.php?topic=70623.0
It would be great to know if this works for you. It looks like there are a few other similar libraries around which might also be worth looking at.
Good luck!
Tim

from mozzi.

Hactari avatar Hactari commented on July 23, 2024

That's great Tim. I can't really try it out tonight, as I'm camping for the weekend. But I'll test it as soon as I can get my laptop online (and out of sight of my wife ;-).

Jaap

Mr Sensorium [email protected] wrote:

Hi Jaap,
just had a quick search and found NBSerial library, for non-blocking serial- there's version 2.5 at the bottom of this page:
http://forum.arduino.cc/index.php?topic=70623.0
It would be great to know if this works for you. It looks like there are a few other similar libraries around which might also be worth looking at.
Good luck!
Tim


Reply to this email directly or view it on GitHub:
#11 (comment)

from mozzi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.