FabAcademy 2023 Jose Luis Reategui

Week 4

Embedded Programming

  • Arduino File
  • C File
  • STM32 file
  • Nvidia Test GPIO Jupyter file
  • Embedded programing. Have you:

    Individual assignment: browse through the data sheet for your microcontroller, write program for a microcontroller development board to interact (with local input &/or output) and communicate (remotely) extra credit: use different languages &/or development environments extra credit: connect external components to the board

    Group assignment: compare the performance and development workflows for other architectures

    ============================= Group Assignment =======================================

    We used the following boards to compare: 1. Esp32 by EspressIf. 2. Arduino by Arduino Foundation. 3. STM32 by ST. 4. Nvidia Jetson by Nvidia. 5. Raspberry Pi by Raspberry.

    This picture shows the boards. From left to right: Esp32, Arduino UNO, STM32, Nvidia Jetson Nano

    Image

    Esp32 it's a microcontroller to create embebded applications, usually works with wifi network and we have to connect to power source with 5V or 3.3V

    Esp32 datasheet

    Image

    Arduino ist's a microcontroller too and works with atmel core to create a MCU. Usually works with 5V.

    Arduino datasheet

    Image

    STM32 works with ARM processor, it's a microcontroller and very powerfull to Embedded aplications

    STM32 datasheet

    Image

    Nvidia Jetson Nano is a MCU works with a microprocessor, with a GPU focus in paralel processing, usually used to create artificial intelligence applications

    Jetson datasheet

    Image

    Raspberry Pi is a MCU that works with a ARM microprocessor, with a CPU focus in serial processing, usually used to create complex control systems more than arduino

    Image

    Raspberry datasheet

  • We found some advantages with stm32 compare with Arduino Atmel 328, some key differences is a SRam Memory and the power consumption, stm32 is more efficient than ATmel, beacuse stm32 has a ultra low power that we can create a power-low applications.
  • SRAM--> Atmel-Arduino (2 KB)/STM32 (20 KB)
  • Power comsumption--> Arduino (5V)/STM32 (2V-3.6V)
  • Flash Memory--> Arduino (32 KB)/STM32 (128 KB)
  • Analog pins--> Arduino (6 pins)/STM32 ()
  • CPU Frecuency--> Arduino (16 MHz)/STM32 (72 MHz)
  • 9-2022 Price--> Arduino (28 USD)/STM32(6 USD)
  • For create scripts with Arduino we have to use ArduinoIDE that use C with a layer to reduce the knowledge curve, this layer creates a memory reduction. STM32 works with C without a layer, it's very important because we have a clean code for the microcontroller and the C use opportunity directly.
  • If we want to use more powerful boards, the microprocessor board it's an interesting option because a lot of features are more powerful than microcontrollers. We test two boards, the first was Ndivia Jetson Nano and the last was Raspberry Pi board

  • CPU--> Nvidia Jetson Nano (Quad-core ARM Cortex-A57)/Raspberry Pi (Quad-core ARM Cortex-A72)
  • GPU (paralel processing)-->Ndivia Jetson Nano(NVIDIA Maxwell architecture with 128 NVIDIA CUDA® cores)/Raspberry Pi
  • To work with Esp32 we used Eclipse IDE + Freertos because has a focus on microcontrollers. We took the following procedure:
  • Install FreeRTOS link
  • Eclipse Embedded CDT (C/C++ Development Tools)
  • Install Eclipse C++/C complement
  • To work with Arduino we used Arduino IDE because has a focus on Atmel-Arduino microcontrollers. We took the following procedure:
  • Arduino IDE
  • To work with ARM we used STM32 Cube because has a focus on STM32 microcontrollers. We took the following procedure:
  • STM32 Cube
  • To work with Nvidia Jetson Nano we used Python because this language work very well. We took the following procedure:
  • Python Jetson Nano procedure
  • To work with Raspberry-pi-4 we used Python too because this language work very well. We took the following procedure:
  • Raspbery-Pi-4 procedure
  • ============================ Individual Assignment ====================================

    1. Documented what you learned from reading a microcontroller datasheet.
    2. What questions do you have? What would you like to learn more about?
    3. Programmed your board
    4. Described the programming process/es you used
    5. Included your code

    Documented what you learned from reading a microcontroller datasheet.

    I found very interesting the pin classification, the ATTiny 44 have two groups, the first one is the A port and the second the B port, this is very important to have programs because We need to send the program to A pin Group or B pin Group

    Image

    Also it's very interesting the minimal connections that We need, for instance:

    1. Pin 14 to Ground. Pin 1 to Energy. These Pins are reserved
    2. Also the PA4,PB3,PA5,PA6, pins are reserved

    Important Information

    1. TWI(I2C): 1
    2. ADC Channels: 8
    3. ADC Resolution (bits): 10
    4. ADC Spped(ksps): 15
    5. ADC Gain Stage: yes
    6. Analog Comparators: 1
    7. Temp.Sensor: Yes
    8. SRAM (kBytes): 0.25
    9. EEPROM (Bytes): 256
    10. ASelf Program Memory: Yes
    11. Temp. Range (degC): -40to85
    12. I/O Supply Class: 1.8 to 5.5
    13. OPerating Voltage(Vcc): 1.8 to 5.5
    14. Flash(kBytes): 4 kBytes
    15. Pin Count: 14
    16. Max. OPerating Freq.(MHz): 20 MHz
    17. CPU: 8-bit AVR
    18. #of Touch Channels: 6
    19. Max I/O Pins: 12
    20. Ext Interrupts: 12
    21. SPI: 1
    22. Timers: 2
    23. PWM Channels: 1
    24. Calibrated RC Oscillator: Yes
    25. Debug Interface: debugWIRE
    Image

    These means We only have 8 pins to create the board

    Programmed your board

    Described the programming process/es you used

    Atmel Studio IDE with C ---------------------------------------------------------------------------------------------------------

    The first step is install Atmel Studio, click in the link below:

  • Atmel Studio
  • The Installation consists in the following steps:

    1. Install AtmelStudio IDE.
    2. Image
    3. Choose the GCC Executable Project, and put a project name
    4. Image
    5. Choose the Attiny 44 from the list, We can choose other options like AtMega328 or Attiny 45
    6. Image
    7. We need to understand the code, here an example.
    8. Image
    9. The Final code have two pines, the first one for button and the second to destinate to LED
    10. Image
    11. To Upload the code we need to configured an External tool called USBTiny, We need to install avrdude.exe
    12. Image

      Hello Board-Jose Reategui from JOSE LUIS REATEGUI on Vimeo.

    Nvidia Jetson Nano ---------------------------------------------------------------------------------------------------------

  • Nvidia Jetson Nano
  • To work with Nvidia Jetson Nano we have to use a JestonGPIO library, this library is like Raspberry GPIO library

  • To work with Nvidia Jetson nano I decided to use Visual Studio Code as an Editor. In this way, I looked for visual studio code web page
  • Image
  • Is compulsory download the correct version related with our Jetson CPU, in my case is arm64 debian version.
  • Image
  • To install Visual Studio Code(VS Code), I choose command line ("crtl"+"alt"+"t") and I left to download folder and I typed the command: (sudo apt install ./code_1.75.1-1675892106_arm64.deb).
  • Image Image
  • We can check if the installation process finish well with the Applications menu: We have to observe the VS Code icon
  • Image
  • I decided to use Dark theme in VS Code.
  • Image
  • now is time to install Python extension from Extension button in the left side, under debug button
  • Image Image
  • once ubicated the python extension we have to push on the "install" blue button
  • Image
  • Another very useful extension is JupyterLab into Visual Studio Code. In this way I wrote in the terminal: "pip3 install JupyterLab"
  • Image
  • To work with Jupyter is necessary write in the extension bar, and pick on "Create: New Jupyter Notebook".
  • Image
  • Jupyter Lab work with code cells, here we can put on our python code.
  • Image
  • When I tried to run my "hello world" code, the system shows an error related with the kernel, to solve this issue I changed "Python 3.9.16" for "Python 3.6.9"
  • Image
  • After the python kernel change the script cells works very well.
  • Image
  • I decided install "sklearn" "numpy" and "matplotlib" beacuse I'm going to use machine learning techniques in my final project.
  • Image
  • previously I installed Pytorch, it means that I can import the library and use it
  • Image
  • To use the Jetson's pins I tried to use RPi. GPIO like a Raspberry-pi-4, in this way I used the command: "sudo pip install RPi.GPIO"
  • Image Image Image
  • The RPi._GPIO doesn't work. Is necessary install the Jetson GIP library
  • Image
  • After the Jetson GPIO installation process. I could use "import Jetson.GPIO as GPIO"
  • Image

    STM32 with STM32CubeIDE--------------------------------------------------------------------------------------------------

    Image

    STM32 Cube IDE is a IDE to work with STM32 boards, has a several interactive tools such as windows to choose board features, pines

  • STM32CubeIDE web page
  • Image

    Go to OS compatibility driver to install the IDE

    After following the installation process and open the IDE

    Image

    We have to choose a workspace and go to File menu, "new", "create a New STM32 project"

    Image

    In the "target selection menu" we can start with MCU/MPU selector

    Image

    But is more confortable for me work with the "board selector" in the next label, because we can select specific board with the "commercial part" or "mounted device".

    Image

    After the last step we have to select the "example selector"

    Image

    Now is time to select the available pinout funcionalities in order to reduce the programming time in the code

    Image

    once the last step finished we have to configure the pinout behavior (lines 96,97,98)

    Image

    We have to custom the debug configuration before the run code process

    Image

    once finish the debug configuration we have to push on click button

    This video shows the blink led program with a STM32 board based on ARM

    Conclusions: Several microcontrollers can work with C or Arduino based on C, but in some cases like STM32 is better to use STM32CubeIDE because the IDE was designed to work very well with ARM architecture. If we have to work with a microprocessor like Nvidia Jetson Nano or Raspberry-pi-4 based on ARM we have to install an Operating systems , it usual to use Ubuntu-Linux. Another very important thing is to know the pin distribution showed in PinOut diagram, We can connect correctly when the pin is controlled from program. Also if we have to work with very specific applications, the embeded program can work into a microcontroller, but if we want to work with machine learning or complex control functions we have to use microprocessors.