public static void Main() { SPI.Configuration Device1 = new SPI.Configuration( Pins.GPIO_PIN_D10, // SS-pin false, // SS-pin active state 0, // The setup time for the SS port 0, // The hold time for the SS port true, // The idle state of the clock true, // The sampling clock edge 1000, // The SPI clock rate in KHz SPI_Devices.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset) ); SPI SPIBus = new SPI(Device1); while (true) { byte[] WriteBuffer = new byte[2]; WriteBuffer[0] = 0; WriteBuffer[1] = 0; SPIBus.Write(WriteBuffer); WriteBuffer[0] = 16; WriteBuffer[1] = 0; SPIBus.Write(WriteBuffer); Thread.Sleep(1000); WriteBuffer[0] = 0; WriteBuffer[1] = 127; SPIBus.Write(WriteBuffer); WriteBuffer[0] = 16; WriteBuffer[1] = 127; SPIBus.Write(WriteBuffer); Thread.Sleep(1000); } }
- Netduino Forums
- → itsme's Content
itsme's Content
There have been 6 items by itsme (Search limited from 07-May 23)
#24038 SPI and digital potentiometer (MCP4231)
Posted by itsme on 10 February 2012 - 05:11 AM in General Discussion
#24027 SPI and digital potentiometer (MCP4231)
Posted by itsme on 09 February 2012 - 07:35 PM in General Discussion
#24021 SPI and digital potentiometer (MCP4231)
Posted by itsme on 09 February 2012 - 04:35 PM in General Discussion
The wires I am using are about 4 inches. I will try shortening the SPI connections a bit.
I do not have an oscilloscope but I'm assuming if I'm going to keep this up it would be a good investment. Any suggestions on a scope that would be good for a novice such as myself that wont completely drain the bank?
Thanks!
#24005 SPI and digital potentiometer (MCP4231)
Posted by itsme on 09 February 2012 - 12:30 AM in General Discussion
Ok to my question. I am trying my hand at running a digital potentiometer(Specifically a MCP4231). I would like to use it as a variable voltage divider to mimic/replace a joystick from an electric wheel chair. So I've read through the datasheet and while I'm pretty sure that I understand how to connect it, I'm not sure that I have the SPI object initialized correctly, or if I do have it initialized correctly, if i am sending the correct commands. Any light shed will be greatly appreciated. Thanks!
Here is my code. Almost verbatim from the wiki.
public static void Main() { SPI.Configuration Device1 = new SPI.Configuration( Pins.GPIO_PIN_D10, // SS-pin true, // SS-pin active state 0, // The setup time for the SS port 0, // The hold time for the SS port false, // The idle state of the clock true, // The sampling clock edge 1000, // The SPI clock rate in KHz SPI_Devices.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset) ); SPI SPIBus = new SPI(Device1); while (true) { // Writes a single byte with value 255 to the SPI device byte[] WriteBuffer = new byte[2]; WriteBuffer[0] = 0; WriteBuffer[1] = 0; SPIBus.Write(WriteBuffer); Thread.Sleep(1000); WriteBuffer[0] = 0; WriteBuffer[1] = 120; SPIBus.Write(WriteBuffer); Thread.Sleep(1000); } }
#24014 SPI and digital potentiometer (MCP4231)
Posted by itsme on 09 February 2012 - 01:43 PM in General Discussion
#43346 Atlas Scientific ENV-RGB Sensor not responding
Posted by itsme on 14 January 2013 - 12:08 AM in Netduino 2 (and Netduino 1)
I just got a Atlas Scientific ENV-RGB sensor from sparkfun, and I've spent the last two days trying to get it to work. I hooked it up according to the datasheet with red going to 3.3V, black to ground, white (tx) to digital pin 0(rx) and green(rx) to digital pin 1(tx) on the Netduino. Also I have the following code.
public static void Main() { SerialPort sp; try { sp = new SerialPort(Serial.COM1, 38400, Parity.None, 8, StopBits.One); sp.Open(); sp.DataReceived += new SerialDataReceivedEventHandler(SerialDataReciever); byte[] message = Encoding.UTF8.GetBytes("Er"); Debug.Print(new string(Encoding.UTF8.GetChars(message))); sp.Write(message, 0, message.Length); while (true) { } } catch (Exception e) { Debug.Print(e.StackTrace); } } public static void SerialDataReciever(object obj, SerialDataReceivedEventArgs args) { SerialPort thePorts = obj as SerialPort; if (thePorts.BytesToRead > 4) { byte[] buffer = new byte[30]; thePorts.Read(buffer, 0, thePorts.BytesToRead); Debug.Print(new string(Encoding.UTF8.GetChars(buffer))); } }
The problem I'm having is that even though my SerialDataReciever method is getting called the bytes are empty when its called. Also by default it should return 5 bytes though the first time that SerialDataReciever is called it only contains 2 bytes, both of which are empty. Does anyone have any experience with this sensor? I'm not sure if I am using the SerialPort class correctly, but from what I've read I feel like it should work. Any help would be greatly appreciated. Thanks.
- Netduino Forums
- → itsme's Content
- Privacy Policy