Sample Code for Raspberry Pi

This article provides step-by-step instructions on using the Raspberry Pi with the CH423 I2C 24 Digital IO Expansion Module, covering hardware and software setup, wiring diagrams, and detailed guidance on running various sample codes to demonstrate different functionalities.

Hardware Preparation

Software Preparation

- [**CH423 python Library**](https://github.com/cdjq/DFRobot_CH423)
- Download [RASPBIAN Official OS](https://www.raspberrypi.org/downloads/raspbian)

Wiring Diagram

  • Connect this module to the Raspberry Pi via I2C

Driver Installing

1.Enable Raspberry Pi I2C. Skip this step if it is already enabled. Open terminal and input the following commands and press "Enter":

pi@raspberrypi:~ $ sudo raspi-config

Then use the UP/Down keys to select "5 Interfacing Options", press Enter, select "P5 I2C" and press Enter to comfirm "Yes". Restart the Raspeberry Pi board.

2.To install Python dependency library and git, the Raspberry Pi needs to be networked. Skip this step if already installed. In the terminal, input the following commands and press Enter:

pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

3.Download the DFRobot_CH423 driver library. In the terminal, type the following commands and press Enter:

pi@raspberrypi:~ $ cd Desktop/ `pi@raspberrypi:~/Desktop $ git clone https://github.com/DFRobot/DFRobot_CH423

Sample Code 1 - demo_blink

  • In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_CH423/python/raspberry/examples
pi@raspberrypi:~/Desktop/DFRobot_CH423/python/raspberry/examples/ $ python demo_blink.py

Sample Code 2 - demo_group

  • In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_CH423/python/raspberry/examples`
`pi@raspberrypi:~/Desktop/DFRobot_CH423/python/raspberry/examples/ $ python demo_group.py

##Sample Code 3 - demo_input

  • In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_CH423/python/raspberry/examples`
`pi@raspberrypi:~/Desktop/DFRobot_CH423/python/raspberry/examples/ $ python demo_input.py

Sample Code 4 - demo_interrupt

  • In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_CH423/python/raspberry/examples`
`pi@raspberrypi:~/Desktop/DFRobot_CH423/python/raspberry/examples/ $ python demo_interrupt.py

Sample Code 5 - demo_sleep

  • In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_CH423/python/raspberry/examples`
`pi@raspberrypi:~/Desktop/DFRobot_CH423/python/raspberry/examples/ $ python demo_sleep.py

Sample Code 6 - demo_water_lamp

  • In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_CH423/python/raspberry/examples`
`pi@raspberrypi:~/Desktop/DFRobot_CH423/python/raspberry/examples/ $ python demo_water_lamp.py

Was this article helpful?

TOP