Recent

Author Topic: h2WiringPi wrapper for Lazarus and Raspberry Pi 4  (Read 629 times)

washburn_it

  • New Member
  • *
  • Posts: 20
h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« on: September 20, 2020, 12:23:04 pm »
Hi,

I'm facing some problems using the "wiringPi" wrapper for Lazarus with a Raspberry Pi4 (2 GB version), version of the wrapper is 2.23 and Lazarus 2.0.
I would like to use the (physical) pin 13 (GPIO27) to read the state of a button (when it is pressed it connects to GND): with Python I can read it correctly (0 if pressed, 1 if not pressed).
Lazarus "digitalRead(P13)" returns always "0" if pressed or not pressed...I know that there is a little confusion about PIN numbering but...am I reading the wrong PIN?
Thank you, regards.


Roberto


jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #1 on: September 20, 2020, 12:37:01 pm »
look at the source code for that function and see what it's doing..

Maybe its looking in a table of constants and that one does not exist?

Or maybe its the difference between bit 1 as actually being addressed as bit 0... Depends who was at the wheel that day..

 Try P12
.
The only true wisdom is knowing you know nothing

washburn_it

  • New Member
  • *
  • Posts: 20
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #2 on: September 20, 2020, 12:48:13 pm »
I forgot to post the initialization: pinMode(P13, INPUT).
What is confusing me is: "GPIO27" corresponds with "P13" const that I find on h2wiringPi.pas?
If I read the "h2wiringPi.pas" I find that "P13" declaration is "P13=2"...what's that "2"? Physical pin 2? GPIO2?
  %)
« Last Edit: September 20, 2020, 12:57:01 pm by washburn_it »

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #3 on: September 20, 2020, 02:12:01 pm »
maybe a slip of the keyboard, is it possible it should be 12 instead ?

Can't you simply do a direct port read , mask out the other bits and see if the remaining bit is on...

 Not sure what the compiler offers you but a Port read normally gives you a 8 bit (byte) read but in the case of where this is different than what I am used to  it could be just a mapped registered in which case you simple apply OR and AND functions to determine the state of the IO.
 
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 10582
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #4 on: September 20, 2020, 03:47:58 pm »
For wiring Pi you need to change the start offset. for Pi3/4. The wiki is based on just Pi1/2.
The offset is different (but the same for Pi models 3 and 4) As I remember correctly there is already an entry for this.
Also note the note here: http://wiringpi.com/

You may accidentally use the wrong version.

I have successfully used it at least on the RPi1 and RPi3 in the past. I suspect the wiki (our wiki!) is outdated.
The needed change is a one line edit. I think I answered this before.
There are three different start addresses:
RPi1 base
RPi2 base
RPi3/4 base (these are the same)

I can't access the right things now, but the start address documentation is on the raspberrypi.org website.
You only need to change the Hexadecimal value and the code should work.
I can post the correct values tomorrow if you wish,
« Last Edit: September 20, 2020, 04:06:44 pm by Thaddy »

hansotten

  • Jr. Member
  • **
  • Posts: 59
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #5 on: September 20, 2020, 05:12:57 pm »
WiringPi is officially deprecated, an unofficial fork is maintained here: https://github.com/WiringPi/WiringPi
by respectable persons like Phil Howard of Pimoroni.

Note https://github.com/laz2wiringpi/laz2wiringpi is 6 years old, so really outdated and not maintained

I wonder if this is future proof ...



washburn_it

  • New Member
  • *
  • Posts: 20
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #6 on: September 20, 2020, 05:40:50 pm »
Well...I've read just now that the official version is not maintained anymore but there is an update for the Pi 4 (v 2.52).
I've made that update and now I found that:
- if the pin is configured as output, it works
- if the same pin is configured as input, it doesn't work...I tried to connect the GPIO27 (or physical pin 13) to physical PIN 17 (it's 3.3V pin) but it still reads "0".

So maybe it's an issue with Pi4 and Lazarus....?
With Python, for example, no problem.


washburn_it

  • New Member
  • *
  • Posts: 20
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #7 on: September 20, 2020, 06:51:25 pm »
I think I found something...I tried writing a small C++ program to read the PIN 13 as input: if the PIN is left "floating" the readings (every 100 ms) change at every read from "0" to "1"...then I see "0 1 0 1 0 1 0 1 0 1...." on video.
If I enable "internal" pull-up function (I need to have "0" when the button is pressed, "1" if not), if the input is not connected to anything (so floating) the reading is always "0".
If I connect the PIN to 3.3V, it reads "1"...then the problem seems to be related to internal pull-up/pull-down feature.
I tried then in Lazarus and I've got the same result, same with Python.
With a "physical" resistor used as pull-up, everything works.


Roberto
« Last Edit: September 20, 2020, 06:53:45 pm by washburn_it »

dogriz

  • Full Member
  • ***
  • Posts: 119
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Re: h2WiringPi wrapper for Lazarus and Raspberry Pi 4
« Reply #8 on: September 23, 2020, 12:44:56 pm »
I had several problems with internal pull-up/down resistors with RaspberryPi, OrangePi and Arduino through years, so I never use them anymore. Only "physical" resistors work for me.
And laz2wiringpi is OK for the GPIO task (it works with OrangePi and https://github.com/zhaolei/WiringOP)
« Last Edit: September 23, 2020, 12:47:51 pm by dogriz »
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

 

TinyPortal © 2005-2018