PCB Christmas Tree

by Marius_M in Circuits > Microcontrollers

393 Views, 2 Favorites, 0 Comments

PCB Christmas Tree

WhatsApp Image 2023-12-02 at 16.45.31_17408963.jpg
PCB Christmas Tree - GIF.gif
WhatsApp Image 2023-12-02 at 16.38.13_fe34d811.jpg
WhatsApp Image 2023-12-02 at 16.45.31_a7cdff25.jpg
PCB Christmas Tree - GIF.gif

Just another PCB Christmas tree, using an ATtiny85 / ATtiny13A.

This project was partially inspired by the awesome project of @nqtronix.

I changed the microcontroller with a more popular one. Also changed some other aspects.

There are 11 LEDs controlled by four ATtiny pins, plus a TTP223 touch sensor linked to another ATtiny pin which acts as a switch who toggle between different lightning patterns (including an OFF "pattern").

I designed the PCB in order to be able to use SMD 1206 LEDs or classic 3mm LEDs.

You can order the PCBs from PCBWay: https://www.pcbway.com/project/shareproject/PCB_Christmas_Tree_2023_dedf2242.html

Please read this entirely before start.

Supplies

In order to get started you will need :

  • 1x Christmas Tree PCB;
  • 1x ATtiny 85 / 13A;
  • 1x TTP223E;
  • 1x microUSB connector (used only for power);
  • 1x AMS1117 3.3V SOT223;
  • 1x 30pF capacitor;
  • 1x 0.1uF capacitor;
  • 1x 1kΩ resistor;
  • 1x 0805 LED;
  • 2x 1uF capacitor;
  • 11x 470Ω resistor;
  • 11x 1206 LEDs (or classic 3mm LEDs);
  • Soldering iron + soldering wire;
  • Arduino IDE;
  • Flashing clip.

Few Words About the PCB

WhatsApp Image 2023-12-02 at 16.38.13_1f49e63e.jpg

Please be aware when you order the PCB. The PCB is designed for a thickness of 1.2mm.

If you want to use SMD LEDs you need to order the PCB with a 1.2mm thickness, otherwise you won't be able to solder the SMD LEDs.

If you plan to use regular 3mm LEDs and for any reason you want a 1.6 mm thick PCB, you have to adjust the width of those middle cuts (where PCBs interconnect with each other and make them 1.6mm as well).

Soldering

WhatsApp Image 2023-12-02 at 16.38.13_b1bf3267.jpg
WhatsApp Image 2023-12-02 at 16.38.13_3e107584.jpg
WhatsApp Image 2023-12-02 at 16.38.13_57c957cc.jpg
WhatsApp Image 2023-12-02 at 16.38.13_2106726c.jpg

The PCB is designed to allow the vertical mount of the SMD LEDs on the edges of those cutouts. This way you can see them from both sides of the PCB.

In order to do that you have to apply some solder on one of the pads and then place the LED on the edge with the help of a tweezer.

Use the same tweezer to keep the led against that edge and apply some more solder until the pads on the LED connect with the PCB pad.

It will become easier after few LEDs but it will be hard anyway.

Is definitely easier to use normal 3mm LEDs (just beware to the polarity), but to be honest I like it more with the SMD LEDs.

After you finish with the LEDs, proceed to solder the resistors, the TTP223 touch sensor and the microUSB connector.


Software and Flashing

145583569-b59e9766-1832-4188-b715-24c346c8e05d.jpeg

Implementation

I'm just a regular guy passionate about making stuff, so don't expect a very neat code. Is not that neat and pretty but it works ! ☺

I used Arduio IDE and ATtiny registers in order to reduce the size of it a little bit, so I can upload it into ATtiny13A as well (as you know ATtiny13A, have a lot less memory available).

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/wdt.h>


// Define pins for switch the LED, plus the chosen interrupt for reacting to


#define INTERRUPT_PIN PCINT2  // This is PB2 per the schematic
#define DATADIRECTIONPIN DDB2 //page 64 data sheet
#define INT_PIN PB2           // Interrupt pin of choice: PB1 (same as PCINT2) - Pin 7


#define LED_PIN1 PB0           // PB0 - Pin 5
#define LED_PIN2 PB1           // PB1 - Pin 6
#define LED_PIN3 PB3           // PB3 - Pin 2
#define LED_PIN4 PB4           // PB4 - Pin 3


/*
 * Alias for the ISR: "PCINT_VECTOR" (Note: There is only one PCINT ISR. 
 * PCINT0 in the name for the ISR was confusing to me at first, 
 * hence the Alias, but it's how the datasheet refers to it)
 */
#define PCINT_VECTOR PCINT0_vect     


volatile uint8_t pushCount = 0; // variables used within ISR must be declared Volatile.


void setup() {
    cli();                    // Disable interrupts during setup
    
    DDRB = (1 << LED_PIN1) | (1 << LED_PIN2) 
         | (1 << LED_PIN3) | (1 << LED_PIN4); //replaces pinMode(LED_PIN1, OUTPUT);


    //configuring and enabling the interrupt 
 
    PCMSK |= (1 << INTERRUPT_PIN);    // Enable interrupt handler (ISR) for our chosen interrupt pin (PCINT1/PB1/pin 6)


    GIMSK |= (1 << PCIE);             // Enable PCINT interrupt in the general interrupt mask


    DDRB &= ~(0 << DATADIRECTIONPIN);  //replaces pinMode(INT_PIN, INPUT);
    
    PORTB |= (1<< INT_PIN); //disable pull-up. Must hook up pulldown resistor [ 1K ].


    sei();                            // enable interrupts after setup


}


void loop() {


  switch(pushCount){
    case 0 :
    pattern1();
    break;
    case 1 :
    pattern2();
    break;
    case 2 :
    pattern3();
    break;
    case 3 :
    pattern4();
    break;
    default:
    pattern1();
  }


}


// This is the interrupt handler called when there is any change on the INT_PIN
// ISR is defined in the headers - the ATtiny85 only has one handler
ISR(PCINT_VECTOR)
{
    if((PINB >> PINB2)&1!=0) {  // or if ( (PINB & PINB2) != 0 ) or (PINB >> PINB2)&1
      if(pushCount > 3) {
        pushCount = 0;
      }else{
        pushCount ++;
      }   
  }
  delay(50); //small debounce
}


void pattern1(){
  PORTB |= (1 << LED_PIN2) | (1 << LED_PIN4); //replaces digitalWrite(LED_PINx,HIGH);
  delay(150);
  PORTB &= ~((1 << LED_PIN2) | (1 << LED_PIN4)); //replaces digitalWrite(LED_PINx,LOW);
  delay(150);
  PORTB |= (1 << LED_PIN1) | (1 << LED_PIN3); 
  delay(150);
  PORTB &= ~((1 << LED_PIN1) | (1 << LED_PIN3));
  delay(150);
}


void pattern2(){
  PORTB |= (1 << LED_PIN1);
  delay(200);
  PORTB &= ~(1 << LED_PIN1);
  PORTB |= (1 << LED_PIN3);
  delay(200);
  PORTB &= ~(1 << LED_PIN3);
  PORTB |= (1 << LED_PIN2);
  delay(200);
  PORTB &= ~(1 << LED_PIN2);
  PORTB |= (1 << LED_PIN4);
  delay(200);
  PORTB &= ~(1<< LED_PIN4);
  
}


void pattern3(){
  PORTB |= (1 << LED_PIN2) | (1 << LED_PIN4);
  delay(80);
  PORTB &= ~((1 << LED_PIN2) | (1 << LED_PIN4));
  delay(80);
  PORTB |= (1 << LED_PIN2) | (1 << LED_PIN4);
  delay(80);
  PORTB &= ~((1 << LED_PIN2) | (1 << LED_PIN4));
  delay(80);
  PORTB |= (1 << LED_PIN1) |  (1 << LED_PIN3);
  delay(80);
  PORTB &= ~((1 << LED_PIN1) | (1 << LED_PIN3));
  delay(80);
  PORTB |= (1 << LED_PIN1) |  (1 << LED_PIN3);
  delay(80);
  PORTB &= ~((1 << LED_PIN1) | (1 << LED_PIN3));
  delay(80);
}


void pattern4(){  // POWER OFF
  PORTB &= ~((1 << LED_PIN1) | (1 << LED_PIN2) | (1 << LED_PIN3) | (1 << LED_PIN4)); //LEDs off
  power_off();
}


void power_off()
{
    cli();                               // Disable interrupts before next commands
    wdt_disable();                       // Disable watch dog timer to save power
    set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode power down
    sleep_enable();
    sleep_bod_disable(); // Disable brown-out detector
    sei();               // Enable interrupts
    sleep_cpu();
    sleep_disable();
}


Compiling and Uploading


BEWARE ! - you must upload the sketch BEFORE soldering the microcontroller to the PCB ! You can try to do it after, but sometimes you'll get an uploading error, so is safer to do it before soldering.

As I said earlier, I'm just a regular guy, so I stick to the basics and I used Arduino IDE to compile and upload the sketch. Depending on what kind of microcontroller do you use, you will need one of the following board packages installed in your Arduino IDE:

For ATtiny85 you will need damellis attiny board package installed https://github.com/damellis/attiny then :

  • Go to Tools -> Board -> ATtiny Microcontrollers and select ATtiny25/45/85.
  • Go to Tools and choose the following board options:
  • Processor: ATtiny85
  • Clock: Internal 1 Mhz
  • Programmer: Arduino as ISP

For ATtiny13/13A you will need MCUdue MicroCore board package installed https://github.com/MCUdude/MicroCore then:

  • Go to Tools -> Board -> MicroCore and select ATtiny13.
  • Go to Tools and choose the following board options:
  • BOD: 1.8 V
  • EEPROM: Retained
  • Clock: 1.2 Mhz internal
  • Timming: Micros disabled
  • Programmer: Arduino as ISP slow (MicroCore)


In order to upload the sketch I used a programmer testing clip ( https://www.aliexpress.com/item/1005002401064440.html ) and an Arduino Uno board.



Final Assembly

WhatsApp Image 2023-12-02 at 16.52.35_96d88090.jpg
WhatsApp Image 2023-12-02 at 16.50.27_5b3d1a83.jpg

After you flashed the sketch to your ATtiny proceed to solder it to the PCB and connect the two parts together.

BEWARE - in the lower part of the PCBs there are two little circles that needs to face each other  when you solder the PCBs together (see the picture).

After you placed the PCBs in the right way, align them properly and then solder all of the connecting pads.

Connect a microUSB cable and enjoy your little PCB Christmas tree ! ☺