Raspberry BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - John Spikowski

Pages: [1] 2 3 ... 13
1
General Discussion / Re: LG Library
« on: January 24, 2021, 02:22:06 am »
It seems that the author of the LG library also wrote pigpio

pigpio repository

pigpio home page

Both libraries seem to be public domain. I need to investigate the difference between them.

2
General Discussion / Re: LG Library
« on: January 18, 2021, 06:16:42 pm »
I tried the DS18B20 on my RPi 3B under Raspbian and was able to get a valid result, It looks like the OWFS library doesn't work.


pi@RPi3B:~ $ cat /sys/bus/w1/devices/28-041780c226ff/w1_slave
3f 01 4b 46 7f ff 0c 10 f3 : crc=f3 YES
3f 01 4b 46 7f ff 0c 10 f3 t=19937
pi@RPi3B:~ $



From what my research has dug up so far is to get one-wire to work from the kernel a re-link needs to be done. One would think Ubuntu's RPi branch would have already addressed this issue of made it easy like Raspian to enable.


3
General Discussion / Re: LG Library
« on: January 18, 2021, 03:56:20 am »
I was able to get access to the DS18B20 using the OWFS interface. Problem is the returned temperature is all over the place. Not sure if this is progress or not.  :(

Reading a 1-wire DS18B20 temperature sensor using OWFS

4
General Discussion / Re: LG Library
« on: January 18, 2021, 01:47:11 am »
I can't seem to get the i2c 1-wire interface going on Ubuntu 64. I was able to get /sys/bus/w1/devices to show up after the modprobe commands but the devices folder is empty. Any advice how to get my DS18B20 to show up?


5
General Discussion / Re: LG Library
« on: January 17, 2021, 03:55:42 am »
I created a repository for the lg library on basic-sandbox.us. The only source I know of is from the author's site as a ZIP.

https://basic-sandbox.us/lg/lg-dev

I created a subdomain of RaspberryBASIC.org to host the lg library. The HTML for the site was created by a Python script that comes in the zip distribution.

https://lg.raspberrybasic.org

I feel much better that this public domain open source project won't disappear after spending time building a ScriptBasic extension module around it.
 






6
General Discussion / Re: LG Library
« on: January 17, 2021, 03:11:29 am »
The tx_pulse.c example.

Code: C
  1. /*
  2. tx_pulse.c
  3. 2020-11-18
  4. Public Domain
  5.  
  6. http://abyz.me.uk/lg/lgpio.html
  7.  
  8. gcc -Wall -o tx_pulse tx_pulse.c -llgpio
  9.  
  10. ./tx_pulse
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. #include <lgpio.h>
  17.  
  18. #define OUT 21
  19. #define LOOPS 120
  20.  
  21. #define LFLAGS 0
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.    int h;
  26.    int i;
  27.    double start, end;
  28.  
  29.    h = lgGpiochipOpen(0);
  30.  
  31.    if (h >= 0)
  32.    {
  33.       if (lgGpioClaimOutput(h, LFLAGS, OUT, 0) == LG_OKAY)
  34.       {
  35.          lgTxPulse(h, OUT, 20000, 30000, 0, 0);
  36.  
  37.          lguSleep(2);
  38.  
  39.          lgTxPulse(h, OUT, 20000, 5000, 0, LOOPS);
  40.  
  41.          start = lguTime();
  42.  
  43.          while (lgTxBusy(h, OUT, LG_TX_PWM)) lguSleep(0.01);
  44.  
  45.          end = lguTime();
  46.  
  47.          printf("%d cycles at 40 Hz took %.1f seconds\n", LOOPS, end-start);
  48.       }
  49.  
  50.       lgGpiochipClose(h);
  51.    }
  52. }
  53.  


jrs@RPi4B:~/lg/EXAMPLES/lgpio$ sudo ./tx_pulse
120 cycles at 40 Hz took 3.0 seconds
jrs@RPi4B:~/lg/EXAMPLES/lgpio$


7
General Discussion / Re: LG Library
« on: January 17, 2021, 03:00:49 am »
A toggle benchmark.

Code: C
  1. /*
  2. bench.c
  3. 2020-11-18
  4. Public Domain
  5.  
  6. http://abyz.me.uk/lg/lgpio.html
  7.  
  8. gcc -Wall -o bench bench.c -llgpio
  9.  
  10. ./bench
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. #include <lgpio.h>
  17.  
  18. #define LFLAGS 0
  19.  
  20. #define OUT 21
  21. #define LOOPS 20000
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.    int h;
  26.    int i;
  27.    double t0, t1;
  28.  
  29.    h = lgGpiochipOpen(0);
  30.  
  31.    if (h >= 0)
  32.    {
  33.       if (lgGpioClaimOutput(h, LFLAGS, OUT, 0) == LG_OKAY)
  34.       {
  35.  
  36.          t0 = lguTime();
  37.  
  38.          for (i=0; i<LOOPS; i++)
  39.          {
  40.             lgGpioWrite(h, OUT, 0);
  41.             lgGpioWrite(h, OUT, 1);
  42.          }
  43.  
  44.          t1 = lguTime();
  45.  
  46.          printf("%.0f toggles per second\n", (1.0 * LOOPS)/(t1-t0));
  47.       }
  48.  
  49.       lgGpiochipClose(h);
  50.    }
  51. }
  52.  


jrs@RPi4B:~/lg/EXAMPLES/lgpio$ sudo ./bench
139130 toggles per second
jrs@RPi4B:~/lg/EXAMPLES/lgpio$


8
General Discussion / Re: LG Library
« on: January 17, 2021, 02:57:26 am »
Here is the chipline.c program.

Code: C
  1. /*
  2. chipline.c
  3. 2020-11-18
  4. Public Domain
  5.  
  6. http://abyz.me.uk/lg/lgpio.html
  7.  
  8. gcc -Wall -o chipline chipline.c -llgpio
  9.  
  10. ./chipline
  11. */
  12. #include <stdio.h>
  13.  
  14. #include <lgpio.h>
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.    int h;
  19.    int i;
  20.    lgChipInfo_t cinf;
  21.    lgLineInfo_t linf;
  22.  
  23.    h = lgGpiochipOpen(0);
  24.    if (h >= 0)
  25.    {
  26.       if (lgGpioGetChipInfo(h, &cinf) == LG_OKAY)
  27.       {
  28.          printf("%d \"%s\" \"%s\"\n", cinf.lines, cinf.name, cinf.label);
  29.  
  30.          for (i=0; i<cinf.lines; i++)
  31.          {
  32.             if (lgGpioGetLineInfo(h, i, &linf) == LG_OKAY)
  33.             {
  34.                printf("%d %d \"%s\" \"%s\"\n",
  35.                   linf.offset, linf.lFlags, linf.name, linf.user);
  36.             }
  37.          }
  38.       }
  39.  
  40.       lgGpiochipClose(h);
  41.    }
  42. }
  43.  


jrs@RPi4B:~/lg/EXAMPLES/lgpio$ sudo ./chipline
58 "gpiochip0" "pinctrl-bcm2711"
0 0 "ID_SDA" ""
1 0 "ID_SCL" ""
2 0 "SDA1" ""
3 0 "SCL1" ""
4 0 "GPIO_GCLK" ""
5 0 "GPIO5" ""
6 0 "GPIO6" ""
7 7 "SPI_CE1_N" "spi0 CS1"
8 7 "SPI_CE0_N" "spi0 CS0"
9 0 "SPI_MISO" ""
10 0 "SPI_MOSI" ""
11 0 "SPI_SCLK" ""
12 0 "GPIO12" ""
13 0 "GPIO13" ""
14 0 "TXD1" ""
15 0 "RXD1" ""
16 0 "GPIO16" ""
17 0 "GPIO17" ""
18 0 "GPIO18" ""
19 0 "GPIO19" ""
20 0 "GPIO20" ""
21 0 "GPIO21" ""
22 0 "GPIO22" ""
23 0 "GPIO23" ""
24 0 "GPIO24" ""
25 0 "GPIO25" ""
26 0 "GPIO26" ""
27 0 "GPIO27" ""
28 0 "RGMII_MDIO" ""
29 0 "RGMIO_MDC" ""
30 0 "CTS0" ""
31 0 "RTS0" ""
32 0 "TXD0" ""
33 0 "RXD0" ""
34 0 "SD1_CLK" ""
35 0 "SD1_CMD" ""
36 0 "SD1_DATA0" ""
37 0 "SD1_DATA1" ""
38 0 "SD1_DATA2" ""
39 0 "SD1_DATA3" ""
40 0 "PWM0_MISO" ""
41 0 "PWM1_MOSI" ""
42 3 "STATUS_LED_G_CLK" "led0"
43 0 "SPIFLASH_CE_N" ""
44 0 "SDA0" ""
45 0 "SCL0" ""
46 0 "RGMII_RXCLK" ""
47 0 "RGMII_RXCTL" ""
48 0 "RGMII_RXD0" ""
49 0 "RGMII_RXD1" ""
50 0 "RGMII_RXD2" ""
51 0 "RGMII_RXD3" ""
52 0 "RGMII_TXCLK" ""
53 0 "RGMII_TXCTL" ""
54 0 "RGMII_TXD0" ""
55 0 "RGMII_TXD1" ""
56 0 "RGMII_TXD2" ""
57 0 "RGMII_TXD3" ""
jrs@RPi4B:~/lg/EXAMPLES/lgpio$

9
General Discussion / Re: LG Library
« on: January 17, 2021, 02:42:10 am »
I installed Ubuntu 20.10 64 bit using the Raspberry Pi Imaging Tool.

Attached is a screenshot.

10
General Discussion / Re: LG Library
« on: January 16, 2021, 08:41:21 pm »
I'm setting up my RPi 4B 4GB with Ubuntu 20.10 64 bit as my RPi development target. With my RPi 4B 8 GB fully loaded with desktop and running GitLab-ce, trying to use the GPIO bus for pulse sampling is asking too much.

I also plan to split this thread into its own development LG thread.

11
General Discussion / Re: LG Library
« on: January 16, 2021, 05:18:34 am »
Success!

The problem was /dev/gpiochip0 needed root permissions.


ubuntu@rpi4b:~/lg/EXAMPLES/lgpio$ sudo ./dhtxx
3 0.0 0.0 (g=4)
2 0.0 0.0 (g=4)
1 0.0 0.0 (g=4)
2 0.0 0.0 (g=4)
0 47.0 23.0 (g=4)
1 47.0 23.0 (g=4)
1 47.0 23.0 (g=4)
0 46.0 23.0 (g=4)
2 46.0 23.0 (g=4)
1 46.0 23.0 (g=4)
3 46.0 23.0 (g=4)
0 46.0 23.0 (g=4)



Metric
Humidity: 46.00 rh
Temperature: 23.00 C
Pressure: 1013.24 hPa

English
Humidity: 46.00 rh
Temperature: 73.40 F
Pressure: 29.92 In. Hg


Next I need to wrap this library in a ScriptBasic extension module.

12
General Discussion / Re: LG Library
« on: January 16, 2021, 05:07:09 am »
I took a peek at the lgpio.c source and the reason it can't find a chip is /dev/gpiochip0 is a null file. The open() function must be returning the error. Seems I've hit a dead end on Ubuntu 64 if this device doesn't exist.

Code: C
  1. sprintf(chipName, "/dev/gpiochip%d", gpioDev);
  2.  
  3. fd = open(chipName, O_RDWR | O_CLOEXEC);
  4.  
  5. if (fd < 0)
  6.    PARAM_ERROR(LG_CANNOT_OPEN_CHIP, "can't open gpiochip (%s)", chipName);
  7.  

13
General Discussion / Re: LG Library
« on: January 16, 2021, 03:56:45 am »
I hooked up my DHT11 to the GPIO bus and ran the example provided. It failed with the chip not found like in mytest.c. My guess is like the WiringPi library hasn't been updated to handle the RPi 4B. Please chime in if you have any ideas. I'm going to try this library on my RPi 3B with 32 Bit Raspian OS just to see if the library works there,


ubuntu@rpi4b:~/lg/EXAMPLES/lgpio$ ./dhtxx
open /dev/gpiochip0 failed (-78)
ubuntu@rpi4b:~/lg/EXAMPLES/lgpio$


14
General Discussion / Re: LG Library
« on: January 15, 2021, 11:32:51 pm »
I modified mytest.c to generate the text for the error code. I'm assuming since I don't have anything connected to the GPIO bus it may be working.  :)

Code: Script BASIC
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <lgpio.h>
  5.  
  6. #define LFLAGS 0
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.    int h;
  11.    h = lgGpiochipOpen(0);
  12.    printf("%s\n", lguErrorText(h));
  13.    if (h >= 0)
  14.    {printf("Got Here\n");}
  15.    lgGpiochipClose(h);
  16. }
  17.  


