EP-0098: Difference between revisions

From 52Pi Wiki
Jump to navigation Jump to search
m (Yoyojacky moved page DockerPi NightLight SKU: EP-0098 to EP-0098)
 
(46 intermediate revisions by 3 users not shown)
Line 7: Line 7:
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.
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.
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 Power expansion board to provide more power.


The module is stacked on the top layer and can be placed with acrylic decoration for better show.
The module is stacked on the top layer and can be placed with acrylic decoration for better show.
Line 13: Line 13:
==Features==
==Features==
[[File:Nlddl06.jpg|right|300px]]
[[File:Nlddl06.jpg|right|300px]]
* Easy to setup
* DockerPi Series
* Programmable
* Control directly(without programming)
* Extend the GPIO Pins
* WS2812 RGB LEDs
* WS2812 RGB LEDs
* Extend the GPIO Pins
* Independent control of each LED
* Can be mounted on top of the stack
* 2 * Demo acrylic supports your quick start
* Can Stack with other Stack board such as Relay module
* 2 * Blank acrylic supports your custom ideas
* Individual control of each Light
* Recommended to be stacked at the top
* With beautiful acrylic light guide,Two factory-made patterns, two of them are blank for you DIY
* Can Stack with other Stack board
* Plug and Play
* Independent of the mainboard hardware (require I2C support)
* One command control
 
* Multiple Programming Language support such as shell, python, C/C++ and so on
==Official Compatibility Test==
==Compatibility List==
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)
* Compatibility
{| class="wikitable" style="text-align: center;"  
{| class="wikitable" style="text-align: center;"  
|-
|-
!Platform !!Nightlight Hat board !! Notes
!Platform !!DockerPi Nightlight!! Notes
|-
|Raspberry Pi 3 Model A Plus|| √ ||
|-
|Raspberry Pi 3 Model B Plus|| √ ||
|-
|Raspberry Pi zero || √||
|-
|-
| Raspberry Pi zero W  || √||
|Raspberry Pi All Platform|| √ ||Not Include CM Series & EOL Platform
|-
|-
|Raspberry Pi 3 Model B|| √||
|Banana Pi M3 || √ ||Python 3 & Modify DEVICE_BUS to 2
|-
|-
|Raspberry Pi 2 Model B|| √||
|Orange Pi Zero || √ || Python 3 & Modify DEVICE_BUS to 0
|-
|Raspberry Pi Model B+|| √||
|-
|-
|}
|}
Line 47: Line 41:
==Gallery==
==Gallery==
{|  
{|  
|[[File:Nlddl02.jpg| 300px| left]]
|[[File:Nlddl04.jpg| 320px| left]]
|[[File:Nlddl03.jpg| 300px| none]]
|[[File:Nlddl01.jpg| 320px| none]]
|[[File:Nlddl04.jpg| 300px| none]]
|}
----
{|
|[[File:Nlddl01.jpg| 300px| left]]
|[[File:Nlddl05.jpg| 300px| none]]
|[[File:Nlddl07.jpg| 300px| none]]
|}
|}


==Package Includes==
==Package Includes==
[[File:Nlddl08.jpg|left|300px]]
* 1 x DockerPi NightLight
<br style="clear:both;">
* 4 x M2.5*12 + 6 Copper stick
* 1 x NightLight Hat Board For Raspberry Pi
* 4 x M2.5*6 Nut
* 4 x M2.5x12 copper sticks
* 4 x M2.5*6 Half-round head screw
* 4 x M2.5x6  screws (Botton)
* 1 x Instructions
* 4 x M2.5x10 screws (Top)
* 1 x Acrylic Pattern Design (Stander)  
* 1 x Acrylic Pattern Design (Stander)  
* 4 x Acrylic Pattern Design (2x Caved and 2x blank)
* 4 x Acrylic Pattern Design (2x Demo and 2x Blank)
 
