💡 ⏰ 🌡️ ↕ 🔠 🔄 💁 🍎
"mikan" Peripheral device driver for collection for MicroPython.
The name of this repository has been changed from "mp_driver" to "mikan" (2022 Nov 02).
Warning
As of 2023 May 04, MicroPython v1.20.0 is available. Use this 1.20.0 for MIMXRT1170-EVK. It's a stable version for the MIMXRT1170-EVK.
For MIMXRT1050-EVKB, you may face a problem when you install the files. It seems the v1.20.0 is not stable to access from PC to flash storage. Use v1.19.1 for proper operation.
It seems the storage operation problem is fixed in latest v1.20 nightly build MIMXRT1050_EVK-20230503-unstable-v1.20.0-39-g61b8e1b2d.bin. This could be an option to play 'mikan' on the MIMXRT1050-EVKB.
What is this?
NXP peripheral device drivers (SDK) for MicroPython and its usage examples and demo.
The drivers provided to operate I²C/SPI peripheral devices. It enables quick evaluation and rapid demo development by simple intuitive interface (API) and flexible MicroPython environment.
Refer to YouTube video (English version), (Japanese version) to find what can be done.
Arduino® Shields Solutions boards and I²C peripheral evaluation boards with
i.MX RT1050 Evaluation Kit
Screen shot of examples/temp_sensor_interrupt.py
examples/temp_sensor_demo_PCT2075DP_ARB.py
operation
"remote_demo" running. Device operation can be done from web browser
Supported devices
- Real Time Clock (RTC)
- Temperature sensor
- LED controller
- GPIO expander
- LCD driver
- Protocol bridge
- SC16IS7xx ( Single UART, Dual UART )
- SC18IS606
- Stepper motor controller
- Accelerometer
Getting started
Note
Install can be done with a package management tool called:mip
.
It can be done with command ofmpremote mip install github:teddokano/mikan
.
Usingmpremote
is easy way to install the library. However it needs to setup the tool on your PC. So in this document, manual install steps described to do it in simple way.
The steps
The instllation can be completed in 2 steps as follows.
- Step 1
- Install MicroPython into the MCU board (Follow instraction to MicroPython download page for each MCU boards).
- Step 2
- Check sys.path (module serch path) on target board
- Connect your MCU board and PC, get REPL environment. When the MIMXRT1050_EVK is connected to terminal, press 'Ctrl + b' keys to get prompt (exit from 'raw' mode).
- Check path setting by typing..
Then you will get list of path like (in case of the MIMXRT1050_EVK)>>> import sys >>> print(sys.path)
or (in case of Raspberry Pi Pico)['', '.frozen', '/flash', '/flash/lib']
['', '.frozen', '/lib']
- Copy "nxp_periph" folder into target's' "lib" (it could be '/flash/lib' or '/lib') directory. For file/folder copying, some tools can be used like Thonny, rshell, etc.
- Now it's ready to play! Choose an example code in "example" folder and run.
- Check sys.path (module serch path) on target board
Video guide
Video guide is available which was explained above.
Take following step1 and step2 to complete the installation.
Step 1: Install MicroPython on the MCU board
Follow this video to install MicroPython into the MCU board. This is an example of i.MXRT1050-EVK.
https://youtu.be/L2AVKoXI4vI
Step 2: Install 'mikan' into the MCU board
Need to copy 'mikan' class driver into the MCU board storage. The guide video shows how to copy using Thonny.
https://youtu.be/rG8MwNkk9xs
What is inside?
Drivers
The drivers are main part of this repo.
The driver code files are in nxp_periph/
.
The drivers are provided as class-libraries with device names (type-numbers). With this class-libraries, the device operations are highly abstracted and simplified. Methods of the class-drivers enables major features of devices and and provides register level access for user custom operation.
For example, for the LED controller (PCA9955B) ...
from machine import I2C # Importing 'I²C' class library from MicroPython's 'machine' module
from utime import sleep # Importing 'sleep' from MicroPython's 'utime' module
from nxp_periph import PCA9955B # Importing the device class library of 'PCA9955B'
i2c = I2C( 0, freq = (400 * 1000) ) # Making an instance of I²C with 400kHz clock setting
led_c = PCA9955B( i2c ) # Making an instance of PCA9955B which is connected to the 'i2c'.
while True: # Looping following part forever
led_c.pwm( 0, 0.5 ) # Letting PCA9955B channel 0 as 50% PWM output
sleep( 0.1 ) # Waiting 0.1 second
led_c.pwm( 0, 0.0 ) # Letting PCA9955B channel 0 as 50% PWM output
sleep( 0.1 ) # Waiting 0.1 second
If register access is needed, write_registers()
and read_registers()
methods are available (for any devices). It takes register name or index/address as first argument.
For write_registers()
second argument is an integer or a list. When it is an integer, the value is written. If the list is given, the values in the list are wrtten into consecutive registers.
For read_registers()
, second argument specifies the number of bytes to read. If it is '1', method returns an integer value. If it is '>1', list will be returned.
led_c.write_registers( "LEDOUT0", [ 0xAA, 0xAA, 0xAA, 0xAA ] ) # example of four 0xAA writing into consecutive registers from "LEDOUT0"
Next sample is a temperature sensor operation. Simple interface enables just read the temperature in celcius.
from machine import I2C # Importing 'I²C' class library from MicroPython's 'machine' module
from utime import sleep # Importing 'sleep' from MicroPython's 'utime' module
from nxp_periph import PCT2075 # Importing the device class library of 'PCT2075'
i2c = I2C( 0, freq = (400 * 1000) ) # Making an instance of I²C with 400kHz clock setting
temp_sensor = PCT2075( i2c ) # Making an instance of PCT2075 which is connected to the 'i2c'.
while True: # Looping following part forever
value = temp_sensor.temp # Reading temperature in celsius value
print( value ) # Showing the value
sleep( 1 ) # Waiting for 1 second
For more information of examples, please find next section of this document.
Examples
The example code files are in examples/
folder.
It shows simple usage examples for the drivers and standalome demo for target devices.
Note
These examples should work on any MicroPython platform but need to absorb hardware difference.
All these examples runs as it is on MIMXRT1050-EVK. If you try on MIMXRT1170-EVK, the hardware I2C has different ID for A4/A5 pins. The ID must be changed from 0 to 2.
Refer to pinout document for each platforms. For i.MXRT, the pinout information is available here.
? | File name | Description | Device type |
---|---|---|---|
LED_controller.py | Simple sample: making an LED_controller instance and how PWM can be controlled | PCA9955B, PCA9956B, PCA9957, PCA9632 | |
💡 | LED_gradation_ctrl.py | Gradation control (hardware) feature demo | PCA9955B, PCA9957 |
💡 | LED_instance.py | Using another class to abstract LED controllers | PCA9955B, PCA9956B, PCA9957 |
💡 | LED_demo.py | Showing idea to use ‘LED class’ to manage LED and white LED individually | PCA9955B, PCA9956B, PCA9957, PCA9632 |
💡 | LED_demo_dual_om13321.py | Showing idea to use ‘LED class’ to manage multiple LED controller devices | PCA9956B |
⏰ | RTC_demo_PCF2131_ARD.py | Operate a PCF2131 through MicroPython’s machine.RTC equivalent APIs. Using 2 interrupt lines | PCF2131 |
RTC_demo_PCF85063AT_ARD.py | Operate a PCF85063 through MicroPython’s machine.RTC equivalent APIs. | PCF85063 | |
temp_sensor_simple.py | Very simple sample to operate a temp sensor | LM75B, PCT2075 | |
🌡️ | temp_sensor_demo_PCT2075DP_ARB.py | Operate with interrupt and heater-resister on ARD board | PCT2075 |
temp_sensor_P3T1085.py | Similar to “temp_sensor_simple.py” but different I2C pin assign. | P3T1085 | |
🌡️ | temp_sensor_demo_P3T1085UK_ARB.py | Similar to “temp_sensor_demo_PCT2075DP_ARB.py” but no heater operation | P3T1085 |
GPIO_demo.py | Operation sample of a PCA9555 API | PCA9555 | |
GPIO_demo_PCAL6xxxA-ARD.py | Operation sample of a PCAL6xxx ARD board. Using interrupt | PCAL6408, PCAL6416, PCAL6524, PCAL6534 | |
🔠 | LCD_demo_PCA8561AHN-ARD.py | Shows direct ON/OFF of segments and using putc(), puts() methods | PCA8561 |
💁 | protocol_bridge_SC16IS7xx.py | Operate an I²C/SPI to UART protocol bridge through MicroPython’s machine.UART equivalent APIs. | SC16IS7xx |
protocol_bridge_SC18IS606_with_AT25010.py | Operate an I²C to SPI protocol bridge through MicroPython’s machine.SPI equivalent APIs. AT25010 as an SPI target | SC18IS606 | |
stepper_motor_simple.py | Operating stepping motor with simple API | PCA9629A | |
stepper_motor_5_motors.py | Operating 5 instances of PCA9629A class | PCA9629A | |
🍎 | accelerometer.py | Simple 3 axis data capturing from FXOS8700 or FXLS8974 | FXOS8700, FXLS8974 |
🍎 | magnetometer.py | Simple compass application using FXOS8700 | FXOS8700 |
Demo (remote demo)
The demo code is avaiable in remote_demo/
.
remote_demo/start_w_auto_IP(DHCP).py
and remote_demo/start_w_fixed_IP.py
are start scripts to run the demo.
This demonstration works with a network connection. The microcontroller performs a HTTP server to provide user interface on web browsers.
For more information, refer to remote_demo/README.md
.
Video is available --> https://youtu.be/usPzhs_2IsI
How to setup? --> https://youtu.be/fkHqdnd4t1s
Applying modification
Refer to How a new device can be added?