Comments (4)
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.
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.
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.
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)
- Compilation errors when including both WaveFolder.h and ResonantFilter.h HOT 3
- Unable to compile for Atmega328PB with Arduino IDE HOT 3
- Sample example not working on UNO R4 HOT 11
- Arduino Nano 33 IoT tested and works with the output on DAC0, which is also called A0 HOT 2
- Output frequency 0.25% off on AVRs HOT 1
- RFC: Mozzi 2.0 part 1: Single compilation unit HOT 7
- RFC: Mozzi 2.0 part 2 - Configuration restructuring HOT 7
- Improving fixMath HOT 5
- Please Change Mozzi's License HOT 10
- Using Mozzi and I2C library for LCD HOT 14
- RFC: Mozzi 2.0 part 3 - Miscellanious
- UNO R4 port broken HOT 2
- Compatability/Compilation Issues w/ Nano 33 BLE Sense HOT 5
- Apparent frequency drops when amplitude increased beyond 8 bits on AVR HOT 3
- mozzi_rand cannot go full range HOT 7
- AVR PWM range is not actually 0-488 ("8.5 bit"), but effectively 0-400 HOT 6
- Minor / infrastructure: Avoid duplicate workflow runs on pushes to PRs HOT 1
- I2S dac with a nano. HOT 12
- VS10XX as DAC HOT 38
- RFC: Analog input scaling - what's the best approach HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mozzi.