NWT.Stuff
I am new to openPLC.   I was just wondering if it is possible to configure the internal pullup and pulldown resistors on RPI inputs in the editor or runtime interface ?

I am quite happy to run some python script on boot if the answer is no 🙂

Great Project and keep up the good work.

Kevin
Quote 0 0
NWT.Stuff
In addition to the above question could you please let me know the default configuration of Inputs & Outputs in your module for RPI V3.  That's basically what "GPIO.Setup" commands you use ?

Many Thanks in advance

Kevin
Quote 0 0
thiagoralves
The pin mapping is available on the project website (getting started -> runtime -> raspberry pi). As for the internal pull up/down, to enable them you need to edit the raspberry pi driver for OpenPLC located in /webserver/core/hardware_layers/raspberry_pi.cpp

for reference, here is how you change pull up/down config on this hardware layer:  http://wiringpi.com/reference/core-functions/

Once you’re finished with your changes, you need to reapply the raspberry pi hardware layer for changes to take effect. On OpenPLC go to hardware, select Raspberry Pi from the drop down menu and click “save changes”
Quote 0 0
NWT.Stuff
Ok thanks for the info Thiago. Good news that I can configure the driver myself. 🙂
Quote 0 0
NWT.Stuff
Firstly didn't realise there was a sub topic for RPI.  Will use that in the future (not sure if you can move this post !!)

This is my simulation board
Sim-Board.jpg 
  
I have 4 outputs and 8 inputs wired (by the way your pin layout is very tidy and easy to wire)

This is an extract from the "rapberrypi.cpp" file on my raspberry pi
//set pins as input
for (int i = 0; i < MAX_INPUT; i++)
{
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
{
pinMode(inBufferPinMask[i], INPUT);
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
{
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
}
}
}


I usually PULL_DOWN buttons to 0V so I started with this. Only Inputs .0 & .1 were working (as they are configured permanently PULL_DOWN). The Inputs (.2 to .7) are certainly behaving as they are PULL_UP.  I had to change my common to 5V and it all works perfectly. 🙂

This is OK for me on the simulation board but my real world systems have pulled down inputs so I will need to solve this issue at some point (or rewire). 

  





Quote 0 0
thiagoralves
Let me make sure I got what you said. Did you mean that PUD_DOWN is only working on %IX0.0 and %IX0.1? Or that they are working on all but %IX0.0 and %IX0.1. As far as I know, there is a physical pull up resistor on the raspberry pi board for the %IX0.0 and %IX0.1 pins due to I2C comms specs. There isn't anything you can do to change that, unless you're willing to desolder the resistors from the board.

For the other pins, if you're having problems enabling the internal pull up/down, make sure you have the latest version of wiring pi installed, as these functions come directly from wiring pi library.
Quote 0 0
NWT.Stuff
OK I'll do a little sketch tomorrow to clarify and check out the pi spec. My gut has always been that the first two are pulled down. But as I am sure you know it's easy to get 0 and 1 confused in this game 🙂

When working in python I usually pull them up. Not because it does anything but more to remind me that they are different. For example I also usualy connect ix0.0 to a ground signal to give me my pi is running and healthy. Will check this this out tomorrow too.

It would help my understanding if you could briefly explain the function of the cpp file and what language it is written in. Not one I am familiar with.



Quote 0 0
thiagoralves
.cpp files are written in C++. This is the main language for the OpenPLC core. Wiring Pi is a C++ library to access Raspberry Pi GPIO pins. OpenPLC Raspberry Pi driver uses Wiring Pi to access and control the Pi's GPIO.
Quote 0 0
NWT.Stuff
Hi Thiago,

I have done some tests in order to get my head round it.  I have attached the conditions and the results in a pdf document.

You can see from the results that with default configuration that pins 0 & 1 are expecting to be pulled down to GND.  This makes sense to me as where I used to work we would use the "old skool" approach of wiring i0 to GND to give us a "Input Card Healthy Signal".  True that we can get this (and even more information) via the comms but most Software engineers liked to have and use this input.

Which brings me back to the .cpp configuration in Open PLC.

What is the order things are done e.g.
 -power on pi = wiring.cpp loaded
 -start plc = raspberrypi.cpp from OpenPLC 

What is the intention of the code in your cpp file

for (int i = 0; i < MAX_INPUT; i++)
{
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
{
pinMode(inBufferPinMask[i], INPUT);
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
{
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
}
}
}


I want to Pull down i2 to i7.  Is my best bet to delete the code in raspberrypi.cpp and configure using wiring.cpp ?
Quote 0 0
thiagoralves
I guess you're making a confusion on what "internal pull up/down" means in terms of GPIO. I'll try to explain here, but if it is still not clear try reading something online (wikipedia has great articles about it). So basically, the internal pull ups work as to avoid the pin to be floating when nothing is connected to it. This is the case for example when you connect a NO button to the pin and the button is not pressed. In this case, there isn't actually anything connected to the pin, because the button is open. If it weren't for the internal pull up/down circuitry, the input would read noise and randomly switch to high/low, which is BAD! So, how does the internal circuitry work? There are two types: pull up and pull down

Pull Up
--------
In this configuration, the GPIO pin is connected to VCC through an internal resistor to limit the current. This means that the state of the pin will always be HIGH if you don't connect anything to it (because internally it is already connected to VCC). The only way to switch the state of this pin is to connect it to GND. Then the current will flow through the internal resistor to GND and the pin will be in LOW state. To be clear, for pins with internal pull up circuitry, you need to connect your buttons to GND to make them switch state

Pull Down
------------
In this configuration, the GPIO pin is connected to GND through an internal resistor to limit the current. This means that the state of the pin will always be LOW if you don't connect anything to it (because internally it is already connected to GND). The only way to switch the state of this pin is to connect it to VCC. Then the current will flow from VCC through the internal resistor to GND and the pin will be in HIGH state. To be clear, for pins with internal pull down circuitry, you need to connect your buttons to VCC to make them switch state.

With all that being said, the Raspberry Pi board has pull up circuitry physically attached to pins %IX0.0 and %IX0.1. There is no way to change this in software. It is hardwired in the board. For the other pins, you can change in software the state of the internal pull up/down circuitry (because this circuitry actually lives inside the Broadcom chip and can be controlled via software). You can change the state through the PUD_UP and PUD_DOWN calls. OpenPLC raspberrypi.cpp driver activates PUD_DOWN (internal pull down circuitry) for all pins except %IX0.0 and %IX0.1 because they are pulled up in hardware. If you want all the pins to have the same behavior as %IX0.0 and %IX0.1 you will need to change that line of code that says PUD_DOWN to PUD_UP. Then you will activate the internal pull up circuitry and they will all be in high state if nothing is connected to them.
Quote 0 0
NWT.Stuff
Hi Thiago,

Thanks for your help and advice.

As we say in England "The penny has finally dropped" 🙂

The  %IX0.0 and %IX0.1 in your mapping are GPIO2 & GPIO3 Physical Pins (3 & 5).  It's about 6 years since I did my first RPI Project and I have just cut and pasted since then.  Got it thanks 🙂

I am hoping to finish my first OpenPLC project tomorrow (fingers crossed).  It's a great tool & project and it's really going to improve my speed and reduce comms to my web & mysql server.

If all goes well I'll celebrate with a donation 🙂

Many Thanks and keep up the good work. Kevin
Quote 0 0