regexp
Thank you @Jona I am trying with the lsit2symbol abstraction.
@whale-av actually Y is stuck to the 15...
I connected a 3D Printer using comport and need to track the position of the extruder.
Directly from Comport I get this info:
comport: X : 0 . 0 0 Y : 0 . 0 0 Z : 0 . 0 0 E : 0 . 0 0 C o u n t X : 0 . 0 0 Y : 0 . 0 0 Z : 0 . 0 0
comport: o k
Trying with your patch I am able to remove spaces (using vl2s and edit):
vl2s: symbol X_:0.0_0_Y:0.0_0_Z:0.0_0_E:0.0_0 C_o_u_n_t X:_ 0.0_0_Y:0.0_0_Z:0.0_0
vl2s: **symbol o_k_
edit: symbol X:0.00Y:0.00Z:0.00E:0.00 Count X: 0.00Y:0.00Z:0.00
edit: symbol ok
Actually I just need the integral number after the axis (X,Y,Z). The second group of axes would be great (current position) but the first group (to go Position) is also OK.
I tried using cylone/nth. But the problem is that the list sometimes is longer so looking for the nth is not a good Idea:
comport: X : 0 . 0 0 Y : 0 . 0 0 Z : 0 . 0 0 E : 0 . 0 0 C o u n t X : 0 . 0 0 Y : 0 . 0 0 Z : 0 . 0 0
comport: X : 10 . 0 0 Y : 0 . 0 0 Z : 0 . 0 0 E : 0 . 0 0 C o u n t X : 10 . 0 0 Y : 0 . 0 0 Z : 0 . 0 0
Looking forward for your replies
Pduino problem
just tested what you uploaded, got this:
netreceive: failed to sett SO_BROADCAST
arduino 1
... couldn't create
and nothing else. i dont get unknown input command msgs anymore, even after setting the proper port and arduino analog pin. im on Win 7 Professional.
now, i moved the moocow folder you attached to my original pd patch folder and got this:
netreceive: failed to sett SO_BROADCAST
comport - PD external for unix/windows
LGPL 1998-2015, Winfried Ritsch and others (see LICENSE.txt)
Institute for Electronic Music - Graz
[comport] Opening COM1
[comport]: could not open device COM1:
failure(2) ERROR_FILE_NOT_FOUND
[comport] opening serial port 1 failed!
route 13 0 20 1 (message->prepend) connection failed
route 14 0 20 1 (message->prepend) connection failed
route 16 0 20 1 (bang->prepend) connection failed
route 17 0 20 1 (bang->prepend) connection failed
[arduino]: version_0.5
[comport]: could not open device COM1:
failure(2) ERROR_FILE_NOT_FOUND
Firmware: StandardFirmata.ino-2.5
UNKNOWN_INPUT_COMMAND: 0 240
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
UNKNOWN_INPUT_COMMAND: 0 239
no more moocow errors anymore, then i set the port, got the firmata 2.5 message, then set pin a0 and got the endless stream of unknown input command msgs that change value when i move the pot. i think we're pretty close, but still not there :/
Pduino problem
arduino-test.pd
Thanks for answering! This is driving me mad lol.. Heres the patch attached, its the arduino test utility for Pduino.
comport is fine, the messages you see there are when you havent set the correct port yet, you select the correct one (in this case port 7) and it doesnt bugger anymore.
Im using pd vanilla 0.49 on Windows, so i have to check any moocow references and change them for "list tosymbol" and "list fromsymbol"? ...ive read on forums moocow shows these warning messages but only when running on windows.
So, to recapitulate, firmata is properly installed on the arduino, and its actually giving out correct output data, but cant get them to be recognized by Pd, hence the unknown input command messages, pretty sure the moocow issue is the culprit but still cant get my head around it.
Pduino problem
Hello everyone, ive got this problem while trying to connect my arduino to Pd. Already installed firmata, used firmata test app to check its ok, and it is. But when i open the arduino-test pd patch, i get this:
netreceive: failed to sett SO_BROADCAST
comport - PD external for unix/windows
LGPL 1998-2015, Winfried Ritsch and others (see LICENSE.txt)
Institute for Electronic Music - Graz
[comport] Opening COM1
[comport]: could not open device COM1:
failure(2) ERROR_FILE_NOT_FOUND
[comport] opening serial port 1 failed!
moocow/string2any 32 -1
... couldn't create
route 13 0 20 1 (message->prepend) connection failed
route 14 0 20 1 (message->prepend) connection failed
route 16 0 20 1 (bang->prepend) connection failed
route 17 0 20 1 (bang->prepend) connection failed
moocow/string2any 32 -1
... couldn't create
moocow/any2string
... couldn't create
moocow/any2string
... couldn't create
moocow/string2any 32 -1
... couldn't create
[arduino]: version_0.5
[comport]: could not open device COM1:
failure(2) ERROR_FILE_NOT_FOUND
Firmware: 2-5.
UNKNOWN_INPUT_COMMAND: 0 480
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 480
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 480
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 480
UNKNOWN_INPUT_COMMAND: 0 479
UNKNOWN_INPUT_COMMAND: 0 480
So, i select the port im using and the A0 pin which is the one with the potentiometer im gonna use, and i get thousands of UNKNOWN_INPUT_COMMAND messages, i turn the pot and the values go from 0 to 1000, and the pd device info block has Firmata 2.5 so its recognizing the device, but cant go beyond that. Any ideas? I see that moocow is missing (and that could be relevant), but couldnt get anything using the "find externals" function.
pduino for Vanilla or how to control arduino outputs from PD
[arduino] is the Pduino abstraction that communicates with Arduino via Firmata, and I think it's vanilla. Any way, if all you want is to control Arduino pins from Pd, you just need to send the correct bytes to Arduino through [comport].
I've written a tutorial on the communication between Pd and Arduino which you can find here, under "Tutorials", it's called "Arduino for Pd'ers".
After I wrote the tutorial I also wrote some abstractions to facilitate this communication, which are not used in the tutorial. You can get them here. Though, these are meant to receive data from the Arduino, not send. Sending data is covered in the tutorial.
Carriage return in messages from Pd to Arduino?
Hadn't seen this post, hence I'm replying so late. In Pd, the comma separates commands, so [3, 80( will send the value 30 and then the value 80 to comport, so the Arduino won't get it.
I think you're making this more complex than needed. Try this in the Arduino code:
int whichPin;
int pwmVal;
int pwmPins[2] = { 9, 10 }; // pins witn PWM capability
void setup() {
Serial.begin(9600);
for (int i = 0; i < 2; i++) {
pinMode(pwmPins[i], OUTPUT);
}
}
void loop() {
if (Serial.available()) {
static int tempVal;
char inChar = Serial.read();
if (isDigit(inChar)) {
// assemble the value in case it's more than one digit
tempVal = tempVal * 10 + inChar - '0';
}
else {
if (inChar == 'p') {
whichPin = tempVal;
tempVal = 0;
}
else if (inChar == 'v') {
pwmVal = tempVal;
tempVal = 0;
analogWrite(pwmPins[whichPin], pwmVal);
}
}
}
}
Then in Pd send a message like this to [comport]
, "print 0p100v". This will set the value 100 to pin 9 (the first pin in the pwmPins array in the Arduino code).
There's no string assembly whatsoever in this code and it should work.
Build a MIDI controller with the Arduino, Firmata and Pure Data
Time to start contributing some knowledge back to the wonderful world that is the internet; today, a step by step nice and easy tutorial on getting started to building your own MIDI controllers with the arduino.
When researching for my ableton controller project, I didn’t find much out there about using firmata on an arduino to send data to software. The standard approach just seemed to be create the code in the arduino language, upload it to your board and hack one of those MIDI to USB cables as a bodge job way of getting the MIDI out of the arduino.
So why firmata and pure data? Well the whole idea of firmata is that you flash it to your arduino, and it throws out serial about whats going on with the arduino inputs and outputs, then you decide how the software treats the readings coming in and going out.
Theory out the way, lets build some controllers. You’ll need a few things…
HARDWARE:
An arduino and something to wire into it (for this i’ll be using a pot)
A USB cable for your arduino
SOFTWARE:
Arduino – http://arduino.cc/en/Main/Software
Pure Data – http://puredata.info/downloads
Firmata – http://at.or.at/hans/pd/objects.html#pduino
Something to patch your new controller into; like Reason or Ableton Live
- SETTING UP FIRMATA AND PURE DATA
Install Pure Data and create a folder to store all your patches somewhere. Unzip Firmata and add the files ‘arduino.pd’, ‘arduino-test.pd’ and ‘arduino-help.pd’ to your new Pure Data folder. The ‘arduino.pd’ file is the object that we use in PD for opening up communication with your arduino and routing it to PD. Done? Awesome, your software is almost set up.
- FLASHING FIRMATA TO YOUR ARDUINO
Install the latest version of arduino and open it up. Connect your arduino with the USB cable to your laptop (i’m using a macbook for this by the way). In the example patches, open up “Standard Firmata”, select your board (im using an arduino mega), and your serial port (look for tty.usbserial for use with a USB cable). Then compile and hit the upload button and your arduino is now ready to use firmata and communicate with Pure Data!
- WIRING UP A POT
Potentiometers are cool, and theres a great arduino tutorial of how to wire one up here: http://www.arduino.cc/en/Tutorial/Potentiometer
Basically, all you need to know is that there are three pins; your two outer pins govern voltage flow across the pot, meaning one has to be 5V and the other has to be ground. It doesn’t matter which, but your 5v pin is going to be where your pot reads maximum, so convention dictates this should be the right hand pin. The center pin needs to be connected to an analog in on the arduino and will read the value of the pot as it sweeps from ground (0v) to 5v.
All wired up? Plug it into your laptop and open Pure Data, we’re ready to get things talking.
- SETTING UP OUR PATCH
Open the example “arduino-test.pd” Pure Data patch you copied over earlier. It should look like this one…
The test patch has everything we need to open a connection and enable pins. Firstly, lets delete a bunch of stuff and make our window a bit bigger. Hit Command + E to enter edit mode in Pure Data.
Ok a quick explaination; the key component here is the ‘arduino’ object. This is being drawn from the file you copied in earlier, and is what communicated with your arduino. Here we can do everything to control the arduino from opening a connection, to receiving data.
The large grid allows us to set the mode of each pin on the arduino. Remember pins 0 and 1 are reserved for Rx and Tx. I’m using analog pin 4 for this demo, so I’ve set my pin mode for pin 4 to ‘analog’.
Now we can plug our arduino in and get a reading from the potentiometer.
- ARDUINO INTO PURE DATA
With your arduino plugged in, hit command and E to bring us out of edit mode. In our patch, click on ‘Devices’ above the arduino object and open up the pure data terminal. (That other thing that loads with PD that has all the scary code in)
The “Devices” message connected to the arduino object pings your computer to find what devices are connected and on what serial ports. Since we’re using a USB cable to connect our arduino, we’re looking for something with ‘usbserial’ in it, in this case; port 2.
Select the relevent port in the green box at the top (remember the first box is ‘0’, second is ‘1’ and so forth) and hit ‘Open’ to establish a connection. Check the terminal to see if the connection was sucessful.
Now lets check we’re getting something in. Create a number box (Command + 3) and connect it to the relevent pin on the ‘Route analog’ box at the bottom. In this case, pin 4.
One more thing; if you’re not getting any readings in, you’ll need to click on ‘pd old analog/digital controls’ and enable your pins here too. What I tend to do in my patches is just not include the large grid but make my own ‘old pd’ controls custom to what i’m enabling/disabling to save space.
Here’s what the ‘old analog/digital controls’ subpatch looks like (pin 4 enabled)…
Come out of edit mode and check that you’ve got readings. If so congratulations! If not, troubleshoot, start with making sure your usb connection is opened, make sure all the correct pins are enabled (remember you’re counting from 0 not 1 on most of these buttons in PD, it’s just the way computers work).
- SCALING READINGS TO MIDI
So we’ve got a reading and chances are it’s to 3 decimal places between 0 to 1. No problem, create a new object (Command + 1) and type “autoscale 0 127”. This allows us to scale the input to a min and max value, in this case 0 to 127 of MIDI. Next, lets get things looking nice, create a new object and type “knob”. Connect this AFTER the autoscale object. (the knob is default set to read inputs from 0 to 127. Then create another number to display the scaled MIDI data coming out, and finally a new object and type “ctlout 1”.
It should look something like this…
The second box should be outputing values from 0 – 127 now, and the knob giving a visual representation of your potentiometer.
Now lets patch it into ableton…
- PURE DATA TO ABLETON LIVE
Firstly, you’ll need to set up your macs IAC driver if you’ve not done this. Basically you’ll need to go into Audio/MIDI preferences and enable your IAC driver. Then create a new input and output. One for input to DAW and one for output from DAW. Google around for a tutorial on this, its really simple, a 30 second job.
After you’ve set up your IAC driver, go back to PD and go to preferences > MIDI Settings, and connect your IAC driver.
Open ableton and go to its MIDI preferences. Create a device listing for your IAC driver and enable its ins and outs into ableton like so…
And thats it! Create an instrument and try to assign something! I’ve got it controlling the brightness of a bass sound here.
Shout out for Facu who requested this tutorial. Hopefully it’ll help some of you looking to get into this stuff and start building things but with no idea where to start.
Error while sending data to more than 2 comports
Dear fellow pd-ers,
I'm using comport to communicate with arduino/teensy for quite long time now, and I didn't encounter any serious issues while using one or two comport objects (and respectively one or two arduinos/teensies). But when I'm trying to connect three at a time, there are some problems, both when when connecting directly to computer's usb ports, and when using powered usb hub. I tried on two different computers. I'm getting this kind of messages in the console:
[comport]: WriteFile:GetOverlappedResult error: 31
[comport] ** ERROR ** couldn't reset params to DCB of device COM42
One of the teensies doesn't react, sometimes Pd freezes and unfreezes only when I disconnect the teensy in question.
Is there some hard limit in Pd - that you can't use more than two comports at once? Teensies are not draining that much power from usb, thei're controlling motor boards that have external power.
Any ideas?
EDIT: I'm using latest available version of PD-Etended
Pduino + Arduino Output to Pins
Unfortunately, snapshot~ doesn't seem to send data at a rate which enables clean signaling of arduino pins. When it comes to audio anything, I find that outputting signal is necessary, as outputting control values just cannot keep up with audio. If you are looking to make a square wave generator that is controllable from puredata, the best way that I have found to do this is by using a combination of arduino, a DAC chip and an op-amp chip. Also, you'll want to use at least a 12 bit DAC, such as mcp4921 or mcp4725, as 8 bit DAC lacks the ability to tune the output fine enough to stay in tune with standard tuning. For opamp choices, you can pretty much take your pick. They all do pretty much the same thing, though you will find that every opamp has it's own unique sound quality. I really love the gritty sound of the CA313. A very good and popular sound for opamp VCO is the tl072 or tl075. There are tons of schematics out there for how to configure a square wave vco with opamps. You would just modify the components to fit the output of your DAC.
Next, you would send your controller values from PD to the arduino and have some code in the ar'dweener to handle communicating with the DAC. You can then add all sorts of fun stuff to your board like digipots, opamp buffers, VCAs and so on to make envelopes, LFOs etc.
If you don't want to track down additional chips (usually ordered from china being the only way to find them, cheap though they tend to be,) but want to have square waves being output directly from the arduino, then you would still be better off having pd send control values to the arduino and then let the arduino handle the signal generation to it's pins. For this purpose, you may want to look at the tone library or the mozzi library. Teensy boards have some expanded audio capabilities as well, but teensy boards are a bit expensive for my taste, as you can get a freakin raspberry pi with a full linux operating system on it for a fraction of what it costs. Still, teensies are great and extremely handy for these types of applications if you dont mind dropping some extra money. I try to build everything to work on cheap arduino clones just for financial and practicality sake.
I have code and patches that I have written to control these types of circuits for many DACs and digipots with SPI and I2C protocalls... let me know if you'd like to check them out for some guidance.
Pduino + Arduino Output to Pins
Dear Forum,
Experienced PD user, intermediate Arduino user here.
My goal is to send several different frequency square waves (to be used as "on" and "off" signals for a circuit) to various output pins on an Arduino.
I am up and running using the Pduino library, and have PD and Arduino talking to each other.
However, I am not able to output audio-rate signals to any Arduino pins. For example, sending a square~ into an appropriately timed snapshot~ to output 0's and 1's to Arduino pins yields random clicking/sputtering Arduino output, rather than the expected steady square wave tone at any freq.
My arduinos play a square wave out through the pins just fine when using the Arduino IDE...so, what am I missing in the communication between Arduino and PD/Pduino? A speed issue?
Thanks in advance for any advice!