EP-0098

From 52Pi Wiki
Jump to navigation Jump to search

DockerPi NightLight

Nlddl01.jpg

Description

DockerPi NightLight is a DockerPi series expansion board with 8 WS2812 RGB LEDs. The expansion board communicates with I2C protocol. It can be used in Raspberry Pi, Jetson Nano and other single board computers (require I2C peripherals).

You can programmatically control the color of each LED, such as Python or C, or you can control the color of each LED directly through system commands without programming. Most Linux distributions include the i2c-tools, which allows you to control this.

DockerPi NightLight can only be used one, but can be stacked with other DockerPi expansion board. If you need to run for a long time, we also recommend that you use our DockerPi expansion board to provide more power.

The module is stacked on the top layer and can be placed with acrylic decoration for better show.

Features

Nlddl06.jpg
  • DockerPi Series
  • Programmable
  • Control directly(without programming)
  • WS2812 RGB LEDs
  • Extend the GPIO Pins
  • Recommended to be stacked at the top
  • Can Stack with other Stack board
  • Independent control of each LED
  • 2 * Pre-make acrylic supports your quick start
  • 2 * Blank acrylic supports your custom ideas
  • Independent of the mainboard hardware (require I2C support)

Official Compatibility Test

Not only support the following development boards, other development boards can be compatible if they have I2C peripherals. (Note: some software changes may be required)

Platform DockerPi Nightlight Notes
Raspberry Pi All Model
Jetson Nano

Gallery

Nlddl02.jpg
Nlddl03.jpg
Nlddl04.jpg

Nlddl01.jpg
Nlddl05.jpg
Nlddl07.jpg

Package Includes

Nlddl08.jpg


  • 1 x DockerPi NightLight
  • 4 x M2.5x12 copper sticks
  • 4 x M2.5x6 screws (Botton)
  • 4 x M2.5x10 screws (Top)
  • 1 x Acrylic Pattern Design (Stander)
  • 4 x Acrylic Pattern Design (2x Caved and 2x blank)

How to use it

  • Turn on the I2C interface

Open a terminal and Run sudo raspi-config
Use the down arrow to select 5 Interfacing Options.
Arrow down to P5 I2C .
Select yes when it asks you to enable I2C.
Also select yes if it asks about automatically loading the kernel module.
Use the right arrow to select the <Finish> button.
Select yes when it asks to reboot.

  • Detect the register of the chip on board

i2cdetect -y 1
you will see this result:

Nightlighti2c09.png


  • Lights up one LED

i2cset -y 1 0x15 0x01 0xff

 The first parameter "0x15" means the address of Nightlight hat.
"0x01" means the first LED's red color, every LED
has a register address, and you can follow this chart, "0xff" means give the LED 100% brightness
and "0x00" will turn of the LED, you can put the value from "0x00" to "0xff" to make a dim LED

Register Map

Register Number Function Value
0x01 LED1 Red 0(FULL OFF) - 255(FULL ON)
0x02 LED1 Green 0(FULL OFF) - 255(FULL ON)
0x03 LED1 Blue 0(FULL OFF) - 255(FULL ON)
0x04 LED2 Red 0(FULL OFF) - 255(FULL ON)
0x05 LED2 Green 0(FULL OFF) - 255(FULL ON)
0x06 LED3 Blue 0(FULL OFF) - 255(FULL ON)
0x07 LED3 Red 0(FULL OFF) - 255(FULL ON)
0x08 LED3 Green 0(FULL OFF) - 255(FULL ON)
0x09 LED3 Blue 0(FULL OFF) - 255(FULL ON)
0x0a LED4 Red 0(FULL OFF) - 255(FULL ON)
0x0b LED4 Green 0(FULL OFF) - 255(FULL ON)
0x0c LED4 Blue 0(FULL OFF) - 255(FULL ON)
0x0d LED5 Red 0(FULL OFF) - 255(FULL ON)
0x0e LED5 Green 0(FULL OFF) - 255(FULL ON)
0x0f LED5 Blue 0(FULL OFF) - 255(FULL ON)
0x10 LED6 Red 0(FULL OFF) - 255(FULL ON)
0x11 LED6 Green 0(FULL OFF) - 255(FULL ON)
0x12 LED6 Blue 0(FULL OFF) - 255(FULL ON)
0x13 LED7 Red 0(FULL OFF) - 255(FULL ON)
0x14 LED7 Green 0(FULL OFF) - 255(FULL ON)
0x15 LED7 Blue 0(FULL OFF) - 255(FULL ON)
0x16 LED8 Red 0(FULL OFF) - 255(FULL ON)
0x17 LED8 Green 0(FULL OFF) - 255(FULL ON)
0x18 LED8 Blue 0(FULL OFF) - 255(FULL ON)
0x19 Button 0x01 - Button Pressed 0x00 - Button Released

Example Demo(Raspberry Pi)

  • Shell Script

The following script demonstrates turn on and turn off each LED.

#!/bin/bash

for i in $(seq 1 24)  
do
        i2cset -y 1 0x15 $i 0xFF   # turn on the led
        sleep 0.5
        i2cset -y 1 0x15 $i 0x00   # turn of the led
        sleep 0.5
done

  • C Language

The following code demonstrates the use of buttons and LEDs.

#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>

#define BUTTON_REG_ADDR 0x19

int main(){
        int fd;
        int is_press = 1;
        int is_draw = 0;
        int i = 0;

        fd = wiringPiI2CSetup(0x15);

        for(i = 1;i<25;i++) wiringPiI2CWriteReg8(fd,i,0x00);

        for(;;)
        {
                if (wiringPiI2CReadReg8(fd, BUTTON_REG_ADDR) == 0x01 )
                {
                        is_press++;
                        is_draw = 1;
                        wiringPiI2CWriteReg8(fd,BUTTON_REG_ADDR, 0x0);
                }
                if(is_press && is_draw){
                        is_draw = 0;
                        for(i = 1;i<25;i++){
                                if(is_press > 3) is_press = 1;
                                if(((i + is_press) % 3) == 0)
                                {
                                        wiringPiI2CWriteReg8(fd,i,0xff);
                                }else{
                                        wiringPiI2CWriteReg8(fd,i,0x00);
                                }
                                delay(100);
                        }

                        wiringPiI2CWriteReg8(fd,BUTTON_REG_ADDR, 0x0);
                }
        }
}

Please note that the library is required for use:
gcc nightlight.c -lwiringPi -o nightlight


  • Python Script

The following code is recommended to be executed using Python 3 and install the smbus library:

import time as t
import smbus

DEVICE_BUS = 1
DEVICE_ADDR = 0x15
bus = smbus.SMBus(DEVICE_BUS)

while True:
    try:
        for i in range(1,25):
            bus.write_byte_data(DEVICE_ADDR, i, 0xFF)
            t.sleep(0.2)
            bus.write_byte_data(DEVICE_ADDR, i, 0x00)
            t.sleep(0.2) 
    except KeyboardInterrupt as e:
        print("Quit the Loop")

Keywords

  • nightlight, dockerpi, raspberry pi, light, i2c, smbus2, iot

Video Tutorial

Youtube.jpeg