First of all, thank you to developers for such a great product.
A brief explanation, I am doing my master thesis developing a “sort of” a medical simulator for a local hospital.
All the simulator needs is to have multiple analogue inputs just to read voltages.
Problem 1:
I have managed to get the voltages from A type sockets pins 3, 4, 5, but I cannot seem to use IO60P16 to read any voltages for me, therefore if you are able to explain me how do I use the IO60P16 to read analogue voltages, please let me know
(or, as an alternative, generating multiple different PWM signals and reading them with different PWM inputs would do the job too as I need to give each metal object in space a different voltage or PWM to be able to identify what the user is currently touching)
Problem 2:
The Gadgeteer device is supposed to be a part of a bigger application.
The “bigger application” is supposed to support various types of I/O devices and use them collect data, show webcam, upload to Azure and so on. One of the devices we are already using is Arduino which is being accessed through System.IO.Ports.SerialPort.
But this seem to have a conflict with libraries required for Gadgeteer.
Error 4 The type 'System.IO.Ports.Handshake' exists in both 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll' C:\Users\Audrius\Documents\Visual Studio 2010\Projects\PasteurWPFTest\Hardware\ArduinoDevice\ArduinoDevice.cs 38 50 PasteurClient
Problem 3:
I thought, OK, let’s make the Gadgeteer classes a class library and try to include it in our project.
So I started a new class library with the following code:
Class library:
using System;
using System.Collections.Generic;
using Gadgeteer;
namespace GadgeteerAdaper
{
public class GadgeteerAdapterBase : Gadgeteer.Program
{
private static List<Socket> sockets = new List<Socket>();
private List<IGadgeteerListener> listeners = new List<IGadgeteerListener>();
public static void Main()
{
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
Socket socket = Socket.GetSocket(10, true, null, null);
sockets.Add(socket);
GadgeteerAdapterBase baser = new GadgeteerAdapterBase();
baser.SetUpGadgeteer();
baser.Run();
}
public GadgeteerAdapterBase()
{
}
public GadgeteerAdapterBase(Mainboard board, List<int> socketNumbers)
{
Mainboard = board;
Socket socket = null;
foreach (int socketNumber in socketNumbers)
{
socket = Socket.GetSocket(socketNumber, true, null, null);
if (!socket.SupportsType('A'))
{
throw new Exception("Socket " + socket.SocketNumber + " does not support type A.");
}
if (socket != null)
{
sockets.Add(socket);
}
}
SetUpGadgeteer();
Run();
}
private void SetUpGadgeteer()
{
Timer timer = new Timer(1);
timer.Tick += new Timer.TickEventHandler(timer_Tick);
timer.Start();
}
private void timer_Tick(Timer timer)
{
int port = 0;
foreach (Socket socket in sockets)
{
int currentValue;
currentValue = (int)System.Math.Round(socket.AnalogInput3.ReadVoltage() * 1024 / 3.3);
ReportToListeners(port++,currentValue);
currentValue = (int)System.Math.Round(socket.AnalogInput4.ReadVoltage() * 1024 / 3.3);
ReportToListeners(port++,currentValue);
currentValue = (int)System.Math.Round(socket.AnalogInput5.ReadVoltage() * 1024 / 3.3);
ReportToListeners(port++,currentValue);
}
}
private void ReportToListeners(int port, int value)
{
#if DEBUG
Microsoft.SPOT.Debug.Print("Port:" + port + " Value:" + value);
#endif
foreach (IGadgeteerListener listener in listeners)
{
if (listener != null)
{
listener.ReceiveGadgeteerUpdate(port, value);
}
}
}
public void RegisterListener(IGadgeteerListener listener)
{
listeners.Add(listener);
}
public void UnregisterListener(IGadgeteerListener listener)
{
if (listeners.Contains(listener))
{
listeners.Remove(listener);
}
}
public Mainboard GetMainboard()
{
return Mainboard;
}
}
}
Interface:
namespace GadgeteerAdaper
{
public interface IGadgeteerListener
{
void ReceiveGadgeteerUpdate(int port,int value);
}
}
I can avoid the arguments in the constructor so that the “bigger application” should not have to care about any objects involved within Gadgeteer, but Main() still doesn’t work well.
I made a separate console app which tries to use the class library but due to reflections, you start getting exceptions of missing libraries and have to add Microsoft.SPOT.Hardware, Microsoft.SPOT.TinyCore to make it work, which is fine, but then eventually I hit the following exception which I have no clue how to go about:
ECall methods must be packaged into a system module.
Microsoft.SPOT.Hardware
at Microsoft.SPOT.Hardware.OutputPort..ctor(Pin portId, Boolean initialState)
at GHIElectronics.Gadgeteer.FEZSpider..ctor() in C:\Gadgeteer SVN\Main\Mainboards\GHIElectronics\FEZSpider\Software\FEZSpider\FEZSpider.cs:line 313
at GadgeteerAdaper.GadgeteerAdapterBase.Main() in c:\users\audrius\documents\visual studio 2010\Projects\GadgeteerBase\GadgeteerBase.cs:line 15
at GadgeteerTester.UnitTest.Init() in c:\users\audrius\documents\visual studio 2010\Projects\GadgeteerTester\UnitTest.cs:line 19
This happens at:
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
The main question is if what I am trying to do is doable, or am I misunderstanding something?
As far as I understand the C# code gets compiled to byte code and sent to the device, but is there any way to send information from the device back to code running on the PC via the Usb cable used for compiling? Or do I need to resort to some sort of “use an additional module” solutions (such as using WiFi, Ethernet modules) to send data back to PC?
This device should be manageable from my “bigger application”, therefore if I use WiFi as an option, and the device gets moved to different premises, someone within the different premises will have to recompile the Gadgeteer code with different Wifi settings? Or can my bigger application somehow take care of this?
I want to enable users to use any Gadgeteer mainboard with my “bigger application”, hence the constructor where I pass a Mainboard. Is this even possible?
How do I go about it?
Sorry for the long post, and thank you for help!
Regards,
Audrius.