|
Post by alexfish on Feb 2, 2019 20:27:53 GMT 1
Hi All & other readers Noticed that first post requires to run code as sudo RE: setting gpio pins this may help And Plus for other readers RE: GPOI PINS on RPI permissions: run without Root first had to find original how to from HEREADD USER: first to find user : in my case username is pi so will have to substitute user name sudo usermod -a -G gpio <user_name> find user echo "$USER" in my case this is pi echo "$USER" pi
Then the bits sudo groupadd gpio sudo usermod -a -G gpio pi sudo grep gpio /etc/group sudo chown root.gpio /dev/gpiomem sudo chmod g+rw /dev/gpiomem
the python code for testing save as gpio.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO.OUT) print "LED on" GPIO.output(18,GPIO.HIGH) time.sleep(1) print "LED off" GPIO.output(18,GPIO.LOW)
from the terminal python gpio.py this is the result ~$ python gpio.py LED on LED off pi@raspberrypi:~/ Have Fun + BR Alex
|
|
|
Post by rikky on Feb 3, 2019 9:37:27 GMT 1
Got it . speak serial: usb_port$ = "/dev/ttyACM0" baudrate = 115200 OPEN usb_port$ FOR DEVICE AS myserial
' Set speed - B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400 SELECT baudrate CASE 0 SETSERIAL myserial SPEED 0 CASE 50 SETSERIAL myserial SPEED 50 CASE 75 SETSERIAL myserial SPEED 75 CASE 110 SETSERIAL myserial SPEED 110 CASE 134 SETSERIAL myserial SPEED 134 CASE 150 SETSERIAL myserial SPEED 150 CASE 200 SETSERIAL myserial SPEED 200 CASE 300 SETSERIAL myserial SPEED 300 CASE 600 SETSERIAL myserial SPEED 600 CASE 1200 SETSERIAL myserial SPEED 1200 CASE 1800 SETSERIAL myserial SPEED 1800 CASE 2400 SETSERIAL myserial SPEED 2400 CASE 4800 SETSERIAL myserial SPEED 4800 CASE 9600 SETSERIAL myserial SPEED 9600 CASE 19200 SETSERIAL myserial SPEED 19200 CASE 38400 SETSERIAL myserial SPEED 38400 CASE 57600 SETSERIAL myserial SPEED 57600 CASE 115200 SETSERIAL myserial SPEED 115200 CASE 230400 SETSERIAL myserial SPEED 230400 DEFAULT SETSERIAL myserial SPEED 9600 END SELECT 'SETSERIAL myserial SPEED & baudrate$ SETSERIAL myserial CMODE CS8 SETSERIAL myserial IMODE ~IGNBRK SETSERIAL myserial IMODE ~BRKINT SETSERIAL myserial IMODE ~ICRNL '~imaxbel //windows SETSERIAL myserial OMODE ~OPOST SETSERIAL myserial OMODE ~ONLCR SETSERIAL myserial LMODE ~ISIG SETSERIAL myserial LMODE ~ICANON SETSERIAL myserial LMODE ~IEXTEN SETSERIAL myserial LMODE ~ECHO SETSERIAL myserial LMODE ~ECHOE SETSERIAL myserial LMODE ~ECHOK SETSERIAL myserial LMODE ~ECHOCTL SETSERIAL myserial LMODE ~ECHOKE : ' only bsd SETSERIAL myserial LMODE NOFLSH SETSERIAL myserial IMODE ~IXON
'I suppose CMODE or ...? (CMODE works) SETSERIAL myserial CMODE ~CRTSCTS
PRINT "connecting " & usb_port$ & " at " & STR$(baudrate) & " b/s." WHILE TRUE INPUT "give here some sendtext : ",sendtext$ IF sendtext$ = "" THEN BREAK OPEN usb_port$ FOR READWRITE AS arduino WRITELN sendtext$ TO arduino IF LEN(sendtext$) > 0 THEN PRINT sendtext$ SLEEP 50 END IF
WEND
CLOSE FILE arduino CLOSE DEVICE myserial
listen seriai: usb_port$ = "/dev/ttyACM0" baudrate = 115200
OPEN usb_port$ FOR DEVICE AS myserial
SELECT baudrate CASE 0 SETSERIAL myserial SPEED 0 CASE 50 SETSERIAL myserial SPEED 50 CASE 75 SETSERIAL myserial SPEED 75 CASE 110 SETSERIAL myserial SPEED 110 CASE 134 SETSERIAL myserial SPEED 134 CASE 150 SETSERIAL myserial SPEED 150 CASE 200 SETSERIAL myserial SPEED 200 CASE 300 SETSERIAL myserial SPEED 300 CASE 600 SETSERIAL myserial SPEED 600 CASE 1200 SETSERIAL myserial SPEED 1200 CASE 1800 SETSERIAL myserial SPEED 1800 CASE 2400 SETSERIAL myserial SPEED 2400 CASE 4800 SETSERIAL myserial SPEED 4800 CASE 9600 SETSERIAL myserial SPEED 9600 CASE 19200 SETSERIAL myserial SPEED 19200 CASE 38400 SETSERIAL myserial SPEED 38400 CASE 57600 SETSERIAL myserial SPEED 57600 CASE 115200 SETSERIAL myserial SPEED 115200 CASE 230400 SETSERIAL myserial SPEED 230400 DEFAULT SETSERIAL myserial SPEED 9600 END SELECT SETSERIAL myserial CMODE CS8 SETSERIAL myserial IMODE ~IGNBRK SETSERIAL myserial IMODE ~BRKINT SETSERIAL myserial IMODE ~ICRNL '~imaxbel //windows SETSERIAL myserial OMODE ~OPOST SETSERIAL myserial OMODE ~ONLCR SETSERIAL myserial LMODE ~ISIG SETSERIAL myserial LMODE ~ICANON SETSERIAL myserial LMODE ~IEXTEN SETSERIAL myserial LMODE ~ECHO SETSERIAL myserial LMODE ~ECHOE SETSERIAL myserial LMODE ~ECHOK SETSERIAL myserial LMODE ~ECHOCTL SETSERIAL myserial LMODE ~ECHOKE : ' only bsd SETSERIAL myserial LMODE NOFLSH SETSERIAL myserial IMODE ~IXON SETSERIAL myserial CMODE ~CRTSCTS
PRINT "connecting " & usb_port$ & " at " & STR$(baudrate) & " b/s." WHILE TRUE OPEN usb_port$ FOR READWRITE AS arduino READLN sendtext$ FROM arduino IF LEN(sendtext$) > 0 THEN PRINT sendtext$ SLEEP 50
END IF
WEND
CLOSE FILE arduino CLOSE DEVICE myserial
Boyh you have to startup in different consoles. One talks to the arduino, The other receives from the arduino. Note: SETSERIAL myserial SPEED ... does not take a variable (yet): 'SETSERIAL myserial SPEED & VAL(baudrate$) 'error => lvalue required as unary '&' operand 'SETSERIAL myserial SPEED & baudrate$ 'error => /usr/include/termios.h:57:12: note: expected 'speed_t {aka unsigned int}' but argument is of type 'char **' so it has to be done with CASE. Until someone finds a solution. Rik.
|
|
|
Post by bigbass on Feb 4, 2019 21:35:38 GMT 1
Thanks Alex for the code demo of setting up the group so that we do not need to run as root when connecting the GPIO pins very useful even a small python snippet which is ok to confirm the point that we can verify the change of root permission I tested your example and it works correctly I have another road to go down because of the gcode converter "grbl" I burned to an arduino where I use bCNC at the moment so that there is an interface to test direction and pulse for x y z I bought a cnc shield and was surprised to find out that the board was designed with an error and this would have been a nightmare to sort out if I didnt have some official software to test with and personally confirm each GPIO pin long story short the step and the direction pins need to be reprogrammed in the grbl software due to a design error on the board hard to believe but very true I spent all day yesterday and some more today getting it to work the fix is easy the confirmation of manually testing everything is what took time this guy goes into all the log details I always jump to the point www.youtube.com/watch?v=1UKY1_hOipQAnd yes he is correct I personally and painstakingly double and triple checked every pin before and after the fix that snippet works I will attach the tested fixed file there are two ways of doing the fix I used the cpu_map.h file instead and all is fine for me this is the fixed snippet of the code you can see the comments show what it was before the fix this only applies to the faulty board I have the ks0152 cnc shield version 4 wiki.keyestudio.com/index.php/Ks0096_keyestudio_CNC_Kit_/_CNC_Shield_V4.0_%2B_Nano_3.0%2B3pcs_a4988_Driver_/_GRBL_Compatiblekeyestudio-v4-fix-grbl.tar.gz (3.44 KB) Joe // Define step pulse output pins. NOTE: All step bit pins must be on the same port. #define STEP_DDR DDRD #define STEP_PORT PORTD #define X_STEP_BIT 5 // Uno Digital Pin 2 #define Y_STEP_BIT 6 // Uno Digital Pin 3 #define Z_STEP_BIT 7 // Uno Digital Pin 4 #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
// Define step direction output pins. NOTE: All direction pins must be on the same port. #define DIRECTION_DDR DDRD #define DIRECTION_PORT PORTD #define X_DIRECTION_BIT 2 // Uno Digital Pin 5 #define Y_DIRECTION_BIT 3 // Uno Digital Pin 6 #define Z_DIRECTION_BIT 4 // Uno Digital Pin 7 #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits P.S Rik I am sorting the cnc driver I didn't get the bacon SETSERIAl to compile maybe tomorrow I can take another look at it I suspect another 32bit / 64bit compiler issue because of the raspberry
|
|
|
Post by alexfish on Feb 8, 2019 17:37:32 GMT 1
Hi Joe
As a bit of a help using GPIO pins
RPI should have at default the methods of Connecting and controlling the GPIO at Hardware level and aptly named PIGS because 'it can be a one' there are CLI commands as well built on top of these libs/ the list
/lib/systemd /lib/systemd/system /lib/systemd/system/pigpiod.service /opt /opt/pigpio /opt/pigpio/cgi /usr /usr/bin /usr/bin/pig2vcd /usr/bin/pigpiod /usr/bin/pigs /usr/include /usr/include/pigpio.h /usr/include/pigpiod_if.h /usr/include/pigpiod_if2.h /usr/lib /usr/lib/libpigpio.so /usr/lib/libpigpiod_if.so /usr/lib/libpigpiod_if2.so /usr/man /usr/man/man1 /usr/man/man1/pig2vcd.1 /usr/man/man1/pigpiod.1 /usr/man/man1/pigs.1 /usr/man/man3 /usr/man/man3/pigpio.3 /usr/man/man3/pigpiod_if.3 /usr/man/man3/pigpiod_if2.3 /usr/share /usr/share/doc /usr/share/doc/pigpio /usr/share/doc/pigpio/README.gz /usr/share/doc/pigpio/changelog.Debian.gz /usr/share/doc/pigpio/copyright
use the man pager on pig2vcd pigpiod pigs
bit of the pigs
Features o hardware timed PWM on any of GPIO 0-31
o hardware timed servo pulses on any of GPIO 0-31
o reading/writing all of the GPIO in a bank as one operation
o individually setting GPIO modes, reading and writing
o notifications when any of GPIO 0-31 change state
o the construction of output waveforms with microsecond timing
o I2C, SPI, and serial link wrappers
o creating and running scripts on the pigpio daemon
BR Alex
|
|
|
Post by bigbass on Feb 8, 2019 18:39:07 GMT 1
thanks Alex I looked over those things before I started coding the gui and found a way around it for what I had to do I went a few steps above this manual approach by using a dedicated micro controller (an arduino nano) that has code burned into the microcontroller that converts any gcode file produced by a CAD program www.cnccookbook.com/secrets-going-cad-image-dxf-stl-gcode-cnc-3d-printing/ now I dont need to manually write code to move the motors to make the part the code burned into the microcontroller uses "grbl" that does all the heavy lifting and make everything easy it translates all the steps and pulses and using a cnc program such as bCNC you can have a real time control and viewer of the progress that allows fine tuning of any pulse (PWM) and manual overrides using gcode commands directly but if you want to test some things manually the wiriring pi and what you posted are excellent for prototyping an idea and are still useful to port ! I just wanted to make a lightwieght test thingy gui to just simulate and run some of the most basic functions pulse x y z and connect to the serial port and send command line gcode (any real professional work uses cnc software) but I was surprised that we can get at least that much done without using java ,python and the arduino ide Joe
|
|
|
Post by bigbass on Feb 10, 2019 22:20:27 GMT 1
Hello Alex
here is another way with just bash removing the python dependencies there's more comments then code to explain whats going on in the second example
this does the same thing you posted in python I just used GPIO17 instead of GPIO18
without comments
heavily commented 100% transparent to what is happening
I called it gpio17 then sudo ./gpio17
#!/bin/bash
# ---run as sudo # ---objective : a better way than using python and its addon libraries # ---which almost everyone uses for the RPI
# ---I would prefer some transparency of all that happens # ---for a simple gpio pin test to light an led # ---by bigbass
if [ "$UID" = "0" ] then echo "Root user"
else echo "Not a root user run as root" exit 1 fi
#---see your pinouts uncomment #pinout
# ---the gpio pins have to be read but they are not visible # ---to the file system until you export the gpio number # ---in this case lets use GPIO 17 # --- create the port initialize it only once
echo 17 > /sys/class/gpio/export
# ---now the pin can be seen by the system but it has not been asigned # ---to be used for input or output so lets do that
#---Now we need to decide is it input or output we use out for this demo
echo out > /sys/class/gpio/gpio17/direction # ---which inturn created /sys/class/gpio/gpiochip128/subsystem/gpio17
#---Now we send a 1 logic which on the raspberry pi is 3.3v #---I suggest that you use a 330 ohm resistor and a 1.7 volt standard led
#WRITE to the GPIO 17 echo 1 > /sys/class/gpio/gpio17/value echo "light on"
#READ from the GPIO 17 if you want to confirm the value only echo "confirm the value or logic level" cat /sys/class/gpio/gpio17/value
# stop here and wait 10 seconds sleep 10s
echo 0 > /sys/class/gpio/gpio17/value echo "light off" sleep 2s
#REMOVE clean up uncomment the 2 echo commands
# ---set pin low then unexport clean up memory and remove from file system echo 0 > /sys/class/gpio/gpio17/value echo 17 > /sys/class/gpio/unexport
|
|
|
Post by alexfish on Feb 11, 2019 12:23:24 GMT 1
Hi Joe
Works as it say's on the tin::
on RPI sudo cmd is auto hence for bash one can add this to the script either way, the user will either be ;prompted for a password' or in RPI it should just run First line of code can use this
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@" Have Fun with Bit Banging on the gpio pins + BR Alex
|
|
|
Post by bigbass on Feb 11, 2019 19:39:21 GMT 1
Hello Alex thanks just when things are finally clear they go and make plans to remove it from the new kernels but not so bad I got it working with the latest tools! sudo apt-get install gpiod
then using the new tools it will do the same thing I posted above with just one line I had to sort though the new docs not much there yet but pieced this together from the --help #---we set the GPIO17 to turn on for 10 seconds logic 1 gpioset --mode=time --sec=10 gpiochip0 17=1
hope that makes it even eaiser and no sudo needed Joe github.com/brgl/libgpiodgit.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/The sysfs interface was the first kernel interface to expose GPIO lines, and over many years it turned out to have quite a number of design deficiencies. People wanted the ability to atomically control multiple lines at the same time, and there were also problems related to event handling and polling, topped off with some line ownership issues. To address these (and some more) problems, a new character-device-based interface was introduced in Linux 4.8, which, for simplicity reasons I will call the “libgpiod interface” (even though libgpiod is actually just the name of the corresponding user-space helper code). Since its introduction, libgpiod is the recommended and best way to control GPIOs under Linux, and the old sysfs interface will be eventually removed completely, possibly in 2020 as current plans go. As Linus Walleij, the current maintainer of the GPIO subsystem put it, “I just want the sysfs to die”. Similarly to sysfs, libgpiod is now a standard kernel interface, and, used with the μArt it too allows you to set and get GPIO pins at the same time while using standard serial communication programs.
|
|
|
Post by alexfish on Feb 11, 2019 20:21:19 GMT 1
Hi Joe
Will have a look at it
Yep in other comments
so decided to try bcm2835 which is available as headers 'search ' bcm2835 re DMA access
did cobble this from several sources and the found some of the bits in raspigcd-master at git hub may be worth reading but could not get this up and running but this does not require the actual "bcm2835" and bacon conversion is drawing a blank with the peripheral structs;
this will compile in c++ < use that because cout will not grunt at the bits to print; but can test with gcc by taking out the c++ headers
here we go testing GPIO connection note will have to sudo all the time as mention at the bcm2835 source site / holders
#include <stdio.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <iostream> #include <stdexcept> #include <unistd.h>
using namespace std;
// #define BCM2708_PERI_BASE 0x20000000 // raspi 1 // from bcm2780 drivers/headers #define BCM2708_PERI_BASE 0x3F000000 // raspi 3 // #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) #define BLOCK_SIZE (4 * 1024) #define INP_GPIO(g) *(gpio.addr + ((g) / 10)) &= ~(7 << (((g) % 10) * 3)) #define OUT_GPIO(g) *(gpio.addr + ((g) / 10)) |= (1 << (((g) % 10) * 3)) #define SET_GPIO_ALT(g, a) *(gpio.addr + (((g) / 10))) |= (((a) <= 3 ? (a) + 4 : (a) == 4 ? 3 : 2) << (((g) % 10) * 3)) #define GPIO_SET *(gpio.addr + 7) // sets bits which are 1 ignores bits which are 0 #define GPIO_CLR *(gpio.addr + 10) // clears bits which are 1 ignores bits which are 0 #define GPIO_READ(g) *(gpio.addr + 13) &= (1 << (g)) #define GET_GPIO(g) (*(gpio.addr + 13) & (1 << g)) // 0 if LOW, (1<<g) if HIGH #define GPIO_PULL *(gpio.addr + 37) // Pull up/pull down #define GPIO_PULLCLK0 *(gpio.addr + 38) // Pull up/pull down clock
// IO Access use struct to read struct bcm2835_peripheral { unsigned long addr_p; int mem_fd; void* map; volatile unsigned int* addr; }; struct bcm2835_peripheral gpio = { GPIO_BASE, 0, 0, 0 };
int map_peripheral(struct bcm2835_peripheral* p){ // Open /dev/mem if ((p->mem_fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) { return 0; }
p->map = mmap( NULL, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, p->mem_fd, // File descriptor to physical memory virtual file '/dev/mem' p->addr_p // Address in physical map that we want this memory block to expose );
if (p->map == MAP_FAILED) { return 0; }
p->addr = (volatile unsigned int*)p->map;
return 1; }
void unmap_peripheral(struct bcm2835_peripheral* p){ munmap(p->map, BLOCK_SIZE); close(p->mem_fd); }
int main() { int x = map_peripheral(&gpio); if (x) {
cout << "Gpio connection memory address : " << gpio.addr_p << "\n"; cout << "Gpio memory size " << (gpio.map, BLOCK_SIZE) << " \n"; unmap_peripheral(&gpio) }else{
cout << "Gpio conection fail\n" ; } return 0; }
ADDED
if low on memory for gcoding / decoding then can use the vcio memory ::as note to this . if use vcio do not run something that uses it
|
|
|
Post by alexfish on Feb 11, 2019 21:43:50 GMT 1
Hi Joe have downloaded the source from BCM2835it compiles and installs out of the box an the blink.c could not be simpler as in the above get peripheral example c code + this should easy convert to bacon
// blink.c // // Example program for bcm2835 library // Blinks a pin on an off every 0.5 secs // // After installing bcm2835, you can build this // with something like: //
// sudo ./blink // // Or you can test it before installing with: // gcc -o blink -I ../../src ../../src/bcm2835.c blink.c // sudo ./blink // // Author: Mike McCauley // Copyright (C) 2011 Mike McCauley // $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $
#include <bcm2835.h> #include <stdio.h>
// Blinks on RPi Plug P1 pin 11 (which is GPIO pin 17) #define PIN RPI_GPIO_P1_11
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1);
if (!bcm2835_init()) return 1;
// Set the pin to be an output bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
// Blink while (1) { // Turn it on bcm2835_gpio_write(PIN, HIGH); // wait a bit bcm2835_delay(500); // turn it off bcm2835_gpio_write(PIN, LOW); // wait a bit bcm2835_delay(500); } bcm2835_close(); return 0; }
BR Alex ADDED will need to look at the main header file : in there are how the BCM2835 is Mapped as regards there numbers ENUM to which pin is on the RPI IE: PIN 15 RPI_GPIO_P1_15 = 22, /*!< Version 1, Pin P1-15 */ RPI_V2_GPIO_P1_15 = 22, /*!< Version 2, Pin P1-15 */
then can say example #define BACON_GPIO_22 RPI_V2_GPIO_P1_15 also looking at the pin detail looks like version 2 has 2 PWM channels RPI_V2_GPIO_P1_12 = 18,can be PWM channel 0 in ALT FUN 5 RPI_V2_GPIO_P1_35 = 19,can be PWM channel 1 in ALT FUN 5
|
|
|
Post by alexfish on Feb 11, 2019 23:28:54 GMT 1
Hi Joe & all
if hav not done so: RE using vcio memory:: there is sample in the opt/vc examine the src/hello_pi/hello_fft
as an example follow this
cd /opt/vc/src/hello_pi/hello_fft pi@raspberrypi:/opt/vc/src/hello_pi/hello_fft $ make make: Nothing to be done for 'all'. pi@raspberrypi:/opt/vc/src/hello_pi/hello_fft $ sudo ./hello_fft.bin Usage: hello_fft.bin log2_N [jobs [loops]] log2_N = log2(FFT_length), log2_N = 8...22 jobs = transforms per batch, jobs>0, default 1 loops = number of test repeats, loops>0, default 1 pi@raspberrypi:/opt/vc/src/hello_pi/hello_fft $ pi@raspberrypi:/opt/vc/src/hello_pi/hello_fft $ pi@raspberrypi:/opt/vc/src/hello_pi/hello_fft $ sudo ./hello_fft.bin 8 9 10 rel_rms_err = 2.7e-07, usecs = 17, k = 0 rel_rms_err = 2.7e-07, usecs = 17, k = 1 rel_rms_err = 2.7e-07, usecs = 16, k = 2 rel_rms_err = 2.7e-07, usecs = 16, k = 3 rel_rms_err = 2.7e-07, usecs = 16, k = 4 rel_rms_err = 2.7e-07, usecs = 17, k = 5 rel_rms_err = 2.7e-07, usecs = 16, k = 6 rel_rms_err = 2.7e-07, usecs = 17, k = 7 rel_rms_err = 2.7e-07, usecs = 17, k = 8 rel_rms_err = 2.7e-07, usecs = 16, k = 9
BR Alex ADDED with reference TO BCM2835 low and behold
look at the source code files and the licence
# BCM2835 "GPU_FFT" release 3.0 # # Copyright (c) 2015, Andrew Holme. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the copyright holder nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Added Further
a bit of the dmesg
registers. [ 0.083228] hw-breakpoint: maximum watchpoint size is 8 bytes. [ 0.083381] Serial: AMBA PL011 UART driver [ 0.085251] bcm2835-mbox 3f00b880.mailbox: mailbox enabled [ 0.085769] uart-pl011 3f201000.serial: could not find pctldev for node /soc/gpio@7e200000/uart0_pins, deferring probe [ 0.154898] bcm2835-dma 3f007000.dma: DMA legacy API manager at af80f000, dma chans=0x1
this bit is interesting [ 0.085769] uart-pl011 3f201000.serial: could not find pctldev for node /soc/gpio@7e200000/uart0_pins, deferring probe
Grep 2835
pi@raspberrypi:~ $ dmesg | grep bcm2835 [ 0.085251] bcm2835-mbox 3f00b880.mailbox: mailbox enabled [ 0.154898] bcm2835-dma 3f007000.dma: DMA legacy API manager at af80f000, dmachans=0x1 [ 0.348587] bcm2835-rng 3f104000.rng: hwrng registered [ 0.806491] bcm2835-wdt 3f100000.watchdog: Broadcom BCM2835 watchdog timer [ 0.806770] bcm2835-cpufreq: min=600000 max=1200000 [ 0.807452] sdhost-bcm2835 3f202000.sdhost: could not get clk, deferring probe [ 0.809624] mmc-bcm2835 3f300000.mmc: could not get clk, deferring probe [ 0.915371] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1) [ 0.917595] mmc-bcm2835 3f300000.mmc: mmc_debug:0 mmc_debug2:0 [ 0.917603] mmc-bcm2835 3f300000.mmc: DMA channel allocated [ 3.023780] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
|
|
|
Post by bigbass on Feb 12, 2019 19:19:38 GMT 1
Hello Alex and other readers
In reference to any command in my case using libgpiod which stands for GPIO device the "d" is device without many demo examples everything looks like an ugly cryptic man page so lets get some real demo examples for raspberry pi use or any linux with a new kernel
the advantage is this will work in a scripted way and we could use it inside a bacon program too with very little code needed to do real work
I figured out how to get some test code going
first I will explain the steps
gpiodetect gpiochip0 [pinctrl-bcm2835] (54 lines) gpiochip1 [brcmexp-gpio] (8 lines) gpiochip2 [brcmvirt-gpio] (2 lines)
will show you in a cryptic way that I will explain in my own words gpiochip0 is a bcm2835 chip that the raspberry pi uses it has 54 lines or GPIO pins that we can control
just remember we will use from now on gpiochip0 for all the demos
here is an interesting demo how to send a logic 1 or 0 to a GPIO pin and it holds that value until a signal / interrupt is given
the advantage of this is that we won't have any "stuck bits" if for safety reasons when controlling connected devices such as motors any failure in the program will exit cleanly with no stuck bits that could cause a motor to stay on which is not an option so doing it this way is the safe way
-------------------------------------------------------------------------- # Set a value on line 17, then daemonize and wait for a signal (SIGINT or # SIGTERM) before releasing them. --------------------------------------------------------------------------
in simple terms SIGTERM is
kill -15 PID or
KILL -SIGTERM PID
in simple terms SIGINT is
kill -2 PID or in the same terminal that you started the command ctrl-c or
KILL -SIGINT PID
whatever is easier for you to use and remember
gpioset --mode=signal --background gpiochip0 17=1 the light is on and stays on in the background that command is running and the terminal is free to use it is waiting for an interrupt signal GPIO17 is HIGH a logic 1
to get the PID of the above command after it is running
pidof gpioset
pidof gpioset 3979
now GPIO17 is HIGH logic 1 and stays on until it receives a signal SIGTERM or SIGINT
we will use SIGTERM the kill command by default issues a SIGTERM but for clarity you could send kill -SIGTERM PID
kill 3979
the pid will always be a different number but this is good now the light is off and everything exited cleanly
Joe
|
|
|
Post by alexfish on Feb 14, 2019 22:25:58 GMT 1
Hi Joe
Still trying to get my head around this gpiod the concept on paper looks find , yet have feeling this is built on top of or out of the bcm28** header file or files , hence still looking. the core apts ;; thinking here if using the terminal then possible use screen & then one can scroll back to bits if the commands are still running
Anyway had a look at the rpi groups ect , the found the spi & 12c are in there , as well as the added gpio;
pi@raspberrypi:~ $ id uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi)
BR Alex
|
|
|
Post by bigbass on Feb 15, 2019 0:03:21 GMT 1
Hello Alex This goes into all the details whats going into the next kernels with GPIO this is the author explaining why and that this will be the official way so we can detect many different chips using linux youtu.be/cdTLewJCL1Y?list=PLbzoR-pLrL6pISWAq-1cXP4_UZAyRteskwhat you posted is still good for the raspberry when we need to go lower into the system and the userland scripted approach to turn on an led and it stays on until it kills the pid that gpioset did # set up a wait signal on GPIO17 and run it in the background # set GPIO17 high with a logic 1 gpioset --mode=signal --background gpiochip0 17=1
# terminate the background wait listening on on GPIO17 # terminate by name pkill gpioset
Joe
|
|
|
Post by bigbass on Jul 1, 2019 16:59:35 GMT 1
This is the best way to Control the gpio pins Using quality software Universal gcode sender It had a problem with the gl Viewer this is java based Making it more complex to Get it working on the raspberry pi3 Will post the complete how to later (have a lot to do now) But the good news it will work Hope to connect this to a real Cnc machine tonight I do have my own motor driver circuit for testing I just dont have my own cnc machine The trick was to rename opt/vc to opt/vc.old To disable the raspberry pi's Special drivers Then run the full kms drivers And reboot then java can build Correctly winder.github.io/ugs_website/github.com/winder/Universal-G-Code-Sendernow anything you can covert from an image to gcode it can be made real ---------------------------------------- a 3d printer makes something by adding layers a cnc machines metal,platic, wood or other materials to produce real world parts and it can be done on a raspberrypi this way we dont use a laptop in a dirty dangerous workshop where it can easily get destroyed *The code I wrote before in this thread was to diagnose all the pins directly and manually at a low level to be used a tool to setup anything and connect it Joe
|
|