diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..e915594e6672ef0207f2f85125a6c84b2edb0dd0
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,40 @@
+  image: docker.io/labrobotica/labrobotica
+
+  variables:
+    GIT_SUBMODULE_STRATEGY: recursive
+
+  stages:
+    - build
+    - test
+    - deploy
+
+  build-package:
+    stage: build
+    script:
+      #- git submodule sync --recursive
+      #- git submodule update --init --recursive
+      - apt update
+      - apt -y install iri-iriutils-dev iri-comm-dev iri-dynamixel-dev
+      - apt -y install gcc-avr avr-libc #firmware dependencies
+      - mkdir -pv build
+      - cd build
+      - cmake -DCMAKE_BUILD_TYPE=RELEASE -DCPACK_PACKAGE_VERSION=$CI_COMMIT_TAG ..
+      - ls ..
+      - make firmware -j $(nproc)
+      - make package -j $(nproc)
+      
+    artifacts:
+      paths:
+        - build/*.deb
+      expire_in: 2 weeks
+    only:
+      - tags
+      
+  update_repo:
+    stage: deploy
+    script:
+      - cd build
+      - "scp -i /root/.ssh/iriLabKeyNopwd -r *battery-monitor*.deb irilabo@147.83.76.226:packages/"
+      - "ssh irilabo@147.83.76.226 -i /root/.ssh/iriLabKeyNopwd -tt /home/irilabo/repo_scripts/update_repo.sh battery-monitor"
+    only:
+      - tags
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
index 6312824c72922d9c617a0bfe5a7e281965e5e29d..23cb002a3f0f59fe7451a3f0dd3f15b4348c77f8 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,4 @@
 [submodule "avr8_smbus_battery_monitor"]
 	path = avr8_smbus_battery_monitor
 	url = ssh://git@gitlab.iri.upc.edu:2202/labrobotica/firmware/avr8_smbus_battery_monitor.git
+	branch = master
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37fdd9d75188f3d5f24b4550052cb0cd2f61923f..3959af14ff99088ff46a0d0ba82e9ca225968d78 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,7 @@ endif(COMMAND cmake_policy)
 
 # The project name and the type of project
 PROJECT(battery_monitor)
+SET(PACKAGE_NAME battery-monitor)
 
 SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
 SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
@@ -65,4 +66,34 @@ ELSE(UNIX)
   )
 ENDIF(UNIX)
 
+IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
+  SET (X86 TRUE)
+  SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
+ELSE ()
+  SET (X86 FALSE)
+  SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
+ENDIF()
 
+IF (UNIX)
+  SET(CPACK_PACKAGE_FILE_NAME "iri-${PACKAGE_NAME}-dev-${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
+  SET(CPACK_PACKAGE_NAME "iri-${PACKAGE_NAME}-dev")
+  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Part of IRI-laboratory libraries. More information at https://gitlab.iri.upc.edu/labrobotica")
+  SET(CPACK_PACKAGING_INSTALL_PREFIX /usr)
+  SET(CPACK_GENERATOR "DEB")
+  SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "labrobotica - labrobotica@iri.upc.edu")
+
+# Uncomment to add the necessary mantainer scripts
+#   SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/debian/preinst;${CMAKE_SOURCE_DIR}/scripts/debian/postinst;${CMAKE_SOURCE_DIR}/scripts/debian/prerm;${CMAKE_SOURCE_DIR}/scripts/debian/postrm")
+SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/debian/preinst;${CMAKE_SOURCE_DIR}/scripts/debian/postinst;${CMAKE_SOURCE_DIR}/scripts/debian/prerm;${CMAKE_SOURCE_DIR}/scripts/debian/postrm;${CMAKE_SOURCE_DIR}/scripts/load_pcspkr;${CMAKE_SOURCE_DIR}/scripts/undo_load_pcspkr.sh")
+
+# Uncomment to add dependencies comma separated
+# SET(CPACK_DEBIAN_PACKAGE_DEPENDS "iri-<package_name>-dev (>= 1.0~${DISTRIB})")
+  SET(CPACK_DEBIAN_PACKAGE_DEPENDS "iri-iriutils-dev (>= 1.0~${DISTRIB}), iri-comm-dev (>= 1.0~${DISTRIB}), iri-dynamixel-dev (>= 1.0~${DISTRIB})")
+
+  INCLUDE(CPack)
+ELSE(UNIX)
+  ADD_CUSTOM_COMMAND(
+    COMMENT "packaging only implemented in unix"
+    TARGET  uninstall
+  )
+ENDIF(UNIX)
\ No newline at end of file
diff --git a/Findbattery_monitor.cmake b/Findbattery_monitor.cmake
index 27623f83806a182b739f2963d7ebb0c27369fcb2..1d21de32df7e4c9c6f90701363d6c764d3aa32d1 100755
--- a/Findbattery_monitor.cmake
+++ b/Findbattery_monitor.cmake
@@ -1,23 +1,24 @@
 #edit the following line to add the librarie's header files
-FIND_PATH(battery_monitor_INCLUDE_DIR battery_monitor.h /usr/include/iri/battery_monitor /usr/local/include/iri/battery_monitor)
+SET(name battery_monitor)
+FIND_PATH(${name}_INCLUDE_DIRS ${name}.h /usr/include/iri/${name} /usr/local/include/iri/${name})
 
-FIND_LIBRARY(battery_monitor_LIBRARY
-    NAMES battery_monitor
-    PATHS /usr/lib /usr/lib/iri/battery_monitor /usr/local/lib /usr/local/lib/iri/battery_monitor)
+FIND_LIBRARY(${name}_LIBRARIES
+    NAMES ${name}
+    PATHS /usr/lib /usr/lib/iri/${name} /usr/local/lib /usr/local/lib/iri/${name})
     
-SET(battery_monitor_INCLUDE_DIRS ${battery_monitor_INCLUDE_DIR})
-SET(battery_monitor_LIBRARIES    ${battery_monitor_LIBRARY})
+SET(${name}_INCLUDE_DIR ${${name}_INCLUDE_DIRS})
+SET(${name}_LIBRARY     ${${name}_LIBRARIES})
 
-IF (battery_monitor_INCLUDE_DIR AND battery_monitor_LIBRARY)
-   SET(battery_monitor_FOUND TRUE)
-ENDIF (battery_monitor_INCLUDE_DIR AND battery_monitor_LIBRARY)
+IF (${name}_INCLUDE_DIRS AND ${name}_LIBRARIES)
+   SET(${name}_FOUND TRUE)
+ENDIF (${name}_INCLUDE_DIRS AND ${name}_LIBRARIES)
 
-IF (battery_monitor_FOUND)
-   IF (NOT battery_monitor_FIND_QUIETLY)
-      MESSAGE(STATUS "Found battery_monitor: ${battery_monitor_LIBRARY}")
-   ENDIF (NOT battery_monitor_FIND_QUIETLY)
-ELSE (battery_monitor_FOUND)
-   IF (battery_monitor_FIND_REQUIRED)
-      MESSAGE(FATAL_ERROR "Could not find battery_monitor")
-   ENDIF (battery_monitor_FIND_REQUIRED)
-ENDIF (battery_monitor_FOUND)
\ No newline at end of file
+IF (${name}_FOUND)
+   IF (NOT ${name}_FIND_QUIETLY)
+      MESSAGE(STATUS "Found ${name}: ${${name}_LIBRARIES}")
+   ENDIF (NOT ${name}_FIND_QUIETLY)
+ELSE (${name}_FOUND)
+   IF (${name}_FIND_REQUIRED)
+      MESSAGE(FATAL_ERROR "Could not find ${name}")
+   ENDIF (${name}_FIND_REQUIRED)
+ENDIF (${name}_FOUND)
diff --git a/README.md b/README.md
index c6cd9a5ab07384c0a2fbc07f53f43d4035f8ffcc..bd3ff6faf7022339cef08adcea3cfd56d0aa7a27 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,64 @@
 battery_monitor library                         {#mainpage}
-================
+============
 
 ## Description
 
 C++ driver to monitor the paylaod battery for the Tibi, Dabo and Teo platforms.
 
+## Installation
+
+* Add the labrobotica repository if it is not already added:
+
+    ``` sudo sh -c 'echo "deb [arch=amd64] http://147.83.76.226/~irilabo/packages xenial main" > /etc/apt/sources.list.d/labrobotica_repo.list' ```
+
+    ``` wget -O - http://147.83.76.226/~irilabo/labrobotica_repo.gpg.key | sudo apt-key add - ```
+
+    ``` sudo apt update ```
+
+* Install the package:
+
+    ``` sudo apt install iri-battery-monitor-dev ```
+
+## Important information
+
+To use this driver is necessary to unload the *ftdi_sio* module, so the device is detected as a serial-usb device.
+This can be achieved with the following command
+   
+   ```sudo rmmod ftdi_sio```
+    
+or executing the following script:
+
+   ```unbind_ftdi_udev.sh -s <serial_number>```
+
+## Disclaimer  
+
+Copyright (C) 20017-2019 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
+
+Mantainer: IRI labrobotica (labrobotica@iri.upc.edu)
+
+Author: shernand (shernand@iri.upc.edu)
+
+All rights reserved.
+
+This file is part of battery_monitor driver library
+battery_monitor driver library is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>
+
+## For developers
+
+<details><summary>click here</summary>
+<p>
+
 ## Dependencies
 
 This package requires of the following system libraries and packages
@@ -19,26 +73,31 @@ This package also requires of the following IRI libraries:
 
  * [iriutils](https://gitlab.iri.upc.edu/labrobotica/algorithms/iriutils "iriutils gitlab page"), a set of basic tools.
  * [comm](https://gitlab.iri.upc.edu/labrobotica/drivers/comm "comm gitlab page"), a set of drivers for standard communication devices.
- * [dynamixel](https://gitlab.iri.upc.edu/labrobotica/drivers/dynamixel "dynamixel gitlab page"), a set of drivers for Dynamixel Bus communications
+ * [dynamixel](https://gitlab.iri.upc.edu/labrobotica/drivers/dynamixel "dynamixel gitlab page"), a driver for dynamixel communication protocol.
+ 
+This package also contains the following packages as Git Submodules:
+
+ * [avr8_smbus_battery_monitor](https://gitlab.iri.upc.edu/labrobotica/firmware/avr8_smbus_battery_monitor), a firmware to read battery information through SMBUS
 
 ## Compilation and installation
 
 Download this repository and create a build folder inside:
 
-> ``` mkdir build ```
+``` mkdir build ```
 
 Inside the build folder execute the following commands:
 
-> ``` cmake .. ```
+``` cmake .. ```
 
 The default build mode is DEBUG. That is, objects and executables include debug information.
 
 The RELEASE build mode optimizes for speed. To build in this mode execute instead
-> ``` cmake .. -DCMAKE_BUILD_TYPE=RELEASE ```
+
+``` cmake .. -DCMAKE_BUILD_TYPE=RELEASE ```
 
 The release mode will be kept until next time cmake is executed.
 
-> ``` make ``` 
+``` make -j $(nproc)``` 
 
 In case no errors are reported, the generated libraries (if any) will be located at the
 _lib_ folder and the executables (if any) will be located at the _bin_ folder.
@@ -46,81 +105,55 @@ _lib_ folder and the executables (if any) will be located at the _bin_ folder.
 In order to be able to use the library, it it necessary to copy it into the system.
 To do that, execute
 
-> ``` make install ```
+``` make install ```
 
-as root and the shared libraries will be copied to */usr/local/lib/iridrivers* directory
-and the header files will be copied to */usr/local/include/iridrivers* dierctory. At
-this point, the library may be used by any user.
+as root and the shared libraries will be copied to */usr/local/lib/iri/battery_monitor* directory
+and the header files will be copied to */usr/local/include/iri/battery_monitor* dierctory.
+At this point, the library may be used by any user.
 
 To remove the library from the system, exceute
 