ubuntu@rpi4b:~/lg/EXAMPLES/lgpio$ gcc mytest.c -o mytest -llgpio
ubuntu@rpi4b:~/lg/EXAMPLES/lgpio$ ./mytest
can not open gpiochip
ubuntu@rpi4b:~/lg/EXAMPLES/lgpio$


15
General Discussion / Re: LG Library
« on: January 15, 2021, 11:16:41 pm »
Here is a list of exported functions from the lg GPIO library.


GPIO

lgGpiochipOpen               Opens a gpiochip device
lgGpiochipClose              Closes a gpiochip device

lgGpioGetChipInfo            Gets gpiochip information
lgGpioGetLineInfo            Gets gpiochip line information
lgGpioGetMode                Gets the mode of a GPIO

lgGpioSetUser                Notifies Linux of the GPIO user

lgGpioClaimInput             Claims a GPIO for input
lgGpioClaimOutput            Claims a GPIO for output
lgGpioClaimAlert             Claims a GPIO for alerts
lgGpioFree                   Frees a GPIO

lgGroupClaimInput            Claims a group of GPIO for inputs
lgGroupClaimOutput           Claims a group of GPIO for outputs
lgGroupFree                  Frees a group of GPIO

lgGpioRead                   Reads a GPIO
lgGpioWrite                  Writes a GPIO

lgGroupRead                  Reads a group of GPIO
lgGroupWrite                 Writes a group of GPIO

lgTxPulse                    Starts pulses on a GPIO
lgTxPwm                      Starts PWM pulses on a GPIO
lgTxServo                    Starts Servo pulses on a GPIO
lgTxWave                     Starts a wave on a group of GPIO
lgTxBusy                     See if tx is active on a GPIO or group
lgTxRoom                     See if more room for tx on a GPIO or group

lgGpioSetDebounce            Sets the debounce time for a GPIO
lgGpioSetWatchdog            Sets the watchdog time for a GPIO

lgGpioSetAlertsFunc          Starts a GPIO callback
lgGpioSetSamplesFunc         Starts a GPIO callback for all GPIO

I2C

lgI2cOpen                    Opens an I2C device
lgI2cClose                   Closes an I2C device

lgI2cWriteQuick              SMBus write quick

lgI2cReadByte                SMBus read byte
lgI2cWriteByte               SMBus write byte

lgI2cReadByteData            SMBus read byte data
lgI2cWriteByteData           SMBus write byte data

lgI2cReadWordData            SMBus read word data
lgI2cWriteWordData           SMBus write word data

lgI2cReadBlockData           SMBus read block data
lgI2cWriteBlockData          SMBus write block data

lgI2cReadI2CBlockData        SMBus read I2C block data
lgI2cWriteI2CBlockData       SMBus write I2C block data

lgI2cReadDevice              Reads the raw I2C device
lgI2cWriteDevice             Writes the raw I2C device

lgI2cProcessCall             SMBus process call
lgI2cBlockProcessCall        SMBus block process call

lgI2cSegments                Performs multiple I2C transactions
lgI2cZip                     Performs multiple I2C transactions

NOTIFICATIONS

lgNotifyOpen                 Request a notification
lgNotifyClose                Close a notification
lgNotifyPause                Pause notifications
lgNotifyResume               Start notifications

SERIAL

lgSerialOpen                 Opens a serial device
lgSerialClose                Closes a serial device

lgSerialReadByte             Reads a byte from a serial device
lgSerialWriteByte            Writes a byte to a serial device

lgSerialRead                 Reads bytes from a serial device
lgSerialWrite                Writes bytes to a serial device

lgSerialDataAvailable        Returns number of bytes ready to be read

SPI

lgSpiOpen                    Opens a SPI device
lgSpiClose                   Closes a SPI device

lgSpiRead                    Reads bytes from a SPI device
lgSpiWrite                   Writes bytes to a SPI device

lgSpiXfer                    Transfers bytes with a SPI device

THREADS

lgThreadStart                Start a new thread
lgThreadStop                 Stop a previously started thread

UTILITIES

lguVersion                   Gets the library version
lguSbcName                   Gets the host name of the SBC

lguGetInternal               Get an internal configuration value
lguSetInternal               Set an internal configuration value

lguSleep                     Sleeps for a given time

lguTimestamp                 Gets the current timestamp
lguTime                      Gets the current time

lguErrorText                 Gets a text description of an error code

lguSetWorkDir                Set the working directory
lguGetWorkDir                Get the working directory


Pages: [1] 2 3 ... 13