Newbie issues: Arduino, M4L and LEDs
Hi,
I have Max 4 Live and the Arduino and a Neopixel WS2812b strip that works nicely with the Arduino. I'm familiar with Ableton but a newbie as regards M4L and the Arduino.
My project is to input simple digital data from Ableton to the Arduino via the Max for Live Arduino connection kit, and use that data to trigger different ledstrip patterns. I'm hoping to send data to the Arduino, either to five or six digital pins so I can trigger an LED pattern when e.g. pin 11 receives a HIGH, or a connection in to one pin that could be values from 0-255 so I can script "if value is between 0-20 then do this, if between 20-40 do this" etc etc.
I have had some modest success: I can load the StandardFirmata on the Arduino, run the Ableton M4L Arduino connector and switch on and off a single Led connected to a digital pin. By assigning that digital pin in output mode in the M4L device to an empty audio effect dial I can make the led flash every time the kick drum of a dance track plays - which is awesome!
But I have two issues:
1)
The Arduino M4L device behaves oddly. I can control any led on the digital pins when there's only one instance of Arduino.amdx. If I try to enable a second pin output on the same Arduino.amdx device Ableton crashes the moment I map it to a new audio effect macro. I can have multiple instances of the Arduino device on different midi tracks, and the first one I enable to a specific pin works but then the others set to different pins don't work - led doesn't light up - and on rechecking the first pin that has stopped working too. I was expecting to be able to use just one device instance and easily stream simple high/low data through it to multiple Arduino ports.
2)
Communication to the Arduino only works in all cases when StandardFirmata is loaded on the Arduino. But Standard Firmata is huge, eats lots of code memory, and I don't understand any of the code which would make it very difficult to incorporate my led commands. I've tried SimpleDigitalFirmata and that doesn't work either.
All my attempts to write a custom sketch that will establish basic serial comms, receive info from the Ableton Max Arduino device and trigger either the LED strip or just an Led stuck directly into a pin and ground have failed.
Example, modified from an "LED pushbutton" sketch, of the kind of thing I'm trying (but which doesn't work):
#include //tells it to use the FastLED library, always use this.
#define NUM_LEDS 150 // Creates variable NUM_LEDS to equal 150, always use this.
#define DATA_PIN 6 // Which data pin, always use this.
CRGBArray leds; //creates an array in memory of 150 leds called "leds", always use this.
// digital pin 2 has a pushbutton attached to it. Give it a name:
int abletonIN = 7; //random, doesn't matter which
int stripOUT = 6;
// the setup routine runs once when you press reset:
void setup() {
// set the led type
FastLED.addLeds(leds, NUM_LEDS); //Tell it the LED type i.e. NEOPIXEL
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(abletonIN, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(abletonIN);
//int buttonState = 1;
if (buttonState = 1)
{
// action A
fill_gradient_RGB(leds,0,CRGB(255,0,0),NUM_LEDS-1,CRGB(0,255,0) );
FastLED.show();
delay(500);
}
else
{
// action B
fill_solid(leds, NUM_LEDS, CRGB::Black); // Set all 150 to red.
FastLED.show();
delay(500);
}
}
I might be going at all this completely the wrong way, any suggestions gratefully received!
This might be what I'm looking for:
https://docs.cycling74.com/max7/tutorials/communicationschapter02
Arduino over serial can work only with single serial object.
If You insert several amxd objects, each having serial object inside,
You will get into trouble.
If You need to send from different tracks or whatever one calls it in ableton,
You must arrange one device which sends data to arduino,
and receives data to send from other m4L devices.
I am not using Live at all, so I can't help You with that.
Turning 7 leds is a trivial task in arduino world, just look into
basic sketch examples for serial communication and LEDs.
Ok thanks for your reply Source Audio!
So can only use one Arduino connecter in Abelton - that's fair enough, I can work with that.
I don't have a problem with controlling the LEDs. It's the M4L Arduino device that is difficult to use.
I am working through the Max Tutorial 2: Serial Communication, which provides a simple Arduino sketch and a max patch, and that's very interesting. It functions: Max talks to Arduino and the Arduino talks back. I will do some more studying.
Are there tutorials, or any detailed documentation on the Arduino connector? I can find very little. If I google "arduino.axmd" I get 8 results, and none of them are from cycling74.com.
Hi
both the Arduino and the [serial] object are well supported in Max, and there are numerous (too many to list here) online tutorials. In M4L, however, there seems to be much much less support, particularly for the [serial] object. I have found that learning to write simple code for the Arduino - away from Max - is the best place to start; getting your circuit and code to do exactly what you want first, that way you can ensure that any faults must lie elsewhere. So I can't recommend using Firmata.
Then do a bit of research into simple M4L stuff, but the Live API and LOM reference pages can be quite daunting I know. This forum is the best place for support.
I recall from two years ago (last time I used M4L and [serial]) that editing a M4L patch, inside Live, while the [serial] port is open caused all sorts of crashes and hangs, maybe that has since changed, but get into the habit of disabling the serial port before editing your patch.
HTH
Brendan
Hi Brendan,
Thanks for the tip about disabling the serial port before modifying the Arduino device - I'll try that out.
I'm taking the approach you recommend, starting from basics and establishing simple serial communication and building from there.
One of many more general questions...
I can use the Max patch that comes with the Max Tutorial 2: Serial Communications to send data to Arduino then get it sent back in various formats that are displayed on the Max Console. Which is informative. But when I use the Arduino.axmd device to send data, is there a simple way to display what values the Arduino is receiving? The M4L Arduino device isn't configured to display output in the same way as the tutorial patch. Can I use the Max Console in conjunction with the Arduino.axmd device? Or could I used the Arduino IDE serial monitor to receive output from the Arduino, or would that clash with or interfere with the com connection between the Ableton device and the Arduino?
Arduino serial monitor and max serial object can't work at the same time.
Only 1 serial communication at a time, does not
matter what software is involved.
I would avoid resending received data from arduino back to max, is that really necessary?
No not necessary, but I wanted to know if there's a way to debug - to record or display what data the Ableton device is passing to Arduino. With the Max serial tutorial you can do that because the Arduino sketch returns what it receives from the Max patch back, and it displays in the Max console. But there doesn't seem any way to do the same if I'm using the Arduino.axmd device....
Is there anywhere online to find information around the connection kit. I too am having trouble with the arduino.axmd
That's exactly the reason not to use any of these premade maxuinos, connection kits and similar.
It does not help You to learn what's going on, and any time spent using that stuff
is just a lost time, and in fact double lost, because once You get to the point that it does not
work, you have to start all the way from the beginning.
Thanks Source Audio, this is REALLY useful info.
I have fully-licensed licensed Ableton with all the Max stuff. I understand I can edit any M4L object in Max as long as I start the editor from within Ableton. Can *any* Max device be loaded in Ableton, or are there limitations? For example I'm working through the Max basic serial communication tutorial which comes with 02cSerialCommunication.maxpat to play with. Could I load that in Ableton and send simple serial messages to the Arduino?
I guess a similar question is, why are Max patches .maxpat while the Ableton Max devices seem mostly to be .amxd - is it easy to convert .maxpat to .amxd?
@ source audio
"That’s exactly the reason not to use any of these premade maxuinos, connection kits and similar.
It does not help You to learn what’s going on, and any time spent using that stuff
is just a lost time"
I am happy that someone else feels the same. I am not a mechanic, but I can drive a car and generally maintain it. If, however, it breaks down, I have to get a professional to fix it. It's the same with Max/Arduino for me - I need to know and control exactly what is going on in my code and patches, so prefabs are no use to me. Externals and libraries? Of course, when I'm lazy.
;)
Totally agree with you, however when my car breaks down i try and find a way to do it myself without knowing the ins and outs of the combustion engine (or bodywork for that matter) - because i don't want to be a mechanic and i will probably never use that information. Same as Max/arduino at the minute.
As much as i want to learn arduino and max, id love to get going with some of this consumer looking stuff.
I changed tactic last night and switched to Hairless Midi and loopMidi, and it worked almost immediately: midi data streaming from Ableton through loopMidi to Hairless Midi and straight to the Arduino - got a C3 midi note to light up an led in pin 13.
It's basically step 10 of this Instructable: http://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/?ALLSTEPS
It mainly focuses on using button switches to send midi data into Ableton from the Arduino, but step 10 covers transfers the other way and supplies a couple of starter Arduino sketches to establish the link, which are simple enough to play about with.
Thanks Stephen.
Yea i tried that option first then switched to the max4life patches as they seemed like they were ready to go. I may now go back to the Instructable and start again.
I am sorry not to be of any help when it comes to Ableton, I am simply not using it.
The question about amxd - maxpat files.
amxd is a variant of max collective, one can replace the header of the amxd file with
one from maxpat, rename from .amxd to .maxpat and then open the file in Max for editing.
Same way one can mod mxf files for editing.
But depending on what and how is embedded in the file,
one could miss some custom externals and bpatchers.