0

I am setting up a Raspberry PI 3 to work with a distance sensor and display to a UWP app. Specifically this model: https://www.tindie.com/products/upgradeindustries/hc-sr05--hy-srf05-precision-ultrasonic-sensor/.

I am looking for a way to run the distance calculation/GPIO in the background in Python, and then display the distance to a UWP app. Does anyone know if this is possible, or could point me in the right direction? Currently the UWP app I have is working, however it does seem unreliable.

Thanks!

Parakoopa
  • 505
  • 1
  • 9
  • 22
  • 1
    I see two options here. You could integrate your UWP app and your python script with a Realtime database, and have your UWP read the values that your python script sends to it. Firebase offers a great realtime database. Otherwise, you could use a library like IronPython to integrate with .NET and use the .NET class libraries within the script. For the IronPython approach, I'm not exactly sure how seamless the integration would be. – Brandon Miller Jan 25 '18 at 18:15
  • I like the option of using a Realtime database, however I need this to work offline..(I know, not very IOT). Do you have any suggestions for offline realtime database? – Parakoopa Jan 25 '18 at 18:52
  • Without internet, your only option would be IronPython. Here's a link with an example of how to read values returned from a Python script in c#. It details how to do it with native C# code, or the fully managed IronPython library (I recommend IronPython because it can catch and return exceptions in your python script): https://medium.com/@dpursanov/running-python-script-from-c-and-working-with-the-results-843e68d230e5 – Brandon Miller Jan 25 '18 at 19:08
  • 1
    Maybe you can create a Python background service and consume it in UWP app. You can start with [AppServiceBlinky](https://developer.microsoft.com/en-us/windows/iot/samples/appserviceblinky) and [Python Blinky app](https://developer.microsoft.com/en-us/windows/iot/samples/helloblinkybackgroundpython) samples. – Rita Han Jan 26 '18 at 07:14

1 Answers1

1

First to write a driver for your ultrasonic in Python, see https://github.com/great-coder/RP_Drivers_Python/blob/master/Ultrasonic.py

Then read this How do I run a Python script from C#?
to call the python script periodically from UWP.
You can write the calculated distance inside of fun1 function in python into a file, then read the file inside the UWP app and update the value.

Coder the Great
  • 143
  • 1
  • 9
  • Thank you for your answer. Do you know where the location of Python would be in Windows 10 iot core? Just trying to fill out all the variables. – Parakoopa Jan 28 '18 at 18:31
  • @Parakoopa You can write a python program and deploy it into your windows iot (See: https://developer.microsoft.com/en-us/windows/iot/samples/helloworldpython), then run your uwp and use python scripts without problem. – Coder the Great Jan 29 '18 at 20:39
  • If you have problem to call your deployed python script on windows iot, you can use SQLite to sync your python with your uwp app. – Coder the Great Jan 29 '18 at 20:54
  • 1
    [SQLite for python](http://www.sqlitetutorial.net/sqlite-python/) | [SQLite for UWP](https://www.tutorialspoint.com/windows10_development/windows10_development_sqlite_database.htm) – Coder the Great Jan 29 '18 at 20:57