tag:blogger.com,1999:blog-8042569099194536366.post2333173470087179015..comments2024-03-28T16:17:52.532+00:00Comments on Captain Bodgit: Raspberry Pi GPIO: Gambas + pigpio librarySteveDeehttp://www.blogger.com/profile/10645378028590228663noreply@blogger.comBlogger20125tag:blogger.com,1999:blog-8042569099194536366.post-45270575394124884042021-03-08T01:13:33.465+00:002021-03-08T01:13:33.465+00:00You are correct... I had the "As Integer"...You are correct... I had the "As Integer" on the other commands, totally missed it on this one. I installed that iand now I get the OPEN and CLOSE print commands with no bad handles.<br /><br />Thank you for that. I found another video explaining how to set the register bits to write (setup) then read an answer... hopefully I now have enough data to get this chip to read a sensor.<br /><br />Thank you very much!<br />Jerryjerryarutherfordhttps://www.blogger.com/profile/11915813537390755580noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-64498652243779324132021-03-07T17:34:54.428+00:002021-03-07T17:34:54.428+00:00Hi Jerry, you seem to be ignoring "Return&quo...Hi Jerry, you seem to be ignoring "Return" values from some or all of the pigpio commands that you are using. For example the Open command should be declared as:-<br />Public Extern i2cOpen(i2cBus As Integer, i2cAddress As Integer, i2cFlags As Integer) As Integer<br /><br />Then in the code:-<br />Dim intHandle as Integer<br />...<br />intHandle = i2cOpen(0, 72, 0)<br />...<br />i2cClose(intHandle)<br /><br />I think that should work, but if not come back to me.<br /><br />You can also ask questions on https://forum.gambas.one where it may be easier to give longer code answers than in the small Comments section here.<br /><br />SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-85099091151097282332021-03-07T17:17:10.332+00:002021-03-07T17:17:10.332+00:00First up... after reading this blog and related in...First up... after reading this blog and related info more carefully... I discovered that the i2cBus -> MUST <- be 1 (not 0) for it to work in a Raspberry Pi... and after changing the code to be...<br /><br />Public Sub BTN_12c_Test_A_Click()<br />Print "Open"<br />i2cOpen(1, 72, 0)<br />Print "Close"<br />i2cClose(1)<br />Print "Done."<br />End <br /><br />It oddly gives an error the first time, but subsequently... runs just fine, Now I need to figure out the proper buffers, registers, and so forth... then program it to make a TEXTBOX or PRINT to show the value returned on a button click. When I get that... I'll put it in a TIMER function and finally be able to read my wind-speed indicator. (Pitot Tube - https://en.wikipedia.org/wiki/Pitot_tube)jerryarutherfordhttps://www.blogger.com/profile/11915813537390755580noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-60026988839786296232021-03-06T16:49:49.620+00:002021-03-06T16:49:49.620+00:00I am attempting to get an ADS1115 A/D chip working...I am attempting to get an ADS1115 A/D chip working on the I2C port. I'm reading the pigpio page cover to cover but I'm missing something with the HANDLE. I have the following defined in the header of my program...<br /><br />Public Extern i2cOpen(i2cBus As Integer, i2cAddress As Integer, i2cFlags As Integer)<br />Public Extern i2cClose(Handle As Integer)<br />Public Extern i2cWriteByte(i2cBus As Integer, i2cByte As Byte)<br />Public Extern i2cReadByte(i2cBus As Integer)<br />Public Extern i2cWriteWordData(i2cBus As Integer, i2cReg As Integer, i2cWord As Integer)<br />Public Extern i2cReadWordData(i2cBus As Integer, i2cReg As Integer)<br /><br />This is below all the GPIO statements which are working just dandy thank you very much!<br /><br />Anyway... I made a button with the attached code... presuming the ADS1115 is addressed as HEX &48 or decimal 72...<br /><br />Public Sub BTN_12c_Test_A_Click()<br />Print "Open"<br />i2cOpen(0, 72, 0) <br />Print "Close"<br />i2cClose(0)<br />Print "Done."<br />End<br /><br />It opens fine, or at least there is no error showing. When it hits the i2cClose(0) command however... it fails with a BAD HANDLE(0) <br /><br />I thought, Ok... maybe this is the first device, so I tried i2cClose(0) which also fails. <br /><br />I am obviously missing the point on how to read/interact with a handle.<br />Can you help me out? All the SERVO, GPIO IN/OUT, and PWM are fine... I just can't seem to get around HANDLE.<br /><br />Thanks,<br />Jerry<br /><br />jerryarutherfordhttps://www.blogger.com/profile/11915813537390755580noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-57950998262690170072019-01-18T09:52:27.707+00:002019-01-18T09:52:27.707+00:00Try adding your user as a member of the gpio group...Try adding your user as a member of the gpio group. If user is "pi" then type in a terminal the command:-<br /><br />sudo adduser pi gpio<br /><br />If this does not work then see the question above from JaimeDrn. I'd probably either modify 'sudoers' so that only my program would run as root (i.e. you would type sudo {program} but not have to supply a password) or use wiringPi instead. SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-29076581353505548812019-01-16T17:49:29.735+00:002019-01-16T17:49:29.735+00:00Hi, I really don't want to run gambas apps as ...Hi, I really don't want to run gambas apps as root, Can I run the initialize portion as a root gambas app at startup.<br />Then run the rest of my gambas apps as normal user io commands as they don't seem to require root after initialization<br />Then run the terminate as a separate root gambas app?<br />thanksAnonymoushttps://www.blogger.com/profile/11207187572330848962noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-32334151158395809772017-05-02T08:36:09.856+01:002017-05-02T08:36:09.856+01:00Hi Terry, it sounds like you are trying to start G...Hi Terry, it sounds like you are trying to start Gambas from the command line without running the Raspbian desktop GUI (X server), or maybe trying to remote connect to the Pi via SSH.<br /><br />Can you confirm how you are running your Pi and whether you can run gambas as user Pi - i.e. does it work if you just type "gambas3" into a terminal window while running the desktop?SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-39801978026334553152017-05-01T10:25:41.340+01:002017-05-01T10:25:41.340+01:00Hi steve. My raspberry OS is jessie. I use gambas ...Hi steve. My raspberry OS is jessie. I use gambas 3.9.2. I have a problem when I want run as root gambas3. I use sudo gambas3 in terminal for root gambas. But when I enter this program, the comment is client is not authorized to connect to server gambas3: cannot connect to X server :1.0. Can you resolved for this problem? thank you<br />Anonymoushttps://www.blogger.com/profile/06443988778577186366noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-70271492237763981072017-04-16T05:07:35.604+01:002017-04-16T05:07:35.604+01:00I'll give PI permissions. Than you again.I'll give PI permissions. Than you again.JaimeDrnhttps://www.blogger.com/profile/13108357290350497761noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-68203839161557477722017-04-12T11:10:08.086+01:002017-04-12T11:10:08.086+01:00Great stuff! But I don't recommend you run the...Great stuff! But I don't recommend you run the Pi3 as user "root".<br /><br />You can run your Gambas executable from the terminal like this: sudo /home/pi/your_exe.gambas<br />...obviously using your path and file name, but including the .gambas extention. Or if you open terminal at the required folder: sudo ./your_exe.gambas.<br /><br />To run your pigpio application as user Pi, you could edit the /etc/sudoers file to give user Pi the required permissions.<br /><br />Or you could use wiringPi instead of pigpio, as this can now be used without admin/root permissions.SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-40611388463538752032017-04-10T16:49:44.897+01:002017-04-10T16:49:44.897+01:00Right! Running gambas as root now all goes well. I...Right! Running gambas as root now all goes well. I really appreciate your help Steve, thank you very much. I'll try to run Pi3 as root.<br />JaimeDrnhttps://www.blogger.com/profile/13108357290350497761noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-17507406798956889682017-04-10T12:01:22.123+01:002017-04-10T12:01:22.123+01:00Hi, sorry that you are having problems with this.
...Hi, sorry that you are having problems with this.<br /><br />I have just set up a Pi3 to my instructions above.<br /><br />If I run Gambas as user Pi, then I get the same result as you (i.e. gpioVersion = 61, but gpioInitialise returns -1).<br /><br />If I then close Gambas, then open a terminal and type: gksu gambas3<br />...I can run the program OK (...and gpioInitialise also returns 61).<br /><br />So are you running Gambas as root using these instructions?<br /><br />NOTE: I'm using Gambas 3.5.4 on Pi<br /><br />NOTE: The first time I tried to run as root my Pi3 hung. This is because I seem to be suffering some sort of file permission problem which is unrelated to Gambas or pigpio (I think there may be a bug in a recent version of Raspbian). So just check that you can use the file manager to view folders in the root directory. If the system shows an hour-glass and hangs, then you have the same problem, and will need to fix using fsck (http://captainbodgit.blogspot.co.uk/2017/01/file-system-repair-forcing-fsck-on.html).SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-78578501811726760342017-04-09T06:08:21.456+01:002017-04-09T06:08:21.456+01:00Hi, I'm using Gambas 3.9.2 under raspbian jess...Hi, I'm using Gambas 3.9.2 under raspbian jessie kernel 4.4. My prog is getting -1 from gpioInitialise(), both with executable and under IDE. I carefully followed installation steps in abyz.co.uk "Download & Install" Method-1. After failing with this, I tried to follow your steps up here but "make -j4" gives me "make: Nothing to be done for 'all'.". This command was run in a terminal while being in the /Home/pi/PIGPIO folder. By the way, gpioVersion() is giving 61. Thanks for you help.<br /> JaimeDrnhttps://www.blogger.com/profile/13108357290350497761noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-43359501168480787282016-09-13T12:11:55.850+01:002016-09-13T12:11:55.850+01:00This is not the correct place for this but I could...This is not the correct place for this but I could not find a private email contact. Due to the loss of Gambas Guru I thought I would try my hand at this forum lark so check out<br />www.gambas.cogier.com<br />It's all new to me but I am having a go!Cogierhttps://www.blogger.com/profile/09512407506342153983noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-90331345198151843102016-09-01T21:07:17.589+01:002016-09-01T21:07:17.589+01:00Yes, that should do it.
I just checked one of my ...Yes, that should do it.<br /><br />I just checked one of my Pi boards (a Pi3 with up-to-date software) and it seems to default all pins to inputs each time it is re-booted. Although I don't think all previous versions have worked this way.SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-77263209664699512852016-09-01T19:46:43.223+01:002016-09-01T19:46:43.223+01:00Have another look at the same link above. I have a...Have another look at the same link above. I have added a few lines of code that will fix this.Cogierhttps://www.blogger.com/profile/09512407506342153983noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-76089415648157001712016-09-01T17:59:40.638+01:002016-09-01T17:59:40.638+01:00Hi Cogier,
OK, that makes sense, my test program h...Hi Cogier,<br />OK, that makes sense, my test program has set all pins as outputs, and that's how they stay after the program ends.<br /><br />I notice that the pigpio library has a gpioGetMode method, so it looks like we could read & store the pin modes, and then set them back to their initial settings at the end of the program...I'll try this when I get a moment.SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-60519919741381950062016-09-01T16:24:23.120+01:002016-09-01T16:24:23.120+01:00Hi SteveDee, Here is what I was trying to explain....Hi SteveDee, Here is what I was trying to explain.<br /><br />http://www.cogier.com/stevedee/Cogierhttps://www.blogger.com/profile/09512407506342153983noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-12059125353397268342016-08-31T07:34:39.282+01:002016-08-31T07:34:39.282+01:00Hi Cogier, not sure I understand the question, but...Hi Cogier, not sure I understand the question, but if you are asking what state the gpio should be returned to after use by a program like yours (i.e. not a program that runs as a gpio controller the whole time the system is powered-up) then there may be 2 sensible options; 1) return gpio to state it was in before your program started, 2) set all pins as inputs (which may be the safest and more practical option).<br /><br />A third alternative is not to worry about it. If a second (different design) gpio program is started after yours is closed, the second program will intialise pins to suit its own purpose.<br /><br />Here are a couple of threads which discuss what happens (and what should happen) to the gpio when the Pi starts: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=47965 ...and... https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=24491<br /><br />Not sure this is very helpful, but do come back if I've missed the point.SteveDeehttps://www.blogger.com/profile/10645378028590228663noreply@blogger.comtag:blogger.com,1999:blog-8042569099194536366.post-35855535627239656662016-08-30T16:32:20.529+01:002016-08-30T16:32:20.529+01:00Hi, This code works well. I have looked around for...Hi, This code works well. I have looked around for advice on what condition is best state to leave the GPIO pins at the end of a program but I can't seem to find any definitive answer. Most of the pins are left 'Open' when this program exits, If you run my GPIO program next to yours you will see what I mean. Is this ideal?Cogierhttps://www.blogger.com/profile/09512407506342153983noreply@blogger.com