Rotary encoder

22 May 2009 . Edited: 22 May 2009

Hi,

I got a SparkFun TW-700198 rotary encoder.  It's not as nice as the website says - rather than being smooth and 'clicky', it's action is more 'gritty', but it does the job. Anyway, I uploaded a picture and the source code:

rotary.zip

[An internet ordering accident landed me with some 2W resistors which are rather large]

Anyway, it's all good but I wonder: 

  1. Are there internal pull ups/downs on the mbed?  Can DigitalIn be extended to allow control of these?
  2. I made a RotaryIn class, following DigitalIn as a template.  Is there a way this can be put into the mbed libs?
  3. Is the source (i.e. class implementation, not just headers) available for viewing anywhere?

I did wonder if someone shouldn't ask SparkFun for their entire catalog of buttons, switches and breakouts in exchange for making them all mbBed ready... hehe.

Regards,
Mike

22 May 2009 . Edited: 22 May 2009

Hi, 

Are there internal pull ups/downs on the mbed?  Can DigitalIn be extended to allow control of these?

There are (up & down), and by default they are set to be pull-down (so not connected gives logical 0). I hadn't exposed controlling them yet, as I wasn't sure how common this type of functionality was on mcus, but if you think it would be useful it could be added.

I made a RotaryIn class, following DigitalIn as a template.  Is there a way this can be put into the mbed libs?

You can't put it in the core mbed library itself, but you can make it another library which people can just pull in as well. e.g. if you put the class code @ http://mbed.co.uk/projects/cookbook/svn/RotaryIn/RotaryIn.(cpp,h) then people can simply use import library to pull it in using the url http://mbed.co.uk/projects/cookbook/svn/RotaryIn and then #include "RotaryIn.h". Make sense? 

Is the source (i.e. class implementation, not just headers) available for viewing anywhere?

No, not yet. The core lib is staying closed at least until i'm happy with the internal architecture and api. Forking is cheap so I don't want fragmentation or to be supporting multiple user-derived libs yet, and I don't want to be restricted in big internal changes or have to support legacy before we even release the first version proper of the
lib :) 

I did wonder if someone shouldn't ask SparkFun for their entire catalog of buttons, switches and breakouts in exchange for making them all mbed ready... hehe.

:) I think that is a wonderful idea! We have ordered a lot from them so could fly!

Cheers,
Simon

23 Apr 2010

Hi Simon,

This info about the default pin mode of DigitalIn would be real handy in the Handbook's description.

Regards,

Barry

23 Apr 2010

Hi again,

Oops - devil's in the "Details"!  I just looked again at the Handbook and it already explains about the pin mode in the Details section. 

Is there a reason a pull-down was chosen?  All of the uP's that I'm familiar with have a weak pull-up resistor as a default on input pins.

Thanks,

Barry