To be able to run the code for the Automatic Magnetic Loop Tuner, that was written for a Teensy 3.2, on a Teensy 4.0 the following changes needed to be done. First I started by changing the version to version 5. It would have been cool to use version 4.0, but that version already existed 😉 So the next best thing was version 5, as a tiny reference to the 5 in my callsign.

ML_v500
The LiquidCristalFast.h library was changed to LiquidCristal.h
The resolution of the ADC was set from 12 (Teensy 3.2) to 10 (Teensy 4.0)
Analogue pins A10 and A12 were assigned.

ML.h
Assigning the pins to the input and output. Just as in the Teensy 3.2 version, Pfwd is assigned to pin A10 but Pref is assigned to pin A12. In the Teensy 4.0 pin A11 is also ADC0 and we need both a ADC0 and a ADC1, not twice ADC0.

ML_PSWR
Used analogeSyncRead() instead of analogeSynchronizedRead()

ML_TRX
For Icom radio’s set the UART output to opendrain=true and for all the others to opendrain=false

ML__Switches_and_Stepper
As the ADC only has 10 bit (1024) compared to 12 bit (4096), we had to divide all values by 4 to know which button is pressed.

Github
The source code is available on Github: https://github.com/ON5IA/ML_v500

Disclaimer
Currently the code works when the Automatic Magnetic Loop Tuner is connected to an Icom IC-7300. Please be aware the Teensy 4.0 is not 5V tolerant, so make sure you never exceed 3,3V on your inputs.

2 Replies to “Changes made to the code to be able to run on a Teensy 4.0”

  • Hi,
    Thanks for porting Loftur’s magnetic loop tuner firmware for teensy 4.0.
    I had fix an issue which I already had in Lofturs’s code.
    I had to comment out the line
    lcd.createChar(0,0); in ML_v500.ino
    According to Arduino reference: “ When referencing custom character “0”, if it is not in a variable, you need to cast it as a byte, otherwise the compiler throws an error.”
    With tis line in the code there were no visible characters on the lcd screen.
    After removing or commenting out this line the code works as expected.
    Since there are no custom characters in the firmware, this line can be removed without consequences.
    Kind regards,
    BĂ©la / HB9HEY

  • Hi BĂ©la, thanks for letting me know. I’ve updated the code and pushed it to Github.
    I’ve also noticed some other changes I can do, but that will be done later.
    73!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.