-> ``` make uninstall ```
+``` make uninstall ```
 
 as root, and all the associated files will be removed from the system.
 
 To generate the documentation execute the following command:
 
-> ``` make doc ```
-
-## How to use it
-
-### Test
-
-A test example is provided, which will output the battery information on the screen.
-
-First, you may need to:
-
- * unload the *ftdi_sio* module, so the device is detected as a serial-usb device:
-
-   * Manually once: 
-
-        ``` sudo rmmod ftdi_sio```
-
-   * Persistently, you can run the provided script
-
-        ```source scripts/unbind_ftdi_udev.sh```
+``` make doc ```
 
- * load the *pcspkr* module, so the motherboard buzzers makes sound when alarms are enabled:
+### Scripts
 
-   * Manually once:
+It's also needed to run some commands, gathered in this script:
 
-        ``` sudo modprobe pcspkr```
+ * Load the *pcspkr* module, so the motherboard buzzers makes sound when alarms are enabled:
 
    * Persistently, you can run the provided script:
 
         ```source scripts/load_pcspkr.sh```
 
-Then you can run the example and see the battery status information on the screen
+   * Or manually once:
 
-> ``` ./bin/battery_monitor_test```
+        ``` sudo modprobe pcspkr```
 
-### Library
+## How to use it
 
 To use this library in an other library or application, in the CMakeLists.txt file, first it is necessary to locate if the library has been installed or not using the following command
 
