Youāll have to create a separate thread to do the polling of the values. Play with the thread sleep depending on what you need.
When using the gyro, call the gyro.Init() method, seems this will stabilize the values a bit. Although Iām getting slightly different values with each poll even if the device is laying still.
I did notice that connecting the modules to the spider in the designer isnāt working correctly, ānot all modules could be connectedā. Had to assign the ports in code.
Hello,
to get my Compass to work i had to do the following and the events fired:
compass.CompassHigh += new Compass.CompassEventHandler(compass_CompassHigh);
compass.CompassLow += new Compass.CompassEventHandler(compass_CompassLow);
//compass.DebugPrintEnabled = false; //for some reason this has no effect even after setting it to false it still prints to the OutPut window.
// Do one-time tasks here
compass.getAngle(); //doing this gets the compass going now my High event fires... and it blocks the thread so you definitely need thread for the compass to run...
void compass_CompassLow(Compass sender, Compass.CompassState state)
{
Debug.Print("Compass is Low");//never fires
}
void compass_CompassHigh(Compass sender, Compass.CompassState state)
{
Thread.Sleep(1000);
compass.getAngle(); //prints to the OutPut window..
}
the Low event never fired ā¦not sure when it is suppose to fireā¦
Also i noticed that when you use the Accelerometer with the Display_T35 you can no longer Plug the T socket to 10 the designer doesnāt allow you even if i have the Accelerometer plugged to itās own socketā¦ some sort of conflict???
As for the Accelerometer i looked at the source code of the driver and they are not even assigning the onAcceleromoter in the _input_Interruptā¦
//it looks like this
private void _input_Interrupt(GTI.InterruptInput input, bool value)
{
}
//and i think it should be like this:
private void _input_Interrupt(GTI.InterruptInput input, bool value)
{
this.OnAccelerometerEvent(this);
}
so to compensate for that they did a fake loop in the Compass driver which once you call the getAngle() it calls the onCompass event and that goes into a loop given the impression of interrupt being fired. not this works but it has issuesā¦ for example they are calling Debug.Print internally and that fills the VS Debugger window even if you stop debugging, i noticed this because i have multiple windows open and suddenly my other VS that has a different project got the buffer of the compass window ā¦
so i guess the seeedstudio driver was put pretty quickly just to get things up and runningā¦
so if you want to the Accelerometer to behave the same way do the following:
I think I found out how to get the interrupt to trigger. In the GyroInit function add:
Write(Register.INT_CFG, (byte)0xB1);
That will cause the interrupt to trigger. Just call the GyroInit function once you set your events.
To clear the latch (and receive the next string of data) you must complete a Read.
Take a look at the PDF for the Gyro included in the source package under section 8.4 Register 23 ā Interrupt Configuration. Thatās where I figured all this out. Hope this helps someone out.
Today I spend some hours on my modules and finally i can say no I2C module works.
tested Compass,Gyro,Accelerator
I tried to reduce everything and finally I wrote this code:
I2CDevice.Configuration con = new I2CDevice.Configuration(0x68, 100); // gyro module (0x68)
using (I2CDevice MyI2C = new I2CDevice(con))
{
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
byte[] RegisterNum = new byte[1] { 0x00 }; // 0x00 ... WHO_AM_I
xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
byte[] RegisterValue = new byte[1];
xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
if (MyI2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction"); // <--- I always get here :(
}
else
{
Debug.Print("Register value: " + RegisterValue[0].ToString());
}
}
This code is from the I2C tutorial. I changed adress to 0x68 (found in the Gyro sourcecode)
In the dokumentation i found the WHO_AM_I Register at 0x00.
I also tried INT_CFG(0x17)
I also tried INT_STATUS (0x1A)
No Response from the module.
Any suggestions ?
Is there a code or something else to test if I2C is working ? Or detect if any module is attached ?
I also tried in the Gyro constructor after socket is initialized
public Gyro(int socketNumber)
{
// This finds the Socket instance from the user-specified socket number.
// This will generate user-friendly error messages if the socket is invalid.
// If there is more than one socket on this module, then instead of "null" for the last parameter,
// put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
Socket socket = Socket.GetSocket(socketNumber, true, this, null);
i2c = new GTI.I2CBus(socket, 0x68, 100, this);
byte[] RegisterNum = new byte[1] { 0x00 }; // 0x00 ... WHO_AM_I
byte[] RegisterValue = new byte[1];
var result = i2c.WriteRead(RegisterNum, RegisterValue, 1000);
if (result == 0)
{
Debug.Print("Gyro not working :(");
}
....
Did you check your Power Source, i know Gus said this many times and he right almost everytime, please double check your USB Port or use a powered USB Hubā¦
The Gadgeteer codeplex (gadgeteer.codeplex.com) site has recently been updated with new drivers for a lot of the Seeed modules.
I believe Seeed will make module installers available directly from their product pages to make it easier for others to install in the future, without having to download and compile the source code.
However, if you would like to try these drivers straightaway you can get the sources from codeplex. They are under the \Modules\Seeed\ directory.
If you download the whole solution included in the \Software\ subsidrectory, you should be able to simply run the TestApp to quickly test the module. You can also build an installer for the driver by building the project under a Release configuration (you must have WiX 3.5 installed). This generates an installer (.msi). When you run the .msi, it installs the module in your designer toolbox.
You should uninstall any previous Seeed drivers to make sure you have the latest version.
Iāll try it but i think it will not work I tried to access the module without any driver direct via I2C bus and get no response. maybe I2C is not working on my spider.
I ordered an Logic Analyser yesterday I hope it arrives tomorow. This should help to find the problem
FYI I have been quite happy using the āopen workbench logic snifferā for several months ( http://www.seeedstudio.com/depot/open-workbench-logic-sniffer-p-612.html?cPath=174 ) which is 10 times faster as the ikalogic for 50USD, however the ikalogic is great because it can generate signals (wnd the owls can not). Similar protocol dissectors.
If you are having trouble with the new modules, and you are using a FEZSpider, it is possible you are having an I2C problem. Run this quick test to see if I2C is fine on your board.
Assemblies required: Microsoft.SPOT.Hardware
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace i2c_test
{
public class Program
{
public static void Main()
{
InputPort I2C_SCL = new InputPort((Cpu.Pin)11, false, Port.ResistorMode.Disabled);
InputPort I2C_SDA = new InputPort((Cpu.Pin)12, false, Port.ResistorMode.Disabled);
bool bSCL = true;
bool bSDA = true;
if (I2C_SCL.Read())
{
bSCL = false;
}
if (I2C_SDA.Read())
{
bSDA = false;
}
if (!bSCL)
Debug.Print("I2C_SCL works!");
else
Debug.Print("I2C_SCL maufunction");
if (!bSDA)
Debug.Print("I2C_SDA works!");
else
Debug.Print("I2C_SDA maufunction");
}
}
}