Notifications
Clear all

Raspberry Pi pin usage???

85 Posts
4 Users
8 Likes
1,739 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@byron Thanks, bookmarked.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Surprising!  I'm finding doing C++ development on the headless Raspberry Pi 4 is so much faster than doing it in Visual Studio on an i7.  I'm slow learning the ropes of using Geany, and its project based compiling system, but once setup, its FAR faster.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@inq Sounds like it may be like mainframe development. Just compile the changed module and then do a CSECT replace link with the existing executable. I instituted that process at IBM Canada since it was how we maintained the mainframe OS in the field before being transferred to HO. I got a nice award and a trip for that. 

OG dude reminiscing. Almost 45 years ago!

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Xylopyrographer
(@xylopyrographer)
Member
Joined: 3 months ago
Posts: 6
 

@inq Seems like we're at about the same place.

I'm expanding into the SBC world after a few years with the ESP32.

I picked a Libre Computing AML-S905X-CC "Le Potato" (Rolls right off the tongue doesn't it!), primarily as it is (relatively) inexpensive, it's available, and it supports a number of Linix distributions. Also uses the Pi3 form factor and "hat" conventions.

Like you, I'm wanting to use C++ to drive the GPIO's and hook up various SPI, I2C devices and do some PWM stuff.

There is a mental shift needed when moving from MCU to MPU space but I'm getting there.

I've settled on Debian as the distro and have found Geany as a probable IDE, which leads me to the question:

Do you have a link to a tutorial/instructions/advise/insight on setting up Geany as a C++ IDE?

FWIW, the Libre folks have a couple articles on using C++. May not be directly applicable to the Pi but may provide some insight, especially the first link on libgpiod or libgpiod2.

Links:

https://hub.libre.computer/t/c-c-gpio-library/209

https://hub.libre.computer/t/how-to-control-gpio-via-c-or-python-3/601

https://hub.libre.computer/t/le-potato-accessing-hardware-pwm-from-c-or-c/815

Many thanks.


   
Inq reacted
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @xylopyrographer

I picked a Libre Computing AML-S905X-CC "Le Potato" (Rolls right off the tongue doesn't it!), primarily as it is (relatively) inexpensive, it's available, and it supports a number of Linix distributions. Also uses the Pi3 form factor and "hat" conventions.

I am by no means an expert on anything SBC or Linux.  I'm still visiting Google a dozen times a day just to do routine tasks I'd know how to do on Windows.  I may have about a dozen Raspberry Pies.  Usually a couple from every generation up through 4.  I did it out of curiosity because of the shiny, novelty of SBC.  The ADHD moment tended to fade because I didn't have a specific project in mind.  I usually  tried things like web servers or at one time did a PLEX server on a 3B.  Very, unsatisfying.  I had never used the pins until the LoRa project that spawned this thread. 

I looked over your Libre links and it does look like a good candidate for hardware.  I'll definitely keep bookmarks for them - Thanks.

I tend to tune my hardware choice very tightly to my project requirements.  I find I have two classes of projects.  For my desires to do A.I. robotics, I need a more powerful, number crunching / large memory unit than micro-controllers can provide.  When I get to that point, I'll be looking at the latest RasPi or more likely some AI/GPU based product like Nvidia Jetson Nano. The other class is at the bottom end of performance.  I want a central, house IoT type server.  It's function is to receive data from many sensor nodes (all ESP8266 nodes so far) and store it in a potentially huge historic database.  It also needs to expose a web-server interface for any browser based client dashboards.  For nodes within range, MQTT works just great over WiFi with the RasPi server being the MQTT broker.  I'm now experimenting with LoRa and using deep sleep to extend battery life of remote units.  In all these cases, I'm only looking at a handful of transactions per hour.  These extremely light requirements scream RasPi Zero class of boards running headless out of sight sipping power on leftover USB adapters.  It's a shame Libre doesn't offer any in the "Zero" style boards.  I have an Orange-Pi Zero coming and it'll be my first non-RaspPi SBC.  I'm hoping generic Debian isn't too different from RaspPi-Debian.

Posted by: @xylopyrographer

FWIW, the Libre folks have a couple articles on using C++. May not be directly applicable to the Pi but may provide some insight, especially the first link on libgpiod or libgpiod2.

The CF going on in the RasPi space about pin libraries is very disheartening for future compatibility.  Ras org or someone like Debian really should use the Windows model of creating a intermediate API where all pin libraries use the API and hardware companies just create the one driver that uses that API - no matter what the underlying chips are.  The RasPi 5 changing chips now breaks all these pin libraries.  I unfortunately didn't read your links before settling on using the pigpio - https://abyz.me.uk/rpi/pigpio/ .  I'll keep lidgpiod/2 bookmarked in case I run into trouble - Thanks.

Posted by: @xylopyrographer

I've settled on Debian as the distro and have found Geany as a probable IDE, which leads me to the question:

Do you have a link to a tutorial/instructions/advise/insight on setting up Geany as a C++ IDE?

I was expecting to get a bare-bone Desktop installation.  I didn't opt for the "with recommended software" on the RasPi OS page as that is huge and most things I don't need.  I expected to install programming stuff.  When I finished there was only Geany and Thonny in programming menu.  I falsely assumed that Geany was just a Notepad++ equivalent.  I optimistically typed in a "hello world" C++ program.  I had hoped it would clue me into what libraries I needed to install.  I was shocked that the Compile/Build/Run buttons worked out of the box of my minimal install!  Are you implying that in generic Debian on Libre, Geany is not installed?... that you have to install it separately?... that gcc and other C++ development files aren't installed?

image

Things get a little more problematic when doing a multi-file project.  My professional career Windows developing didn't prepare me for make files.  It appears that Geany can do multi-file projects using just settings in Geany and I tried to ferret it out using this Wiki page - https://wiki.geany.org/howtos/configurebuildmenu but was unsuccessful.  Any Google search I found always fell back to using a make file.  I finally came up with this one (my first make file ever) for my current project and dropped it into my project folder.  Geany transparently recognized it and used it for the build button on my project. 

all: InqVault

LoRa.o: LoRa.cpp LoRa.h
	gcc -c LoRa.cpp -o LoRa.o

DB.o: DB.cpp DB.h
	gcc -c DB.cpp -o DB.o

InqVault.o: InqVault.cpp InqVault.h
	gcc -c InqVault.cpp -o InqVault.o

Main.o: Main.cpp
	gcc -c Main.cpp -o Main.o

InqVault: Main.o LoRa.o DB.o InqVault.o
	gcc Main.o InqVault.o DB.o LoRa.o -o InqVault -lpigpio -lrt -pthread -lm -lstdc++

clean:
	rm *.o InqVault

The whole experience of developing, C++ with Geany was shockingly simple compared to setting up a Visual Studio professional environment.  The compiles using gcc with Geany are near instant (on a RasPi4) compared to Arduino IDE or VS C++ programs on a Windows box.

My many years writing INO/C++ on Arduino has forced me to become an intuitive / psychic 😎 debugger.  So far I haven't really needed to debug in Geany / RasPi.  According to the Wiki, it is possible, but I haven't researched that.  If you have or go down that route, would you share any links you find useful for debugging?

VBR,

Inq

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@inq Did you forget me telling you about the kernel level drivers in raspberry pi os? I am including a pic of a summary of the libgpiod API.

I think this is what you are looking for, but if I am mistaken, please forgive me my interest and enthusiasm from wasting your time and jumping on your thread. I do not know yet if it will work with the Pi5, but like you my Pi work is primarily focused on the ZERO W and ZERO 2 W.

  https://forum.dronebotworkshop.com/raspberry-pi/raspberry-pi-pin-usage/#post-44155

Screenshot 2023 12 06 at 09.55.23

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @zander

@inq Did you forget me telling you about the kernel level drivers in raspberry pi os? I am including a pic of a summary of the libgpiod API.

I think this is what you are looking for, but if I am mistaken, please forgive me my interest and enthusiasm from wasting your time and jumping on your thread. I do not know yet if it will work with the Pi5, but like you my Pi work is primarily focused on the ZERO W and ZERO 2 W.

  https://forum.dronebotworkshop.com/raspberry-pi/raspberry-pi-pin-usage/#post-44155

-- attachment is not available --

I didn't forget.  Maybe we're talking at cross-purposes.  I read your reference in-full and although it was written pretty well... it was very poorly linked and didn't get me to anything like SPI.  This is the actual documentation that article discusses - https://docs.kernel.org/driver-api/gpio/index.html   If you click on the SPI link all you get are a bunch of C structs and a hundred pages of details (just for SPI).  The one I finally chose has 5 functions! https://abyz.me.uk/rpi/pigpio/cif.html#spiOpen I was able to replace the WiringPi library in the Sandeep LoRa library in an evening.  If I started with the kernel driver, I'd be here next year still trying to wrap my head around it.  

But the point STILL is that kernel library talks to a pin I/O chip directly.  I don't want to work down at the level of the kernel!  Great performance, terrible for portability and future changes (like RaspPi 5 doesn't use that chip).  Would you want your hard developed project to be worthless on the next generation?  That does not appear (that I can determine) to be possible in the RasPi or SBC world.  

I am hoping that the library author I chose will port his library to future SBC's I/O chips.  His library is not tied to Raspberry Pi, but works on a host of other computers already.

If you want to start with kernel driver for your work.  I'll be rooting for you!  I will keenly watch your thread on the subject!  

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1111
 

@inq  

When you first posted this topic I was not aware of the hardware changes to the rpi 5 relating to the GPIO pins and, like you, I had not had much cause to use its GPIO pins.   I see for python rpi did include an updated gpiozero module and also so other libraries in their latest rpi os. 

But for c++, in case you did not peruse the rpi forum for c/c++ then I paste the following link as the pertinent post may be of interest if your future purchases happed to include a rpi5

https://forums.raspberrypi.com/viewtopic.php?p=2152059#p2152059


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@inq I think either we are seeing different things, or I am misunderstanding. I see a sample program that is what I envisioned. I did not go as deep as you went looking at the kernel i/f since I didn't see a need, but I may be mistaken. In the remote chance you didn't see it, I am including the sample program. I will experiment with it after my medical procedure and look forward to either admitting my error out of ignorance, or a welcome comparison between what I think the approach is and what you think. 

It would be instructive if I knew why the sample program example is not what you need and you felt the need to look at the kernel driver i/f instead.

Normally I would feel very confident in my research, but you know how much I respect your skills, so I will leave it here and await my experiments before I will say more.

If I am off track, a simple 'off track' response is enough, I have no need to defend myself, I just thought this was what you were looking for.

#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
  const char *chipname = "gpiochip0";
  struct gpiod_chip *chip;
  struct gpiod_line *lineRed;    // Red LED
  struct gpiod_line *lineGreen;  // Green LED
  struct gpiod_line *lineYellow; // Yellow LED
  struct gpiod_line *lineButton; // Pushbutton
  int i, val;

  // Open GPIO chip
  chip = gpiod_chip_open_by_name(chipname);

  // Open GPIO lines
  lineRed = gpiod_chip_get_line(chip, 24);
  lineGreen = gpiod_chip_get_line(chip, 25);
  lineYellow = gpiod_chip_get_line(chip, 5);
  lineButton = gpiod_chip_get_line(chip, 6);

  // Open LED lines for output
  gpiod_line_request_output(lineRed, "example1", 0);
  gpiod_line_request_output(lineGreen, "example1", 0);
  gpiod_line_request_output(lineYellow, "example1", 0);

  // Open switch line for input
  gpiod_line_request_input(lineButton, "example1");

  // Blink LEDs in a binary pattern
  i = 0;
  while (true) {
    gpiod_line_set_value(lineRed, (i & 1) != 0);
    gpiod_line_set_value(lineGreen, (i & 2) != 0);
    gpiod_line_set_value(lineYellow, (i & 4) != 0);

    // Read button status and exit if pressed
    val = gpiod_line_get_value(lineButton);
    if (val == 0) {
      break;
    }

    usleep(100000);
    i++;
  }

  // Release lines and chip
  gpiod_line_release(lineRed);
  gpiod_line_release(lineGreen);
  gpiod_line_release(lineYellow);
  gpiod_line_release(lineButton);
  gpiod_chip_close(chip);
  return 0;
}

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@byron @inq Thanks for that link; it shows that the latest pi5 kernel library works; note the version is at the time 2.1. Apparently some tried libgpiod NOT libgpiod-2.1. Here is a link to the samples that have been tested. I think that is the source of some confusion, it is now libgpiod-2.1 NOT the old libgpiod. See attached screen shot for dates etc, that appears to me at least to explain the current confusion.

