Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Fred007

Member Since 07 Jul 2011
Offline Last Active Aug 04 2014 11:54 AM
-----

Posts I've Made

In Topic: Opinions needed on CAN interface project

04 August 2014 - 11:55 AM

Thanks. It is for an automotive project, and I was already thinking of some kind of onboard computer, so will probably go with a regular windows application for this. Thanks.


In Topic: Scaling Analog Ports

11 June 2014 - 02:59 AM

Thanks so much for the help, sorry to go dark on this thread. Got distracted with some cloud services stuff. Yes, I realized that i needed to factor the 3.3v supply. The device is a HM1500LF humidity sensor. The code I have for reading the actual humidity is:

 

        private float _referenceVoltage = 3.3f;
 
            double voltage = analogInput.Read() * _referenceVoltage;
            humidity = 0.03892 * (voltage * 1000) - 42.017;    
 
Close enough for what I am doing.

In Topic: Plus 2 serial issue with HA7S

29 May 2014 - 05:42 PM

using System;
using System.Collections;
using System.IO;
using System.IO.Ports;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace ndSerialTestHA7S
{
    public class Program
    {
        private const byte R = 82;
        private const byte S = 83;
        private const byte W = 87;
        private const byte s = 115;
        private const byte CR = 13;
        private static SerialPort _serialPort = null;
        private static Queue _serialQueue = new Queue();
        private static Object _lockQueue = new Object();
        public static AutoResetEvent unblockRead = new AutoResetEvent(false);
        public const int _readTimeout = 3000;
        public static void Main()
        {
            _serialPort = new SerialPort(SerialPorts.COM1);
            _serialPort.BaudRate = 9600;
            _serialPort.DataBits = 8;
            _serialPort.StopBits = StopBits.One;
            _serialPort.Parity = Parity.None;
            _serialPort.Handshake = Handshake.None;
            _serialPort.DataReceived += new SerialDataReceivedEventHandler(inboundSerial);

            byte[] devAddress = new byte[45];
            try
            {
                _serialPort.Open();
                writeSerial(R);
                readSerial(devAddress);
                log(devAddress);
                writeSerial(S);
                readSerial(devAddress);
                log(devAddress);
                writeSerial(s);
                readSerial(devAddress);
                log(devAddress);
                writeSerial(s);
                readSerial(devAddress);
                log(devAddress);
                int i = 1;
            }
            catch (SystemException se)
            {
                Debug.Print("Ha7s: " + se.Message);
            }
        }
        private static void inboundSerial(object sender, SerialDataReceivedEventArgs data)
        {
            while (_serialPort.BytesToRead > 0)                     // While there is data on the serial bus
            {
                lock (_lockQueue)
                {
                    _serialQueue.Enqueue((byte)_serialPort.ReadByte());
                }
            }
            unblockRead.Set();
        }
        private static void writeSerial( byte[] data, int len )
        {
            for (int i = 0; i < len; i++)
                _serialPort.WriteByte(data[i]);
        }
        private static void writeSerial(byte data)
        {
            _serialPort.WriteByte(data);
        }
        private static void log( byte[] buffer )
        {
            string message = "Log: ";
            message += new String(Encoding.UTF8.GetChars(buffer));
            Debug.Print(message);
        }
        private static void zero( byte[] buffer, int l)
        {
            for (int i = 0; i < l; i++)
                buffer[i] = 0;
        }
        private static int readSerial(byte[] data, byte termChar = CR)
        {
            zero(data, 20);
            int bytesRead = 0;
            bool keepChecking = true;
            while (keepChecking && (_serialQueue.Count > 0))                   // Have something in the queue
            {
                lock (_lockQueue)                                              // grab lock while dequeing
                {
                    data[bytesRead] = (byte)_serialQueue.Dequeue();            // grab a byte from the queue
                }
                if (data[bytesRead] == termChar)                               // Hit terminating character, stop grabbing bits
                    keepChecking = false;
                bytesRead++;
            }
            while (keepChecking)
            {
                bool signaled = unblockRead.WaitOne(_readTimeout, false);
                if (!signaled)                                              // Timed out, exit loop
                    keepChecking = false;
                else
                {
                    while (keepChecking && (_serialQueue.Count > 0))        // Have something in the queue
                    {
                        lock (_lockQueue)                                   // grab lock while dequeing
                        {
                            data[bytesRead] = (byte)_serialQueue.Dequeue(); // grab a byte from the queue
                        }
                        if (data[bytesRead] == termChar)                    // Hit terminating character, stop grabbing bits
                            keepChecking = false;
                        bytesRead++;
                    }
                }
            }
            return bytesRead;
        }
    }
}

I think it must be something in my setup, do I need to have a ground wire added somewhere for the plus2? (as opposed to a plus?) I have tried two plus 2 devices, two different HA7S devices, multiple temp sensors, and always get indeterminate results from the serial queries. Its like something is stepping on the UART queue, or inbound characters. Not at all like the behavior on the plus, very timing dependent. Started off with a  fairly simple program to just test the serial commands and can't get any good, or consistent results. Even flashed one unit back to 4.2.2 and have the same issues. Entire test program in message.

 

Would really appreciate any pointers. Thanks.


In Topic: Plus 2 serial issue with HA7S

28 May 2014 - 06:33 PM

I also swapped out the HA7S and still have the same behavior. Will investigate the code a bit, doing some very simple interrupt handling, but will try a smaller example.


In Topic: Digital IO interrupt causing USB reset?

06 May 2014 - 03:21 PM

Ok, a hard post to write, but please ignore this. I failed to create a NativeEventHandler and was just assigning the method address. Whoops. Caused all kinds of nasty problems, but not right away. As I saw in another post, please ignore, nothing to see here...


home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.