Phidget module

BlitzMax Forums/BlitzMax Programming/Phidget module

Kistjes(Posted 2009) [#1]
Hello,

In between two projects I managed to create a first version of a Phidget module (see www.phidgets.com).

Note: This module is developed and tested on a Windows XP computer. I don't know where Phidget installs the lib file on MacOS and Linux. Probably the file phidget21.bmx needs to be updated. If there is anyone who can give me the correct install path, I would be very grateful.

EDIT: version 1.01 update: Added the Phidget Temperature Sensor board.

Version 1.0 supports the following Phidget boards:

* Accelerometer
* InterfaceKit
* PhidgetLED
* PhidgetRFID
* PhidgetServo
* PhidgetPHsensor
* PhidgetEncoder

I do not have a PH sensor and Encoder, so I haven't tested them yet. But they work rather straight forward, so I expect no problems there.

You can download the module here.

Installation:
* Create a kistjes.mod folder in the BlitzMAX\mod folder.
* put the unzipped phidget.mod in kistjes.mod
* build/document the module
* See the examples for the use of the module.

Enjoy!

Many thanks to Brucey for helping me out!!!!

Kistjes


wmaass(Posted 2009) [#2]
Kistjes many thanks for doing this! I only have the 8/8/8 board, vibration sensors, light sensors, an IR distance sensor and a temp sensor. I plan to get a hold of some of the ones you currently support. Better yet, I have a need to get my head around developing a mod for some hardware at work. This might be a good opportunity for me to learn from your mod. Do you mind if I mess about with your stuff and try and add support for the sensors I own?

EDIT: Looks like support for my sensors is already there by looking at InterfaceKit.bmx.


Kistjes(Posted 2009) [#3]
That's right! Look at the Phidget documentation about the interface kit. All the sensors you mention are analog inputs for the 8/8/8 Interfacekit board.

The boards that are not supported by phidget module v1.0 are:
* Phidget Advanced Servo
* Phidget Motor Control
* Phidget Stepper
* Phidget Temperature Sensor
* Phidget TextLCD
* Phidget TextLED
* Phidget Weight Sensor.

Edit: @ wmaass: O, I see you have a temp sensor. I'll try to add that board to the module this week.

EDIT: module updated! Temperature Sensor added. Download module from first post.


wmaass(Posted 2009) [#4]
Super! I'm tempted to neglect all my yard work today and hide in my office to play with this.


Kistjes(Posted 2009) [#5]
That's exactly what I've done today 8-)

Enjoy the Phidgets! And please let me know if the module works as wanted.


Brucey(Posted 2009) [#6]
That's exactly what I've done today

... welcome to my world :-p


wmaass(Posted 2009) [#7]
Well here is how I solved the yard work problem. I removed the mower blade from the mower and took it to a shop for sharpening. Get it back Monday, too bad :)

Anyway, everything is working perfectly Kistjes! So what I plan to do now is build 2 IR Distance sensors into some sort of housing and use them to get angle and speed of golf putts. Then I'll use the data for a mini-putt game I've had on the back burner for some time. Thanks again for this and thank you Brucey for helping :)


wmaass(Posted 2009) [#8]
Kistjes,
If you run the InterfaceKit Full example that comes with the Phigets SDK you will notice an input sensitivity slider for the analog sensors. I think this is done by messing about with SetAnalogInputChangeTrigger. When I try it seems to work but my test program just exits after a few seconds (it does manage to print data from the sensor). It is probably due to poor programming on my part but I thought I would run this by you to see what you think:

SuperStrict
Import kistjes.phidget21

'create an InterfaceKit instance
Local oKit:TmsInterfaceKit = TmsInterfaceKit.Create()

'if succeeded...
If oKit Then

	'open connection to InterfaceKit board
	oKit.OpenPhidget()
		
End If

'set ratiometric
oKit.SetRatiometric(1)
oKit.SetAnalogInputChangeTrigger(0, 20)

Global sensorvalue:Int

oKit.SetOnAnalogInputChangeHandler(OnChangeMe, Null)


Local changetrig:Int = oKit.GetAnalogInputChangeTrigger(0)
Print changetrig

Graphics(800, 600, 0)

SetClsColor(255, 255, 255)
SetColor(0, 0, 0)
	
SetBlend(ALPHABLEND)

While Not KeyHit(KEY_ESCAPE)
	Cls

'Local sensorvalue:Int = oKit.GetAnalogInput(0)
'Print sensorvalue

	Flip(0)

Wend

oKit.RemovePhidget()
	

GCCollect()
End

Function OnChangeMe:Int(bpPhidgetHandle:Byte Ptr, userData:Object, iIndex:Int, iValue:Int)
	sensorvalue = iValue
	Print sensorvalue
	
	Return 0
End Function




wmaass(Posted 2009) [#9]
I updated the code above and now the data continues to print but now I get a

"Unhandled Exception:GC bbGCFree: mem has non-0 refs"

or a

"Unhandled Exception:clrMemBit error: membit not set"

after a minute or so.


Brucey(Posted 2009) [#10]
Oooh. You shouldn't see things like that!

Sounds like there's a bug in the wrapper.


wmaass(Posted 2009) [#11]
Yes, seems random too - unhandled exceptions in d3d7graphics, pollsystem, d3d7max2d...all kinds of havoc.

Seems to work better with flip(0) changed to flip(1) if that makes any sense.


Brucey(Posted 2009) [#12]
The reason it appears random is because the error occurs when the GC is attempting to clean up some pointers - it does this at various times when it thinks it needs to - so you'll see it pop up in all kinds of places.


wmaass(Posted 2009) [#13]
Sounds like a job for Super Kistjes :)


Kistjes(Posted 2009) [#14]
Hi,

Sorry for the delay.

I get the same error :(
Please give me some time to figure out what's wrong.

I'll see what I can do.

Sounds like a job for Super Kistjes :)

Do we become cynically? 8-)


wmaass(Posted 2009) [#15]
No worries, take your time.


North(Posted 2009) [#16]
Heyas,

i'm about to order me a package from phidgets including the 8/8/8+onboard usb, the temperature+humidity sensors and dual relay interfaces.
I'm wondering if you had any plans to include the relays/temp+humidity sensors into your wrapper?

kind regards

Nicholas


Spot-Nothing(Posted 2010) [#17]
Hey Kistjes!

Just wondering: Is this module still actively in development? I would *love* to see some updates - If I can help with a little donation to support extended Phidgets support, just let me know.


Spot-Nothing(Posted 2010) [#18]
Or is there perhaps anyone else planning to integrate Phidgets through a module? They're just awesome - highly recommended!


Kistjes(Posted 2010) [#19]
Hi spot_bot,

There is 'only' one problem in the Phidget module I can't solve.
The callback functions for change of sensor value detection (like OnAnalogInputChanged()) do not work reliable.
Still want to look at it but I'm stuck at the moment. Sorry about that.

All other functionality works great. So if you can write your code by checking input values yourself (I know it is a dirty workaround) you can use the module quite well.

What are your plans with the Phidgets?


Spot-Nothing(Posted 2010) [#20]
Hi Kistjes,

Thanks for replying! My plans are using Phidgets for a console (desktop) game on an exhibition and I want to try out the Phidgets to make controlling the game more immersive by attaching accelerometers to gloves that are sending the steering signals to the console through bluetooth.


Kistjes(Posted 2010) [#21]
Whow, ambitious project ;-)
The Phidget module should be able to manage that.
Good luck!

Please inform me about the progress and the results of the exhibition game.


Beaker(Posted 2010) [#22]
Is this still in development? I would love to see support for Advanced Servo.


Kistjes(Posted 2010) [#23]
@ Beaker: The Phidget module already supports the advanced servo controller.

There is still an unsolved problem with the callback functions for all phidget boards.
So, you can set or get the position of a servo motor but you probably will get an error when you use the OnPositionChange function. Sorry about that.

Recently I implemented a phidget interface in MS-Expression Blend (.Net + c#). I came across a similair problem with the callback functions. After some research I learned that it had something to do with threats. Phidget-threat conflicting with UI-threat.

I'm not sure the problem with this module is the same but perhaps it is.
If anyone has an idea... please let me know.

Good luck with your servo project!