CircuitPython on Teensy 4!

CircuitPython 7.0.0-rc.3 was posted already too. Looks like it had just one fix for RP2040 over rc2. Following this because I am about to try CircuitPython for a little project using I2C myself.
 
CircuitPython 7.0.0-rc.3 was posted already too. Looks like it had just one fix for RP2040 over rc2. Following this because I am about to try CircuitPython for a little project using I2C myself.
It seems to be working quite well now. I have 3 I2C devices and an SPI display on it. Turns out a megabyte of ram and 600MHz makes a big difference in how things run. Runs very smoothly. Like buttah. I appreciate the help.
 
I'm experiencing a problem with PWM output on my Teensy 4.1 using Circuitpython. Does anyone have an idea what could be wrong?

I've tried following:
Code:
import board
import pwmio

pwmio.PWMOut(board.D1, frequency=1000, duty_cycle=60000)
But an LED connected to the output of pin 1 does not light up at all. If I try setting the same pin with digital out, then it works. It also works if I use PWM output with C code loaded through the regular Teensyduino IDE. Any ideas?
 
I have a new little project using mlx90640+St7789 based display
was using the new Raspberry Pi pico + circuitpython
but did have very poor update-rates because of the slow processor

(i2c @ 800khz, st7789 spi @ 62Mhz) so no slowdown there
also the Pico have to little ram for that application

I know I could use c/c++ but the code was already done in python
and did not want to spend to much time right now on

And because I now have a spare Teensy 4.0
I wanted to just try it out with CircuitPython

But did run into some problems

Did download the CircuitPython firmware hex (adafruit-circuitpython-teensy40-en_US-7.2.3.hex)
from https://circuitpython.org/

successfully programmed it using teensy loader 1.56
but also in that process it was upgrading the bootloader

All went well with Thonny
uploading some libs

but after I did got the code in a working state
the teensy crashed
and entered (in simple words) 'a non usable state'

and the only option was to use the '15sec recovery'

It's now running the blink program of what I can see

but when I press the program button it just flashes the 'program'-led
and no response in teensy loader.

What can I try to do?
 
...

but after I did got the code in a working state
the teensy crashed
and entered (in simple words) 'a non usable state'

and the only option was to use the '15sec recovery'

It's now running the blink program of what I can see

but when I press the program button it just flashes the 'program'-led
and no response in teensy loader.

What can I try to do?

Get a simple BLINK.ino ready with 'Verify'
In open Teensy Loader and Help / Verbose window made clear.
Try an upload.
What shows in the Loader Verbose window text?

Something with an 'Opps' - 'no code for this case'?
Capture and post that text.

This sounds similar to an observed issue Paul was investigating. Seen here on a MicroMod unit that was returned to PJRC to investigate.
 
false alarm
Surely windows was getting haywire because of
the failing 'CircuitPython' code
And after restart of windows (had to use the reset switch after a stuck shutdown, :p windows in a nutshell)

I could reflash the hex again, so no worry.

edit.
next time I will not use the automatic code.py
and hopefully I can then resolve the problem.


In the end I will off course go for the c/c++ route
using teensy 4.0

can use
https://forum.pjrc.com/threads/66816-MLX90640-Thermal-Camera-and-a-Teensy-4-0?highlight=mlx90640
as a starting point
 
either windows is crap or there is issues with CircuitPython
both in combination is not working

when running the python code
I get the following
Code:
Connection lost (EOF)

and after a while the mouse/keyboard stops responding
until I remove the teensy
(they are connected to the same hub)

and windows is stuck with the CIRCUITPY 'drive'
the only resolve is to hard reset the computer
if I want to connect any usb device again

could be a power issue but only have the mlx connected at the moment
 
either windows is crap or there is issues with CircuitPython
both in combination is not working
...

Had a couple instances of Teensy going offline weeks back. Standard Arduino - not cPy
It was plugged into a HUB.
If I unplug and replug the HUB - the Teensy came back online. It is a powered HUB, and IIRC power was not removed so devices survive - just the HUB leaving and returning to reconnect.

