[maxmsp] Arduino, Max MSP & serial data
Joe Bicker
notyouraveragejoe at gmail.com
Mon Dec 10 10:06:39 MST 2007
- Previous message: [maxmsp] Arduino, Max MSP & serial data
- Next message: [maxmsp] Arduino, Max MSP & serial data
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thanks for your replies. I actually figured out on my own that polling is the natural thing to do. I'd been staring at arduino's C code for too long and my brain had melted a little. I could be wrong, but the range of 2550 I got from the fact that the servos I use seem to reach their mechanical limit with pulses of 3000 microseconds (3 milliseconds) and 550 microseconds (.55 milliseconds). And yes, I realise that's actually a range of 2450 microseconds but my mother tells me I'm special and that's enough for me. Within arduino, using the delayMicroseconds() function allows me to set the pulse to within 1 microsecond, so I assume (probably wrongly) that I have a pulse resolution of 1 microsecond. The mechanical range of the servos is slightly larger than 180 degrees, probably 200. Importantly though, I got my "handshake" working. I send a byte from Max, then arduino saves a variable for the pulse time for servo 1, and the arduino sends (Serial.print()) "120" or "x" back and I have a 'sel 120' object to get that to bang an 'int', sending the value for the pulse time of servo 2, which the arduino has been patiently waiting for (for all of a few milliseconds). I'm a happy Joe. On 10/12/2007, MarkDavid Hosale <markdavid at mdhosale.com> wrote: > > Hi Joe- > I am not sure what you are trying to do but I have some sample code > that should address all of your questions: > http://www.mdhosale.com/md_arduino/ > > If I understand you correctly, then I think you have some > misconceptions about how the communication works between Arduino and > Max's Serial object. > > > I'm very aware of the Serial.print function in the arduino code but > > the serial object in max seems to ignore it until I send it a bang. > > > This is the correct behavior. You need to bang the serial object > regularly if you want the data to read and/or write consistently. You > can think of this as a software side "polling" of the values, which > happens independently of the cycling of the processor on the Arduino > board, which is controlled in the Arduino code. Adjusting the > software side "polling" in essence is a balance between application > performance and quicker value reads. > > > I could very well send it a constant stream of timed bangs but I > > get the feeling that's intensive, unnecessary and probably won't > > work reliably at fast speed. > > > You should keep the polling between 15 and 100 ms. As for servos, > they need to be sent values at a regular rate of about 20 ms. > Otherwise they get jumpy. > > > Mainly to control more than one servo, but also to possibly > > increase my precision (I have a range of about 2550 with the servo, > > but sending serial bytes means I have to multiply the input number > > by ten, so my resolution is actually lower). > > I am confused by your range of 2550 (and the math), because usually > servos are controlled via an angle of rotation. For example, 0-180 > degrees depending on the specifications of the motor you are using. > > In the link above you can find examples of how to control several > motors and receive input at the same time. > > hope this helps- > MD > > > > > On Dec 9, 2007, at 2:16 PM, Joe Bicker wrote: > > > Hi, I've been playing around with sending serial data to the > > arduino board to controla servo motor, but it seems to be a case of > > feeding it one bit at a time, much like you spoonfeed a baby rather > > than giving it a whole meal to chew over. > > I'd like to send more than one byte. Mainly to control more than > > one servo, but also to possibly increase my precision (I have a > > range of about 2550 with the servo, but sending serial bytes means > > I have to multiply the input number by ten, so my resolution is > > actually lower). > > In order to do this, I figure I need to have some sort of > > handshaking going on (getting the arduino to "ask" for the next > > byte). I'm very aware of the Serial.print function in the arduino > > code but the serial object in max seems to ignore it until I send > > it a bang. > > I could very well send it a constant stream of timed bangs but I > > get the feeling that's intensive, unnecessary and probably won't > > work reliably at fast speed. > > > > In short, what's the best way to send a byte from arduino to max, > > and have that immediately trigger something in max, without any > > user input? > > > > This would be a great help and greatly increase my chances of > > success in my project, and I will prompty erect a shrine in your > > honour (in my mind) > > Cheers! > > > > Joe > > _______________________________________________ > > maxmsp mailing list > > maxmsp at cycling74.com > > http://www.cycling74.com/mailman/listinfo/maxmsp > > _______________________________________________ > maxmsp mailing list > maxmsp at cycling74.com > http://www.cycling74.com/mailman/listinfo/maxmsp > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.cycling74.com/pipermail/maxmsp/attachments/20071210/f669accf/attachment.htm
- Previous message: [maxmsp] Arduino, Max MSP & serial data
- Next message: [maxmsp] Arduino, Max MSP & serial data
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
