I'm in the process of converting a PLC application over to the Netduino in order to reduce cost. I've been using Crouzet PLC's but they are too expensive and have too little RAM. The Netduino with a keypad, 2 line LCD and a cheap 4 relay board will do what I need at a fraction of the cost.
- Netduino Forums
- → cce1911's Content
cce1911's Content
There have been 59 items by cce1911 (Search limited from 17-June 23)
#51765 Using a Netdruino 2 as a PLC
Posted by
cce1911
on 29 July 2013 - 02:51 PM
in
Netduino Plus 2 (and Netduino Plus 1)
#52262 Interrupt event handler conflicts
Posted by
cce1911
on 21 August 2013 - 01:47 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I have a N+2 driving 2 stepper motors with the Sparkfun Easydriver. I have wired up several external buttons
InterruptPort ipT1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);ipT1.OnInterrupt += Target_OnInterruptT1;InterruptPort ipT2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);ipT2.OnInterrupt += Target_OnInterruptT2;
?
Here are my event handlers
static void Target_OnInterruptT1(uint data1, uint data2, DateTime time) { if (dtLastHit.AddMilliseconds(intBounceWait) > time) return; // prevent bounce dtLastHit = time; Debug.Print("Hit T1 = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff")); } static void Target_OnInterruptT2(uint data1, uint data2, DateTime time) { if (dtLastHit.AddMilliseconds(intBounceWait) > time) return; // prevent bounce dtLastHit = time; Debug.Print("Hit T2 = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff")); }
My problem is that when I press button T1 it randomly executes Target_OnInterruptT2 or Target_OnInterruptT1. No rhyme or reason. The same thing happens if I press button T2.
What is odd is that I've used this same exact board with 5 buttons, in the past, and had no problems. Any idea what is happening? I thought it might be EMI from the Easy driver, but I still get the same behavior even if I disconnect power to the stepper motors.
I'm scratching my head...
#51812 Toolbox.NETMF.Hardware.DS1307 problem
Posted by
cce1911
on 31 July 2013 - 04:26 AM
in
Netduino Plus 2 (and Netduino Plus 1)
It looks like this wiring diagram may have been for the N+: http://netmftoolbox....ailable classes
The N+2 has pins SC and SD. When I wired my RTC to these pins, everything worked.
#51796 Toolbox.NETMF.Hardware.DS1307 problem
Posted by
cce1911
on 30 July 2013 - 07:16 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I purchased this RTC: http://www.adafruit.com/products/264
But when I go to set the time using the Toolbox.NETMF.Hardware.DS1307 I get the following error:
"Something went wrong setting the time. Did you use proper pull-up resistors and is there a 3V battery connected?"
The wiring is pretty simple and I've double checked it (see pic).The kit has the resistors and the battery, any ideas?
Here is the code where it fails:
DS1307 RTC = new DS1307();
RTC.SetTime(2013, 7, 29, 23, 14, 0);
here is the toolbox code where the call is throwing an exception
public void SetTime(DateTime Time)
{
// Writing 7 bytes to the buffer, starting at address 0
int BytesTransferred = this._Device.Write(new byte[] {
0x00,
(byte)Tools.Hex2Dec(Time.Second.ToString()),
(byte)Tools.Hex2Dec(Time.Minute.ToString()),
(byte)Tools.Hex2Dec(Time.Hour.ToString()),
(byte)Tools.Hex2Dec(((int)Time.DayOfWeek).ToString()),
(byte)Tools.Hex2Dec(Time.Day.ToString()),
(byte)Tools.Hex2Dec(Time.Month.ToString()),
(byte)Tools.Hex2Dec((Time.Year - 2000).ToString())
});
if (BytesTransferred != 8) throw new ApplicationException("Something went wrong setting the time. Did you use proper pull-up resistors and is there a 3V battery connected?");
}
#52135 Failed allocation while writing text file
Posted by
cce1911
on 14 August 2013 - 01:42 AM
in
Netduino 2 (and Netduino 1)
In my N+2 app, I log things to a text file for later debugging. I use this code in a function:
using (var filestream = new FileStream(@"SDrunlog.txt",FileMode.Append)) { StreamWriter streamWriter = new StreamWriter(filestream); streamWriter.WriteLine(DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff") + ": " + strMsg); streamWriter.Close(); //Debug.Print(DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff") + ": " + strMsg); }
When my log file gets over 33k I get a failed allocation error when creating the new streamwriter:
StreamWriter streamWriter = new StreamWriter(filestream);
Any idea on what is causing this and how to avoid it?
#54703 Button Interrupts
Posted by
cce1911
on 15 December 2013 - 04:48 PM
in
Netduino Plus 2 (and Netduino Plus 1)
CW2, thanks for your response. I made the changes you suggested and still had a problem. Then I realized that I had not tied the 3v button cell ground to the NP2 ground. Once I did that, everything seems to work just fine.
#52165 Failed allocation while writing text file
Posted by
cce1911
on 14 August 2013 - 08:01 PM
in
Netduino 2 (and Netduino 1)
Val, thanks for the reply. I've decided to start a new log file at 25k, but I will give Debug.GC a try.
-Capel
#54700 Button Interrupts
Posted by
cce1911
on 15 December 2013 - 03:32 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I'm seeing some odd behavior for what should be a simple project. Maybe I'm missing something and someone can point out the error of my ways?
What I'm trying to do is capture a sensor input. To test my code I've simulated the sensor with a simple momentary push button. See the schematic attached.
The problem is when I push one button, it triggers the interrupt for the other buttons. Here is my code:
public class Program2 { static DateTime dtLastPress; static int intBounceWait = 200; public static void Main() { InterruptPort ipT1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT1.OnInterrupt += T_OnInterruptT1; InterruptPort ipT2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT2.OnInterrupt += T_OnInterruptT2; InterruptPort ipT3 = new InterruptPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT3.OnInterrupt += T_OnInterruptT3; InterruptPort ipT4 = new InterruptPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT3.OnInterrupt += T_OnInterruptT4; Thread.Sleep(Timeout.Infinite); } static void T_OnInterruptT1(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T1 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(1, time); } static void T_OnInterruptT2(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T2 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(2, time); } static void T_OnInterruptT3(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T3 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(3, time); } static void T_OnInterruptT4(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T4 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(4, time); } static void RecordPress(int intTarget, DateTime time) { Debug.Print("T" + intTarget.ToString() + " = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff")); } }
If I run the code and press the buttons in order (T1, T2, T3, T4) I get the following output:
#51766 Adafruit Motor shield v2 library
Posted by
cce1911
on 29 July 2013 - 02:53 PM
in
Netduino Plus 2 (and Netduino Plus 1)
#54235 How to drive multiple lasers?
Posted by
cce1911
on 22 November 2013 - 08:06 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Paul,
Thanks for this very informative post. I was trying to avoid adding 9 components to my system, but based on your observations, that may be unavoidable. Given this, would MOSFETs be a better choice than Darlington pairs?
-Capel
#54229 How to drive multiple lasers?
Posted by
cce1911
on 22 November 2013 - 06:07 PM
in
Netduino Plus 2 (and Netduino Plus 1)
So I have gotten my shift register to work with my N+2, but the lasers I'm trying to drive require 300mA of current each. So to drive 9 of these, I need almost 3A at 2.5 - 4.5 vdc. This is way too much for the N+2 and the 74HC595. I've been looking at some transistor arrays, but I'm not sure how to wire them. Can anyone point me to a circuit that uses this 8ch Darlington Sink driver (or something similar)?
#51228 Whacky Device Advice?
Posted by
cce1911
on 08 July 2013 - 07:05 PM
in
General Discussion
The moles will be anywhere from 10 yards to 35 yards from the central controller and up to 10 yards from each other.
#49404 N2 to NP2 issue
Posted by
cce1911
on 14 May 2013 - 02:17 AM
in
Netduino Plus 2 (and Netduino Plus 1)
Ok, so I referenced
using SecretLabs.NETMF.Hardware.Netduino;
and I still get the same exception.
I next tried moving the button assignments around and now I get the same exception, but on a [font="arial, helvetica, sans-serif;"]different InterruptPort assignment.[/font]
[font="arial, helvetica, sans-serif;"]Keep in mind that I'm moving from a Netduino 2 to a Netduino + 2. Chris' post refers to N+ to N+2.[/font]
#49372 N2 to NP2 issue
Posted by
cce1911
on 12 May 2013 - 10:50 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I have code that works fine when running on N2, but when I run the same code on the N2+ I get a System.ArgumentException on this line of code:
// Input Trigger - This input starts the cycle
InterruptPort inpTrigger = new InterruptPort(Pins.GPIO_PIN_A5, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
It is simply a button to start my program running.
BTW I am using:
using SecretLabs.NETMF.Hardware.NetduinoPlus;
Any suggestions?
-Capel
#49406 N2 to NP2 issue
Posted by
cce1911
on 14 May 2013 - 03:03 AM
in
Netduino Plus 2 (and Netduino Plus 1)
Upon closer examination, here is the debug output:
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
Any suggestions?
#49456 N2 to NP2 issue
Posted by
cce1911
on 15 May 2013 - 03:26 AM
in
Netduino Plus 2 (and Netduino Plus 1)
This was a strange issue and I never did figure out why the N2 code would not run on the N+2, I did find a work around.
Basically, I defined the input using the Auto-Repeat button (http://forums.netdui...n-press-sample/) and it worked. Don't ask me why this worked, but it did.
#51226 Whacky Device Advice?
Posted by
cce1911
on 08 July 2013 - 06:34 PM
in
General Discussion
I'm at the conceptual stage of a project and would like some advice. The project can best be described as a game. The "Whack-a-Mole" game is a pretty close approximation of what I'm trying to do except the "moles" are further apart. If you don't know what this game is, watch this 22 seconds of video: https://www.youtube....h?v=D0n8N98mpes
There will be n number of devices in the network and one master controller. I'm thinking the controller will be a laptop, but I'm open to other ideas.
Each device will "display" according to an algorithm running on the master controller. If the mole is whacked while its displayed, a signal should be sent back to the master controller with the time it was whacked.
So my question is what is the best way for the master controller to communicate with the moles? After doing some research, it seems to me that each mole should be an N+2 with a Edimax BR-6258n wireless router running the NeonMika webserver. However, my concern is speed. Would Bluetooth be a better option or maybe one of the Xbee protocols? What about using a Mini instead of a N+2?
#51238 NeonMika.NetduinoControl & NeonMika.Webserver.ClientLibrary
Posted by
cce1911
on 09 July 2013 - 01:57 AM
in
Project Showcase
What version of Visual Studio is this built in? I get an error saying the project is incompatible with VS2010.
#51764 N+2 Socket problem
Posted by
cce1911
on 29 July 2013 - 02:40 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I found the problem with my code. In the server app, the 2nd while loop should have had totalread instead of 0 for the second parameter of the .receive call. I was overwriting the data each time. Maybe this will help someone in the future...
#49087 Compatible SD Shield?
Posted by
cce1911
on 06 May 2013 - 02:43 AM
in
Netduino 2 (and Netduino 1)
I definitely have a conflict with the SPI pins. If I free up D10-D13 I'm 2 pins short of what I need for the project.
#49077 Compatible SD Shield?
Posted by
cce1911
on 05 May 2013 - 08:15 PM
in
Netduino 2 (and Netduino 1)
NooM,
I have the N2 with a 2gb SD card.
The reason I say it does not appear to work is because my app works when the I/O is connected to the N2, but when I plug in the SD shield and move all the I/O wires to it, the app will not run. Nowhere does the documentation say it is Netduino compatible, I was assuming it was when I bought it, now I'm trying to confirm this assumption. I have not written any code to read/write to the SD card, yet.
You can see my initial schematic here: http://forums.netdui...uttons-and-lcd/
I'm not familiar with eeproms, would you point me to some tutorials? I like the sound of cheap:)
#51667 N+2 Socket problem
Posted by
cce1911
on 24 July 2013 - 07:42 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I'm new to sockets and just can't seem to get my app working. What I want to do is send a log file from the N+2 back to my laptop. The approach I took was to prepend the file size to the byte array before sending. However, I never seem to receive exactly what I send. I realize this is a very common problem with folks who are new to sockets and I've searched high and low to find tips on how to avoid this problem. Maybe this is something unique to N+2, but I kind of doubt it.
Here is my code. I've got a client app that runs on the N+2 and a console app running on my laptop. The data file I'm retrieving is attached below. This sort of works, but is not delivering the file consistently. Any help you can give me would be appreciated.
Client app running on N+2. When you press the onboard button, it sends the file.
[font="'courier new', courier, monospace;"]using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;[/font]
[font="'courier new', courier, monospace;"]namespace SocketClient
{[/font]
[font="'courier new', courier, monospace;"] public class Program
{
static string strDeviceIP = "";
static string strDeviceSubnet = "";
static string strDeviceGateway = "";
static string strDevicePort = "";
static string strControllerIP = "";[/font]
[font="'courier new', courier, monospace;"] public static OutputPort opLED = new OutputPort(Pins.GPIO_PIN_D13, false);
InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);[/font]
[font="'courier new', courier, monospace;"] public static void Main()
{
strDeviceIP = "192.168.2.102";
strDeviceSubnet = "255.255.255.0";
strDeviceGateway = "192.168.2.2";
strControllerIP = "192.168.2.222";
strDevicePort = "9999";
InterruptPort btn = new InterruptPort(Pins.ONBOARD_SW1, false,[/font]
[font="'courier new', courier, monospace;"]Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
btn.OnInterrupt += new NativeEventHandler(ButtonPress);[/font]
[font="'courier new', courier, monospace;"] while (true)
{
}
}[/font]
[font="'courier new', courier, monospace;"] public static void ButtonPress(uint data1, uint data2, DateTime time)
{
opLED.Write(true);[/font]
[font="'courier new', courier, monospace;"] Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress hostAddress = IPAddress.Parse(strControllerIP);
IPEndPoint endpoint = new IPEndPoint(hostAddress, Int32.Parse(strDevicePort));[/font]
[font="'courier new', courier, monospace;"] string fileName = "runlog2.txt";
// read the file into a byte array
byte[] data = File.ReadAllBytes(@"SD" + fileName);
byte[] sizeinfo = new byte[4];
byte[] senddata = new byte[4 + data.Length];[/font]
[font="'courier new', courier, monospace;"] // check to make sure it's not too big
if (data.Length > 850 * 1024)
{
Debug.Print("File too large");
}[/font]
[font="'courier new', courier, monospace;"] // convert data.length into a byte array
sizeinfo[0] = (byte)data.Length;
sizeinfo[1] = (byte)(data.Length >> 8);
sizeinfo[2] = (byte)(data.Length >> 16);
sizeinfo[3] = (byte)(data.Length >> 24);[/font]
[font="'courier new', courier, monospace;"] // prepend the size into the senddata array
sizeinfo.CopyTo(senddata, 0);[/font]
[font="'courier new', courier, monospace;"] // copy read data into the senddata array
data.CopyTo(senddata, 4);[/font]
[font="'courier new', courier, monospace;"] // send the data
socket.Connect(endpoint);
socket.Send(senddata);
socket.Close();
opLED.Write(false);
}
}
}[/font]
[font="'courier new', courier, monospace;"]Here is my server side console app.[/font]
[font="'courier new', courier, monospace;"] [/font]
[font="'courier new', courier, monospace;"]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Threading;[/font]
[font="'courier new', courier, monospace;"]namespace SocketConsole
{
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(new ThreadStart(Listener));
thread1.Start();[/font]
[font="'courier new', courier, monospace;"] while (true)
{
}
}[/font]
[font="'courier new', courier, monospace;"] public static void Listener()
{
try
{
Socket sktMain = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sktMain.Bind(new IPEndPoint(IPAddress.Parse("192.168.2.222"), 9999));
sktMain.Listen(10);
var message = new ArrayList();[/font]
[font="'courier new', courier, monospace;"] while (true)
{
// create the client socket
using (var client = sktMain.Accept())
{
//If connected,
if (SocketConnected(client, 100))
{
while (SocketConnected(client, 100))
{
byte[] sizeinfo = new byte[4];[/font]
[font="'courier new', courier, monospace;"] //read the size of the message into sizeinfo
int totalread = 0, currentread = 0;
currentread = totalread = client.Receive(sizeinfo, 4, SocketFlags.None);[/font]
[font="'courier new', courier, monospace;"] while (totalread < sizeinfo.Length && currentread > 0)
{
currentread = client.Receive(sizeinfo, totalread, sizeinfo.Length - totalread, SocketFlags.None);
totalread += currentread;
}[/font]
[font="'courier new', courier, monospace;"] int messagesize = 0;
messagesize |= sizeinfo[0];
messagesize |= (((int)sizeinfo[1]) << 8);
messagesize |= (((int)sizeinfo[2]) << 16);
messagesize |= (((int)sizeinfo[3]) << 24);[/font]
[font="'courier new', courier, monospace;"] byte[] data = new byte[messagesize];
totalread = 0;
currentread = totalread = client.Receive(data, 0, data.Length - totalread, SocketFlags.None);
var received = Encoding.UTF8.GetChars(data);[/font]
[font="'courier new', courier, monospace;"] int diff = data.Length - totalread;[/font]
[font="'courier new', courier, monospace;"] while (totalread < messagesize && currentread > 0)
{
currentread = client.Receive(data, 0, data.Length - totalread, SocketFlags.None);
totalread += currentread;
for (var i = 0; i < received.Length; i++)
message.Add(received[i]);
}
string fName = "runlog.txt";
if (File.Exists(fName)) File.Delete(fName);[/font]
[font="'courier new', courier, monospace;"] BinaryWriter bWrite = new BinaryWriter(File.Open(fName, FileMode.Create));
bWrite.Write(data);
bWrite.Close();
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}[/font]
[font="'courier new', courier, monospace;"] // socket polling
static bool SocketConnected(Socket s, int ms)
{
return !(s.Poll(ms, SelectMode.SelectRead) & (s.Available == 0));
}[/font]
[font="'courier new', courier, monospace;"] }
}[/font]
Attached Files
-
runlog.txt 3.51KB 4 downloads
#51676 N+2 Socket problem
Posted by
cce1911
on 25 July 2013 - 03:15 AM
in
Netduino Plus 2 (and Netduino Plus 1)
If I look at the byte array data, after receiving all the data, every byte above 255 has a value of 0. It's as if it stops reading at 255. If I debug.print in the while loop filling "data", I get the following output:
client accepting data client.Receive sizeinfo: currentread = 4, totalread = 4 total message size = 3296 client.Receive data: currentread = 252, totalread = 252 client.Receive data: currentread = 256 totalread = 508 client.Receive data: currentread = 256 totalread = 764 client.Receive data: currentread = 256 totalread = 1020 client.Receive data: currentread = 256 totalread = 1276 client.Receive data: currentread = 256 totalread = 1532 client.Receive data: currentread = 256 totalread = 1788 client.Receive data: currentread = 256 totalread = 2044 client.Receive data: currentread = 256 totalread = 2300 client.Receive data: currentread = 256 totalread = 2556 client.Receive data: currentread = 256 totalread = 2812 client.Receive data: currentread = 256 totalread = 3068 client.Receive data: currentread = 228 totalread = 3296 client.Receive data final: currentread = 228 totalread = 3296
So it is accepting 256 bytes each time, but they are all zero. Obviously, I don't understand what's going on:(
#49064 Compatible SD Shield?
Posted by
cce1911
on 05 May 2013 - 03:53 PM
in
Netduino 2 (and Netduino 1)
I purchased a Seedstudio SD shield (http://www.seeedstud...l?cPath=132_134
) but it does not appear to work. Has anyone used this shield with the Netduino?
If not, what shield do you suggest?
I need to store 18 configuration values (double) from one power up to the next...
-Capel
#52087 N+2 Socket problem
Posted by
cce1911
on 11 August 2013 - 12:52 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Zero, so far I have only tested with a single client.
- Netduino Forums
- → cce1911's Content
- Privacy Policy