Grovepi collision sensor not working with c#

Hi All,

I am using collision sensor with VS2017, c# and windows iot Core.
I create a small app to check the sensor but when I try, I received always 1 value (no related with a collision o vibration) rarely 0

Do you have any idea about the issue?

Alessandro

1 Like

Greetings!

Can we see the app you created?  What driver libraries do you have installed?

Most of us here use Raspbian for Robots, plain-vanilla Raspbian with the Dexter libraries installed, or ROS, (Robot Operating System) with the Dexter libraries installed - our abilities to help with Windows IoT Core may be very limited, but we’ll try!

Hi @jimrh

thanks a lot for your message. Here the piece of code that I used:
IGrovePi _collision;
_collision = DeviceFactory.Build.GrovePi();
_collision.PinMode(Pin.DigitalPin2, PinMode.Input);

//Get Value from sensor
message.Collision = _collision.DigitalRead(Pin.DigitalPin2);

The library that I use is GrovePi library for Windows IoT v. 1.0.10.

I decided to use c# because I am preparing a prototype to connect with Azure… and send information to D365 CRM and on PowerBI.

I am preparing a conference in Microsoft.

Alessandro

1 Like

Alessadro,

I’m confused.

Though I know little about c#, shouldn’t you instantiate a copy of the distance sensor class?  There may be a specific protocol for accessing that data, maybe it’s i2c? I don’t know.

Can you provide a link to the specific Seed sensor module used - on their website would be best.  This way we can look it up and see what’s happening.

Caveat: I know little to nothing about c# and Windows IoT - I haven’t had the chance to mess with them yet - but I am willing to try to help you troubleshoot it.

Sigh,
I can understand why you’re using M$ solutions, but it might be easier to use the methods and libraries Seed provides for the Ardunio.

One thing I can suggest is - if they have sample code for the Pi, or the Arduino - try it with a “native” system using their supplied “native” code to verify if it works or not.  Though it’s unlikely, people have  received defective parts - and you might be fighting with a part that doesn’t work.  Verify it works first.

Hi @jimrh thanks a lot for the information. I use the library GrovePI from https://github.com/DexterInd/GrovePi/tree/master/Software/CSharp

GrovePi _collision = DeviceFactory.Build.GrovePi(); //Create obj
_collision.PinMode(Pin.DigitalPin2, PinMode.Input); //Set obj as input on Pin2

//Get Value from sensor
message.Collision = _collision.DigitalRead(Pin.DigitalPin2); //Read value

for other sensors I have classes:

_airQualitySensor = DeviceFactory.Build.AirQualitySensor(Pin.AnalogPin2);
message.AirQuality = _airQualitySensor.AirQuality();

All work fine but for collision (Where I use generic GrovePi) interface does not run.

Here the code for DigitalRead:

public byte DigitalRead(Pin pin)
{
var wbuffer = new byte[4] {(byte) Command.DigitalRead, (byte) pin, Constants.Unused, Constants.Unused};
var rBuffer = new byte[1];
var i2cTransferResult = DirectAccess.WritePartial(wbuffer);
Delay.Milliseconds(10);
if (i2cTransferResult.Status != I2cTransferStatus.FullTransfer)
{
return 0;
}
i2cTransferResult = DirectAccess.ReadPartial(rBuffer);
if (i2cTransferResult.Status != I2cTransferStatus.FullTransfer)
{
return 0;
}

        return rBuffer[0];
    }

The sensor is: https://wiki.seeedstudio.com/Grove-Collision_Sensor/

Thanks a lot for your time and your help. I don’t know how can resolve the issue.

Alessandro

1 Like

I’ll take another look at this later, but right now you need to verify that your sensor works properly.

Can you find another way of implementing it, maybe in Raspbian for Robots, (on a different SD card, for testing), and try it there?  Those of us here are more familiar with DexterOS or Raspbian for Robots than Windows IoT.  Try it that way and see what happens.

Once you get it working in R4R, you can take the knowledge learned and (hopefully!) apply it to your IoT programming.

Hi @jimrh

finally I setup all on Raspbian. I used this python code:

import time
import grovepi

Connect the Grove Collision Sensor to digital port D2

SIG,NC,VCC,GND

collision_sensor = 2

grovepi.pinMode(collision_sensor,“INPUT”)

while True:
try:
print(grovepi.digitalRead(collision_sensor))
time.sleep(.5)

except IOError:
    print ("Error")

but I have always 1 as value.

Do you have any idea? I installed and updated GrovePI firmware

Alessandro

1 Like

Do you have a different sensor to try?

Unless someone else knows more about this than I do, I’m wondering if you have either a bad sensor or a bad cable.

Other than that, I’m not sure what to tell you.