[vc_row][vc_column][vc_column_text]![]()
Linker 4-digit 7-segment module is a Four Yang digital tube display module with 12 pins, the driver chip is TM1637, Just need 2 root signal lines can control four digital tube through micro controller; following we will use WiringPi to drive the LED Bar:
(refer to the library, plz refer to http://learn.linksprite.com/raspberry-pi/guide-on-how-to-use-gpio-on-raspberry-pi/)[/vc_column_text][vc_tour][vc_tab title=”Hardware prepare” tab_id=”1427941865-1-41″][vc_column_text]RaspberryPi x1
Linker 4-digit 7-segment module x1
Linker Cable x1[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram ” tab_id=”1427941865-2-32″][vc_column_text]
[/vc_column_text][/vc_tab][vc_tab title=”Test code ” tab_id=”1427942481286-2-6″][vc_column_text]
#include "TM1637.h"
#define clk 4//pins definitions for TM1637 and can be changed to other ports
#define dio 5
int setup()
{
if(wiringPiSetup()==-1)
{
printf("setup wiringPi failed ! n");
return 1;
}
pinMode(clk,INPUT);
pinMode(dio,INPUT);
delay(200);
TM1637_init(clk,dio);
TM1637_set(BRIGHTEST,0x40,0xc0);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
printf("Digital Tube test code!n");
printf("Using DATA = GPIO5, CLK = GPIO4.n");
}
int main()
{
int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F
int8_t ListDisp[4];
unsigned char i = 0;
unsigned char count = 0;
delay(150);
setup();
while(1)
{
unsigned char BitSelect = 0;
i = count;
count ++;
if(count == sizeof(NumTab)) count = 0;
for(BitSelect = 0;BitSelect < 4;BitSelect ++)
{
ListDisp[BitSelect] = NumTab[i];
i ++;
if(i == sizeof(NumTab)) i = 0;
}
TM1637_display(0,ListDisp[0]);
TM1637_display(1,ListDisp[1]);
TM1637_display(2,ListDisp[2]);
TM1637_display(3,ListDisp[3]);
delay(500);
}
}
[/vc_column_text][/vc_tab][vc_tab title=”Run Test ” tab_id=”1427942487551-3-7″][vc_column_text]1.Download the file: include TM1637.h/TM1637.c/Makefile(click to download: TestLibrary)
2. Unzip: copy the TM1637.h/TM1637.c/Makefile to the directory:pi@raspberrypi ~/wiringPi/wiringPi ( replace the Makerfile under the current directory) the excute pi@raspberrypi ~/wiringPi/wiringPi $ make and compile ,make then the TM1637.o file will generate at the current directory.
3. Build a .c file and write the example code to it/save:$vi digitaltube_test.c
4.Compile the code: $ gcc digitaltube -o digitaltube ../wiringPi/TM1637.o -lwiringPi
5.Run the code: $sudo ./digitaltube
6.The result as following:

Leave a Reply
You must be logged in to post a comment.