Main Site Documentation

Rotary Hi Module


#1

Having a problem with a new Rotary H1 Module - something I haven’t used before but in theory is super simple - direction and counts.

My problem is I can read direction but not counts. My configuration is a FEZ Cobra II Net with 2 line character display connected to Socket 1 and the Rotary H1 connected to Socket 3. Compiled to target .net micro framework 4.2.

The unit is powered by a quality external 12V DC supply and connected to my development system via USB.

I have distilled the code down as below - I know its not pretty but served to eliminate everything else!.

It displays “up - 0” when I turn in a clockwise direction and
"down - 0" when turned anticlockwise.

Checking the counts variable in debug confirms is has read 0.

Any thoughts or suggestions would be appreciated.

TrevorG

Public Sub ProgramStarted()

Dim counts As Integer
Dim display_string As String

char_Display.Clear()
Debug.Print("Program Started")

While 2 > 1
  char_Display.Clear()

 counts = rotaryH1.GetCount()

  If rotaryH1.GetDirection = GTM.GHIElectronics.RotaryH1.Direction.Clockwise Then
    display_string = "up - " + counts.ToString
  Else
    display_string = "down - " + counts.ToString
  End If
  char_Display.PrintString(display_string)


  Thread.Sleep(500)

End While

End Sub


#2

Hi,
at the moment I do not remember the exact reason, but I remember that it did not work on every socket where it was expected to work. So I would try another socket.
Kind regards
Roland


#3

Hi Roland,

Appreciate you comments - tried swapping the display and rotary module without any change. There are only two options on the FEZ Cobra to connect the rotary module and display ( unless you use the extender).

Also took out the display and added a button/led - modified the code to switch the led on if “counts > 0” - alas no led.

Regards

Trevor


#4

Just had a short look on your code, you use a while loop in the Program.Started method,
please have a look on this thread.

Actually I have not the time to look up my code, perhaps in aroun 10 hours or on the weekend.


#5

With the while Loop in another thread it works


Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics

Namespace Cobra_Rotary_Test
    Partial Public Class Program

        Private readerThread As Thread

        Public Sub ProgramStarted()
            Debug.Print("Program Started")
            readerThread = New Thread(AddressOf runReaderThread)
            readerThread.Start()
        End Sub

        Private Sub runReaderThread()
            Dim counts As Integer
            'Dim display_string As String

            While True
                counts = rotaryH1.GetCount()

                If rotaryH1.GetDirection = GTM.GHIElectronics.RotaryH1.Direction.Clockwise Then
                    Debug.Print("up - " + counts.ToString)
                    ' display_string = "up - " + counts.ToString
                Else
                    Debug.Print("down - " + counts.ToString)
                    ' display_string = "down - " + counts.ToString
                End If
                'char_Display.PrintString(display_string)
                Thread.Sleep(500)
            End While
        End Sub
    End Class
End Namespace


#6

Hi Roland,

Thanks you for you code.

Inserted your code into my project and physically removed the display as well any code related to it.

The debug output is :

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

Using mainboard GHI Electronics FEZCobra II version 1.0
Program Started
down - 0
up - 0
up - 0
up - 0
up - 0
up - 0
up - 0
up - 0
down - 0
down - 0
down - 0
down - 0
up - 0
up - 0
up - 0
up - 0
down - 0
down - 0

The program is happily detecting change in direction just not the counts.

Regards

Trevor


#7

Hi Roland,

First up - thanks again for your assistance.

Second Up - we are working :smiley:

The short version is I upgraded the firmware in the FII to 4.2.11.2 and all is well.

It may also be my imagination but the deploy process is much “snappier”.

Regards

Trevor