Main Site Documentation

How do I ask for help in coding?


#1

The best way to get help from the community is by making it easy for everyone to help. The community does not know what hardware you’re trying to run and how much experience you have.

Help us, help you.

Ideally, if you have a problem with a sensor or a component of the system then make a small testing project where you only use what is absolutely necessary in as few lines as possible. Be sure to provide a link to the datasheet and where you ordered your device from. Finally, do not forget to tell us what FEZ or NETMF device you are suing and how it is connected to the sensor/device.

[title]Examples[/title]
Lets say I’m writing drivers for SMB380 but it is not working and I need help
http://www.fezzer.com/project/34/accelerometer-extension/

[title]Very Bad Question[/title]

No one would be able to help you with such a question. You need to provide more information. :slight_smile:
Also, make your question more specific. For example, are you asking how SPI works? Are you asking how to connect the device? Are you asking how to program in C#?
We can’t help if we do not know what you need.

[title]Bad Question[/title]

[quote]I have SMB380 connected over SPI to FEZ Panda. This is how I setup SPI but I still can’t make it work
_spi = new SPI(new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.UEXT10, false, 0, 0, true, true, 100, SPI.SPI_module.SPI2));

I don’t know why since I have it working on my other device named xxxx.
[/quote]

This question still lacks information. The fact that its working on device xxxx doesn’t tell us how to help.

[title]Good Question[/title]

[quote]My SMB380 driver isn’t working. I have it connected to SPI. Can someone take a look at my code please?

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace GHIElectronics.NETMF.FEZ
{
	public static partial class FEZ_Extensions
	{
		static public class Accelerometer
		{
			static SPI _spi;
			static private byte[] read = new byte[2];
			static private byte[] write = new byte[2];

			static public void Initialize()
			{
				if (FEZ.FEZ_System.GetSystemType() == FEZ_Type.Domino)
				{
					_spi = new SPI(new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.UEXT10, false, 0, 0, true, true, 100, SPI.SPI_module.SPI2));
				}
				else if (FEZ.FEZ_System.GetSystemType() == FEZ_Type.Mini)
				{
					_spi = new SPI(new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.UEXT10, false, 0, 0, true, true, 100, SPI.SPI_module.SPI1));
				}
				else
				{
					throw new Exception("Unknown System Type!");
				}

				byte val;

				val = ReadRegister(0x14);
				val &= 0xE0;
				WriteRegister(0x14, val);
				WriteRegister(0x15, 0xC1);
				WriteRegister(0x0B, 0x40);
			}

			static private byte ReadRegister(byte address)
			{
				write[0] = (byte)(0x80 | address);
				write[1] = 0xFF;
				_spi.WriteRead(write, read);
				return read[1];
			}

			static private void WriteRegister(byte address, byte value)
			{
				write[0] = address;
				write[1] = value;
				_spi.WriteRead(write, read);
			}

			static public void GetXYZ(out sbyte x, out sbyte y, out sbyte z)
			{
				x = (sbyte)ReadRegister(0x02);
				x = (sbyte)ReadRegister(0x03);

				y = (sbyte)ReadRegister(0x04);
				y = (sbyte)ReadRegister(0x05);

				z = (sbyte)ReadRegister(0x06);
				z = (sbyte)ReadRegister(0x07);
			}
		}
	}
}

Here is how I test the code:

using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.FEZ;
using System.Threading;

public class Program
{
	public static void Main()
	{
		sbyte x_val,y_val,z_val;
		FEZ_Extensions.Accelerometer.Initialize();

		while (true) //infinite loop
		{
			FEZ_Extensions.Accelerometer.GetXYZ(out x_val, out y_val, out z_val);
			Debug.Print("X:" + x_val.ToString() + " Y:" + y_val.ToString() + " Z:" + z_val.ToString());
			Thread.Sleep(100);
		}
	}
}

[/quote]

Now we have enough information but we’re still missing one thing… What is SMB380?

[title]Excellent Question[/title]
Same as the good question above but also add a link to your device datasheet.

[quote]Here is the datasheet if you need it http://www.bosch-sensortec.com/content/language1/downloads/SMB380_Flyer_Rev1.3.pdf
I am using the extension sold by GHI on this website"[/quote]

[line]

[title]Tag your Code[/title]
Whenever posting code, add code tag so everyone can read it easily. Most users ignore posts that have code not tagged.
[line]
This is tagged code

public class Program
{
	public static void Main()
	{
		sbyte x_val,y_val,z_val;
		FEZ_Extensions.Accelerometer.Initialize();

		while (true) //infinite loop
		{
			FEZ_Extensions.Accelerometer.GetXYZ(out x_val, out y_val, out z_val);
			Debug.Print("X:" + x_val.ToString() + " Y:" + y_val.ToString() + " Z:" + z_val.ToString());
			Thread.Sleep(100);
		}
	}
}

[line]
This is untagged code…which one is easier to read?
public class Program
{
public static void Main()
{
sbyte x_val,y_val,z_val;
FEZ_Extensions.Accelerometer.Initialize();

	while (true) //infinite loop
	{
		FEZ_Extensions.Accelerometer.GetXYZ(out x_val, out y_val, out z_val);
		Debug.Print("X:" + x_val.ToString() + " Y:" + y_val.ToString() + " Z:" + z_val.ToString());
		Thread.Sleep(100);
	}
}

}

[line]
I hope this will enhance the overall assistance provided by GHI and the community.