==How to use it==
* Turn on the I2C interface
Open a terminal and Run sudo raspi-config<br>
Use the down arrow to select 5 Interfacing Options.<br>
Arrow down to P5 I2C .<br>
Select yes when it asks you to enable I2C.<br>
Also select yes if it asks about automatically loading the kernel module.<br>
Use the right arrow to select the <Finish> button.<br>
Select yes when it asks to reboot.<br>
* Detect the register of the chip on board
<code> i2cdetect -y 1 </code><br>
you will see this result:
[[File:Nightlighti2c09.png|left|300px]]
<br style="clear:both;">
* Lights up one LED
<code> i2cset -y 1 0x15  0x01 0xff </code><br>
<Pre> 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</pre>


==Register Map==
==Register Map==
{| class="wikitable" style="text-align: center;"  
{| class="wikitable" style="text-align: center;"  
|-
|-
!Register Number !! Color !! Mark
!Register Address!! Function !! Value
|-
|-
|0x01|| red color || No.1 LED
| 0x01 || LED1 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
|0x02|| green color || No.1 LED
| 0x02 || LED1 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
|0x03|| blue color || No.1 LED
| 0x03 || LED1 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x04||red color || No.2 LED
| 0x04 || LED2 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x05||green color|| No.2 LED
| 0x05 || LED2 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x06 ||blue color || No.2 LED
| 0x06 || LED2 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x07 || red color || No.3 LED
| 0x07 || LED3 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x08 || green color || No.3 LED
| 0x08 || LED3 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x09 || blue color || No.3 LED
| 0x09 || LED3 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
|0x0a|| red color || No.4 LED
| 0x0a || LED4 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
|0x0b|| green color || No.4 LED
| 0x0b || LED4 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
|0x0c|| blue color || No.4 LED
| 0x0c || LED4 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x0d||red color || No.5 LED
| 0x0d || LED5 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x0e||green color|| No.5 LED
| 0x0e || LED5 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x0f ||blue color || No.5 LED
| 0x0f || LED5 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x10 || red color || No.6 LED
| 0x10 || LED6 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x11 || green color || No.6 LED
| 0x11 || LED6 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x12 || blue color || No.6 LED
| 0x12 || LED6 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x13||red color || No.7 LED
| 0x13 || LED7 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x14||green color|| No.7 LED
| 0x14 || LED7 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x15 ||blue color || No.7 LED
| 0x15 || LED7 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x16 || red color || No.8 LED
| 0x16 || LED8 Red || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x17 || green color || No.8 LED
| 0x17 || LED8 Green || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x18 || blue color || No.8 LED
| 0x18 || LED8 Blue || 0(FULL OFF) - 255(FULL ON)
|-
|-
| 0x19 || button || 0x01 - Button Pressed  0x00 - Button Released
| 0x19 || Button || 0x01 - Button Pressed  0x00 - Button Released/Manually Reset
|}
|}


==Example Demo==
==Configuring I2C(Raspberry Pi)==
* Shell script
Run '''sudo raspi-config''' and follow the prompts to install i2c support for the ARM core and linux kernel<br />
simple script to light up all LED's individually in a loop.<br>
Go to '''Interfacing Options'''
[[File:Raspi-config-1.png |none|320px]]
then '''I2C'''
[[File:Raspi-config-2.png |none|320px]]
Enable!
[[File:Raspi-config-3.png |none|320px]]
Done!
[[File:Raspi-config-4.png |none|320px]]
 
==Direct control without programming(Raspberry Pi)==
The following script demonstrates turn on and turn off each LED.<br>
<pre>
<pre>
#!/bin/bash
# lights up each LED individually in a loop.
#!/bin/bash
#!/bin/bash
#


LED_array=(0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18)
for i in $(seq 1 24)
while true
do
do
         for i in `seq 0 24`
         i2cset -y 1 0x15 $i 0xFF  # turn on the led
        do
        sleep 0.5
                i2cset -y 1 0x15 ${LED_array[i]} 0xFF  # turn on the led  
        i2cset -y 1 0x15 $i 0x00  # turn of the led
                sleep 0.5                               # delay
        sleep 0.5
                i2cset -y 1 0x15 ${LED_array[i]} 0x00  # turn of the led
                sleep 0.5                               # delay
        done
done
done
</pre>
</pre>
save this script in a file named "nightlight.sh" and then give it executive permission:<br>
==Program in Language C(Raspberry Pi)==
<code> chmod +x nightlight.sh </code><br>
Create source code and name it "led.c"<br>
<code> sudo ./nightlight.sh </code><br>
----
* Test DEMO in Language C
Please make sure your Raspberry Pi has been already connected to internet <br>
In this demo, please make sure you have installed wiringPi library before you compile this C code.<br>
<pre>
sudo apt-get update
sudo apt-get -y install git-core
cd
git clone git://git.drogon.net/wiringPi
cd ~/wiringPi
git pull origin
cd ~/wiringPi
./build
</pre>
** Test wiringPi’s installation
run the gpio command to check the installation:
<pre>
gpio -v
gpio readall
</pre>
That should give you some confidence that it’s working OK.<br>
And then create a file called "nightlight.c" and write following code:
<pre>
<pre>
#include <stdio.h>
#include <stdio.h>
Line 235: Line 180:


</pre>
</pre>
save it and then compile it by this command:<br>
Compile!
<code> gcc nightlight.c -lwiringPi -o nightlight </code><br>
 
run it:<br>
<code>gcc led.c -lwiringPi -o led</code><br>
<code> sudo ./nightlight  </code><br>
 
Exec It!
 
<code>./led</code><br>
----
----
* Python script
 
you can also use Python script to driver the board.<br>
==Program in Language Python(Raspberry Pi)==
first, make sure you have installed "smbus2" library.<br>
The following code is recommended to be executed using Python 3 and install the '''smbus''' library:<br>
if not, please open a terminal and input python and then:<br>
<code>sudo pip3 install smbus2 </code><br>
and then Create a new file named " nightlight.py" and copy and paste this code:<br>
<pre>
<pre>
#!/usr/bin/env python
#
import time as t
import time as t
import smbus
import smbus
import sys


DEVICE_BUS = 1
DEVICE_BUS = 1
Line 264: Line 208:
             t.sleep(0.2)  
             t.sleep(0.2)  
     except KeyboardInterrupt as e:
     except KeyboardInterrupt as e:
        sys.exit()
         print("Quit the Loop")
         print("Quit the Loop")
</pre>
</pre>
save it and run:
<code> python nightlight.py </code><br>
----
----
==Program in Java(Raspberry Pi)==
Create a new file named:NightLight.java and paste following code:
<pre>
import java.io.IOException;
import java.util.Arrays;
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException;
import com.pi4j.platform.PlatformAlreadyAssignedException;
import com.pi4j.util.Console;
public class NightLight {
    public static final int DOCKERPI_NIGHTLIGHT_BOARD = 0x19;
    public static final byte RESET_BIT = (byte) 0x00;
    // NightLight Address
    public static final int NIGHTLIGHT_REG_ADDR = 0x15;
    // LED of NightLight
    public static final byte LED1_RED = (byte) 0x01;
    // NightLight LED status
    public static final byte NIGHTLIGHT_ON = (byte) 0xFF;
    public static final byte NIGHTLIGHT_OFF = (byte) 0x00;
    public static void main(String[] args)
            throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {
        int i = 1;
        final Console console = new Console();
        I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);
        I2CDevice device = i2c.getDevice(DOCKERPI_NIGHTLIGHT_BOARD);
        while (true) {
            if (device.read(BUTTON_ADDR) == 0x01) {
                console.println("the button has been pressed");
                device.write(BUTTON_ADDR, RESET_BIT);
                i++;
                if (i > 2) {
                    i = 1;
                }
            }
            if (i == 1) {
                console.println("Turn off LED!");
                device.write(LED1_RED, NIGHTLIGHT_OFF);
                Thread.sleep(5000);
            }
            if (i == 2) {
                console.println("Turn on LED!");
                device.write(LED1_RED, NIGHTLIGHT_ON);
                Thread.sleep(5000);
            }
        }
    }
}
</pre>
*Compile it and running:
<pre>javac NightLight.java -classpath .:/opt/pi4j/lib/'*'</pre>
<pre>sudo java -classpath .:classes:/opt/pi4j/lib/'*' NightLight</pre>
==Keywords==
==Keywords==
* nightlight, dockerpi, raspberry pi, light, i2c, smbus2, iot
* DockerPi,RGB,RGB LED,WS2812,Colorful
 
==Video Tutorial==
==Video Tutorial==
[[File:Youtube.jpeg|thumb|left|200px]]
[[File:Youtube.jpeg|thumb|left|200px]]

Latest revision as of 18:24, 27 August 2021

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 Power 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)
  • Extend the GPIO Pins
  • WS2812 RGB LEDs
  • Independent control of each LED
  • 2 * Demo acrylic supports your quick start
  • 2 * Blank acrylic supports your custom ideas
  • Recommended to be stacked at the top
  • Can Stack with other Stack board
  • 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 Platform Not Include CM Series & EOL Platform
Banana Pi M3 Python 3 & Modify DEVICE_BUS to 2
Orange Pi Zero Python 3 & Modify DEVICE_BUS to 0

Gallery

Nlddl04.jpg
Nlddl01.jpg

Package Includes

  • 1 x DockerPi NightLight
  • 4 x M2.5*12 + 6 Copper stick
  • 4 x M2.5*6 Nut
  • 4 x M2.5*6 Half-round head screw
  • 1 x Instructions
  • 1 x Acrylic Pattern Design (Stander)
  • 4 x Acrylic Pattern Design (2x Demo and 2x Blank)

Register Map

Register Address 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 LED2 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/Manually Reset

Configuring I2C(Raspberry Pi)

Run sudo raspi-config and follow the prompts to install i2c support for the ARM core and linux kernel
Go to Interfacing Options

Raspi-config-1.png

then I2C

Raspi-config-2.png

Enable!

Raspi-config-3.png

Done!

Raspi-config-4.png

Direct control without programming(Raspberry Pi)

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

Program in Language C(Raspberry Pi)

Create source code and name it "led.c"

#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);
                }
        }
}

Compile!

gcc led.c -lwiringPi -o led

Exec It!

./led


Program in Language Python(Raspberry Pi)

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

import time as t
import smbus
import sys

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:
        sys.exit()
        print("Quit the Loop")

Program in Java(Raspberry Pi)

Create a new file named:NightLight.java and paste following code:

import java.io.IOException;
import java.util.Arrays;

import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException;
import com.pi4j.platform.PlatformAlreadyAssignedException;
import com.pi4j.util.Console;

public class NightLight {

    public static final int DOCKERPI_NIGHTLIGHT_BOARD = 0x19;
    public static final byte RESET_BIT = (byte) 0x00;

    // NightLight Address
    public static final int NIGHTLIGHT_REG_ADDR = 0x15;

    // LED of NightLight
    public static final byte LED1_RED = (byte) 0x01;

    // NightLight LED status
    public static final byte NIGHTLIGHT_ON = (byte) 0xFF;
    public static final byte NIGHTLIGHT_OFF = (byte) 0x00;

    public static void main(String[] args)
            throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

        int i = 1;
        final Console console = new Console();

        I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);
        I2CDevice device = i2c.getDevice(DOCKERPI_NIGHTLIGHT_BOARD);

        while (true) {
            if (device.read(BUTTON_ADDR) == 0x01) {
                console.println("the button has been pressed");
                device.write(BUTTON_ADDR, RESET_BIT);
                i++;
                if (i > 2) {
                    i = 1;
                }
            }
            if (i == 1) {
                console.println("Turn off LED!");
                device.write(LED1_RED, NIGHTLIGHT_OFF);
                Thread.sleep(5000);
            }
            if (i == 2) {
                console.println("Turn on LED!");
                device.write(LED1_RED, NIGHTLIGHT_ON);
                Thread.sleep(5000);
            }
        }
    }
}
  • Compile it and running:
javac NightLight.java -classpath .:/opt/pi4j/lib/'*'
sudo java -classpath .:classes:/opt/pi4j/lib/'*' NightLight

Keywords

  • DockerPi,RGB,RGB LED,WS2812,Colorful

Video Tutorial

Youtube.jpeg