Using pduino and Firmata to read values from the Grove I2C Touch sensor
Hi @alexandros
code is below, if you can figure anything out that would be great !
/* GroveI2CTouchTest.pde - Sample code for the SeeedStudio Grove I2C Touch Sensor
http://seeedstudio.com/wiki/index.php?title=Twig_-_I2C_Touch_Sensor_v0.93b
Prerequisite: A modification of the Grove I2C Touch sensor is needed Solder a pin to
the INT terminal in the I2C sensor to connect it to one pin in Arduino Created by
Wendell A. Capili, August 27, 2011. http://wendellinfinity.wordpress.com
Released into the public domain.*/
#include <Wire.h> // include I2C library
#include <i2c_touch_sensor.h>
#include <MPR121.h>
// include our Grove I2C touch sensor library
// initialize the Grove I2C touch sensor
// IMPORTANT: in this case, INT pin was connected to pin7 of the Arduino
// (this is the interrupt pin)
i2ctouchsensor touchsensor; // keep track of 4 pads' states
//boolean padTouched[4];
long previousMillis = 0;
long interval = 100;
void setup()
{
Serial.begin(9600); // for debugging
Serial.print("begin to init");
Wire.begin(); // needed by the GroveMultiTouch lib
touchsensor.initialize(); // initialize the feelers // initialize the containers
//for(int i=0; i<=3; i++)
//{
// padTouched[i]=false;
//}
}
void loop()
{
unsigned char MPR_Query=0;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
touchsensor.getTouchState();
}
for (int i=0;i<12;i++)
{
if (touchsensor.touched&(1<<i))
{
Serial.print("pin ");
Serial.print(i);
Serial.println(" was touched");
}
}
}
/*
touchsensor.readTouchInputs(); // test read the touch sensors
// loop through our touch sensors 1 to 4
for(int i=0; i<=3; i++)
{
// get the touch state based on pin #
if(feelers.getTouchState(i))
{
if(!padTouched[i])
{ // print in serial that it was touched
Serial.print("Pad ");
Serial.print(i);
Serial.println(" was touched");
}
// flag the touch sensor state
padTouched[i]=true;
}
else
{
if(padTouched[i])
{
// print in serial that it was released
Serial.print("Pad ");
Serial.print(i);
Serial.println(" was released");
} // reset the touch sensor state
padTouched[i]=false;
}
}*/
Beatmaker Abstract
http://www.2shared.com/photo/mA24_LPF/820_am_July_26th_13_window_con.html
I conceptualized this the other day. The main reason I wanted to make this is because I'm a little tired of complicated ableton live. I wanted to just be able to right click parameters and tell them to follow midi tracks.
The big feature in this abstract is a "Midi CC Module Window" That contains an unlimited (or potentially very large)number of Midi CC Envelope Modules. In each Midi CC Envelope Module are Midi CC Envelope Clips. These clips hold a waveform that is plotted on a tempo divided graph. The waveform is played in a loop and synced to the tempo according to how long the loop is. Only one clip can be playing per module. If a parameter is right clicked, you can choose "Follow Midi CC Envelope Module 1" and the parameter will then be following the envelope that is looping in "Midi CC Envelope Module 1".
Midi note clips function in the same way. Every instrument will be able to select one Midi Notes Module. If you right clicked "Instrument Module 2" in the "Instrument Module Window" and selected "Midi input from Midi Notes Module 1", then the notes coming out of "Midi Notes Module 1" would be playing through the single virtual instrument you placed in "Instrument Module 2".
If you want the sound to come out of your speakers, then navigate to the "Bus" window. Select "Instrument Module 2" with a drop-down check off menu by right-clicking "Inputs". While still in the "Bus" window look at the "Output" window and check the box that says "Audio Output". Now the sound is coming through your speakers. Check off more Instrument Modules or Audio Track Modules to get more sound coming through the same bus.
Turn the "Aux" on to put all audio through effects.
Work in "Bounce" by selecting inputs like "Input Module 3" by right clicking and checking off Input Modules. Then press record and stop. Copy and paste your clip to an Audio Track Module, the "Sampler" or a Side Chain Audio Track Module.
Work in "Master Bounce" to produce audio clips by recording whatever is coming through the system for everyone to hear.
Chop and screw your audio in the sampler with highlight and right click processing effects. Glue your sample together and put it in an Audio Track Module or a Side Chain Audio Track Module.
Use the "Threshold Setter" to perform long linear modulation. Right click any parameter and select "Adjust to Threshold". The parameter will then adjust its minimum and maximum values over the length of time described in the "Threshold Setter".
The "Execution Engine" is used to make sure all changes happen in sync with the music.
IE>If you selected a subdivision of 2, and a length of 2, then it would take four quarter beats(starting from the next quarter beat) for the change to take place. So if you're somewhere in the a (1e+a) then you will have to wait for 2, 3, 4, 5, to pass and your change would happen on 6.
IE>If you selected a subdivision of 1 and a length of 3, you would have to wait 12 beats starting on the next quater beat.
IE>If you selected a subdivision of 8 and a length of 3, you would have to wait one and a half quarter beats starting on the next 8th note.
http://www.pdpatchrepo.info/hurleur/820_am,_July_26th_13_window_conception.png
Animata / eyesweb / MAC
Hi kinolab, here interesting news for you:
As a gift for the beginning of 2011, there's a new "unstable" version
of OpenNI & Sensor modules with MacOSX support!
Other new features:
* Added support for multiple sensors.
* Improved README! (much more detailed instructions...)
* Some bug fixes...
Previous version features:
* A brand new .NET wrapper and .NET samples (OpenNI.net).
NITE binaries for all supported platforms (including MacOSX) will also
be released very soon.
The source code is located at:
https://github.com/OpenNI/OpenNI/tree/unstable
https://github.com/PrimeSense/Sensor/tree/unstable
GitHub:
git clone https://github.com/OpenNI/OpenNI.git -b unstable
git clone https://github.com/PrimeSense/Sensor.git -b unstable
Binaries:
Windows:
http://openni.org/sites/default/files/unstable/OpenNI-Bin-Win32-v1.0....
http://downloads.primesense.com/unstable/Sensor-Bin-Win32-v5.0.0.25.exe
Ubuntu 10.10 x86:
http://openni.org/sites/default/files/unstable/OpenNI-Bin-Linux32-v1....
http://downloads.primesense.com/unstable/Sensor-Bin-Linux32-v5.0.0.25...
Ubuntu 10.10 x64:
http://openni.org/sites/default/files/unstable/OpenNI-Bin-Linux64-v1....
http://downloads.primesense.com/unstable/Sensor-Bin-Linux64-v5.0.0.25...
MacOSX 10.6:
http://openni.org/sites/default/files/unstable/OpenNI-Bin-MacOSX-v1.0...
http://downloads.primesense.com/unstable/Sensor-Bin-MacOSX-v5.0.0.25....
We're really amazed from the awesome response of the community!
And thanks for everyone that's helped.
Ziv.
What's faster, you think? "Audio" or data?!
i think the only difference is the rate at which the messages are processed.
at control rate (data) i think the refresh rate is something around 70hz, but at audio rate, it's whatever you set your samplerate too (so well into the tens of thousands). audio rate therefore will be more intensive, but also more accurate.
If you can't hear a difference then control rate is gonna save you those CPU cycles.
Array issue please help
@Nk said:
So am I right in thinking the first 'filename' is left channel/stereo and the 2nd 'filename' is right channel?
No, but holy shit you seem to have stumbled on how to isolate a single channel of a multichannel file. So, thanks for that!
Well, you're sort of right, but they're not filenames; they're array names. What I was trying to say with my earlier example (and sorry for not being clear, I was rushing a bit) is that you would have two arrays, in this case named "rightarray" and "leftarray". These two arrays would hold the right and left channel of a stereo file "foo.wav", respectively.
Now, when [soundfiler] loads a multichannel file, it puts each channel in a different array depending on the number of array names you give it. If you only give it one, it loads the first channel of the file. If you give it two, it loads the first two, etc. With stereo files, the first channel is the left one and the second is the right one. So if you only give it one array, it will only load the left channel. In order to load the right channel, you have to give it a second array name. But, it seems that if you make both array names the same, it will load the left channel into the array, and then overwrite that with the right channel. Brilliant!
Arduino, ultrasonics and Pd: HELP needed for degree project!
Dear Pd'ers… I'm fairly new to Pd and have been using it during my 'Audio Production' degree at SAE college in London. I'm here to ask for help on my final degree project, which aims to control objects within Pd by way of proximity sensors connected to Arduino.
I have had moderate success, first using a Sharp GPD12 IR sensor connected to an analog port on an Arduino Diecimila, then a Devantech SRF02 connected via I2C to Arduino. I have managed to get Pure Data reading the sensor values using the Pure Data example included in SimpleMessageSystem (http://www.arduino.cc/playground/uploads/Code/SimpleMessageSystem.zip)... and only altering the number of the comport the Arduino appears on.
On the Arduino end, I have added the SimpleMessageSystem library, and am using the following sketch to run one or both of the sensors depending on whether or not I omit the SRF02 or GPD12 parts of the code.
// top //
#include <Wire.h>
#include <Servo.h>
#include <SimpleMessageSystem.h>
int sensorPin = 0;
int sensorValue = 0;
Servo servo1;
#define sensorAddress 0x70
#define readInches 0x50
#define readCentimeters 0x51
#define readMicroseconds 0x52
#define resultRegister 0x02
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void sendCommand (int address, int command) {
Wire.beginTransmission(address);
Wire.send(0x00);
Wire.send(command);
Wire.endTransmission();
}
void setRegister(int address, int thisRegister) {
Wire.beginTransmission(address);
Wire.send(thisRegister);
Wire.endTransmission();
}
int readData(int address, int numBytes) {
int result = 0;
Wire.requestFrom(address, numBytes);
while (Wire.available() < 2 );{
}
result = Wire.receive() * 256;
result = result + Wire.receive();
return result;
}
void loop()
{
// SRF02 READING //
sendCommand(sensorAddress, readInches);
delay(70);
setRegister(sensorAddress, resultRegister);
int sensorReading = readData(sensorAddress, 2);
Serial.println(sensorReading);
delay (200);
// GPD12 READING //
sensorValue = analogRead(sensorPin);
int range = (6787 / sensorValue);
Serial.println(range);
delay(200);
}
// bottom //
Pure data is picking up the sensor's output as a decimal number, through the serial port, correctly, and showing this as a number in the SPECIAL CHARACTER section of the Pd patch, which I can then use to control various Pd parameters, like a slider for example.
If printing both sensor readings to the serial, the Pd patch will pick up the two sensor values alternately, but there seems no way of differentiating the two sensors within Pd, as they both come through the serial. I have tried prepending the serial print at the Arduino stage with a tag such as "IR" or "UL" for each sensor, but this simply ends up in nothing coming through in Pd.
Using one sensor gives the ability to control parameters with a fairly narrow detection range, but for the final version I would like to incorporate 4 or 5 sensors in order that I can cover nearly a full 360 degree range.
After a bit of research I have gone and bought 4 x Maxsonar EZ0's. They've got a wider range than the Devantech sensors, and can operate via I2C, serial or PWM. A number of people online seem to mention the improved stability when operating via PWM, so I thought this could be kinda useful.
I am going to London Hackspace tomorrow to get help with wiring up the sensors to my Arduino Diecimila, but for now, my main problem seems to be how to achieve greater communication between Pure Data and the sensors. It's all very good and well being able to take the decimal readout from an analog input to give one set of values in Pd, but I would like to know how to either to read (and trigger) each sensor discretely via PWM, or to somehow differentiate between each sensor's analog output, so that I can have the different sensors controlling different objects within Pd.
As well as SimpleMessageSystem, I looked at using the Pduino object. But to be honest, it is either not working properly (I have noticed reported issues with bugginess), or I am being stupid, as it has totally boggled my brain. In theory though, it seems like it should be able to do what I want, ie. send and receive commands between Arduino and Pd.
****************************************
So…. my questions for anyone out there with a knowledge of using Arduino + multiple sensors (preferably Maxsonar EZ's) with Pd are:
What is most appropriate for my project?
- Simple Message System or Pduino?
- analog or PWM?
And how do I get proper communication between the two platforms so I can discern discrete values from each sensor?
I'd really like to get a discussion going with this as (a) it would really help me in my degree (which ends in about 4 weeks!!!) and (b) I really want to share what I am doing, especially as the discussions on Arduino/Pd communication on the various forums seem a little patchy (at least for noobs like me). I also hope to continue my research in the future, sharing any findings I make with the community…
****************************************
PS. In the sharing spirit, please check out the Radio Tuner patch I've just posted over on the patch section of this forum - it's my first successful attempt at Pd... I hope you enjoy
Questions about "homemade" sensors
Hi!
I want to make my own DJ-program and controller. I have made one in Max/MSP before and thought I'd try PD (Pure Data) this time. I think I can manage that, but the controller will be harder. I want to make it as much from scratch as I can, using homemade sensors and sensor-interfaces from gamepads or something like that. I want them to use OSC to communicate with PD. For starters I want to have buttons (cue/play), sliders (the speed/pitch of the song) and something that rotates without start- or stop-points (also speed/pitch of sound (when spinning this forward the speed goes up, when spinning it backward the speed goes down), adjusting cue-points, and, maybe later, scratching). I know that homemade sensors are unstable and deteriorate with time, but hope I can learn more about this and maybe find information about materials that don't deteriorate as much or how to make them not deteriorate. Can someone point me in the right direction here? Maybe to a better forum for these types of things? Or to some kind of tutorial or guide? I have searched the internet and this forum, without finding anything.
If I can't use homemade sensors, I wonder where I can find the types of sensors I need and maybe if it would be better to use Phidgets or Arduino or something like that. And in that case – what things like that? Can I just buy slider/fader from some kind of electronics-store and connect it to a sensor-interface I made from a gamepad? Do I need to calibrate something? How do I find information about these things? Can you recommend specific sensors or stores?
The goal is to spend as little money as possible, but it has to be possible for me to be able to build this within “reasonable” time and without spending much time practicing and reading.
Thank you!
Ear Training Program
@Psyko_Logical said:
I knocked together a quick example for you. It doesn't have all the features of the site you linked to, but it should be enough to get you started.
It chooses and plays a random note from a two octave range, then plays another note within one octave a second later. It then stores the interval and compares it to your answer, and outputs "Correct" or "Incorrect" to the main Pd window.
Also, it has 12 choices instead of eight; minor2nd to octave.
Hope this helps you out. Let me know if you don't understand why I did something the way I did.
OK, maybe I'm missing something obvious here, but I don't know how to add attachments, so I uploaded it to Filedropper.
thx for the reactions!
but... i didn't use synths yet so I'm quite confused what you are exactly doing.
also this ''inside'' boxes are confusing. I guess already a bit too hard for me.
I made something different
I think I don't want to make an Invertrainer anymore but an Instrument Recognizer.
Now I made a quite easy 1 with MIDI (used SimpleSynth)
I'd like to know how u can get audio files in.
Some example for the Instrument Recognize Test:
Take 10 different instruments ( Guitar, Violian, Contrabass, Altviolin, Trumpet, Bassoon etc. )
U hear 1, and you have to guess what it is.
In the end I'd like to have each instrument with 3 different sounds ( depends on how many audio files I got for each instrument)
Also I'd like to have a counter Inside the PD screen and I want to see if your wrong or right ( also inside the PD screen)
Take my attachment as a really simple example.
Digital inputs not reading in arduino/pduino
Hi all..
I've been having troubles reading the digital inputs of an arduino duemilanove (328) using the pduino firmware. I mean having troubles like not reading anything from them at all.
Analog ins and digital outs work fine, but the DI do not want to read anything. I've checked that they are OK (I can effectively read them) with other sketches including the button read example from the arduino website, so there are no hardware issues.
I've tried he latest version of the pduino firmware, and went all the way back to pduino 0.4 with firmata 2.0. I even changed the moocow objects for flatspace as someone hinted somewhere here but to no avail (yes, I'm on windows XP).
I've tried the pduino-help and pduino-test patches included with the download and everything works except the digital input reading.
.. and of course, the digital ports are enabled and the pins' output mode are in 0 (input) and the serial port is set correctly both with the selector and inside the [arduino] object (just in case)
The toggle objects do not change at all in the lower right section of the pduino-test patch. As a matter of fact nothing comes out of any [route digital] object, even if it is directly connected to the [arduino] object
Am I missing something here?
any help would be appreciated
thanks
rick
Pd + arduinome +\[ pduino \]
hi there
we made a4*4 arduinome (just like monome) recently , and to the arduino firmware, we let it send signals when we press any pad.
here's our arduinome pic:
http://picasaweb.google.com/lh/view?q=arduinome&psc=G&filter=1#5356250085481394178
http://picasaweb.google.com/lh/view?q=arduinome&psc=G&filter=1#5356250079543724418
but you know, only we send pduino firmware to arduino, pduino can recieve the right messages like : "analog 0 0.222" "digital 12 1" ...
and the 1st time I connect pduino , I just seen what was happened when I just connect pduino with no pduino firmware but just my arduinome fireware.
of caurse error messages but occasionally right .
here's the pd consle pic :
http://picasaweb.google.com/malianglight/Arduinome#5356250267147449202
and now I m thinking that : we are trying to send serial signals to pd, so why we could not give up pduino object , just using serial connection object in pd ?
I dont know how can we setup a serial connection in pd , I just find serial object but it just had one inlet , How could we go next step ?