Arduino and Teensy libraries: Difference between revisions
| Line 144: | Line 144: | ||
WS2812Serial /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/WS2812Serial | WS2812Serial /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/WS2812Serial | ||
EEPROM 2.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/EEPROM | EEPROM 2.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/EEPROM | ||
Used platform Version Path | |||
Used platform Version Path | teensy:avr 1.59.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0 | ||
teensy:avr 1.59.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0 | |||
The compiled code is in the ''build'' directory. | The compiled code is in the ''build'' directory. | ||
Revision as of 11:53, 22 December 2024
Back to Basebot
Installation of Arduino and Teensy support
This is probably not needed if you intend to use MS Visual Studio.
Arduino (version 2.xx)
- Install the newest Arduino - see https://www.arduino.cc/en/software.
Add Teensy board support
- Add the Teensy hardware support - see https://www.pjrc.com/teensy/td_download.html, including
- Add https://www.pjrc.com/teensy/package_teensy_index.json to the file->preferences
- In the boards manager (Tools->Boards->Boards manager), search for Teensy and install support for Teensy boards.
Add libraries
- In the Library manager (Tools->Manage libraries), search for "MPU9250_asukiaaa" and "Adafruit GFX library" and install both, including dependencies. These are used to interface the IMU and support for the small display.
Board select
Select the Teensy 4.1 board (tool->board->Teensy->4.1).
Select the port the robot is connected to - it is easier to connect it first.
Arduino command line interface
See https://docs.arduino.cc/arduino-cli/
Install Arduino CLI
Get the install script and let it install arduino-cli into the directory ~/bin. It will detect the download platform and install an appropriate version.
cd curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh cd bin pwd
Add this directory to the PATH.
nano ~/.bashrc
Add at the end (assuming your login name is local)
export PATH=$PATH:/home/local/bin
Add Teensy boards
Make a configuration file (in a hidden file called ~/.arduino15/arduino-cli.yaml).
arduino-cli config init
Copy the URL for Teensyduino https://www.pjrc.com/teensy/package_teensy_index.json and add it to the configuration file.
nano ~/.arduino15/arduino-cli.yaml
Make it look like this:
board_manager: additional_urls: ["https://www.pjrc.com/teensy/package_teensy_index.json"]
After this, update the index
arduino-cli core update-index
Install Teensy support
Find the install name of the board type to install
$ arduino-cli core search teensy ID Version Name teensy:avr 1.59.0 Teensy (for Arduino IDE 2.0.4 or later)
Then, install and configure the Teensy support
arduino-cli core install teensy:avr
Install libraries
Robobot need (especially) these libraries.
- Adafruit GFX Library
- MPU9250_asukiaaa
If the exact name is not known, then search, e.g.:
arduino-cli lib search name:"Adafruit GFX Library"
Install
arduino-cli lib install "Adafruit GFX Library" arduino-cli lib install "MPU9250_asukiaaa"
Compile
With the board connected, find the board type name:
$ Arduino-cli board list Port Protocol Type Board Name FQBN Core /dev/ttyACM0 serial Serial Port (USB) Unknown /dev/ttyAMA10 serial Serial Port Unknown usb3/3-2 teensy Teensy Ports Teensy 4.1 teensy:avr:teensy41 teensy:avr
In this case, the key name is "teensy:avr:teensy41"
Command line compile the teensy_firmware_8.ino in the directory ~/svn/robobot/teensy_firmware_8
cd ~/svn/robobot/teensy_firmware_8 arduino-cli compile --fqbn teensy:avr:teensy41 --build-path build ../teensy_firmware_8
The compile for Teensy 4.1 is copied into a script called compile (remember to chmod +x compile).
$ cat compile #!/bin/bash arduino-cli compile --fqbn teensy:avr:teensy41 --build-path build ../teensy_firmware_8
It takes a while to compile and should have a few warnings only.
$ ./compile Memory Usage on Teensy 4.1: FLASH: code:149300, data:41316, headers:9060 free for files:7926788 RAM1: variables:60352, code:146136, padding:17704 free for local variables:300096 RAM2: variables:12640 free for malloc/new:511648 Used library Version Path ADC 9.1 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ ADC MPU9250_asukiaaa 1.5.13 /home/local/Arduino/libraries/MPU9250_asukiaaa Wire 1.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ Wire Adafruit GFX Library 1.11.11 /home/local/Arduino/libraries/Adafruit_GFX_Library Adafruit BusIO 1.16.2 /home/local/Arduino/libraries/Adafruit_BusIO SPI 1.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/SPI USBHost_t36 0.2 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ USBHost_t36 SdFat 2.1.2 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ SdFat WS2812Serial /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/WS2812Serial EEPROM 2.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/EEPROM Used platform Version Path teensy:avr 1.59.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0
The compiled code is in the build directory.
Upload
The arduino-cli upload for Teensy requires a graphical interface, but there is a command line alternative.
Install command line uploader
cd cd git git clone https://github.com/PaulStoffregen/teensy_loader_cli.git cd teensy_loader_cli make
This makes the executable binary teensy_loader_cli. This compiled file can be copied to /usr/local/bin for easy access.
sudo cp ~/git/teensy_loader_cli /usr/local/bin
The upload
The hex file is in the build directory.
$ cd ~/svn/robobot/teensy_firmware_8/build $ sudo teensy_loader_cli -v -w --mcu=TEENSY41 teensy_firmware_8.ino.hex Teensy Loader, Command Line, Version 2.3 Read "build/teensy_firmware_8.ino.hex": 199680 bytes, 2.5% usage Waiting for Teensy device... (hint: press the reset button)
The Teensy board will cut battery power during upload,
so, press the "power" button before the small reset button on the Teensy board.
Then it uploads:
Found HalfKay Bootloader Programming.................................................................. Booting
After booting, you can release the power button.