Almost like some Hub/Windows grief got it removed.

That was weeks back - I never saw what may have been the cause - and no recall of the sketch or context - but some 3 times the sketch at hand caused that and found 'resolution' was hub un-plug ????
> was likely T_4.1: MTP testing or working with lockable 1062 bootloader ???
-> cPy presents as a media device? Maybe it relates to MTP type message processing?????

Before I found the Hub Unplug to 'work' the Teensy would reconnect when USB cable was unplugged from Hub and put onto another port ... IIRC.
 
Great, now things will get further fragmented between C/C++ and python

ugh, I don't want to learn python, I don't like it. Now there will be a mix of both in the Teensy user community.

You python people are taking over everything. :(
 
Its just a tool in the toolkit, know the strengths and weaknesses of each tool and choose appropriately - programming is universal,
the particular language is details, important details indeed, but I'd suggest seeing the bigger picture. C/C++ requires much more
discipline to use safely, for instance, in some circumstances this is a big millstone round your neck.
 
I'm just really frustrated with the fragmentation of languages in microcontrollers.
I want to learn C/C++, to me, learning python is a distraction, I'll get to that later, after I've mastered C/C++.
But what's frustrating is buying hardware and the only libraries I can find to use it are in python.
But python is becoming more and more popular by the day, it's trendy language.
But I just plain don't like it. I don't like it's lack of curly brackets. I don't like the so called "easier to read" syntax.
Maybe my brain just works different, python is not easier to read, it's too natural language.

It's more like Basic 2.0, it's the Jr, kids language, for learning, pushed in schools, because "it's easier".
Just trendy STEM crap pushed by hobby electronics stores.
 
A lot of people love Python. Personally, I get tripped up by the white space requirements, but I can understand why it's so appealing for so many people who didn't start with C or C++.

I was under the impression Adafruit was publishing by Circuit Python and Arduino (C++) libraries for all their hardware. Are some of their products now Python only? Or is someone other than Adafruit publishing substantial libraries for Circuit Python?
 
For me, it is not my language of choice. But as they say at times when you are in Rome...

My first experiences with it was with ROS and I found with some SBC boards like RPI, I hated it, as for example some simple Python scripts, like to read in bytes from a Joystick and slight translation, like Button 1 on my joystick is changed to Button 3.... And found with PySerial at the time, that simple script would eat up more or less whole hole core of the RPI... Rewritten in C++ the cpu hit was negligible.

But recently I have been playing with it, as the new High Level Analyzers for the newer Saleae Logic software, you develop the HLA using Python... So I have been experimenting and converted my Low Level Analyzer(LLA) over to instead be an HLA and it with lots of asking questions and a lot of google searches, it is working OK. Some of it is sort of fun of using a table(dictionary?) where for example I have a state table, with each state being a string and associated with it I have a function to call, when I am in that state...

But yes you don't know how many times I have to reload the HLA after edits, because I screwed up the spacing or forgot to add a : to things like - else:
 
Not a particular fan of Python only because I have got use to C++ at this point. I do agree that the PySerial interface to dreadfully slow and glad @KurtE found away around it!

Unfortunately if you want to do any image processing things its easier to use things like OpenCV or OpenMV.
 
I have a Pimoroni Tiny2040 that I am very frustrated with.
They say I can do C++ code for it, but the whole RP2040 ecosphere is python stuff.

Adafruit is good about stuff, Sparkfun is ok, Pimoroni not a whole lot of support.

Teensy, is amazing!

I'm not a pro folks, so be patient with me. All I know is self taught. no degrees, no professional experience, no real friends (to me internet doesn't count, it doesn't work for me like that)
I'm also not so much into this internet socialization stuff, I didn't grow up with it. so I my come off as a jerk some times.
 
A lot of people love Python. Personally, I get tripped up by the white space requirements, but I can understand why it's so appealing for so many people who didn't start with C or C++.

I was under the impression Adafruit was publishing by Circuit Python and Arduino (C++) libraries for all their hardware. Are some of their products now Python only? Or is someone other than Adafruit publishing substantial libraries for Circuit Python?

I agree, I've hated Python ever since it came out due to the white space requirements. I'm a perl programmer from way back, and I would have preferred perl to have won the mindspace that Python got, but that is just me grousing....

Adafruit does tend to release Circuit Python for most of the boards that they produce, but they often times don't take the effort to do a full port for boards that they resell from other vendors. The Teensy 4.0/4.1 boards are the only counter example I can think of.

IIRC, many of the RP2040 vendors use something called Micro Python for their boards, not Circuit Python.

There is a third party RP2040 Arduino layer that people use. I've downloaded it. I don't recall if I've actually done anything on the RP2040 boards I've gotten. I do recall seeing invalid json messages regarding the rp2040 port, and I haven't investigated.

As I understand it, the RP2040 is roughly at the same performance level of the Teensy LC (i.e. M0 level). I do recall seeing that there are a bunch of restrictions in the board, such as having to know which PWM timer a particular pin is using if you are going to use multiple PWM pins. But it seems to be fairly cheap, and it seems to be more available than some of the other chips used.
 
Yeah, Circuit Python / Micro Python mix adds an extra level of frustration.

I'm not saying python is bad, I just don't like it. But I'm still learning, and another language is a distraction from my self determined curriculum.
And an inexpensive board with that level of performance is quite distracting. I was seduced by the adorable size of the Tiny2040.
But it's just oddball enough that it's a challenge to get anything to work on it. Pimoroni isn't as good at providing info and software as Adafruit is.

So, I put it aside and bought two Teensy 4.1's
 
Sorry, I know I should probably look through these 6 pages carefully and maybe my internal questions have already been answered elsewhere.

For example wondering about is, how compatible are the sources and functionality on the Teensy 4 and 4.1 on CircuitPython versus MicroPython.

I just setup my Windows machine to build CircuitPython, so I thought I would play.

But I wonder things like: On my T4.1 that has MicroPython on it, the internal SD card appears to work, I have not tried it too much, but was able to use: ampy to store and retrieve files from the sdcard. Will this also work on CircuitPython. I am pretty sure it does not show up on the MSC drive. I probably double check that.

What about support for the other other hardware components? Like Serial, SPI, I2C?
I probably just need to experiment, but was looking at the board configuration files:

Like under Teensy4.1, the pins.c file I see:
Code:
    { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO_AD_B0_03) },
    { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_03) },

    { MP_OBJ_NEW_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_GPIO_AD_B0_03) },
    { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO_AD_B0_02) },

    { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO_AD_B0_02) },
    { MP_OBJ_NEW_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_GPIO_AD_B0_02) },
