Page 1 of 1

Controlling DIO pins using Python

Posted: 13 Feb 2018, 17:50
by jbarry
Hello All,

Sorry if this seems like a stupid question but I want to be able to change the state of the Ouput Pins and read the values from the Input Pins using python. I am trying to host a webpage from the RevPi Core and then read input pins and control output pins with the push of a button on a webpage. Is this at all possible? How do I access the pins?

Thanks,

jbarry

Re: Controlling DIO pins using Python

Posted: 13 Feb 2018, 19:29
by volker
please read the tutorials. There is an example ("running light") for older and newer Python versions.
I would also like to emphasize that using Node.Red is pretty easy and you get to such a Webinterface by jsut dragging and dropping ready to use "Nodes". Accessing what we call the "central process image" (which reflects the IO states of DIO modules) can be easily done using a "sysetm node" and configure it to use the command shell program "piTest" for setting or reading IO pins of our DIO/DI/DO modules. Good luck and come back for questions if you get stuck in this approach.

Re: Controlling DIO pins using Python

Posted: 21 Feb 2018, 14:45
by jbarry
volker - Thank you for the reply. I have figured out how to edit the central process image using python. Now I need a way to open a web browser on the same network as the RevPi and be able to access the GPIO pins from that web browser. Do you have a suggested solution for this?

Thanks in advance!

Jbarry

Re: Controlling DIO pins using Python

Posted: 21 Feb 2018, 21:21
by volker
Easiest way would be to use Node.Red. I'm sorry we not yet have any tutorial for that so I can only try and give you a clue how to start. Please try to use Google and you will find lots of videos and blogs about using node.red on a Raspi.

So here is the principal way:
Open the Node.Red editor on the RevPi GUI. Drag a "system" node on the workbench as data injection point. This node can be configured to execute any command line. As command please use "piTest -r 1,xxx" (where xxx is the name of your process variable you have configured in PiCtory). When the node executes this command it takes the console output as data for the node's data flow output. Connect this output to the input of a GUI-node (if you know how to use http then you can also use some http to format the output - or use the template node to make an even more complex output). This is principally all. You now only need an injection ode to get the system node trigered every n seconds.
May be this all does not yet make sens to you . But believe me: You can learn this in an hour. Just try it and use some internet tutorial on Node.Red and you will see how easy it is to build a data flow with Webserver output on a dashboard.
You can reach this webserver dashboard with the IP of your device and a special port number (1880) and the subpage "ui". the page under IP:1880 is by the way a GUI for the editor. So you do not need to run the RevPi GUI (startx) to work with Node.Red- You can do it from any browser in the same network as your RevPi. Please be careful with exposing your system to the internet . There are several tutorials on the web how to make this in a secure way.