Arduino and pure data
Hello. I'm trying to use Arduino with Puredata using the Firmata Library. I downloaded Firmata and installed the library as instructed in the readme, and then loaded 'AnalogFirmata' from the library examples. When I try to compile this example (or any of the others) I receive a string of error statements. Code and errors listed below. Any suggestions?
Code:
/* This firmware supports as many analog ports as possible, all analog inputs,
* four PWM outputs, and two with servo support.
*
* This example code is in the public domain.
*/
#include <Firmata.h>
#include <Servo.h>
/*==============================================================================
* GLOBAL VARIABLES
*============================================================================*/
/* servos */
Servo servo9, servo10; // one instance per pin
/* analog inputs */
int analogInputsToReport = 0; // bitwise array to store pin reporting
int analogPin = 0; // counter for reading analog pins
/* timer variables */
extern volatile unsigned long timer0_overflow_count; // timer0 from wiring.c
unsigned long nextExecuteTime; // for comparison with timer0_overflow_count
/*==============================================================================
* FUNCTIONS
*============================================================================*/
void analogWriteCallback(byte pin, int value)
{
switch(pin) {
case 9: servo9.write(value); break;
case 10: servo10.write(value); break;
case 3:
case 5:
case 6:
case 11: // PWM pins
analogWrite(pin, value);
break;
}
}
// -----------------------------------------------------------------------------
// sets bits in a bit array (int) to toggle the reporting of the analogIns
void reportAnalogCallback(byte pin, int value)
{
if(value == 0) {
analogInputsToReport = analogInputsToReport &~ (1 << pin);
}
else { // everything but 0 enables reporting of that pin
analogInputsToReport = analogInputsToReport | (1 << pin);
}
// TODO: save status to EEPROM here, if changed
}
/*==============================================================================
* SETUP()
*============================================================================*/
void setup()
{
Firmata.setFirmwareVersion(0, 2);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
servo9.attach(9);
servo10.attach(10);
Firmata.begin();
}
/*==============================================================================
* LOOP()
*============================================================================*/
void loop()
{
while(Firmata.available())
Firmata.processInput();
if(timer0_overflow_count > nextExecuteTime) {
nextExecuteTime = timer0_overflow_count + 19; // run this every 20ms
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
if( analogInputsToReport & (1 << analogPin) )
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}
Error Statements:
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:61: error: typedef 'callbackFunction' is initialized (use __typeof__ instead)
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:61: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:61: error: expected primary-expression before 'int'
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: typedef 'sysexCallbackFunction' is initialized (use __typeof__ instead)
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'argv' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:81: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:81: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:86: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:87: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:88: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:90: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:91: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:91: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:91: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:95: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:95: error: 'callbackFunction' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:96: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:97: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:98: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:98: error: 'sysexCallbackFunction' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:98: error: 'void FirmataClass::attach(int, int)' cannot be overloaded
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:95: error: with 'void FirmataClass::attach(int, int)'
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:99: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:104: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:105: error: ISO C++ forbids declaration of 'byte' with no type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:105: error: expected ';' before '*' token
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:107: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:108: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:109: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:110: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:112: error: 'boolean' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:115: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:116: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:117: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:118: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:119: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:122: error: 'sysexCallbackFunction' does not name a type
In function 'void setup()':
Separate control of two midi devices
>>I had been hooking the sampler up to the midi out from the x-station<<
does the x-station have a midi 'thru' port too? or just in and out? because if you want to send midi to the sampler via another device, you'd probably have to have a midi thru port to do that (if i recall correctly)
if you don't have a midi through port, then i think it would be best to use the midi-usb device you have.
set the electribe to receive on midi channel 1 only. and then attach it to the the midi-usb device with a midi cable.
connect the x-station to the electribe's midi 'thru' outlet with a midi cable. set the x-station to recieve on midi channel 2 only.
then open pd and set midi output to the midi-usb device name, and then [noteout 1] should talk to the electribe only, and [noteout 2] should talk to the x-session
one more thing:
does the x-station have its own power source? if so, then disconnect the usb cable. you won't need it. but if the device needs usb for power, then maybe you can still leave it connected via usb as well, but don't select it as a device in pd, because it will be receiving midi messages via the electribe anyway.
one more thing again: really if the x-station has a midi through port, then just attach that to the electribe and all your worries should be gone.
Interfacing PD with the Arduino ... how?
i got a problem in uploading the file to the board. ( I have press play, same error found. When I press upload to I/O, below error found)
anyone can help?
thx
////////////////////////////
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:61: error: typedef 'callbackFunction' is initialized (use __typeof__ instead)
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:61: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:61: error: expected primary-expression before 'int'
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: typedef 'sysexCallbackFunction' is initialized (use __typeof__ instead)
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'byte' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:64: error: 'argv' was not declared in this scope
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:81: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:81: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:86: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:87: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:88: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:90: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:91: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:91: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:91: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:95: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:95: error: 'callbackFunction' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:96: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:97: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:98: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:98: error: 'sysexCallbackFunction' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:98: error: 'void FirmataClass::attach(int, int)' cannot be overloaded
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:95: error: with 'void FirmataClass::attach(int, int)'
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:99: error: 'byte' has not been declared
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:104: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:105: error: ISO C++ forbids declaration of 'byte' with no type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:105: error: expected ';' before '*' token
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:107: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:108: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:109: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:110: error: 'byte' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:112: error: 'boolean' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:115: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:116: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:117: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:118: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:119: error: 'callbackFunction' does not name a type
/Applications/arduino-0012/hardware/libraries/Firmata/Firmata.h:122: error: 'sysexCallbackFunction' does not name a type
In function 'void setup()':
Best way to do this tree...
Thanks obiwannabe. Before you posted, I had just found a way to get things working. It's messy and probably not the most efficient way of doing things though, but again it works how I need it. Right now, I'm using routeing, moses, and some send/receives. I'll take a look at lists since they seem like that may have been a better route to go.
I'm sorry, I probably didn't explain well what I am trying to achieve. Every 8 notes, I wanted a pattern (algorithmic) to go back to Note 1 and find a new pattern (which may be the same as the previous one). Looking at the diagram, each box is the option(s) that can be chosen by the random generator. A 1/2 = 500ms, 1 = 1000ms, 2 = 2000ms, and 4 = 4000ms. At note 1, if a 2 is chosen, the next one can only be a 2, and the next only a 1, next a 3, next a 4, 3, or 1. If a 1 is chosen for note 5, then the next note must be a 4, next a 1/2, and last a 1/2, then back to note 1 again ( 4 or 2). There is no direct link between step and note length other then the fact that the order of note lengths reach an even point at the end of every 4 and 8 notes.
Basically, I originally had an algorithmic note generator, where the notes were picked from moses divide/split points. The problem is, with 4 instruments playing simultaneously, the rhythms were too random. So, I wanted to line them up every 4 and 8 notes. With the diagram setup, every 4 notes and 8 notes, the notes start together, while in between they can deviate randomly in their rhythm (note length).
I hope that makes more sense. I'm a student, and learning PD for the first time. So I'm sure my way isn't the most efficient, but it's all I could think of. =) The patch is almost completed, and I can upload it once finished if interested.
Best way to do this tree...
I'm making an algorithmic based program and I just thought of a new way that I'd like to generate length of notes. I'm still new to pd and programming in general, so I was wondering what the best and easiest way would be to go about making something like my chart below:
4 = note lengths of 4000ms (4 seconds), 2 = 2 seconds, 1 = 1 second, 1/2 = half second. So similar to whole, half, quarter, and eight notes. If the first note (when banged from a random 50/50 chance) is a 4, then the second note can be a 1 or a 2. If the second note is a 1, the third note must be a 2 and so on. I hope the diagram explains what I am trying to accomplish. The goal in doing this is so that on every 4 and 8 notes, the notes line up again (since I have 4 parts to this music generation).
I originally was doing something else to get note lengths, using a route 8 and a random note was triggered by a metronome, and then the metronome (received this length and) didn't choose another until the length of the first note finished. I'm having a hard time switching over to this new concept.
This notelength, is passed to a random note chooser using route 8.
Any help would be great! =)
Escher-esque chord progressions
I've been getting into writing patches that generate music all by themselves, using mathematical
rules that apply quite nicely to music theory. I've made a few rhythm patches that make nice cross
rhythms using metronome division and delays (with values derived from multiples of the master
metronome), and i'll post these too if anyone is interested.
In this thread I'm showing off my "Mauritz Escher like Chord progressions" patch.
Screenshot:
Mp3: http://responsible7.googlepages.com/zenpho_escher_pd.mp3
Patch: http://responsible7.googlepages.com/zenpho_escher.pd
First some basic music theory:
(skip this if you're comfortable with chords, 7ths, and inversions)
A major scale is constructed of 8 notes, with the "root" note doubled at the 8th note.
For the key of C major (all the "white" notes on a piano) the names and numbers of the notes in
the scale of C-major are:
Name, Number:
C, 1st (root)
D, 2nd
E, 3rd
F, 4th
G, 5th
A, 6th
B, 7th
C, 8th (remember the root is doubled at the octave)
A triad is constructed of the 1st, the 3rd, and the 5th notes in the scale.
A SEVENTH chord is constructed of a triad (notes 1,3 and 5) PLUS the 7th note in the
scale. So a C major 7th is note 1,3,5,7 or C,E,G,B.
Up until now we've been describing "standard" voicings of the chords, in other words, the notes
are played so that the root is the lowest pitched note, the 3rd is higher, the 5th is higher
still, and the 7th is the note just below the octave of the root.
At the risk of sounding redundant, "octave numbers" after the note name help clarify which octave
the note is to be played in. To play a C major 7th on the third octave, we would write:
C3,E3,G3,B3. To play it an octave higher we would write: C4,E4,G4,B4.
"Inversions" of chords re-order the pitches of the notes, but still play notes with the same
"name" as the 3rd, 5th, 7th etc. For example:
C3,E3,G3,B3 is a standard C major 7th...
...and G2,C3,E3,B3 is an inversion. All the notes are there (C,E,G,B) but they are in a different
order to the normal "Root, Third, Fifth, Seventh" arrangement. In this case, we say that "the
fifth is in the root".
Okay so now we know what a major 7th chord is. Lets deal with chord progressions.
Now imagine playing C3,E3,G3,B3 and removing the "root" (the C3) from the notes played,
we have a chord that reads "E3,G3,B3" - we were playing C major 7th and now we're playing E minor.
*THIS IS A VERY IMPORTANT STEP* Moving from C major 7 to E minor sounds "natrual" because the
notes that occour in C major 7 ALSO occour in the E minor.
Now lets make this E minor chord a 7th...
We've said before that a 7th chord can be constructed by playing the 1st, 3rd, and 5th notes, PLUS
the 7th note in the scale.
The scale of E minor (a flavour of minor) is:
Name, Number
E, 1st (root)
F#, 2nd
G, 3rd
E, 4th
B, 5th
C, 6th
D, 7th
E, 8th (octave)
The 7th note is "D" so we add the D note to our E minor triad to make E minor 7th.
E minor 7th is therefore: "E3,G3,B3,D4".
We can extend this E minor again, removing the root, working out the new scale for G major, adding
the 7th to make G major 7th, and again, and again, and again... but if we do - we keep moving
*UP IN PITCH* and spiral off the end of the keyboard.
HOW THE PATCH WORKS
Okay, so what my patch does is to take the idea of generating new 7th chords over and over,
but to play inversions of these chords so that the notes stay inside a single octave. If the
"root" note is in the 3rd octave, C3 for example. Then when I move to E minor, the D4 is
transposed to be a D3, to keep within this octave range.
Due to the fact that there are 12 semitones in an octave, and notes that fall outside the octave
range will wrap around to be an octave lower. The maths for generating the new chords basically
involves taking each note in the current major 7th chord and adding two semitones to each note in
turn.
Now our terminology could cause confusion here, because there are "notes in a scale" and "notes in a chord"... So I'm going to define some notation to show when i'm talking about the notes in a
chord.
For example:
A C major 7th has the notes C3,E3,G3,B3.
Note-1-in-the-chord is to be defined as chord_note_1.
Note-2-in-the-chord is defined as chord_note_2.
Note-3-in-the-chord is defined as chord_note_3.
Note-4-in-the-chord is defined as chord_note_4.
chord_note_1 has the pitch C3.
chord_note_2 has the pitch E3.
chord_note_3 has the pitch G3.
chord_note_4 has the pitch B3.
It is important to be clear about the idea of "pitch", "chord_notes" and "scale_notes" because
because chord_note_3 has the pitch "G3" and scale_note_3 of C major which is the pitch "E3".
Back to the procedure for generating new seventh chords.
We generate a major 7th to begin with.
C3,E3,G3,B3.
We add 2 semitones to chord_note_1 to get "D3", and we leave the other notes alone.
Our chord now reads: D3,E3,G3,B3.
Which is an "inversion" of E minor 7th.
This time we add 2 semitones to chord_note_2 to get "F#3", and we leave the other notes alone as
before.
Our chord now reads: D3,F#3,G3,B3
This is an inversion of G major 7th.
This time we add 2 semitones to chord_note_3 to get "A3", we leave the other notes.
Our chord now reads: D3,F#3,A3,B3
This is an inversion of B minor 7th.
This time we add 2 semitones to chord_note_4 to get C#4...
*BUT C#4 IS OUTSIDE THE OCTAVE 3! So we TRANSPOSE it down to C#3*
Our chord now reads: D#3,F#3,A3,C#3
This is an inversion of D major 7th.
After my patch modifies all 4 chord_notes, it moves back to chord_note_1, and adds another
2 semitones... over and over.
Eventually we get back to C major 7th again, but on the way we move through a variety of different
chords that evokes very interesting changes of moods.
Want to try playing with it?
Mp3: http://responsible7.googlepages.com/zenpho_escher_pd.mp3
Patch: http://responsible7.googlepages.com/zenpho_escher.pd
Latency with midi
I'm looking for some help about a latency problem with midi processing using pd under Windows XP.
Here is the point : I'm using pd to process some midi data coming from electronic drums. These data are then sent to another software (e.g. Nuendo) thanks to virtual midi ports (MIDI Yoke). Assuming '<->' is a midi connection (virtual or physical), it looks like,
drums module <-> Sound Card (Midi Ports) <-> Pure Data <-> Midi Yoke <-> Nuendo
The problem is that pd introduces some latency... and pd is definitely responsible for that... because the following setup does not introduce latency :
drums module <-> Sound Card (Midi Ports) <-> Midi CC <-> Midi Yoke <-> Nuendo
(Midi CC allows to connect virtual ports between them)
The last point is that latency does not seem to be sensitive to the patch. I tried a simple midi thru patch and another patch with complex treatments and nothing changed...
Help