Monday, November 29, 2021

Simple exercise to control GPIO on Raspberry Pi, C and Python

Simple exercise to control GPIO on Raspberry Pi, tested on Raspberry Pi Zero 2 W running "Raspbian GNU/Linux 11 (bullseye)".

blink.c, in C language:
#include <stdio.h>
#include <pigpio.h>

#define led 17

int main(void){
	printf("- IO Test on\n");
	printf("- Raspberry Pi Zero 2 W\n");
	
	gpioInitialise();
	gpioSetMode(led, PI_OUTPUT);
	
	while(1){
		gpioWrite(led, 1);
		time_sleep(1);
		gpioWrite(led, 0);
		time_sleep(1);
	}

}

To compile it link to pigpio library:
$ gcc blink.c -o blink -lpigpio

To run it with sudo:
$ sudo ./blink


py_LED.py, in Python:
from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)


Thursday, November 18, 2021

My Raspberry Pi Zero 2 W

 My Raspberry Pi Zero 2 W received:




Raspberry Pi Zero 2 W installed new 32-bit Raspberry Pi OS (bullseye), running neofetch:



Check Board name and version using cpuinfo:
pi@raspberrypi:~ $ cat /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 1
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 2
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 3
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

Hardware	: BCM2835
Revision	: 902120
Serial		: 000000009470cd94
Model		: Raspberry Pi Zero 2 Rev 1.0


Check OS version using /etc/os-release:
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"




Related:

Documents: