Cours:PiPico : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
 
(12 révisions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
=Créer/configurer un projet vscode=
+
= Brochage =
*pico_project.py
+
 
**git clone https://github.com/raspberrypi/pico-project-generator.git
+
https://datasheets.raspberrypi.com/pico/Pico-R3-A4-Pinout.pdf
** ./pico_project.py --gui
+
 
**ne pas cocher "create VSCode project"
+
=utilisation de l'ide arduino=
 +
 
 +
https://github.com/earlephilhower/arduino-pico
 +
 
 +
 
 +
=Créer/configurer un projet VScode ou QtCreator=
 +
 
 +
== Création assistée d'un projet ==
 +
 
 +
À l'aide de ''pico_project.py'' :
 +
* ''git clone https://github.com/raspberrypi/pico-project-generator.git''
 +
* ''./pico_project.py --gui''
 +
* ne pas cocher "create VSCode project"
 +
 
 +
Attention, ne pas oublier de spécifier le chemin vers le SDK :
 +
* ''export PICO_SDK_PATH=../../pico-sdk'' en remplaçant ''../../pico-sdk'' par le chemin vers le SDK.
 +
 
 +
== Ouverture avec  VScode ==
 +
 
 +
Dans VSCode, ouvrir le dossier contenant le projet (''ie'' le fichier <code>CMakeLists.txt</code>), en sélectionnant <code>GCC for arm-none-eabi</code> commme compilateur dans le menu déroulant de configuration du projet.
 +
 
 +
== Ouverture avec QTCreator ==
 +
 
 +
QtCreator est capable de lire et interpréter le fichier ''CMakeLists.txt'' comme descripteur de projet, il suffit donc
 +
* d'ouvrir (comme projet) le fichier ''CMakeLists.txt''
 +
 
 +
=Registres=
 +
 
 +
==gpio==
 +
<source lang=cpp>
 +
#include "pico/stdlib.h"
 +
#include "hardware/regs/addressmap.h"
 +
 
 +
unsigned int& gpioOUT = *(unsigned int*) (SIO_BASE + 0x10);
 +
unsigned int& gpioOE  = *(unsigned int*) (SIO_BASE + 0x20);
 +
 
 +
unsigned int& gpioCtrl0 = *(unsigned int *) (IO_BANK0_BASE+0x4);
 +
//facultatif
 +
unsigned int& padsBank0_GPIO0 = *(unsigned int *) (PADS_BANK0_BASE+0x4);
 +
 
 +
 
 +
int main() {
 +
    // facultatif
 +
    padsBank0_GPIO0|=(1<<6); // input enable
 +
    padsBank0_GPIO0&=~(1<<7); // output disable
 +
    // piloter la broche avec fonction SIO
 +
    gpioCtrl0=5;
 +
    // sortie enable
 +
    gpioOE=1<<0;
 +
    while (true)
 +
    {
 +
        gpioOUT&=~(1<<0);
 +
        sleep_ms(200);
 +
        gpioOUT|=(1<<0);
 +
        sleep_ms(10);
 +
    }
 +
}
 +
</source>
  
 
=GPIO=
 
=GPIO=
  
https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__gpio.html
+
https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#hardware_gpio
  
 
{| class="wikitable"
 
{| class="wikitable"
Ligne 32 : Ligne 89 :
 
*pwm_config_set_clkdiv(&config, 4.f);
 
*pwm_config_set_clkdiv(&config, 4.f);
 
*pwm_init(slice_num, &config, true);
 
*pwm_init(slice_num, &config, true);
*pwm_set_gpio_level(PICO_DEFAULT_LED_PIN, fade * fade);
+
*pwm_set_gpio_level(PICO_DEFAULT_LED_PIN, fade * fade); // rapport cyclique 16 bits
  
  
Ligne 41 : Ligne 98 :
 
**https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf partie 7.1
 
**https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf partie 7.1
 
**https://www.electronicshub.org/program-raspberry-pi-pico-with-visual-studio-code/
 
**https://www.electronicshub.org/program-raspberry-pi-pico-with-visual-studio-code/
 +
*https://github.com/raspberrypi/picotool

Version actuelle datée du 11 février 2025 à 12:50

Brochage

https://datasheets.raspberrypi.com/pico/Pico-R3-A4-Pinout.pdf

utilisation de l'ide arduino

https://github.com/earlephilhower/arduino-pico


Créer/configurer un projet VScode ou QtCreator

Création assistée d'un projet

À l'aide de pico_project.py :

Attention, ne pas oublier de spécifier le chemin vers le SDK :

  • export PICO_SDK_PATH=../../pico-sdk en remplaçant ../../pico-sdk par le chemin vers le SDK.

Ouverture avec VScode

Dans VSCode, ouvrir le dossier contenant le projet (ie le fichier CMakeLists.txt), en sélectionnant GCC for arm-none-eabi commme compilateur dans le menu déroulant de configuration du projet.

Ouverture avec QTCreator

QtCreator est capable de lire et interpréter le fichier CMakeLists.txt comme descripteur de projet, il suffit donc

  • d'ouvrir (comme projet) le fichier CMakeLists.txt

Registres

gpio

#include "pico/stdlib.h"
#include "hardware/regs/addressmap.h"

unsigned int& gpioOUT = *(unsigned int*) (SIO_BASE + 0x10);
unsigned int& gpioOE  = *(unsigned int*) (SIO_BASE + 0x20);

unsigned int& gpioCtrl0 = *(unsigned int *) (IO_BANK0_BASE+0x4);
//facultatif
unsigned int& padsBank0_GPIO0 = *(unsigned int *) (PADS_BANK0_BASE+0x4);


int main() {
    // facultatif
    padsBank0_GPIO0|=(1<<6); // input enable
    padsBank0_GPIO0&=~(1<<7); // output disable
    // piloter la broche avec fonction SIO
    gpioCtrl0=5;
    // sortie enable
    gpioOE=1<<0;
    while (true)
    {
        gpioOUT&=~(1<<0);
        sleep_ms(200);
        gpioOUT|=(1<<0);
        sleep_ms(10);
    }
}

GPIO

https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#hardware_gpio

Syntaxe void gpio_init(uint gpio)
Paramètres
gpio numéro de gpio
  • gpio_put(LED_PIN, 1);
  • gpio_set_dir(LED_PIN, GPIO_OUT);
  • gpio_set_pulls (uint gpio, bool up, bool down)

Pwm

  • gpio_set_function(PICO_DEFAULT_LED_PIN, GPIO_FUNC_PWM);
  • uint slice_num = pwm_gpio_to_slice_num(PICO_DEFAULT_LED_PIN);
  • pwm_config config = pwm_get_default_config();
  • pwm_config_set_clkdiv(&config, 4.f);
  • pwm_init(slice_num, &config, true);
  • pwm_set_gpio_level(PICO_DEFAULT_LED_PIN, fade * fade); // rapport cyclique 16 bits


liens