https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/examples

Screenshot 2023 12 06 at 11.24.47

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @byron

But for c++, in case you did not peruse the rpi forum for c/c++ then I paste the following link as the pertinent post may be of interest if your future purchases happed to include a rpi5

> https://forums.raspberrypi.com/viewtopic.php?p=2152059#p2152059

Thank you for this and that is terribly discouraging... and the avatar is the same as the library website.  (joan might be the author).  That's one more reason I don't need a RasPi 5.  Hopefully they'll work out these features before I even consider it.

BTW - It is strange that working with the pins on my RasPi4, I could do it instantly with Thonny (pre installed) even at the user level.  Yet... it runs on top of C/Assembler libraries that I could not get to readily with C++.  And even now, libraries require me to run with sudo.  Not that that is an issue since I'll be running it as a daemon once finished, but I find those aspects incongruous.  But it definitely points to Raspberry Pi being Python centric.  I can totally understand that being in step with their teaching philosophy, but it makes me wonder how/why they seem to hamstring the native language of Linux.  🙄 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1111
 

@zander  And thanks for your link, I see that there are python bindings for that lib - gpiod - so thats good to know, for me anyway 😎 


   
Ron reacted
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @zander

@inq I think either we are seeing different things, or I am misunderstanding. I see a sample program that is what I envisioned.