But I don't see any anything under pins 7 and 8 for rx2/tx2...

Where in the Micropython stuff I see things in files like mpconfigboard.h:
Code:
// UART config: 8 UARTs at the pins for Teensy 4.1
#define MICROPY_HW_UART_NUM     (sizeof(uart_index_table) / sizeof(uart_index_table)[0])
#define MICROPY_HW_UART_INDEX   { 0, 6, 4, 2, 3, 8, 1, 7, 5 }

#define IOMUX_TABLE_UART \
    { IOMUXC_GPIO_AD_B0_12_LPUART1_TX }, { IOMUXC_GPIO_AD_B0_13_LPUART1_RX }, \
    { IOMUXC_GPIO_AD_B1_02_LPUART2_TX }, { IOMUXC_GPIO_AD_B1_03_LPUART2_RX }, \
    { IOMUXC_GPIO_AD_B1_06_LPUART3_TX }, { IOMUXC_GPIO_AD_B1_07_LPUART3_RX }, \
    { IOMUXC_GPIO_B1_00_LPUART4_TX }, { IOMUXC_GPIO_B1_01_LPUART4_RX }, \
    { IOMUXC_GPIO_B1_12_LPUART5_TX }, { IOMUXC_GPIO_B1_13_LPUART5_RX }, \
    { IOMUXC_GPIO_AD_B0_02_LPUART6_TX }, { IOMUXC_GPIO_AD_B0_03_LPUART6_RX }, \
    { IOMUXC_GPIO_EMC_31_LPUART7_TX }, { IOMUXC_GPIO_EMC_32_LPUART7_RX }, \
    { IOMUXC_GPIO_AD_B1_10_LPUART8_TX }, { IOMUXC_GPIO_AD_B1_11_LPUART8_RX },
