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.

gbreder

Member Since 02 Jan 2011
Offline Last Active Jun 18 2016 11:51 AM
-----

#28253 SparkFun Inventor's Kit / CIRC-05 | 8 More LEDs - 74HC595 Shift Register

Posted by gbreder on 28 April 2012 - 09:26 AM

Hi,
I'm happy to help. I've mode some major and some minor changes. All major changes are listed below. The whole result was zipped and attached. But be aware that my Netduino GO hasn't arrived yet. So the code is completely untested.

  • The "controller" isn't nested anymore. A nested type is only used if it is related to its parent in some way.
  • The method "UpdateLeds" was moved inside "ShieldBaseController" because it was accessing only OutputPorts from it.
  • All output ports are now private.
  • The statement "bits[led]" and its "bits" array was replaced by a bit shift operation "1 << led".
  • The "mask[led]" was also expressed as (inverted) bit shift "~(1<<led)". For example 1<<4 would result in 16 (or 0x10) and the "~" will invert every bit in the byte so you will get 0xEF or 239. Less manual calculations and less code results in less errors :-)
  • Some minor renaming and other unimportant stuff

There is still room for improvement. You could change your SPI bit bang mode to native SPI from the Netduino. I've attached a class for the 74HC595 from my classic Netduino as example. You can also provide the parameter "GoSockets.Socket5" for your "new ShieldBase()" through the constructor of the class.

Regards
Guido


#27840 Power consumption / limits

Posted by gbreder on 21 April 2012 - 06:57 PM

Hi, I would get a capacitor with a higher voltage. Something like 50V to 60V. If the TSR-1 needs 22uF you should get exactly the 22uF. If you need 1000uF for the rectifier you should get one and put them both in parallel. But I would put the rectifier capacitor near the rectifier and the TSR cap near the TSR. This should give the best result. Capacitor theory (oversimplified): Small caps can filter very small ripple (but not huge ripple) because they take little time to load and unload. Huge caps can filter huge ripple (but not small ripple) because it takes a long time to load and unload. Regards Guido


#27791 Multiple I2C devices

Posted by gbreder on 21 April 2012 - 07:39 AM

Hi teo,
without the data sheet of the gyro I would guess something like that:
device.ReadInternalAddressBytes(i2cconf2, rbuf, 27, 1);
because the fourth parameter is the count of bytes that are used for the internal address and your internal address fits nicely in on byte.
But only the data sheet of your gyro sensor can answer your question.

Guido
  • teo likes this


#27764 Multiple I2C devices

Posted by gbreder on 20 April 2012 - 10:28 PM

Hi teo,
most possibly your firmware is something like 4.0.6 or so.
A good firmware for repeated start bit support is Version: 4.1.1 BETA 1 (version 4.1.1.0 b1)
You have to update the tiny booter decrompressor too. A superb how to is in the wiki.
After that you can update the firmware of your Netduino.

Version 4.1.1.0 b1 is really stable. My under floor heating runs on 4.1.1.0 b1 till january. The 4.2.0.0 will be great too but until now the same program gets stuck after 6 to 12 hours if it runs on 4.2.

Regards
Guido
  • teo likes this


#27626 Multiple I2C devices

Posted by gbreder on 19 April 2012 - 07:38 AM

Hi teo, I will try your code at a later time but in the meantime please answer me: which Netduino firmware are you running? Guido P.S: I've tested your code. Works well on firmware 4.2.0.0 RC4. I have none of your devices of course but the exception should occur without them...
  • teo likes this


#27524 Power consumption / limits

Posted by gbreder on 18 April 2012 - 08:15 AM

Hi,
the really hot resistor is a possible way but I wouldn't recommend it. I've build a switching power supply my self (based on the LM2596, but they are also available fully assembled.

For example the TSR1 module is very easy to use: One Pin is Vin, one is Ground and the last puts out your 5V. And this goes up to 2.5Amps 1Amp without a heatsink.

Regards
Guido

P.S.: Paul pointed out that the maximum power output is 1A instead of 2.5A. Thanks.


#27144 Multiple I2C devices

Posted by gbreder on 13 April 2012 - 08:05 AM

Hi teo,
the most important thing is that the class will be used like this:
I2CAdapter adapter = I2CAdapter.Instance;
adapter.WriteBytes(...);
instead of something like that:
Picture picture = new Picture();
picture.Load(...);

Regards
Guido
  • teo likes this


#27093 Multiple I2C devices

Posted by gbreder on 12 April 2012 - 07:18 PM

Hi,
a class like the following will most possibly fit your requirement:

using System;
using System.Reflection;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace Netduino.Extender.TransferAdapters
{
	/// <summary>
	/// Wire-up the I2C device to the Netduino as follows:
	/// SDA -> Analog Pin 4;
	/// SCL -> Analog Pin 5;
	/// GND -> GND.
	/// </summary>
	public sealed class I2CAdapter
	{
		private static readonly Object _I2CLock = new object();
		private static readonly I2CAdapter _Instance = new I2CAdapter();

		private readonly I2CDevice _I2CDevice;

		/// <summary>Creates a new <see cref="I2CAdapter"/> instance </summary>
		/// <remarks>
		/// At this time the .NET Micro Framework only supports a single I2C bus. 
		/// Therefore, creating more than one I2CAdapter instance will generate an
		/// exception. 
		/// </remarks>
		private I2CAdapter()
		{
			//Initialize the I2CDevice with a dummy configuration
			_I2CDevice = new I2CDevice(new I2CDevice.Configuration(0, 0));
		}

		public static I2CAdapter Instance
		{
			get { return _Instance; }
		}

		private I2CDevice.I2CWriteTransaction CreateInternalAddressWriteTransaction(byte[] buffer, uint internalAddress,
		                                                                            byte internalAddressSize)
		{
			I2CDevice.I2CWriteTransaction writeTransaction = I2CDevice.CreateWriteTransaction(buffer);

			ModifyToRepeatedStartTransaction(internalAddress, internalAddressSize, writeTransaction,
			                                 typeof (I2CDevice.I2CWriteTransaction));

			return writeTransaction;
		}

		private I2CDevice.I2CReadTransaction CreateInternalAddressReadTransaction(byte[] buffer, uint internalAddress,
		                                                                          byte internalAddressSize)
		{
			I2CDevice.I2CReadTransaction readTransaction = I2CDevice.CreateReadTransaction(buffer);

			ModifyToRepeatedStartTransaction(internalAddress, internalAddressSize, readTransaction,
			                                 typeof (I2CDevice.I2CReadTransaction));

			return readTransaction;
		}

		/// <summary>
		/// To use the new I2C InternalAddress feature (repeated start bit) in the v4.1.1 alpha,
		/// add the following method to your code...
		/// and then call it instead of built-in I2CDevice.CreateWriteTransaction/CreateReadTransaction functions when appropriate.
		/// </summary>
		/// <param name="internalAddress"></param>
		/// <param name="internalAddressSize">The InternalAddressSize parameter defines
		/// the # of bytes used to represent the InternalAddress. The InternalAddress is a set of bytes sent to a device before the
		/// buffer--often a register # or memory location to write/read. When used in an I2C ReadTransaction, an extra start bit will
		/// be sent to the I2C device after the InternalAddress (followed by the traditional buffer read/write).</param>
		/// <param name="transaction"></param>
		/// <param name="transactionType"></param>
		private static void ModifyToRepeatedStartTransaction(uint internalAddress, byte internalAddressSize,
		                                                     I2CDevice.I2CTransaction transaction, Type transactionType)
		{
			FieldInfo fieldInfo = transactionType.GetField("Custom_InternalAddress",
			                                               BindingFlags.NonPublic | BindingFlags.Instance);
			fieldInfo.SetValue(transaction, internalAddress);

			fieldInfo = transactionType.GetField("Custom_InternalAddressSize", BindingFlags.NonPublic | BindingFlags.Instance);
			fieldInfo.SetValue(transaction, internalAddressSize);
		}

		public int WriteInternalAddressBytes(I2CDevice.Configuration i2CConfiguration, byte[] bytesToWrite,
		                                     uint internalAddress, byte internalAddressSize)
		{
			int bytesTransfered = ExecuteI2CTransactions(i2CConfiguration,
			                                             CreateInternalAddressWriteTransaction(bytesToWrite, internalAddress,
			                                                                                   internalAddressSize));

			// I2CDevice.Execute returns the total number of bytes transfered in BOTH directions for all transactions
			if (bytesTransfered < (bytesToWrite.Length))
			{
				Debug.Print("WriteInternalAddressBytes: I2C expected + '" + bytesToWrite.Length + "' but could write + '" +
				            bytesTransfered + "'.");
			}

			return bytesTransfered;
		}

		public int ReadInternalAddressBytes(I2CDevice.Configuration i2CConfiguration, byte[] bytesToRead, uint internalAddress,
		                                    byte internalAddressSize)
		{
			int bytesTransfered = ExecuteI2CTransactions(i2CConfiguration,
			                                             CreateInternalAddressReadTransaction(bytesToRead, internalAddress,
			                                                                                  internalAddressSize));

			// I2CDevice.Execute returns the total number of bytes transfered in BOTH directions for all transactions
			if (bytesTransfered < (bytesToRead.Length))
			{
				Debug.Print("ReadInternalAddressBytes: I2C expected + '" + bytesToRead.Length + "' but could read + '" +
				            bytesTransfered + "'.");
			}

			return bytesTransfered;
		}

		public int WriteBytes(I2CDevice.Configuration i2CConfiguration, byte[] bytesToWrite)
		{
			int bytesTransfered = ExecuteI2CTransactions(i2CConfiguration, I2CDevice.CreateWriteTransaction(bytesToWrite));

			// I2CDevice.Execute returns the total number of bytes transfered in BOTH directions for all transactions
			if (bytesTransfered < (bytesToWrite.Length))
			{
				Debug.Print("WriteBytes: I2C expected + '" + bytesToWrite.Length + "' but could write + '" + bytesTransfered + "'.");
			}

			return bytesTransfered;
		}

		public int ReadBytes(I2CDevice.Configuration i2CConfiguration, byte[] bytesToRead)
		{
			int bytesTransfered = ExecuteI2CTransactions(i2CConfiguration, I2CDevice.CreateReadTransaction(bytesToRead));

			// I2CDevice.Execute returns the total number of bytes transfered in BOTH directions for all transactions
			if (bytesTransfered < (bytesToRead.Length))
			{
				Debug.Print("ReadBytes: I2C expected + '" + bytesToRead.Length + "' but could read + '" + bytesTransfered + "'.");
			}

			return bytesTransfered;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="configuration">Netduino needs only the 7 most significant bits for the address e.g. 0x91 >> 1 = 0x48.</param>
		/// <param name="transaction"></param>
		/// <returns></returns>
		private int ExecuteI2CTransactions(I2CDevice.Configuration configuration, I2CDevice.I2CTransaction transaction)
		{
			lock (_I2CLock)
			{
				_I2CDevice.Config = configuration;

				// Execute the read or write transaction, check if byte was successfully transfered
				int bytesTransfered = _I2CDevice.Execute(new[] {transaction}, 100);
				return bytesTransfered;
			}
		}
	}
}
This class takes a I2CDevice.Configuration for each read and write and can be used multiple times for diffrent devices. It should be tread-safe. To get an instance of this class please call "I2CAdapter.Instance" (singleton pattern). The Read/WriteInternalAddressBytes methods are used in Firmware 4.1.1 beta 1 and 4.2.0 RCx. They won't work in 4.0. If there are errors in my code or if there are suggestions for improvement please let me know.
Now you should be able to use the one I2C bus of your Netduino with ease for diffrent devices.

Regards
Guido
  • teo likes this


#24732 Joystick and Bluetooth Module

Posted by gbreder on 27 February 2012 - 01:24 PM

Hi xikky, 1. There is no diffrence between these two models. Both are 2-axis analog sticks with a pushbutton. 2. You solder the stick and about 5 pins into the breakout board and you're done. You newly created joystick board can be connected directly to the anlaog pins of the Netduino or by some of the available "proto shields". Don't forget to connect AREF to 3.3V if your Joystick is connected to 3.3V... Regards Guido


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.