Table of Contents
Arduino IDE
IDE vs CLI
Arduino, Arduino CLI, include path
Arduino mpu 6050
Using microcontrollers
A microcontroller is a type of integrated circuit (IC), a chip.
A microcontroller is programmable.
1. Upload, burn, or flash a program into the chip's memory.
2. Power-up the chip in normal mode, and your program starts running automatically.
Each microcontroller contains a logic processor which runs a specific language.
The manufacture provides a compiler, and instructions for loading a compiled program into the microcontroller.
It may seem like a hassle to deal with all of the details and quirks of programming the many various microcontrollers available.
The Arduino IDE, and several similar products, attempt to simplify this situation for beginner developers by providing tools that operate universally across all microcontroller products.
Ideally you can write a C++ program for the ATmega328P microcontroller, and then later run that same program on an ESP32 microcontroller.
The Arduino IDE takes care of all the chip-specific details behind the scenes and lets the developer concentrate on the program logic.
Unfortunately, programs like this often become gate-keepers, hiding the truth from ordinary folks. “You don't need to know that.” Sooner or later, as a result of problem solving, developers are forced to spend inordinate amounts of time figuring out what the IDE is doing, in order to debug the problem.
Terms
sketch = a c++ program in a text file with extension “.ino”.
Packages, cores, libraries, tools
package vs core vs platform
components:
- editor
- compiler
- uploader
“List all boards that have the support platform installed.”
“Search for a board in the Boards Manager using the specified keywords.”
“Upload the bootloader on the board using an external programmer.”
“completion script”
“platform”
Boards Manager - the compiler and uploader work differently depending on the board.
The “board” refers to the PCB, the microcontroller.
With the IDE, you are always working with one microcontroller. The microcontroller is connected to a serial port. You use the Boards Manager to specify the mfg/model of the microcontroller.
1. Plug your microcontroller into a serial port on your computer. 2. In the IDE menu, goto Tools - Boards Manager.
Tools menu:
- Board - select your board mfg/model from the menu. If it's not there, click on Boards Manager to select and install the core for your board mfg/model.
- Port - Which port is your board plugged into? Select from menu.
- Get board info - If Board and Port are selected correctly, returns the mfg/model of the connected board.
- Manage libraries - Download and install software libraries for special functions and specific boards. Select from menu.
core = package = platform
$: arduino-cli upload ... Error during Upload: Platform 'arduino:avr' not found: platform arduino:avr is not installed Try running `arduino-cli core install arduino:avr` $: arduino-cli core list ID Installed Latest Name arduino:esp32 2.0.13 2.0.13 Arduino ESP32 Boards esp32:esp32 2.0.13 2.0.13 esp32 $: arduino-cli core install arduino:avr Downloading packages... arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7 downloaded arduino:avrdude@6.3.0-arduino17 downloaded arduino:arduinoOTA@1.3.0 downloaded arduino:avr@1.8.6 downloaded Installing arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7... Configuring tool.... arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7 installed Installing arduino:avrdude@6.3.0-arduino17... Configuring tool.... arduino:avrdude@6.3.0-arduino17 installed Installing arduino:arduinoOTA@1.3.0... Configuring tool.... arduino:arduinoOTA@1.3.0 installed Installing platform arduino:avr@1.8.6... Configuring platform.... Platform arduino:avr@1.8.6 installed $: arduino-cli core list ID Installed Latest Name arduino:avr 1.8.6 1.8.6 Arduino AVR Boards arduino:esp32 2.0.13 2.0.13 Arduino ESP32 Boards esp32:esp32 2.0.13 2.0.13 esp32
| Platform name in Boards Manager | folder |
|---|---|
| ESP32 Arduino (Arduino) | /home/john/.arduino15/packages/esp32/hardware/esp32/2.0.13/boards.txt |
| Arduino AVR Boards | /home/john/.arduino15/packages/arduino/hardware/avr/1.8.6/boards.txt |
| ESP32 Arduino | /home/john/.arduino15/packages/arduino/hardware/esp32/2.0.13/boards.txt |
Where are the human names of the platforms displayed in the Boards Manager menu?
File - Preferences: /home/john/.arduino15/preferences.txt
Boards Manager - where is this list of “packages”?
Library Manager - where is this list of libraries?
Folder Structure
File - Preferences
Sketchbook location:
Additional Boards Manager URLs:
Package installed into:
/home/john/.local/bin/arduino/arduino-1.8.19/
Boards Manager installs into:
/home/john/.arduino15/packages/arduino/hardware/avr/
/home/john/.arduino15/packages/arduino/hardware/esp32/2.0.13/
/home/john/.arduino15/packages/esp32/hardware/esp32/2.0.13/
Failure on Upload
My ports:
- /dev/ttyS4 - always showing
- /dev/ttyUSB0 - showing when I have a board plugged in
My boards:
- Arduino Uno -
- Adafruit ESP32 Feather (Huzzah32) -
- Arduino Nano ESP32 -
- ESP32 CAM AI Thinker -
“Failed to get PID of a device on /dev/ttyS4, using standard reset sequence.”
My board, the ESP32-CAM-MB is plugged into the USB port.
Arduino IDE, Tools, Port shows one available USB port.
I am a member of the dialout group, so I have permissions on that port.
$ ls -al /dev/ttyS5 crw-rw---- 1 root dialout 4, 68 Oct 15 14:56 /dev/ttyS4 $ groups john adm dialout cdrom sudo dip plugdev lpadmin lxd sambashare wireshark
The ESP32-CAM-MB requires the ? drivers. Those are supposed to be installed automatically with this Ubuntu distribution.
Cores
One core is written for each microcontroller chip.
| microcontroller | core |
|---|---|
| ATmega328P | AVR |
| SAMD21 | SAMD |
Libraries
Tools
Uploading Software to a Microcontroller
Uploading software to a microcontroller is done with serial communications.
Serial Communications
FTDI - FTDI is a company name. They make a chip for serial communications that is used in many boards.
CH340C - USB to serial converter chip, made by SeeedStudio
reset
boot mode
enter the bootloader
serial communications - data transfer, 1 wire, 1 bit at a time, 2 parties: transmitter and receiver, 2 pins: RX, TX. wires from master's TX to listener's RX. Baud rate, stop bit, parity bit. Choice of signal methods: TTL or RS232.
USB - not considered “serial communications”, USB to serial converter
RS232 - a serial communication, +/-13V
TTL - Transistor-transistor-logic, a serial communication, 0 to 3.3V/5V
UART - Universally Asynchronous Receiver/Transmitter, a transmission method
USB to Serial chip
CP2102,, Silicon Labs, SINGLE-CHIP USB TO UART BRIDGE, requires drivers https://www.sparkfun.com/datasheets/IC/cp2102.pdf
FT232RL,, FTDI, (my board is from HiLetGo, is NOT genuine FTDI, and I have NOT gotten it to work with ESP32-CAM)
CH340G, CH340C - USB to serial chip, used by ESP32-CAM-MB (mine is from Aideepen, and it works)
Atmega16U2 - an MCU programmed as a USB-to-serial converter (used by Arduino Uno R3)
USB to Serial board
FTDI, , 6 pins: DTR, RX, TX, VCC, CTS, GND
chips and boards, ICs and PCBs
boards: converter, adapter, module, programmer, breakout, developer,
Logic
Math, Computer Science
If, then, else
Assembly Language
Must be assembled and linked, using an assembler and linker.
Logic can be implemented in assembly language programming. Not logic itself. Test, branch on condition. Expressed via flowchart instead of pseudo-code. branch = jump = goto
Compare x to 3 if greater, goto a label if lesser, goto a different label if equal, goto still another label