That's all well and good if I really wanted to work directly with the pins.  I don't want to have to do bit-banging to work with the SPI interface of the LoRa module.  I may have stopped my research too soon, but I didn't find that kernel stuff having higher-order stuff like an SPI interface without having to write thousands of lines of interface code to use their SPI structs.  Here is the SPI page for that kernel level stuff - https://docs.kernel.org/driver-api/spi.html .  It is literally 100 pages (JUST FOR SPI INTERFACE)  I like writing code, but that borders on masochism.  🙄  

As pigpio library works on all older RasPi <= 4 and I'm targeting a box full of Raspberry Pi Zero - W's that I have for this program, I'm good to go so far.  

Now that might change - I just got notification, my Orange-Pi Zero is in the mailbox.  We'll have to see if I can use it with my program.  Those results will be in my project thread - InqBee / InqVault.  This one has run its course.

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@inq ARGH, I give up (almost) NOT Joan, KERNEL! Carry on, I will test with my PI4 and 5 when it gets here and let you know. I will only be using what is built into Raspberry Pi OS, NO add on libraries!

BTW, type 'apropos gpio' on your PI4 to see what is built in. I am real curious to find out about remote-gpio (needs to be enabled in raspiconfig)

If someone has a PI5, try that and screen print the results for me.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@inq Ok, until I can test, I am only dealing in theory. I look forward to comparing results. I also have an Orange Pi ZERO (I think) so let us know how that goes.

FWIW, I think we have a different definition of bit banging.

Agreed, enough for now, let's both do some testing and get back later with concrete results.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 3 / 6