Automation Hat C# library for Windows IoT Core


#1

Hi, folks. In case anyone is interested, I wrote a C# library for the Automation Hat for use in a Windows IoT Core project I am working on.

It is available here:

I tried to stay as close as possible to the Python function reference as possible.


#2

Cool. I did a blinkt port last weekend and it is available at

Needs some debugging work though.


#3

This is good stuff, I need to pick Windows IoT up again and see what’s changed. When I first tried it, it was impossible to set pin muxes and change things like i2c and SPI to be regular IO pins, so it made supporting some of our hardware impossible. I guess that’s fixed now?

Incidentally, Android has the same problem, with no forthcoming sane solution as far as I know.


#4

@MarcJennings Very nice!

@gadgetoid Sorry, I can’t speak to pin mux. I don’t personally have a need to change those. In this particular case, for my project, I am using I2C pins for their regular purpose, and I just avoided SPI pins. Which hardware did you run into problems with? I found the Automation Hat to be really awesome, so I was thinking of picking up some of your other pieces to experiment with.


#5

@jcoliz I think I was using a Display-o-Tron 3000, but it was a while ago now.

Looking over the updated pin mappings diagrams for W10 IoT, which now have a documented “Alternate Function” I’m guessing the problem has long been solved: https://developer.microsoft.com/en-us/windows/iot/docs/pinmappingsrpi

In fact, there’s a whole section specifically about muxing, which has been very sensible implemented and should be pretty much transparent:

Some GPIO pins can perform multiple functions. By default, pins are configured as GPIO inputs. When you open an alternate function by calling I2cDevice.FromIdAsync() or SpiDevice.FromIdAsync() , the pins required by the function are automatically switched (“muxed”) to the correct function. When the device is closed by calling I2cDevice.Dispose() or SpiDevice.Dispose(), the pins revert back to their default function. If you try to use a pin for two different functions at once, an exception will be thrown when you try to open the conflicting function. For example,


#6

Ah yes, it looks like it has all been sorted now, rather nicely.


#7

Hi togehter,
please can you give me an example for create an input event
with the IotFrosting.Pimoroni?

Best Regards

Timo


#9

Could you describe a bit more the context around when you would use such an event and what it might do? Is there an analogous sample in the python library that might serve as an example?


#10

No Problem,
i need an Event (Trigger) when a signal change the state from True to False.

for example
I constantly monitor input 1. If Input 1 changes the status from True to False a method is to be called.

br Timo


#11

@Timo, the README and existing Automation Hat Sample both cover that case.

Hat.Input[0].Updated += (s, a) => { if (s.State) Hat.Output[0].Toggle(); };


#12

Hi, thanks it runs very good. Sorry for my short statements, my English is not so good…
I looked at your in your Code… i works very well. because i have Problems with access to a Textbox, for example.

Can you give me a short Example:

When I call the event, I want to increase the text field by 1. However, if I want to access this text field I always get an error.
Do you have an idea here or can tell me what I do wrong?

Hat.Input[0].Updated += (s, a) =>
{
if (s.State)
Hat.Output[0].Toggle();

test += 1;
TextBox1.Text= test;

};
The error occurs because I access the control from another task, right?

Can you give me another example how I can make something like that?

Thanks

br Timo


#13

Any code that changes the UI, you have to run from the UI thread.

https://stackoverflow.com/questions/10579027/run-code-on-ui-thread-in-winrt

Generally speaking, you can take the text of the exception you get and drop that into web search. This almost always leads to the answer.


#14

Hey, it works fine now.

Many thanks

Br Timo