Advertise here

Adafruit 0.56" 7-Segment Backpack and SAMD21 Xplained pro

Adafruit 0.56" 7-Segment Backpack and SAMD21 Xplained pro




if you want to display numbers using 7 segment , there are many choices to choose from , in this quick tutorial I will use Adafruit 0.56" 7-Segment Backpack based on HT16K33 (controlled through I2C ).




I re-write the code based on Adafruit library to work with Atmel studio and ASF4




you can use any ATMEL/Microchip Xplained pro / mini board to run this code "but you need to setup your configuration first on Atmel start
Connection 

7segment          samd21 xplained Pro

      SCL          >>        PA09
      SDA         >>        PA08
      VCC         >>        VCC(3.3V)
      GND        >>         GND

I write the code without a library so you can use it to build your own library 

functions 

begin(address) 

start I2C communication , default address 0x70

void setBrightness(uint8_t b)

set the brightness for the 7 segment ,where

b : brightness level ( 0 - 15 )

writeDigitNum(digit ,number,dot)

write a number to a specific digit   
where 

digit : where to write the number
number : number to display 
dot : if you want the dot to be on or off


void printNumber(long n, uint8_t base)

display an integer number , where 

n: number 

base: number format (BIN,DEC,HEX)

void printFloat(double n, uint8_t fracDigits, uint8_t base)

print a float number ,where

n: number 
fracDigits: number of fractional number to display
base:number format (BIN,DEC,HEX)

void drawColon(bool state)
void writeColon(void)

draw a colon and active it using writeColon function



simple Code: 


simple demo code to show you the basic functions 



display Time using built-in RTC 



this is another code to display time on the 7 segment 




disadvantage: SAMD21 doesn't have a backup battery (no VDD line for RTC voltage source) so you will lost the time whenever you power it off or reset the board . 



SAMD21 Calendar driver isn't accurate , the time will lag least 15-20min everyday ! so I recommend you to use external RTC for better results





No comments

Powered by Blogger.