Raspberry PI GPIO Example

what kind of input do you need to read frequently?

Hi MarkusR
This is digital input equivalent to a PLC’s High Speed Counter input.
As an example scenario : counting the products moving on a conveyor at a speed for 20 products per second
That is why I have to have a very low latency . As suggested by Eugene, Interrupts are the best way, but I am not so strong in python to write a program which communicates with Xojo. And I somehow do not feel comfortable with the idea of 2 programs for a single task.
Thanks for your response

You said your program loops, which would explain 100% CPU usage. If it’s not looping, I would not expect a 20ms timer that reads some ports and updates some controls to use 97-100% CPU. Are you sure your program is not looping? It should just sit idle until the timer fires.

Not sure that a thread is giving you any benefit here; Xojo only uses one CPU core no matter how many threads you run, unless you use Worker apps.

Hi
First of all, I am sorry. I did not get things straight. Somewhere my replies were misleading. Yes , my progam has a loop in a separate thread. I also use a thread.sleep for 20ms.
Ok , thanks for pointing out, I will try the 20ms timer.
BTB, I am from the Desktop (C#) world. You rightly brought the single core usage of Xojo to my attention. Seeing the threads example I got carried away.
I will also look into Worker apps.
And my thanks to all of you. Honestly, i have worked with various other s/w and forums, but the response in Xojo forum tops the list.

i have a idea to run the Python script in a shell and read the output data in xojo Shell.
this Python could count perfect the signals often and output it each second as sum with print.
https://documentation.xojo.com/api/os/shell.html
the python interpreter need to start with the name of the .py script.
as example the interpreter path is hidden in remark at the first line of a .py script #! /usr/bin/python

Hello Sass,

Here are answers to some of your questions:

WiringPi is deprecated, which means that the library is not being updated. I do not know when the library would stop working.

Yes, both libraries are installed in the Raspberry Pi OS, and only pigpio is being updated.

Here is the link where it is mentioned that the WiringPiISR is not safe with Xojo (contribution with @MarkusR ): gpio event at level change - #2 by Eugene_Dakin

@Julia_Truchsess is a professional and this is likely your best option, if you are to use Xojo with the Raspberry Pi.

Eugene,
I really appreciate your effort in replying . I have been trying to get your book online , but the payment is failing consistently. I will raise the issue with my credit card company and find if it is any way related to international transaction being blocked.
I will try again today.
Thanks a lot.

And, I am trying Julia’s suggestion. I am trying to use the timer event in the MainWindow itself. That part is ok, I am just trying to get the pigpio library to work . OF course, I am scouring some of the help on the internet finding how to use the library, which is a bit difficult, in the absence of your book (my purchase attempt failed multiple times)

Another avenue to purchase the book is through the XojoLibrary at: http://xojolibrary.com/. If you are having problems purchasing the book, then you can contact Marc (the owner of the store):

support at xDevLibrary.com
(You’ll need to assemble that email address yourself as I haven’t made it clickable.)

I tried even that .
I think even that leads to the same Gumbooks… I even tried paypal which returned the same error. But that is excepted as the same card is linked with paypal. So i will be trying today and if the same issue persists will be calling the credit card provider for help.
Thanks for your help

If you send me a private message, I can send you Example 5-2 which is the ‘blink LED’ example. It just makes sure that everything is setup properly on your Raspberry Pi. :slight_smile:

Edit: If you download the Table of Content at: Program Raspberry Pi 4B Electronics with Xojo - Buster Edition, then it has Example 5-2 described.

sorry that is GUMROAD.

Appears that there is some issue. Same error while trying to make the purchase now.

Yes, send Marc an email at: support at xDevLibrary.com, he is really good at helping.

Ok will do that. But I suspect it is my card provider. A couple of months back my card was used by someone in Mexico to get Netflix account. I had raised an issue then. They blocked international transactions and then provided me with a new card. I strongly suspect this is the issue. I will contact them during the working hours today and try to get the book.
Thanks

Hi Julia
Thanks for your suggestions. I just completed the trial with timer as follows
a) Reverted back to the Older GPIO library (by Paul ?).
b) Removed thread and thereby the loop
c) Used a timer with 10ms time period
d) Read a single GPIO , update a Counter value and write to Sqlite
The overall CPU used : Maximum of 45%
I had to give up trying the pigpio library as I was not able to find proper documentation / examples for Xojo
Now I will try to read 4 GPIOs and write to 4GPIOS and test the same.
Next I will try the Worker App way
Thanks once again.
NOTE: it would have been nice to have some sort of file upload feature on this forum so that there could be improvements and a base for others to pickup

1 Like

Hi
I have tried the Worker Class. The CPU overload seems to really drop or I am not sure if I am checking it right.
When I used the Timer the CPU usage was around 25 - 45 %
But when i used the Worker class it came down to 3%
The Worker class is working. I have used a loop in the worker class. i used debug breakpoints. I am able to see the input read value change from 0 to 1 and vice versa based on my changing the physical button state. The count value is also increasing for each time the input goes high.

I am now stuck at 1 issue , i have to pass the count value and the input state to the main window. I have tried the “WorkerReadGPI0.SendProgress” and the JobProgressed without any result.
I am trying to update a control on the Mainwindow from JobProgressed. i am using the SendProgress to send the count a string (Count.ToString)
I am not able to get much info on how to use these in the Xojo Documentation

Thanks

this Worker class can only communicate via string.
suggested was json string via JSONItem.
Worker is somehow a endless loop where each request return a value in your case.
are you sure that is better and really without cpu usage?

how i think it is working

Start <- Once
JobRequested -> JobRun + SendProgress 
JobCompleted 
JobProgressed <- for UI Updates
Stop

xojo came with 2 examples of this worker class.

Hi MarkusR
Thanks for your reply
Yes I got the Flow Sequence.
I used teh SendProgress in JobRun, then I tried updating the UI from the JobProgressed Event. That does not work (probably by design). I thought this might work based on the UI update happening on the JobRequested. But now I think that The Job Run is spawned in a separate Core or thread (in debug mode)

Whatever, I used the JobProgressed Event to update a variable in MainWindow. Then in MainWindow used a Timer to update the UI. This is working
Now I am trying to build / compile the program to send to raspberry Pi. Because the Worker class runs as thread in the debug mode and it uses 100% CPU . I want to try to run as a compiled app which might show the actual CPU usage.
But again, I am stuck here. I am using a Xojo Free License for RPi. I am not sure if this version allows compile. So relying on my friend "google " to find info on this
Overall, going through the hurdles …

i think Worker is part of Desktop License … No License = No Build.
you could also test my mentioned idea with std in/out from shell with help of a Python script.
Python IDE for a test is preinstalled at pi.