I see absolutely no point going out of your way to change your coffee-drinking habits or obtain beans exclusively for growing Cannabis. You shouldn't use fresh grounds because they will contain much higher levels of alkaloids that may have a negative effect (caffeine). It is just that coffee grounds are a very common organic by-product... ultimately it is organic matter.
Grass clippings actually have more nitrogen, phosphorous and potassium; probably other minerals as well, maybe with some exception. They are both nitrogen sources, but the grass clippings will undoubtedly be more abundant (and pragmatic) for composting than coffee grounds, unless you are getting spent grounds from a coffee shop.
Coffee grounds are convenient food for earthworms because they are already really ground up. But, just like grass clippings, banana peels, tealeaves, vegetable peels, etc. they need to be composted (thoroughly decayed by microbes) to get the most benefit from them.