Notes Related to Teensy 3.1 ARM MCU Board
The Teensy 3.1 board can be used for projects written in C, Arduino and/or MicroPython. I'm intrigued by the possibilities in an educational setting. With that in mind I will acquire one of these boards and explore the possibilities.
The pjrc Teensy web page gives a good set of instructions on the installation for the Teensy 3.1. The steps include downloading software for Arduino and then downloading and installing Teensyduino. Even the Micro Python project assumes this will be done.
I'll need to get a board to try this.
Followed the instructions on the PJRC Teensy website. I tried one of the simple Arduino examples that blinks a LED. I then made a change to the blink rate and duty cycle. All worked as expected.
A number of lines of comments were pulled out.
/*
Blink -- This example code is in the public domain.
*/
int led = 13;
// the setup routine runs once:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a 0.1 second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(900); // wait for a 0.9 second
}
The Arduino comes with a large number of libraries that provide access to the numerous peripheral modules built into the MCU. Most of these libraries are c++ files.
It is also possible to create user libraries. User libraries can be either C or C++ files; however, since most Arduino libraries define c++ classes and making use of those requires C++.
I have created a sample C file that implements a state machine that detects predefined text input and returns commands in the form of an enum.
See
- http://forum.pjrc.com/threads/24861-Teensy-3-1-without-arduino-IDE
- https://www.pjrc.com/teensy/gcc.html
Followed the essential instructions on the teensy web pages by changing references in the makefile to refer to the 3.1 and not the 3.0. For this (all references to 128 were changed to 256).
One section seemed to indicate I should change the line commented out for windows but it turned out the comment was wrong and I left it like it is to work on windows computer.
# path location for Teensy Loader, teensy_post_compile and teensy_reboot
TOOLSPATH = $(ARDUINOPATH)/hardware/tools # on Linux
#TOOLSPATH = $(ARDUINOPATH)/hardware/tools/tools/avr/bin # on Mac or Windows
I simplified the example program and saved it as main.c
#include "WProgram.h"
int main(void)
{
pinMode(13, OUTPUT);
while (1) {
digitalWriteFast(13, HIGH);
delay(101);
digitalWriteFast(13, LOW);
delay(900);
}
}
The alterations to the Makefile were exactly the same as under windows.
In the case of main.cpp I tested it essentially as extracted from the downloaded Teensyduino archive.
I should have a closser look at this template (setup for Linux) Also see
Currently the Teensy 3.1 port of Micro Python builds under Linux and not under Windows.
The tool chain required for the build can be found at https://launchpad.net/gcc-arm-embedded.
Downlaod the current Linux *.tar.bz2 file. Instructions regarding unpacking the file and moving it to the correct location as well as adding the extracted folders to the enviroment variable can be found at http://eliaselectronics.com/stm32f4-tutorials/setting-up-the-stm32f4-arm-development-toolchain/
An interactive session with Micro Python looked like this (many features listed are not yet implemented in Teensy 3.1)
Executing main.py
Micro Python v1.2-59-gecb5792 on 2014-08-11; Teensy-3.1 with MK20DX256
Type "help()" for more information.
>>>
>>> help()
Welcome to Micro Python!
For online help please visit http://micropython.org/help/.
Quick overview of commands for the board:
pyb.info() -- print some general information
pyb.gc() -- run the garbage collector
pyb.delay(n) -- wait for n milliseconds
pyb.Switch() -- create a switch object
Switch methods: (), callback(f)
pyb.LED(n) -- create an LED object for LED n (n=1,2,3,4)
LED methods: on(), off(), toggle(), intensity(<n>)
pyb.Pin(pin) -- get a pin, eg pyb.Pin('X1')
pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
Pin methods: init(..), value([v]), high(), low()
pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object
pyb.ADC(pin) -- make an analog object from a pin
ADC methods: read(), read_timed(buf, freq)
pyb.DAC(port) -- make a DAC object
DAC methods: triangle(freq), write(n), write_timed(buf, freq)
pyb.RTC() -- make an RTC object; methods: datetime([val])
pyb.rng() -- get a 30-bit hardware random number
pyb.Servo(n) -- create Servo object for servo n (n=1,2,3,4)
Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]])
pyb.Accel() -- create an Accelerometer object
Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz()
Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name
Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD
Pin pull modes are: pyb.Pin.PULL_NONE, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN
Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n)
Control commands:
CTRL-A -- on a blank line, enter raw REPL mode
CTRL-B -- on a blank line, enter normal REPL mode
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, do a soft reset of the board
For further help on a specific object, type help(obj)
>>>
CTRL-A Z for help |115200 8N1 | NOR | Minicom 2.6.1 | VT102 | Offline
MicroPython was compiled following the instructions at (links to Teensy forum)
and
MicroPython was cross compiled on a Linux computer. Once the hex file is created it can be loaded onto the Teensy3.1. I accessed Micropython via Minicom on Linux. I also accessed it using PuTTY on a Windows computer. A short interactive session with MicroPython can be seen here: