0

AVR Library for WS2803 LED Driver IC

ledySo today I will be sharing with you one of my maybe not so recent but reliable libraries. It is for WS2803 which I think is really cool IC that allows you to control outputs with PWM using SPI to control data being sent.

 

The amount of components needed is really minimal as we only need to provide one single reference resistor which will limit the amount of current for our outputs.

 

One thing you could ask is how do you connect to it without a lot of hustle ? Well I personally for my electronical challenges use ATB Development boards manufactured by Atnel.pl. Reason for this specific set ? Well first of all it is extremely high quality packed with all items which you would even imagine you could need 😀 Take a look …

 

What you see here below is previous version and the newest and shiniest version of ATB devboard.
2016-06-25 225703

2016-06-25 225650

 

Packed like this I’m ready to challenge the WS2803 … I won’t be providing connection schematics as internet and datasheet are available all over the internet.

Library is available under here and you can just go ahead and download it. Since I have been developing this on AVR Atmega32 it is using hardware SPI defined in SPI library.

The only pins you need there is MOSI and CLK. This is all needed to drive WS2803. Since there is no magic in sending data using SPI protocol let’s dive into WS803 library.

Before you begin I think you should now that I have written my own implementation of delay function. Reason for that is in this version I haven’t used interrupts and needed to be able to control delays with variables.

static inline void delay_ms(uint16_t count) 
{
  while(count--) 
  {
      delay_ms(1);
  }
}

Once you add library files to you project you will need to first define yourself buffer. I have tendency of defining how many outputs I will have and using that definition in the rest of my program.

So you could do the following to start …

define WS2803_LED_CNT 18 

uint8_t ws_buf[ WS2803_LED_CNT ];
uint8_t * ptrBuf = ws_buf;

 

Now we are ready to start fun…. easiest is to try and light out all of LEDs ( outputs ). For this we will use function which operating on memory sets all values in our buffer to single value

ws2803_set_all( ptrBuf , 255);    
ws2803_shift_out( ptrBuf ); 
delay_ms(3000);

Easy 🙂 Well – most up to date is always the github and there you will be able to find remaining functions and some examples i.e.

  • Fade in
  • Fade out
  • Draw line
  • Light up one by one

RafPe_WS2803__Repository_with_library_designed_to_drive_ws2803_from_AVR

0

CNC your custom usb slide-in PCB

So I had troubles properly naming title of this post. So as a short explanation my passion also includes electronics 🙂 and today I felt like playing with USB and RS232 ( reason for that will be obvious in one of later posts ).

Now in order to get this working I could most probably just get USB port and solder some cables into it but I think this would totally miss the idea of fun – especially in my case.

So where do we start ? We need to make a design ? No problemos 🙂 using Eagle CAD I have created board schematic ( as in my case schematic for electronics is not needed 🙂 )

The final design after a moment looked like this :

usbslider_01

 

So that was the easy part right ? Well yes 🙂 However I do not forget that “sharing is caring” thats why you can download the project here

 

Ok so how do we get our project from digital world to our matrix 🙂 ? There are several available methods :

  • Chemical etching
  • UV
  • CNC
  • Order your PCB at professional services

 

In my experience I have already been through chemical etching and though it works nice – yeah….. at certain point you get tired of all that action you need to execute . UV I have not yet played with ( but it also includes chemical toys ). Professional services is also not an option as this project is so small and I need it kinda … now 🙂 so we are left with cool one …. CNC

2016-06-21 231039

 

 

Now with help of a bit of machine software and some PCB material I got the board ready in like 7 minutes. Machine is capable of faster operations but with PCB I would be risking damage to reallllyyyyy small drill bits ( talking from expensive experience here 🙁 ) so thats perfectly fine with me. After machine was done I was presented with the following view 🙂

IMG-20160620-WA0003

 

hey ya! That is what I wanted 🙂 However for next version I will need to ditch that outline margin as it was nice enough to connect all points of my board which for USB is not so good !

From there only a bit of soldering and some hot tube to isolate remains and we got this :

 

2016-06-21 221342

2016-06-21 222812

 

As it may not look sooooo super PRO 🙂 but this is a POC prototype to make sure when I need more and order from professional services I get exactly what I expect.

 

If you are using CNC for PCB – leave a comment – interested in your approach

 

 

 

0

Ansible – Using template lookup

For some of actions / modules / roles it might be that you would like to use your Jinja template as variable. I have been looking some time for this lookup module. Therefore to save you from crawling over internet this is how could you use it

Example of Jinja template

  location ~ \.php$ {
    try_files $uri =404;
    root           /var/www/htdocs/;
    fastcgi_pass   unix:/var/run/php65-php-fpm.sock;
    fastcgi_intercept_errors        on;
    fastcgi_buffers 256 16k;
    fastcgi_max_temp_file_size 0;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;

    {% if env is defined and env=="testos" %}
    auth_basic           "Ninja Test ";
    auth_basic_user_file {{ nginx_basic_auth }} ;
    {% endif %}
  }

And then within our playbook we define it as following

---
- name: Testing
  hosts: localhost
  vars:
    - blabla: "Testing123"
    - testing: "{{ lookup('template', 'template.j2') }}"

  tasks:
  - debug: msg="{{testing}}"

 

Are you using this in other way ? Comment whats your approach 🙂

0

Ansible – Using dictionary to deploy pem certificates

When automating certificate deployments I wanted to have smart way of deploying them. So I went ahead and decided to use dictionaries.

For this example my variables looked more like as following :

ssl_certificates:
    domain_uno_com:
      owner: haproxy
      group: haproxy
      mode: "u=r,go="
      certificate: |
                                              -----BEGIN CERTIFICATE-----
                                              dslkajfafak234h23o4h32jkh43jqtghkjafhads;fhd89fuad9f6a8s7f6adsf
                                              < ..................... bogus info uno ...................... >
                                              yjEdslkajfafak234h23o4h32jkh43jZlcmlTaWduLCBJbmMuMR8wHQYDVQQL23
                                                -----END CERTIFICATE-----
      key: |
                                              -----BEGIN PRIVATE KEY-----
                                              dslkajfafak234h23o4h32jkh43jqtghkjafhads;fhd89fuad9f6a8s7f6adsf
                                              < ..................... bogus info uno ...................... >
                                              yjEdslkajfafak234h23o4h32jkh43jZlcmlTaWduLCBJbmMuMR8wHQYDVQQL23
                                              Edslkajfafak234h==
                                              -----END PRIVATE KEY-----
      
    domain_duo_com:
      owner: haproxy
      group: haproxy
      mode: "u=r,go="
      certificate: |
                                              -----BEGIN CERTIFICATE-----
                                              dslkajfafak234h23o4h32jkh43jqtghkjafhads;fhd89fuad9f6a8s7f6adsf
                                              < ..................... bogus info duo ...................... >
                                              yjEdslkajfafak234h23o4h32jkh43jZlcmlTaWduLCBJbmMuMR8wHQYDVQQL23
                                                -----END CERTIFICATE-----
      key: |
                                              -----BEGIN PRIVATE KEY-----
                                              dslkajfafak234h23o4h32jkh43jqtghkjafhads;fhd89fuad9f6a8s7f6adsf
                                              < ..................... bogus info duo ...................... >
                                              yjEdslkajfafak234h23o4h32jkh43jZlcmlTaWduLCBJbmMuMR8wHQYDVQQL23
                                              Edslkajfafak234h==
                                              -----END PRIVATE KEY-----

 

Once we have that within our playbook we will be using the following actions to create ourselves pem files

       - name: SSL certificates Web | Create certificate key files
         copy:
           dest: "{{web_ssl_folder}}/{{ item.key.replace('_','.') }}.pem"
           content: "{{ item.value.certificate + '\n' + item.value.key }}"
           owner: "{{ item.value.owner }}"
           group: "{{ item.value.group }}"
           mode: "{{ item.value.mode }}"
         with_dict: ssl_certificates
         no_log: true

 

Now when we run our playbook what will happen is we will get within folder defined under web_ssl_folder  new certificates called respectively domain.uno.com.pem and domain.duo.com.pem.