-> ``` FIND_PACKAGE(<library name>) ```
+``` FIND_PACKAGE(battery_monitor) ```
 
 In the case that the package is present, it is necessary to add the header files directory to the include directory path by using
 
-> ``` INCLUDE_DIRECTORIES(${<librray name>_INCLUDE_DIR}) ```
+``` INCLUDE_DIRECTORIES(${battery_monitor_INCLUDE_DIRS}) ```
 
 and it is also necessary to link with the desired libraries by using the following command
 
-> ``` TARGET_LINK_LIBRARIES(<executable name> ${<library name>_LIBRARY}) ```
-
-## Disclaimer  
-
-Copyright (C) 2009-2018 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
+``` TARGET_LINK_LIBRARIES(<executable name> ${battery_monitor_LIBRARIES}) ```
 
-Mantainer: IRI labrobotics (labrobotica@iri.upc.edu)
+## Examples
 
-Author: shernand (shernand@iri.upc.edu)
-
-This package is distributed in the hope that it will be useful, but without any warranty. It is provided "as is" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program is with you. should the program prove defective, the GMR group does not assume the cost of any necessary servicing, repair  or correction.
-
-In no event unless required by applicable law the author will be liable to you for damages, including any general, special, incidental or consequential damages arising out of the use or inability to use the program (including but not limited to loss of data or data being rendered inaccurate or losses sustained by you or third parties or a failure of the program to operate with any other programs), even if the author has been advised of the possibility of such damages.
-
-You should have received a copy of the GNU Lesser General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>
+There is one example called _test\_battery\_monitor_, which prints the battery information on the screen.
 
+```./bin/battery_monitor_test```
 
+</p>
+</details>
\ No newline at end of file
diff --git a/avr8_smbus_battery_monitor b/avr8_smbus_battery_monitor
index 09ac7168c041ef4fa6cfb9ad2daa314eb4c32684..aec8861f06509bf01008483d7f68abd4ad49b12f 160000
--- a/avr8_smbus_battery_monitor
+++ b/avr8_smbus_battery_monitor
@@ -1 +1 @@
-Subproject commit 09ac7168c041ef4fa6cfb9ad2daa314eb4c32684
+Subproject commit aec8861f06509bf01008483d7f68abd4ad49b12f
diff --git a/src/battery_monitor.h b/include/battery_monitor.h
similarity index 100%
rename from src/battery_monitor.h
rename to include/battery_monitor.h
diff --git a/privileges.sh b/privileges.sh
deleted file mode 100755
index 0f97b5e2a940f211d62105f67a3202364c5b350f..0000000000000000000000000000000000000000
--- a/privileges.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-sudo chown root:audio bin/battery_monitor_test
-sudo chmod u+s bin/battery_monitor_test
diff --git a/scripts/debian/postinst b/scripts/debian/postinst
new file mode 100644
index 0000000000000000000000000000000000000000..6c7c6f8cb9b0ee6538846b7775191f3d31b34390
--- /dev/null
+++ b/scripts/debian/postinst
@@ -0,0 +1,31 @@
+#!/bin/bash
+set -e
+case "$1" in
+  configure)
+    #echo "Running postinst script"
+    
+    # TEST
+    # echo "pkg name $DPKG_MAINTSCRIPT_PACKAGE"
+    # echo "pkg files: dpkg -L <pkg_name>"
+    # dpkg -L $DPKG_MAINTSCRIPT_PACKAGE
+    # TEST
+    
+    #/usr/share/iri/battery_monitor/scripts/unbind_ftdi_udev.sh -s A600eB1Y
+    #/usr/share/iri/battery_monitor/scripts/unbind_ftdi_udev.sh -s A600eByq
+    #/usr/share/iri/battery_monitor/scripts/unbind_ftdi_udev.sh -s A900WSG1
+    # SERIAL DABO: A600eB1Y
+    # SERIAL TIBI: A600eByq
+    # SERIAL TEO:  A900WSG1
+    /var/lib/dpkg/info/iri-battery-monitor-dev.load_pcspkr
+  ;;
+  abort-upgrade)
+
+  ;;
+  abort-remove)
+
+  ;;
+  abort-deconfigure)
+
+  ;;
+esac
+exit 0
\ No newline at end of file
diff --git a/scripts/debian/postrm b/scripts/debian/postrm
new file mode 100644
index 0000000000000000000000000000000000000000..8fa7731c6f72c62a866dd0e99e2d361a9dc78d1d
--- /dev/null
+++ b/scripts/debian/postrm
@@ -0,0 +1,26 @@
+#!/bin/bash
+set -e
+case "$1" in
+  remove)
+    # echo "Running postrm script"
+  ;;
+  purge)
+
+  ;;
+  upgrade)
+
+  ;;
+  disappear)
+
+  ;;
+  failed-upgrade)
+
+  ;;
+  abort-install)
+
+  ;;
+  abort-upgrade)
+
+  ;;
+esac
+exit 0
diff --git a/scripts/debian/preinst b/scripts/debian/preinst
new file mode 100644
index 0000000000000000000000000000000000000000..0a57abee54dd1f29c74acfe75203f2503d156311
--- /dev/null
+++ b/scripts/debian/preinst
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -e
+case "$1" in
+  install)
+    #echo "I'm a preinst script"
+  ;;
+  upgrade)
+
+  ;;
+  abort-upgrade)
+
+  ;;
+esac
+exit 0
diff --git a/scripts/debian/prerm b/scripts/debian/prerm
new file mode 100644
index 0000000000000000000000000000000000000000..4163bc19ce65151e50f6fed7801302715158d2a0
--- /dev/null
+++ b/scripts/debian/prerm
@@ -0,0 +1,31 @@
+#!/bin/bash
+set -e
+case "$1" in
+  remove)
+    #echo "Running prerm script"
+    # TEST
+    # echo "pkg name $DPKG_MAINTSCRIPT_PACKAGE"
+    # echo "pkg files: dpkg -L <pkg_name>"
+    # dpkg -L $DPKG_MAINTSCRIPT_PACKAGE
+    # TEST
+    
+    #/usr/share/iri/undo_unbind_ftdi_udev.sh -s A600eB1Y
+    #/usr/share/iri/undo_unbind_ftdi_udev.sh -s A600eByq
+    #/usr/share/iri/undo_unbind_ftdi_udev.sh -s A900WSG1
+    # SERIAL DABO: A600eB1Y
+    # SERIAL TIBI: A600eByq
+    # SERIAL TEO:  A900WSG1
+    echo "You may want to remove pcspkr from /etc/modules, which was added when this package was installed."
+    #/var/lib/dpkg/info/iri-battery-monitor-dev.load_pcspkr
+  ;;
+  upgrade)
+
+  ;;
+  deconfigure)
+
+  ;;
+  failed-upgrade)
+
+  ;;
+esac
+exit 0
diff --git a/scripts/load_pcspkr.sh b/scripts/load_pcspkr
old mode 100644
new mode 100755
similarity index 87%
rename from scripts/load_pcspkr.sh
rename to scripts/load_pcspkr
index a441ac41b7fea80b4dabd971ecdb5bbd724bb051..fb4272bf36cdb1f57616f09ee2b4756fd2f2841b
--- a/scripts/load_pcspkr.sh
+++ b/scripts/load_pcspkr
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "--- load_pcspkr.sh ---"
+
 echo "Add pcspkr module to /etc/modules so it is loaded on startup"
 
 LINE='pcspkr'
diff --git a/scripts/set_example_privileges.sh b/scripts/set_example_privileges.sh
new file mode 100755
index 0000000000000000000000000000000000000000..9c65944f2c6ca30f5f07f55bcd2118f12787f3ec
--- /dev/null
+++ b/scripts/set_example_privileges.sh
@@ -0,0 +1,3 @@
+echo "battery_monitor_test: setting example privileges (needs sudo)"
+sudo chown root:audio bin/battery_monitor_test
+sudo chmod u+s bin/battery_monitor_test
\ No newline at end of file
diff --git a/scripts/unbind_ftdi_udev.sh b/scripts/unbind_ftdi_udev.sh
deleted file mode 100644
index 5d36c1e2ca22dbdccc6cf9ba87952b92d1518a39..0000000000000000000000000000000000000000
--- a/scripts/unbind_ftdi_udev.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-VENDOR=${1:-0403}
-PRODUCT=${2:-6001}
-FILE=${3:-99-ftdi.rules}
-
-echo "Add udev rule so ${VENDOR}:${PRODUCT} devices do not load ftdi_sio driver"
-
-LINE0="#The following 2 lines make ${VENDOR}:${PRODUCT} devices not load ftdi_sio driver"
-LINE1="ATTRS{idVendor}==\"${VENDOR}\", ATTRS{idProduct}==\"${PRODUCT}\", MODE:=\"0666\""
-LINE2=$"ATTRS{idVendor}==\"${VENDOR}\", ATTRS{idProduct}==\"${PRODUCT}\", RUN+=\"/bin/sh -c 'echo \$kernel > /sys/bus/usb/drivers/ftdi_sio/unbind'\""
-FILE=/etc/udev/rules.d/$FILE
-
-sudo touch $FILE
-grep -qF -- "$LINE0" "$FILE" || echo "$LINE0" | sudo tee -a "$FILE" > /dev/null
-grep -qF -- "$LINE1" "$FILE" || echo "$LINE1" | sudo tee -a "$FILE" > /dev/null
-grep -qF -- "$LINE2" "$FILE" || echo "$LINE2" | sudo tee -a "$FILE" > /dev/null
-
-sudo service udev restart
-echo "Need to unplug-plug devices for changes to take effect"
\ No newline at end of file
diff --git a/scripts/undo_load_pcspkr b/scripts/undo_load_pcspkr
new file mode 100755
index 0000000000000000000000000000000000000000..8507293d43626ccfed68fbd33e98a66e0151c829
--- /dev/null
+++ b/scripts/undo_load_pcspkr
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+echo "Remove pcspkr module from /etc/modules"
+
+LINE="pcspkr"
+FILE=/etc/modules
+
+
+sudo sed -i "/$LINE/d" $FILE
+sudo rmmod pcspkr
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2f4fb50c9348230ee47ee7110a2ba7fd3abf9d7c..5a72474c988bf358c27dd04f25195a2d47644fc9 100755
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 # driver source files
 SET(sources battery_monitor.cpp)
 # application header files
-SET(headers battery_monitor.h)
+SET(headers ../include/battery_monitor.h)
 
 # locate the necessary dependencies
 FIND_PACKAGE(iriutils REQUIRED)
@@ -9,17 +9,17 @@ FIND_PACKAGE(comm REQUIRED)
 FIND_PACKAGE(dynamixel REQUIRED)
 
 # add the necessary include directories
-INCLUDE_DIRECTORIES(.)
-INCLUDE_DIRECTORIES(${iriutils_INCLUDE_DIR})
-INCLUDE_DIRECTORIES(${comm_INCLUDE_DIR})
-INCLUDE_DIRECTORIES(${dynamixel_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(../include)
+INCLUDE_DIRECTORIES(${iriutils_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${comm_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${dynamixel_INCLUDE_DIRS})
 
 # create the shared library
 ADD_LIBRARY(battery_monitor SHARED ${sources})
 
-TARGET_LINK_LIBRARIES(battery_monitor ${iriutils_LIBRARY})
-TARGET_LINK_LIBRARIES(battery_monitor ${comm_LIBRARY})
-TARGET_LINK_LIBRARIES(battery_monitor ${dynamixel_LIBRARY})
+TARGET_LINK_LIBRARIES(battery_monitor ${iriutils_LIBRARIES})
+TARGET_LINK_LIBRARIES(battery_monitor ${comm_LIBRARIES})
+TARGET_LINK_LIBRARIES(battery_monitor ${dynamixel_LIBRARIES})
 
 # link necessary libraries
 INSTALL(TARGETS battery_monitor
@@ -28,4 +28,39 @@ INSTALL(TARGETS battery_monitor
         ARCHIVE DESTINATION lib/iri/${PROJECT_NAME})
 INSTALL(FILES ${headers} DESTINATION include/iri/${PROJECT_NAME})
 INSTALL(FILES ../Findbattery_monitor.cmake DESTINATION ${CMAKE_ROOT}/Modules/)
+INSTALL(FILES  ../scripts/load_pcspkr 
+               ../scripts/undo_load_pcspkr
+               DESTINATION share/iri 
+               PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
 ADD_SUBDIRECTORY(examples)
+
+find_package(Git QUIET)
+if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
+# Update submodules as needed
+    option(GIT_SUBMODULE "Check submodules during build" ON)
+    if(GIT_SUBMODULE)
+        message(STATUS "Submodule update")
+        execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
+                        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                        RESULT_VARIABLE GIT_SUBMOD_RESULT)
+        if(NOT GIT_SUBMOD_RESULT EQUAL "0")
+            message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
+        endif()
+    endif()
+endif()
+
+SET(firmware_dir avr8_smbus_battery_monitor)
+
+if(NOT EXISTS "${PROJECT_SOURCE_DIR}/${firmware_dir}/Makefile")
+    message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
+endif()
+
+add_custom_target(firmware COMMAND make
+                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../${firmware_dir}
+)
+
+INSTALL(FILES 
+          ${CMAKE_CURRENT_SOURCE_DIR}/../${firmware_dir}/avr8_battery_monitor_eeprom.hex
+          ${CMAKE_CURRENT_SOURCE_DIR}/../${firmware_dir}/avr8_battery_monitor.hex
+        DESTINATION lib/firmware/iri/${PROJECT_NAME}
+        OPTIONAL)
diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt
index 79cad01556ed4cdbbfd53625f73f4415cef22cb3..87b3022aab24aecef50b089f6eeec9f209d88964 100755
--- a/src/examples/CMakeLists.txt
+++ b/src/examples/CMakeLists.txt
@@ -4,6 +4,6 @@ ADD_EXECUTABLE(battery_monitor_test battery_monitor_test.cpp)
 TARGET_LINK_LIBRARIES(battery_monitor_test battery_monitor)
 
 add_custom_command(TARGET battery_monitor_test POST_BUILD 
-  COMMAND sh ./privileges.sh 
+  COMMAND sh ./scripts/set_example_privileges.sh 
   WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})