• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeRaspberry PiLinker Kit for Raspberry PiHow to use Linker LED Bar on the Raspberry
Previous Next

How to use Linker LED Bar on the Raspberry

Posted by: admin , March 30, 2015

[vc_row][vc_column][vc_column_text]图片1

The work principle of Linker LED Bar is like our normal LED, only our LED Bar use one LED driver chip MY9221 to drive it, then the several module will be in  series together. MY9221 is similar to the LED driver chip as SPI, could drive 12 LED lamps, and the light of each LED lamp can be PWM modulated by the date which the serial port send in.

We will use the WiringPi to drive the LED Bar.[/vc_column_text][vc_tour][vc_tab title=”Hardware Prepare ” tab_id=”1427719016-1-39″][vc_column_text]RaspberryPi  x1

Linker ADC Base For RPi   x1

Linker LED Bar   x1

Linker Cable   x1[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1427719016-2-8″][vc_column_text]Connect Linker LED Bar to JP7’s Base Board with linker Cable(Notice the cover of the wire must short connect to VCC and 3V3)

图片2

图片3[/vc_column_text][/vc_tab][vc_tab title=”Test Code” tab_id=”1427720258085-2-6″][vc_column_text]

/*
* LED bar test program for RaspberryPi
* www.linksprite.com
*/
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
 
#define DATA_Pin 4  //DATA IN
#define CLK_Pin  5  //CLK IN
 
#define CmdMode  0x0000  // Work on 8-bit mode
#define ON 0x00ff       // 8-bit 1 data
#define SHUT 0x0000     // 8-bit 0 data
 
static int s_clk_flag = 0;
 
void send16bitData(unsigned int data)
{
    int i;
    for(i=0;i<16;i++)
    {
        if(data & 0x8000)
        {
            digitalWrite(DATA_Pin, HIGH);
        }
        else
        {
            digitalWrite(DATA_Pin, LOW);
        }
 
        if(s_clk_flag)
        {
            digitalWrite(CLK_Pin, LOW);
            s_clk_flag = 0;
        }
        else
        {
            digitalWrite(CLK_Pin, HIGH);
            s_clk_flag = 1;
        }
    delayMicroseconds(10);
        data <<= 1;
    }
}
 
//latch routine for MY9221 data exchange
void latchData(void)
{
    int latch_flag = 0;
    int i;
    digitalWrite(DATA_Pin, LOW);
    delayMicroseconds(500);
    for(i=0;i<8;i++)
    { 
        if(latch_flag)
        {
            digitalWrite(DATA_Pin, LOW);
            latch_flag = 0;
        }
        else
        {
            digitalWrite(DATA_Pin, HIGH);
            latch_flag = 1;
        } 
    }
    delayMicroseconds(500);
} 
 
 
void sendLED(unsigned int LEDstate)
{
  unsigned char i;
  for(i=0;i<12;i++)
  {
    if(LEDstate&0x0001)
      send16bitData(ON);
    else
      send16bitData(SHUT);
    LEDstate=LEDstate>>1;
  }
}
 
int setup()
{
    printf("LED bar test code!n");
    printf("Using DATA = GPIO4, CLK = GPIO5.n");   
    
    if(wiringPiSetup()==-1)
    {
    printf("setup wiringPi failed ! n");
    return 1;
    }
           
    pinMode(DATA_Pin,OUTPUT);   //Data pin
    pinMode(CLK_Pin,OUTPUT);  //CLK pin
    digitalWrite(DATA_Pin, LOW);
    digitalWrite(CLK_Pin, LOW);
    s_clk_flag = 0;
}
 
int main()
{
  setup();
  while(1)
  {
    unsigned int i = 0x0000;
    unsigned int loop = 0x0;
    while(i<=0x03ff)
   {
     send16bitData(CmdMode); //set LED Bar mode
     sendLED(i);     //send LED Bar data
     latchData();  //make it come into effect
     i=i*2+1;
     delay(100);
   }
  }
}

[/vc_column_text][/vc_tab][vc_tab title=”Slide” tab_id=”1427720776178-3-0″][vc_column_text]1. Build a new.c file to write the example code and save :$vi led_bar_test.c

2.Compile the code :$ gcc led_bar_test.c -o led_bar -lwiringPi

3.Run the code :$sudo ./led_bar

4.The result : As the following, the led bar will flash as following

图片4[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors