I²C/SPI peripheral device driver for collection for MicroPython.
The name of this repository has been changed from "mp_driver" to "mikan" (2022 Nov 02).
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
- Real Time Clock (RTC)
- PCF2131 (for both I²C and SPI interface can be used)
- PCF85263A
- PCF85063A
- PCF85063TP
- PCF85053A
- Temperature sensor
- LED controller
- GPIO expander
- LCD driver
- I²C bus multiplexer/switch
- Protocol bridge
- SC16IS7xx ( Single UART, Dual UART )
- SC18IS606
- Stepper motor controller
- Accelerometer
- Analog Front-End
- Bus repeater (I²C buffer)
- PCA9617A :No class driver available since this device doesn't need software control. Evaluation board demo code only
- Level shifter (Voltage translator)
- NTS0304E :No class driver available since this device doesn't need software control. Evaluation board demo code only
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 is available which was explained above.
Take following step1 and step2 to complete the installation.
Follow this video to install MicroPython into the MCU board. This is an example of i.MXRT1050-EVK.
https://youtu.be/L2AVKoXI4vI
Need to copy 'mikan' class driver into the MCU board storage. The guide video shows how to copy using Thonny.
https://youtu.be/rG8MwNkk9xs
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 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.
The example code files are in examples/general/
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 I²C 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 | Folder | Description | Device type |
---|---|---|---|---|
💡 | LED_controller.py | example/general/ | Simple sample: making an LED_controller instance and how PWM can be controlled | PCA9955B, PCA9956B, PCA9957, PCA9632 |
💡 | LED_gradation_ctrl.py | example/general/ | Gradation control (hardware) feature demo | PCA9955B, PCA9957 |
💡 | LED_instance.py | example/general/ | Using another class to abstract LED controllers | PCA9955B, PCA9956B, PCA9957 |
💡 | LED_demo.py | example/general/ | Showing idea to use ‘LED class’ to manage LED and white LED individually | PCA9955B, PCA9956B, PCA9957, PCA9632 |
💡 | LED_demo_dual_om13321.py | example/general/ | Showing idea to use ‘LED class’ to manage multiple LED controller devices | PCA9956B |
⏰ | RTC_demo_PCF2131_ARD.py | example/general/ | Operate a PCF2131 through MicroPython’s machine.RTC equivalent APIs. Using 2 interrupt lines | PCF2131 |
⏰ | RTC_demo_PCF2131-ARD_demo(I2C).py | example/ARD_boards/ | Operate a PCF2131 through MicroPython’s machine.RTC equivalent APIs. Using 2 interrupt lines (Similar to RTC_demo_PCF2131_ARD.py ) |
PCF2131 |
⏰ | RTC_demo_PCF2131-ARD_demo(SPI).py | example/ARD_boards/ | Operate a PCF2131 through MicroPython’s machine.RTC equivalent APIs. Using 2 interrupt lines (Similar to RTC_demo_PCF2131_ARD.py ) |
PCF2131 |
⏰ | RTC_demo_PCF2131-ARD_simple(I2C).py | example/ARD_boards/ | Simple operation sample through MicroPython’s machine.RTC equivalent APIs. | PCF2131 |
⏰ | RTC_demo_PCF2131-ARD_simple(SPI).py | example/ARD_boards/ | Simple operation sample through MicroPython’s machine.RTC equivalent APIs. | PCF2131 |
⏰ | RTC_demo_PCF85063AT-ARD.py | example/ARD_boards/ | Operation sample through MicroPython’s machine.RTC equivalent APIs. Using alarm interrupt | PCF85063A |
⏰ | RTC_demo_PCF85263ATL-ARD.py | example/ARD_boards/ | Operation sample through MicroPython’s machine.RTC equivalent APIs. Using alarm and timestamp interrupts | PCF85263A |
⏰ | RTC_demo_PCF85063TP-ARD.py | example/ARD_boards/ | Operation sample through MicroPython’s machine.RTC equivalent APIs. | PCF85063TP |
⏰ | RTC_demo_PCF85053A-ARD.py | example/ARD_boards/ | Operation sample through MicroPython’s machine.RTC equivalent APIs. Using alarm interrupt | PCF85053A |
🌡️ | temp_sensor_simple_PCT2075_LM75B.py | example/general/ | Very simple sample to operate a temp sensor | LM75B, PCT2075 |
🌡️ | temp_sensor_simple_P3T1085_P3T1755_P3T1035_P3T2030.py | example/general/ | Very simple sample to operate a temp sensor with different I²C pin assign. | P3T1085, P3T1755, P3T1035, P3T2030 |
🌡️ | temp_sensor_simple_P3T1085_P3T1755_P3T1035_P3T2030-ARD.py | example/ARD_boards/ | Similar to “temp_sensor_simple.py” but different I²C pin assign. | P3T1085, P3T1755, P3T1035, P3T2030 |
🌡️ | temp_sensor_demo_PCT2075DP-ARD.py | example/ARD_boards/ | Operate with interrupt and heater-resister on ARD board | PCT2075 |
🌡️ | temp_sensor_demo_P3T1085UK-ARD.py | example/ARD_boards/ | Similar to “temp_sensor_demo_PCT2075DP-ARD” but no heater operation | P3T1085 |
🌡️ | temp_sensor_demo_P3T1755DP-ARD.py | example/ARD_boards/ | Similar to “temp_sensor_demo_PCT2075DP-ARD” but no heater operation | P3T1755 |
🌡️ | temp_sensor_demo_P3T1035_P3T2030-ARD.py | example/ARD_boards/ | All 8 sensors operated together | P3T1035, P3T2030 |
↕ | GPIO_demo.py | example/general/ | Operation sample of a PCA9555 API | PCA9555 |
↕ | GPIO_demo_PCAL6xxxA-ARD.py | example/general/ | Operation sample of a PCAL6xxx ARD board | PCAL6408, PCAL6416, PCAL6524, PCAL6534 |
↕ | GPIO_PCAL6534A-ARD_simple.py | example/ARD_boards/ | Operation sample of a PCAL6534 ARD board | PCAL6534 |
↕ | GPIO_PCAL6534A-ARD_demo.py | example/ARD_boards/ | Operation sample of a PCAL6534 ARD board. Using interrupt | PCAL6534 |
↕ | GPIO_PCAL9722A-ARD_simple.py | example/ARD_boards/ | Operation sample of a PCAL9722 API | PCAL9722 |
↕ | GPIO_PCAL9722-ARD_demo.py | example/ARD_boards/ | Operation sample of a PCAL9722 ARD board. Using interrupt | PCAL9722 |
🔠 | LCD_demo_PCA8561AHN-ARD.py | example/general/ | Shows direct ON/OFF of segments and using putc(), puts() methods | PCA8561 |
💁 | protocol_bridge_SC16IS7xx.py | example/general/ | Operate an I²C/SPI to UART protocol bridge through MicroPython’s machine.UART equivalent APIs. | SC16IS7xx |
💁 | protocol_bridge_SC18IS606_with_AT25010.py | example/general/ | 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 | example/general/ | Operating stepping motor with simple API | PCA9629A |
🔄 | stepper_motor_5_motors.py | example/general/ | Operating 5 instances of PCA9629A class | PCA9629A |
🍎 | accelerometer.py | example/general/ | Simple 3 axis data capturing from FXOS8700 or FXLS8974 | FXOS8700, FXLS8974 |
🍎 | magnetometer.py | example/general/ | Simple compass application using FXOS8700 | FXOS8700 |
🌊 | afe.py | example/general/ | Simple AFE (NAFE13388) operation to show measured voltage on 2 input channels | NAFE13388 |
- | BusSwitch_PCA9846PW-ARD.py | example/ARD_boards/ | Demo to show I²C bus switch function with EEPROMs | PCA9846 |
- | BusRepeater_PCA9617ADP-ARD.py | example/ARD_boards/ | Demo to show I²C bus repeater (buffer) function with several signal voltages combinations using an EEPROM | PCA617A |
- | LevelShifter_NTS0304EUK-ARD.py | example/ARD_boards/ | Demo to show level shifter (voltage translator) function with several signal voltages combinations using a digital potentiometer | NTS0304E |
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
Refer to How a new device can be added?
💡⏰🌡️↕🔠🔄💁🍎🌊