Jan 7, 2022

Teensyduino Features and Techniques [Part 1]

The Teensyduino is a high-performance Arduino-compatible microcontroller family. In addition to the hardware, developer Paul Stoffregen has contributed substantially to the development of extended capabilities of the Arduino's “tailored C++” language for the Teensy family and made these capabilities compatible and usually applicable to other Arduino hardware boards. This article applies to the 32-bit Teensy 3.x and 4.x hardware.

The Teensyduino 3 (T3.2) is a standard, extremely versatile model, and is my goto choice for most hardware development. (Recent models (~2021) extend IO and peripherals (T3.5 T3.6) and faster models in similar form factors (T4.x), each with at least one tradeoff.)

Excellent combined feature suite

This combination of features are most relevant to me and distinguish it from other arduino-esque platforms:
  • Small (~ 0.8 x 1.5")
  • Fast (96 MHz)
  • Runs on 3.3V or 5V, and I/O is 5V tolerant
  • Includes a DAC 
  • 32-bit processor
  • Multiple UARTs and USB direct programming
  • Supports formatted printing including floats printf() & sprintf()
also nice:
  • real-time clock (RTC), just add 32kHz xtl on bottom
  • auto-incrementing timer variable types (elapsedMillis, elapsedMicros) [example...]

Quirks

  • 1st time it is programmed, usually requires an extra step (manual btn press to load)
  • The button is not a Reset, but rather a program Load. (There is a reset pin on bottom side of the board to which a button may be added)

Particularly useful specialty libraries

  • u8g2    (fast lib for nearly all OLED displays; includes multiple fonts)
  • TeensyStepper (very fast pulse rates, synchronous across multiple motors)
  • SoftPWM (allows PWM on any digital pin)
  • FastLed & its fast math routines (8 & 16-bit sin, cos, random)

Example: Serial.printf() 

TBD

Example: elapsedMillis() 

for multiple repeating events at different rates

/* snippet that shows multiple independent non-blocking time intervals for events.
   Can be based on milliseconds or microseconds.
*/

  . . . 
const uint16_t SEC_INTERVAL  = 1000;
const
uint16_t MEAS_INTERVAL = 5; // fast rate to capture changes const uint16_t OLED_INTERVAL = 200;
const uint16_t LED_INTERVAL  = 500;

. . . const uint16_t status_led_flash_duration = 12; . . .
elapsedMillis since_msec;              // ms to count a sec
elapsedMillis since_meas;
elapsedMillis since_oled;
elapsedMillis since_led;
. . .
void loop() {
    if (since_meas >= MEAS_INTERVAL) {        // make flux measurement
        since_meas = 0;

	measureFlux();
    }

    if (since_oled >= OLED_INTERVAL) {        // update value on OLED screen
        since_oled = 0;

        oledUpdateValue(G);
    }

    if (since_msec >= 1000) {	              // each second, update the time
        since_msec = 0;

        total_sec ++;
        uint16_t sec  = total_sec % 60;
        uint16_t hour = total_sec / 3600;
        uint16_t min  = (total_sec % 3600)/60;

	 . . .
        sprintf(msg, " %02d:%02d:%02d", hour, min, sec);  // update time field   
        display.print(msg);
       
    }
}   							 
 
 ... 


1 comment:

basyaabbs said...

Mr Gamble - DrMCD
All about Mr Gamble. In the online betting market, Mr 제주도 출장마사지 Gamble offers 의왕 출장샵 a variety 목포 출장안마 of sports betting products, sports betting and casino games. In-Play  Rating: 사설토토 4.2 · 충청북도 출장안마 ‎2 votes