PDuino - simultaneous analog input and digital output problems
Hello!
I'm trying to get PDuino working in a setup where I have Arduino reading an analog input and also controlling a relay on the digital output. I have tried the StandardFirmata sketch for Arduino but it doesn't seem to be able to read the analog input with this sketch (it controls the digital output no problem with this however). When I use the AllInputsFirmata instead, it reads the analog inputs just fine but I'm getting no response on the digital outputs.
Is there perhaps something where you can't use analog inputs and digital outputs at the same time? Could I be doing something else wrong? I've tried all the other Firmata sketches that come with the Pduino setup files (out of desperation!) but with no success. Any help greatly appreciated!
recursive patching
i was thinking about "recursive patching" lately, meaning to call an abstraction inside of an abstraction inside of an abstraction inside of an abstraction inside of an abstraction inside of an abstraction and so on.
It is clear to me, that this has to be done with dynamic patching in order to stop the process at some point. So the question is not how to implement this, but in what case something like this could be useful? Do you know of any "recursive" patches? The only thing i can think about are reverberators and i actually tried this using a feedback-delay line inside of a feedback-delay line inside of a feedback-delay line inside of a feedback-delay line inside of a feedback-delay line inside of a feedback-delay line feedback-delay line inside of a feedback-delay line inside of a feedback-delay line.. with rather unimpressive results.
Any ideas?
How to use OSC namespaces in MobMuPlat?
Is it possible to parse the namespace of OSC messages in MobMuPlat?
MobMuPlat handles OSC communication in a wrapper patch that provides a message called 'fromNetwork'.
Say the OSC message is: /level1/level2/levelN format value
It has the format: [path format value]. The path here uses a namespace that subdivides according to levels.
With oscparse, the namespace in the path could be parsed like this :
netreceive -> oscparse-> list trim -> route level1 -> route level 2 ... route levelN
https://forum.pdpatchrepo.info/topic/9856/oscformat-and-oscparse-integer-not-routing-as-expected/8
With MobMuPlat's 'valueFromNetwork', is it still possible to "route" the value of the message according to the namespace? Since valueToNetwork contains a list where the first argument is the entire path, I can only split the first argument from the remaining arguments:
receive fromNetwork -> route list -> route /level1/level2/levelN
But I can't further split within the path itself to divide leve1/level2/levelN:
receive fromNetwork -> route list -> route .level1 -> route level2 -> route levelN.
Is there a way of doing this?
how can I get the full error text on a Mac?
@jameslo Spacing each loadbang for me has been trial and error..... to get a patch to work.... although you have to think the patch through in terms of "what" should load before "what".
I see you using [catch] but no "no corresponding catch" messages so maybe not the problem.
In the windows patch the arrays are strange? If you open them is there actually anything inside? I doubt it. The $0 has not been translated in their names, and they are exact copies of each other (all the "left" are the same and all the "right" are the same)...... unless the $0's are different having been drawn from separate abstractions with different $0 values. Again, I doubt that is the case looking at your screenshot.. But if they are different it must be a load timing issue again. The OS might need a little more time to re-read the file repeatedly.
So there is probably one that has created correctly, and the others cannot because they have the same name, or none have created because an I/O read was abandoned as a request to read again was received. Actually that is likely?? Read the same file again.... well, I will cancel the last read then!!... might be the response from the OS, and might be different depending on which OS it is, and whether it has an SSD or a hard drive. All OS's will treat media files differently than other file types. They often load just the header and a few Mbytes of media and wait for instruction to continue.
That is (maybe) where the problem lies, especially as the error prints just after loading the exact same wav file numerous times.
If the $0's are all the same then you should find that giving them $1 names instead of $0 will solve the problem.
You could try printing each loadbang in your sequence to the terminal (with an identifier) to narrow down the exact moment or the error, but I am pretty sure it is that $0, or a "read the file again" issue.
David.
[gme~] / [gmes~] - Game Music Emu
Allows you to play various game music formats, including:
AY - ZX Spectrum/Amstrad CPC
GBS - Nintendo Game Boy
GYM - Sega Genesis/Mega Drive
HES - NEC TurboGrafx-16/PC Engine
KSS - MSX Home Computer/other Z80 systems (doesn't support FM sound)
NSF/NSFE - Nintendo NES/Famicom (with VRC 6, Namco 106, and FME-7 sound)
SAP - Atari systems using POKEY sound chip
SPC - Super Nintendo/Super Famicom
VGM/VGZ - Sega Master System/Mark III, Sega Genesis/Mega Drive,BBC Micro
The externals use the game-music-emu library, which can be found here: https://bitbucket.org/mpyne/game-music-emu/wiki/Home
[gme~] has 2 outlets for left and right audio channels, while [gmes~] is a multi-channel variant that has 16 outlets for 8 voices, times 2 for stereo.
[gmes~] only works for certain emulator types that have implemented a special class called Classic_Emu. These types include AY, GBS, HES, KSS, NSF, SAP, and sometimes VGM. You can try loading other formats into [gmes~] but most likely all you'll get is a very sped-up version of the song and the voices will not be separated into their individual channels. Under Linux, [gmes~] doesn't appear to work even for those file types.
Luckily, there's a workaround which involves creating multiple instances of [gme~] and dedicating each one to a specific voice/channel. I've included an example of how that works in the zip file.
Methods
- [ info ( - Post game and song info, and track number in the case of multi-track formats
- this currently does not include .rsn files, though I plan to make that possible in the future. Since .rsn is essentially a .rar file, you'll need to first extract the .spc's and open them individually.
- [ path ( - Post the file's full path
- [ read $1 ( - Reads the path of a file
- To get gme~ to play music, start by reading in a file, then send either a bang or a number indicating a specific track.
- [ goto $1 ( - Seeks to a time in the track in milliseconds
- Still very buggy. It works well for some formats and not so well for others. My guess is it has something to do with emulators that implement Classic_Emu.
- [ tempo $1 ( - Sets the tempo
- 0.5 is half speed, while 2 is double. It caps at 4, though I might eventually remove or increase the cap if it's safe to do so.
- [ track $1 ( - Sets the track without playing it
- sending a float to gme~ will cause that track number to start playing if a file has been loaded.
- [ mute $1 ... ( - Mutes the channels specified.
- can be either one value or a list of values.
- [ solo $1 ... ( - Mutes all channels except the ones specified.
- it toggles between solo and unmute-all if it's the same channel(s) being solo'd.
- [ mask ($1) ( - Sets the muting mask directly, or posts its current state if no argument is given.
- muting actually works by reading an integer and interpreting each bit as an on/off switch for a channel.
- -1 mutes all channels, 0 unmutes all channels, 5 would mute the 1st and 3nd channels since 5 in binary is 0101.
- [ stop ( - Stops playback.
- start playback again by sending a bang or "play" message, or a float value
- [ play | bang ( - Starts playback or pauses/unpauses when playback has already started, or restarts playback if it has been stopped.
- "play" is just an alias for bang in the event that it needs to be interpreted as its own unique message.
Creation args
Both externals optionally take a list of numbers, indicating the channels that should be played, while the rest get muted. If there are no creation arguments, all channels will play normally.
Note: included in the zip are libgme.* files. These files, depending on which OS you're running, might need to accompany the externals. In the case of Windows, libgme.dll almost definitely needs to accompany gme(s)~.dll
Also, gme can read m3u's, but not directly. When you read a file like .nsf, gme will look for a file that has the exact same name but with the extension m3u, then use that file to determine track names and in which order the tracks are to be played.
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.
HC-SR04 Ultrasonic Sensor with Pd (How long does a bang last?)
Hi,
I'm trying to use an HC-SR04 Ultrasonic sensor through arduino with Pure Data using Pduino and Standard Firmata. Pduino works perfectly and I am able to get data from many other sensors. This particular sensor is slightly different because it needs me to send a pulse of length 30 micro seconds at a time interval of more than 60 milliseconds to the trigger pin of the sensor, which triggers the ultrasonic waves from the transmitter. The receiver of the sensor measures the ultrasonic waves as they bounce back after reflecting from an external object to measure the distance.
My problem is that I am trying to figure out how to give a 30 microsecond pulse as an output from Pd, which leads me to ask, how long does a 'Bang' last? Is there another way to set up a pulsing mechanism where I can control the time interval of the pulse? Something like the pulseIn() function in Arduino IDE?
creating a unique text file for mulitple instances of an abstraction
@nicnut
$0 is a VERY bad idea, as its value can change when reopening the patch, depending on other patches and abstractions already open. You will end up with text files with meaningless unpredictable names
It is great though for keeping messages private within a patch or an abstraction....
Also a $1 in a message box takes the value of the first atom of an incoming list ($2 the second), and is not the value of an argument of the abstraction. $1, $2 etc. only take the arguments of an abstraction when they are in an object box.
You can use a float, or a symbol as an argument.
Symbols can be easier to "follow" though the patch and the text file names, as they carry more meaning.
Give your abstractions its arguments (or just one if the text file name is all you need... $1) ....... [abstr 1 x y woof]...... [abstr 2 z a howl] etc.....
Then use one of them to name the text file to write....... so writing $4.txt would write woof.txt for the first and howl.txt for the second.
Writing $1.txt would write 1.txt for the first and 2.txt for the second....
Writing $2.txt would write x.txt for the first and z.txt for the second....
Etc.
Here is an example........ example.zip
[mother] contains two copies of [abstr]........ [abstr 1] and [abstr 2].
You will see that the 1, or the 2, replace the [$1] value which is then sent to the $1 in the write message.
If you want to use a symbol then replace [$1]... the float object...... with [symbol $1]....... as in the [abstr] example.
David.
Problem loading libraries (iemguts)
Eighteen-year-old Shen Qiang says he soon thereafter began winning Canadian contests, and came in Canada in 2004. He will be a proud representative of the Canadian Olympic team this summer. While he didn't immigrate explicitly to further his table tennis career (he came with his family, who live in Toronto), he's happy with Table Tennis Canada's sports app, and is looking forward to the autumn opening of this new 24-hour training centre in Ottawa, so that he can work harder on his sport. Produced in northeast China, Shen first picked up a paddle at nine. He quit college to proceed to Harbin, a town 300 kilometers away, to train full-time and represent the province of Heilongjiang and had left home. The contest in China was extremely intense, '' he states. https://ok.ru/group/53953306755154/ The athletes trained five days a week, six hours a day; they were paid to train fulltime and compete, he says. "In China, it is very competitive because in the event you do not make results then you will be removed from the team, and if you don't have table tennis without a school, there is no future for you."
video playback framerate wrong
@jbvidigal Hello again......
Yes, you can load the audio ready to play...... it goes to the $0-soundfile table ready to be played from ram. The video though is played from disc, in sync with the audio. The video file cannot be "pre-loaded" as such......
I think the problem you have is that you are putting my patch (or yours probably) as a sub-patch [pd something] and so all of the $0's have the same value derived from the main patch.
You need to copy the contents of your [pd-something] into a new patch window and save that as "something.pd". Then in your main patch you retype your sub-patch objects as [something 1] for the first and [something 2] etc. (abstractions - not sub-patches) and then they will each have a different value for $0.
All that is of course a "maybe" as I have not seen your patch. Zip yours up without the media files if you still hit a brick wall, and we can all have a look and better let you know how to solve any problems.......
David.