Which gives me the feeling like they maybe support the different uarts...

Sorry again I should probably just try each of these out more to get better understanding of what may work or not.

Also wondering as it looks like CircuitPython was forked from MicroPython, if it would make sense to try to incorporate some of the changes that happened on Micropython after Circuit Python forked?

Thanks again.
 
@KurtE
Since I have the T4.1 setup already I tried running ampy with circuitpython installed.

Doing a 'ls' works:
Code:
....\Micropython>ampy --port /COM33 ls
/.Trashes
/.fseventsd
/.metadata_never_index
/System Volume Information
/boot_out.txt
/code.py
/lib
but trying to put a file on the T4.1 does not:
Code:
D:\Users\Merli\Documents\Micropython>ampy --port /COM33 put bno055.py
Traceback (most recent call last):
  File "d:\python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "d:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "D:\PYTHON27\SCRIPTS\ampy.exe\__main__.py", line 7, in <module>
  File "d:\python27\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "d:\python27\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "d:\python27\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "d:\python27\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "d:\python27\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "d:\python27\lib\site-packages\ampy\cli.py", line 264, in put
    board_files.put(remote, infile.read())
  File "d:\python27\lib\site-packages\ampy\files.py", line 214, in put
    self._pyboard.exec_("f = open('{0}', 'wb')".format(filename))
  File "d:\python27\lib\site-packages\ampy\pyboard.py", line 279, in exec_
    raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', '', 'Traceback (most recent call last):\r\n  File "<stdin>", line 1, in <module>\r\nOSError: [Errno 30] Read-only filesystem\r\n')

On the other hand, as you mentioned, putting the same file with Micropython installed works but puts all uploaded files on the sdcard if one is installed into the builtin sdcard on the T4.1. Didn't try it with no sdcard though.
 
@KurtE
As mentioned, been working on an update to circuitpython so you can change the clock speed - basically is a port of clock.c from the T4 core.

1. In /ports/mimxrt10xx/common-hal/microcontroller the file Processor.c has to be updated to:
View attachment Processor.c

2. In ports/mimxrt10xx/peripherals/mimxrt10xx clocks.h should change to:
View attachment clocks.h

and

3. In ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062 clocks.c should change to:
View attachment clocks.c

How to call it I have no idea - maybe someone can take it from here

EDIT: or what else needs to be changed .... FYI @tannewt
 
Last edited:
quick update:
Which gives me the feeling like they maybe support the different uarts...

Ran the script up on the page: https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial
And output shows:


Code:
RX pin: board.D15 	 TX pin: board.D14
RX pin: board.D25 	 TX pin: board.D24
RX pin: board.D16 	 TX pin: board.D17
RX pin: board.D21 	 TX pin: board.D20
RX pin: board.DAT3 	 TX pin: board.D20
RX pin: board.D0 	 TX pin: board.D1
RX pin: board.D52 	 TX pin: board.D1
RX pin: board.D28 	 TX pin: board.D29
RX pin: board.D34 	 TX pin: board.D35
RX pin: board.D48 	 TX pin: board.D35
RX pin: board.D21 	 TX pin: board.DAT2
RX pin: board.DAT3 	 TX pin: board.DAT2
RX pin: board.D0 	 TX pin: board.D53
RX pin: board.D52 	 TX pin: board.D53
RX pin: board.D7 	 TX pin: board.D8
So looks like it is possible
 
Back
Top