raspberry pi - ghdrako/doc_snipets GitHub Wiki
Konfiguracja w windiws aby pisac w c
sudo apt update
sudo apt upgrade
sudo apt-get install -y vlc
vlc
vlc /home/pi/pimylifeup.mp4
cvlc
Downloader
Oled
qBittorrent, Aria2, and AriaNg for the WebUI,Samba
SSH
Pico
Pico has two cores. Pico’s two Cortex-M0+ processor cores run at 48MHz (48 million cycles per second),though this can be changed in software up to 133MHz (133 million cycles per second) if your program needs higher performance.
The microcontroller’s RAM is built into the same chip as the processor’s cores themselves, and takes the form of six individual memory banks totalling 264kB (264,000 bytes) of static RAM (SRAM). The RAM is used to store your programs and the data they need. RP2040 includes 30 multifunction general-purpose input/output (GPIO) pins, 26 of which are brought out to physical pin connectors on your Pico and one of which is connected to an on-board LED. Three of these GPIO pins are connected to an analogue-to-digital converter (ADC), while another ADC channel is connected to an on-chip temperature sensor.
RP2040 includes two universal asynchronous receiver-transmitter (UART), two serial peripheral interface (SPI), and two inter-integrated circuit (I2C) buses for connections to external hardware devices like sensors, displays, digital-to-analogue converters (DACs), and more. The microcontroller also includes programmable input/output (PIO), which lets the programmer define new hardware functions and buses in software.
Your Pico includes a micro USB connector, which provides a UART-over-USB serial link to the RP2040 microcontroller for programming and interaction, and which powers the chip. Holding down the BOOTSEL button when plugging the cable in will switch the microcontroller into USB Mass Storage Device mode, allowing you to load new firmware.
RP2040 also includes an accurate on-chip clock and timer, which allows it to keep track of the time and date. The clock can store the year, month, day, day of the week, hour, minute, and second, and automatically keeps track of elapsed time as long as power is provided.
Finally, RP2040 includes single-wire debug (SWD) for hardware debugging purposes, brought out to three pins at the bottom of your Pico.
3V3 logic
- Your Pico’s GPIO pins work at 3.3 volts. Applying a higher voltage to them may damage them.
PINs
- 3V3 -
- VBUS - 5V power
- sensor_pir = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_DOWN)
pull-down
Raspberry Pi Pico ma wbudowane, programowalne rezystory dla każdego pinu GPIO. Najlepiej sie zdecydowac i w calym projekcie korzystac z jednego rodzaju np Pull-down
3.3V ─── Przycisk ─── GPIO (z pull-down)
Wewnętrzne rezystory pull-up i pull-down są potrzebne, ponieważ przycisk nie wymusza konkretnego stanu napięcia, gdy jest otwarty (nie wciśnięty).
Jeśli nie użyjesz rezystora, to po puszczeniu przycisku pin GPIO znajdzie się w stanie nieokreślonym (floating) – będzie działał losowo, łapiąc zakłócenia i czasem odczytując 1, a czasem 0, mimo że nic nie naciskasz.
- Pull-down (do GND, stan domyślny = 0):
- Gdy przycisk jest puszczony, rezystor podciąga pin do 0V (stan niski – 0).
- Gdy przycisk jest wciśnięty, łączy pin z 3.3V, zmieniając stan na 1.
- Pull-up (do 3.3V, stan domyślny = 1):
- Gdy przycisk jest puszczony, rezystor podciąga pin do 3.3V (stan wysoki – 1).
- Gdy przycisk jest wciśnięty, łączy pin z 0V, zmieniając stan na 0.
Dlaczego to działa?
- Rezystor jest wystarczająco duży (np. 10kΩ), więc nie zakłóca działania przycisku, ale jednocześnie ustala domyślny stan pinu.
- Bez niego po puszczeniu przycisku stan wejścia GPIO byłby przypadkowy.
Raspberry Pi Pico ma wbudowane rezystory pull-up i pull-down, więc wystarczy je włączyć w kodzie, np.:
from machine import Pin
przycisk = Pin(15, Pin.IN, Pin.PULL_DOWN) # Pin 15 z pull-down
PWM
If you want to go the other way, and have your digital microcontroller create an analogue output, you’d normally need a digital-to-analogue converter (DAC) – but there’s a way to ‘fake’ an analogue signal, using something called pulse-width modulation or PWM.
A microcontroller’s digital output can only ever be on or off, 0 or 1. Turning a digital output on and off is known as a pulse and by altering how quickly the pin turns on and off you can change,or modulate, the width of these pulses – hence ‘pulse-width modulation’.
Every GPIO pin on your Pico is capable of pulse-width modulation, but the microcontroller’s pulse-width modulation block is made up of eight slices, each with two outputs.
PWM conflict
Make sure you keep track of the PWM slices and outputs you’re using, making sure to only connect to pins with a letter and number combination you haven’t already used. If you’re using PWM_A[0] on pin GP0 and PWM_B[0] on pin GP1, things will work fine, and will continue to work if you add PWM_A[1] on pin GP2; if you try to use the PWM channel on pin GP0 and pin GP16, though, you’d run into problems as they’re both connected to PWM_A[0].
No volatile storage
Pico’s file system is 1.375MiB in size. Storage: 2MB external flash RAM
Your Pico’s file system works regardless of whether or not it’s connected to your Raspberry Pi or another computer.
main.py
Your program will run every time your Pico is powered on without being connected to Thonny. If you don’t want that to happen, you can simply open main.py in Thonny and delete all the code in it before saving it again. With an empty main.py, your Pico will simply sit and wait for instructions again.