Motor Shield Revesing DC Motor in Firmata

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
StevenA
 
Posts: 5
Joined: Wed May 09, 2012 11:38 am

Motor Shield Revesing DC Motor in Firmata

Post by StevenA »

Hi, I've found online a very basic interface to Arduino using Firmata, seen here: http://www.acraigie.com/programming/fir ... tions.html

However, it's for Arduino and I've not found how one could reverse a DC motor using the the Adafruit motor shield within Firmata. I've laid out the I/O pins with with two photoresistors, limit switches for the directions which the motors will go, and, the DC motors are on the PWM pins.

I A0 Photoresistor1
I A1 Photoresistor2
I A2 Limit M1 Forward
I A3 Limit M1 Reverse
I A4 Limit M2 F
I A5 Limit M2 R
I D13 Limit M4 F
I D12 Limit M4 R
O D~11 M1
I D~10 Limit M3 F
I D~9 Limit M3 R
O D8 Relay1
O D7 Relay2
O D~6 M4
O D~5 M3
- D4 Open
O D~3 M2
- D2 Open
Tx D1 Tx
Rx D0 Rx

Looking at that link, the PR's and limits on inputs should give me a visual indication, but could someone describe how Firmata could handle reversing a motor on the PWM pins?

Thanks, Steven

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by adafruit_support_bill »

The H-bridges are controlled by the 74HC595 serial-to-parallel latch via digital pins 4, 7, 8 and 12. Additionally, the speed is controlled by one of the PWM pins (the exact pin depends on which channel the motor is on). You would have to look at the library source code and replicate the modes and activities on those pins to accomplish the motor reversal.

What is it you are trying to accomplish (aside from just reversing the motor)? There may be simpler solutions than replicating the motor library in Firmata.

StevenA
 
Posts: 5
Joined: Wed May 09, 2012 11:38 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by StevenA »

Oh, so other pins are used and then they may not be available for use as inputs for limit switches....

I'm building a spectrograph for my 36" telescope and since this device could be 13 feet in the air I'd like to remotely control it. I've built the Adafruit Motor Shield and have attached it to my Arduino board. I'm hoping there is a path to create a GUI with buttons so I can mouse-click on that will activate a relay to turn the power to one of two calibration lamps, argon and neon, slowly turn four reversible DC motors that will be pully'd to two micrometer stages and one to rotate a 200mm camera lens focus, plus, a fourth DC motor to slowly go from 0 to 90 degrees to rotate in a mirror to divert the calibration light into the device and back again when not calibrating. I know Arduino can control 4 DC motors.

The computer on the telescope that'll control the spectrograph, is part of an adhoc network where I remote desktop control it from 20 feet away from another laptop.

A description of what I'd like is;
A GUI of sorts; to activate the individual outputs to turn on the lamps via relay activation with Light Dependent Resistors on inputs so Arduino can determine that the lamps actually lit, buttons to rotate each of the DC motors slowly PMW reversibly.

The spectrograph will have two CCD cameras for me to see visually something that indicates the motors have turned or optic rotated in so the Firmata link I posted is very close albeit simplistic.

I know what I need. I have an idea how it's all supposed to work. I'm good at mechanical, electronics and optics but some pieces (coding) elude me.

The motor limit switches could have two per input and then I'd have more pins available for motor control. I'd just have to pay attention to the direction I was going and back up when I saw the switch input go high so it goes low again to stay within the usable range of motion.... It's very rudimentary but I don't need fancy.

Steven

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by adafruit_support_bill »

With 4 DC motors in use, you will have 10 pins left over:

2, 9, 10, 13 and analog 0-5. (the analogs can be used for digital also.) 2 lamp outputs will consume 1 pin each. How many limit switches did you need?

StevenA
 
Posts: 5
Joined: Wed May 09, 2012 11:38 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by StevenA »

Hmmm, the lamp selector relay with the NO contact for Argon, NC for Neon, is one of the four digital outputs, the second of four would be an output that runs a relay that allows 120vac to get to the lamp selector relay. The photoresistors mounted under each lamp take up analog A0 and A1 inputs.

That leaves two digital I/O's and 4 Analog I's, or 6 inputs total for any limit switches. Certainly the reversable DC motor rotating from 0-90 degrees with a mirror attached to it will need two limits. The micrometer linear bearing stage will consume two with its limits. The grating stage doesn't possibly need them as it won't be moving too much to get red to blue onto the CCD chip. The 200mmf3.5 camera lens may need one since rotating past infinty is bad for the lens (there is no "to infinity and beyond" on this one...). That would leave one unused pin of the ten..., or teh camer lens get's the last so I would know the focus depth if it reached that end too.

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by adafruit_support_bill »

Sounds like a tight fit, but not impossible. There is always the Mega if you need more pins.

There are i2c port expanders also, but I'm not sure you could get them to work with Firmata.

Firmata seems like a reasonable way to control individual pin operations like your relays, sensors and limit switches. It can probably be made to drive the DC motors on the motor shield too. The AF_Motor library source code is the best reference on what pin manipulations are required to do that.

StevenA
 
Posts: 5
Joined: Wed May 09, 2012 11:38 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by StevenA »

That sounds like some code needs to be written and gets executed somehow.... :?

With regard to the Firmata test pin interface link I sent, with that I could 'see' inputs go high or low as the calibration light turned on and illuminated the photoresistors or if a limit switch is tripped, yes? Just by running that Firmata program and looking at the monitor? And, it has a button to mouse-click on to turn an output on that had a relay attached? So I can click to turn on the lamp output and see the input respond to light? That's my assumption right now.

I've built the Adafruit Motor Shield but interacting with motors with it appears problematic in terms of simplicity like the above assumption on Firmata and input visualization and clicking to activate outputs....

If I ditch the shield and use relays (I know, not very high-tech), I could use two digital outputs per motor; one relay controls a DPDT relay with integrated limit switches, like I've built before, for direction, and, a second output that enables second relay to provide 'some DC voltage' to that first directional relay. To me this is more straight forward and may work with the simplistic Firmata interface. Those limit switches on direction open to stop that direction of travel and the other set of contacts in the limit then sees the motor voltage. If the motor voltage were 5vdc that second set of contacts on the limit could be put on an Arduino input and visuallized in the Firmata test interface that the limit were reached....

Does this sound plausable and my assumptions correct about the Firmata test interface?

Thanks, Steven
Attachments
DPDT Motor Drive with Limits.JPG
DPDT Motor Drive with Limits.JPG (24 KiB) Viewed 1889 times

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by adafruit_support_bill »

If I ditch the shield and use relays (I know, not very high-tech)...
That is a workable solution - and likely easier to implement in Firmata. And it sounds like you are a lot more comfortable with the electrical than the coding side too.
Does this sound plausable and my assumptions correct about the Firmata test interface
I am not a Firmata user, but that is consistent with my understanding of its capabilities. You might check over at the Processing Forum. You will probably find more Firmata users over there. http://forum.processing.org/

StevenA
 
Posts: 5
Joined: Wed May 09, 2012 11:38 am

Re: Motor Shield Revesing DC Motor in Firmata

Post by StevenA »

Thanks.

Since my limited coding skills are limited to websites, to use code which I don't have complete command of could get me in trouble if something were to break and not function in the future. That Firmata test interface is canned ready to load anywhere and the circuits I make I would be intimately familiar with. Though not elegant, if something should stop working I have a reasonably good chance of getting it up and running soon. To me that appears to be a good first step into robotics until such time as I've played more. With this project there's not much time to play, it's all business to keep the schedule I have, to make the spectrograph operational by summer of 2013.

Thanks for the details.
Steven

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”