Of course if you add more entries you will get more created. So for you the only thing to change from here is the owner and possibly the rights ( although think twice 🙂 )

9

Vyos – Site to site VPN using VTI and OSPF

Hey! So today we will be challenging setup of vyos site-to-site VPN. In theory there is nothing really difficult about that one – its just choosing the right options.

What I would really would like to highlight here which I believe is quite useful ( although not always possible to achieve ) is to use VTI ( Virtual Tunnel Interface ) instead of local/remote prefixes ( more reading here ). So let’s get to do it 🙂 All of these commands will be part of single commit.

First we tackle the virtual interface

set interfaces vti vti0 address 10.1.0.1/32
set interfaces vti vti0 description 'VPN_VTI0'

Of course description is optional however I like the system to be well described so other people can also benefit from understanding quickly what and why is it.

Next I fill out phase 1 and phase 2 settings. And here I cannot help much as it will differ per endpoint you are setting your vpn with. So treat this only as point of reference

# Phase 2 
set vpn ipsec esp-group ESP-Default compression 'disable' 
set vpn ipsec esp-group ESP-Default lifetime '3600' 
set vpn ipsec esp-group ESP-Default mode 'tunnel' 
set vpn ipsec esp-group ESP-Default pfs 'dh-group2' 
set vpn ipsec esp-group ESP-Default proposal 1 encryption '3des' 
set vpn ipsec esp-group ESP-Default proposal 1 hash 'sha1' 

# Phase 1 
set vpn ipsec ike-group IKE-Default dead-peer-detection action 'clear' 
set vpn ipsec ike-group IKE-Default dead-peer-detection interval '30' 
set vpn ipsec ike-group IKE-Default dead-peer-detection timeout '90' 
set vpn ipsec ike-group IKE-Default ikev2-reauth 'no' 
set vpn ipsec ike-group IKE-Default key-exchange 'ikev1' 
set vpn ipsec ike-group IKE-Default lifetime '86400' 
set vpn ipsec ike-group IKE-Default proposal 1 dh-group '2' 
set vpn ipsec ike-group IKE-Default proposal 1 encryption 'aes256' 
set vpn ipsec ike-group IKE-Default proposal 1 hash 'sha256'

 

Cool – so we got the base – now we need to define which interface will handle our VPN traffic

set vpn ipsec ipsec-interfaces interface 'eth1' 
set vpn ipsec logging log-modes 'all'

 

And then I move to configuring site-to-site vpn

# Setup the site-2-site config
set vpn ipsec site-to-site peer <remote-IP-address> authentication id '<local-WAN-IP-address>' 
set vpn ipsec site-to-site peer <remote-IP-address> authentication mode 'pre-shared-secret' 
set vpn ipsec site-to-site peer <remote-IP-address> authentication pre-shared-secret 'this-Of-course-Is-Some-paaaassshpraseeee' 
set vpn ipsec site-to-site peer <remote-IP-address> connection-type 'initiate' 
set vpn ipsec site-to-site peer <remote-IP-address> default-esp-group 'ESP-Default' 
set vpn ipsec site-to-site peer <remote-IP-address> ike-group 'IKE-Default' 
set vpn ipsec site-to-site peer <remote-IP-address> ikev2-reauth 'inherit' 
set vpn ipsec site-to-site peer <remote-IP-address> local-address '<local-WAN-IP-address>' 

Once done we need to associate our VTI interface with this site to site VPN. This is done by issuing the following

# Make use of our VTI interface
set vpn ipsec site-to-site peer <remote-IP-address> vti bind vti1
set vpn ipsec site-to-site peer <remote-IP-address> vti esp-group ESP-Default

 

Cool – easy wasn’t ? 🙂 Now we can configure OSPF. I did mine this way

set protocols ospf parameters router-id <remote-IP-address>
set protocols ospf area 0.0.0.0 network 192.168.1.0/24
set protocols ospf area 0.0.0.0 network 192.168.2.0/24
set interfaces vti vti0 ip ospf network point-to-point

 

Full config as usual available in github

 

 

Any experience on challenges ? Maybe better ways ? Post in comments!