Mar 28, 2015

MQTT + Websocket

Sometime ago I was thinking in study a IoT protocol, looking for some minutes in web I discovered that one of the most popular protocols that're running in nowadays is MQTT. MQTT is a protocol publish-subscribe type very interesting because was created by IBM a long time ago, used in internal communication with servers and clusters, now we use this to integrate many different devices in a flexible network that can be managed where will you're. The protocol works with a simple topology, in this network you need to have a Broker(concentrator), similar to an Access Point, and the Clients or devices.
The Clients can publish or subscribe in Topics, those are managed by the broker. When a client subscribe a topic, he will receive all data published to this topic, and if he want he could publish in whatever topic in the network. It's real simple as I describe, and you can test on your PC in five minutes to confirm, but the best thing about this protocol is your port to TCP/IP stack, imagine that you're on a trip and you forgot to turn off your skip iron, if you have implemented MQTT in your home, you can connect to the internet and publish a simple "turn off" or "off" in a topic called, "iron clothes" now you drive safe without to back home. One of variants of this protocol are the port to WSN (Wireless Sensor Networks) with MQTT-SN, that is the same protocol but in different radios technologies, some ZigBee devices have fully compatible support to communicate with protocol and you can study how to implement in different applications and scenarios. Now I will teach how to install a broker MQTT and communicate him with a webscoket.

1 - First things first is to search for a lightweight/versatile broker, for the moment let's use MOSQUITTO

su #Insert your root password
apt-get install cmake libssl-dev build-essential
cd ~
git clone
cd libwebsockets/
mkdir build
cd build
cmake ..
make install
cd ~
git clone
cd org.eclipse.mosquitto

Now, open the file and edit the line "WITH_WEBSOCKETS:=no" change to yes and change "WITH_SRV=yes" to no .After install the pre-reqs. to compile mosquitto broker...
apt-get install uuid-dev xsltproc docbook-xsl
make test
make install
ln -s /usr/local/lib/ /usr/lib/
/sbin/ldconfig #Update the linker

Feb 16, 2015

Restoring an old laptop LCD

Since my hp laptop die by a George Foreman Grill temperature processor, I decided to recycle him or some parts but I didn't  have idea of how to do this until a time ago. I bought a LCD controller and I removed the LCD from the laptop, now I get a extended monitor that costs me 23$(ebay price of controller), see below some photos of this:

Feb 12, 2015

Upgrade Debian 7.8 to 8.0

After I started to use Debian 7.8 with gnome 3.4 (that's who comes with the image) I realized that some extensions that I want to use aren't supported in this version of gnome . If you see in the Debian website, the stable version launched in 10 of January of 2015 is perfect, but still use the gnome 3.4 and I preferred to upgrade my version to test once, a unstable testing version. The unstable version, "Jessie" in Debian 8 it's great and comes with gnome 3.14!!!! The steps that I follow are simple and remember to do by your own risk, try to test before in a virtual machine.
1- First update the source list replacing all words of "wheezy" by "jessie"  in the "/etc/apt/sources.list".
2- After update and install all packages:
apt-get update
apt-get upgrade
apt-get dist-upgrade
And go to prepare a cup of coffee, mainly if your internet is slow......It takes sometime to finish, but in the end you will be happy to see a image like this:

Feb 11, 2015

Wallpaper of the blog

This is a wallpaper of the blog, like everyone who is inspired by GNU/Linux's in 1600x900 because of my monitor, and if you want in higher resolution, just ask!

Feb 7, 2015

8x8 RGB Matrix Booster Pack in Tiva Launchpad

Like i promise, almost in the end of the week, here is another post. In four months ago i bought this booster pack from tindie and i forgot to read that the board didn't come with components, dammit!. I need to buy all the components from because there's no store to buy SMD components here where i live, i start to buy and after two long months, all components arrived from our Chinese friends. I also forgot to read that besides the components, there isn't library for use this on Tiva launchpad, but reading the code, is very simple to port to other uControllers. I re-write the code from RobG that is for msp430, and i added in the github to use in the Tiva Launchpad. The API is very simple and the board use a TLC5947, that's PWM LED driver where you send the data through serial (SPI) of each LED(R.G.B) and a 74HC138, a demux to select the line to ground. I try to use the SPI module from Tiva but it didn't work as i expected (i didn't discovered the pattern of this TLC and i was tired to search about it) then i just convert to hardware SPI, like Robg. 
The code works sending each color of each RGB LED, in other words, to write one line you use 24 chars of memory because of this, remember to declare const the data that will be write in the matrix, if not you can overload the heap of the uC. To write in all the matrix, you need to call this function:
 bool SendSSITLC(unsigned char *matrix_t, uint16_t offset,uint16_t limit);
eight times passing a char vector of colors an offset in this vector if you need sure, and the limit of this vector. In the main.c example you will see the Launchpad write in the matrix, but you can change easily, changing the pattern.h file. See above some photos of the matrix and the code running:

Jan 24, 2015

ESP8266 First Impressions

It's Have Been the while since i posted something in the blog , but now i will pay attention and i promise to post at least one new by week . To start again , let 's talk about the IoT revolution called " ESP8266 " ,
this small module is cheaper than an arduino nano because costs $5 bucks, it's ridiculous the chinese price and if you buy in aliexpress or ebay, you'll also see the free shipping. I'm Developing a home automation network and i'm using the Stack of LAMP, but with this module i'm thinking to change the socket communication with the hardware level to MQTT or TCP protocol instead of use the use this guy CC2530-ZigBee(one day i will post something about this). Espressif company launch this module as a solution for IoT and embedded systems, and our chinese friends develop different types of modules with the same IC. Here you will see all names of modules with 8266
OK, like everyone else, i bought this module from china and i will wait a long time to arrive (normal way in Brazil). Some specs of the module are:

  • 802.11 b / g / n
  • Wi-Fi Direct (P2P), soft-AP
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Built-in temperature sensor
  • Support antenna diversity
  • off leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • SDIO 2.0, SPI, UART
  • STBC, 1x1 MIMO, 2x1 MIMO
  • A-MPDU, A-MSDU aggregation and the 0.4 Within wake
  • 2ms, connect and transfer data packets
  • standby power consumption of less than 1.0mW (DTIM3)

Seeing this specs wee can have an idea from what is the max range of this device, based in the Friss tranmission equation, let's calculate how is the reach of this module:

Range = [10 ^ (19.5Tx power + 3Rx antenna gain + 3Tx antenna gain + 91Rx Sensitivity  )/20] / 41.88 x Loss Factor
            = 6.53 Km 

Don't call me crazy because this is the max distance in a open transmission with a shielded module and a 3dBi antenna. But if we consider at least 10%, we have 653 meters!. I had tested this module in my house, with the wireless router TG-862 from Arris, and it works perfectly. For the first test i decided to update the firmware, because the module works with AT commands and in the old fw, some commands are not implemented yet like baudrate configuration. To update the fw, you need python 2.7 and a USB RS-232 serial to TTL converter. I'm using Ubuntu 14.04 LTS (Trusty Tahr), but you can use other distro, just clone this repo of esp-tool and download the firmware from this. I chose the v0018000902, because is the last when this post is up. After you download you need to prepare the hardware, it's simple and i will show what i did. The pins from the ESP-8266 are:
First you need to cross between your RX and TX pins from your conversor, then power with a 3.3V source with 200mA of fan out. To enable the chip, just connect CH_PD pin to VCC. Now open a terminal and verify what device is your serial converter, use this command to to this:
ls /dev/tty*
After plug and unplug your device to see which adapter has changed and then after you discover, you put this:
sudo screen /dev/ttyUSB0 115200
When you open the terminal, just put "AT" and after press ctrl+m and ctrl+j (carry return, line feed), if you see an "OK", you're ready to send the commands to the module. This list of commands that i tested are:
AT+CWJAP="yourwifinetwork","yourpassword" #Get and ip com dhcp
AT+CIPMUX=1 #Multiple connections
AT+CIPSTART=4,"TCP","",8080 #Connect to tcp server in my ip, localhost through port 8080
AT+CIPSEND=4,12 #Send data to the server
>Hello World!
I used a tcp_server described in python to test the module, but you can use any other to test, if you want my code, just ask here.

Sep 18, 2014

Controlling Robotic arm with TIVA Launchpad

It's been while since i had posted something different from a tutorial, then because of this i will show a simple project to control a robotic arm. In my course on the university there's a old robotic arm called "robix", this is a educational kit that was bought to learn robotic in pascal, but with the over the years this was left for the students that are doing the last project of the course, that here we call this as TCC(final course project). 


Seeing this kit i had thought how to control with the Tiva launchpad ARM, and searching a little about this i discovered that i need to generate six PWM's signals to control the servo motors in the kit. In this picture below you will see how is the signal that you need to generate to control a simple servo motor.

Considering this i read the datasheet to discover how to generate a huge PWM time like 20ms. Viewing the feedback from the E2E forum i discovered that to generate this kind of PWM i will need a longer timer from the uC like the Wide Timer module, configuring this i need to discover the duty cycle from the servo motors in the arm to control the angles. The servo motors from the arm are the MG-995, and in this site you can see some parameters like the duty active of any kind of servo, then with this information i developed a library to control the robot and any kind of motor for the Tiva launchpad. In the "servo.h" file you have some parameters to define how your servo works, like the active duty cycle in micro-seconds for each servo and others.

    ███████╗   ███████╗   ██████╗
    ██╔════╝   ██╔════╝   ██╔══██╗
    █████╗     ███████╗   ██████╔╝
    ██╔══╝     ╚════██║   ██╔═══╝

    Author: Anderson Ignacio da Silva
    Date: 08/08/2014

    PWM Pins:
    Channels  |   Pin
       0          PC4
       1          PC5
       2          PC6
       3          PC7
       4          PD0
       5          PD1

        -To initialize just call InitServo()
        -Change the duty with SendServo(Channel,0-180 degrees)
        -If your servo has a different duty period, you can ch
         ange the time definitions in "servo_api.h"
        -Remember to change the MIN and MAX duty of each servo


#ifndef SERVO_API_H
#define SERVO_API_H
 #include "servo_api.h"
// #ifndef SERVO_API_H
// #define SERVO_API_H
//  #include "servo_api.c"
// #endif

/*  Definitions       */
#define PWM_FREQUENCY   50
#define PWM_PERIOD      20000  //Time in us

/* Some times for popular motors 
    -Time for max PWM servo (us)   MG995=2100 &  HS422=2300
    -Time for min PWM servo (us)   MG995=500  &  HS422=800 

#define MAX_SERVO_0     1900
#define MIN_SERVO_0      500

#define MAX_SERVO_1     1900
#define MIN_SERVO_1      500

#define MAX_SERVO_2     1900
#define MIN_SERVO_2      500

#define MAX_SERVO_3     1900
#define MIN_SERVO_3      500

#define MAX_SERVO_4     1900
#define MIN_SERVO_4      500

#define MAX_SERVO_5     1900
#define MIN_SERVO_5      500

#define MAX_SERVO_5     1900
#define MIN_SERVO_5      500
//#define DEBUG_SERVO

/*  Prototypes  */
void SendServo(uint8_t SelServo,uint8_t ValServo);
void CfgModPWM(void);
void CalcServo(void);
void InitServo(void);

To control the outputs you can see the .h file that has the instructions of how initialize and send position for the servo motors. To use this code you can copy from my repository in github and share your problems or doubts about the simple api for control servo motors. In this video below you see how the arm controls the robix using this api:

Thanks to read this post and see you next time.

Jul 24, 2014


Hello everyone, i have been busy with my college and other projects, but i want to share a complete tutorial for develop firmware on the TIVA launchpad from texas. It has been a while since texas instruments change your arm family name, now with the TIVA series, some problems may occur when you use this tutorial for the old name[STELLARIS] that i did in a few months ago. In this post you will see that some tools are the same as we have been using in the stellaris family, in fact, the lm4f120 microcontroller has almost the same architecture that tm4c123g and you can flash the same code, but when you use some specific peripherals the instantiated libraries can change and this can be a big problem. This tutorial is based on Doragasu tutorial. We will install all the necessary tools and after, configure the ECLIPSE-CDT to develop our codes with one of the best IDEs to the linux. Alright, lets install all the tools in the "~/tools" folder in your linux distribution.

[DISCLAIMER] - This tutorial is based on debian linux distributions.

ARM toolchain
First we need the toolchain for arm and then add the repository to your ppa directories and install the tool, to simplify our lives:
sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded -y
sudo apt-get update -y &>> /dev/null
sudo apt-get install gcc-arm-none-eabi -y

In the place of StellarisWare, we have now the TivaWare library, to download go to TI website and download the TIVAWARE library (SW-TM4C-, after unzip into a folder, lets call “tools” folder in your home directory:
mkdir -p ~/tools/tivaware
sudo apt-get install -y unzip &>> /dev/null
unzip -u ~/Downloads/SW-TM4C- -d ~/tools/tivaware
cd ~/tools/tivaware

Lm4flash is the programmer for arm and other architectures, you can use OpenOCD to program and load to the microcontroller, but lets use this. Install the dependencies:

sudo apt-get install libusb-1.0-0-dev -y
sudo apt-get install libtool libusb-dev -y
Install git control version:
sudo apt-get install git -y
cd ~/tools
git clone
cd lm4tools/lm4flash
Add lm4flash programmer to your PATH and udev rules for usb device:
sudo echo "export PATH=$PATH:$HOME/tools/lm4tools/lm4flash" &>> ~/.profile
echo 'ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", GROUP="users", MODE="0660"' | sudo tee /etc/udev/rules.d/99-stellaris-launchpad.rules
sudo usermod -aG users $USER 

Let's build OpenOCD (Open On-Chip Debugger) with ICDI (in-circuit debug interface) support to debug the Tiva-LaunchPad:
cd ~/tools
git clone openocd
sudo apt-get install autoconf automake texinfo 
sudo apt-get -o Dpkg::Options::="--force-overwrite" install gdb-arm-none-eabi
./configure --enable-maintainer-mode --enable-ti-icdi
sudo make install

Installing Eclipse
First install eclipse with:
sudo apt-get install eclipse-cdt -y
And then, open eclipse:
Configuring the project template:
The first screen that you will see is the workspace:

1 - Select "ok" and create your workspace projects into home folder. After goto menu: File > New > Project and select the C project

2 - Go next and select this Executable > Empty Project and Toolchains: Cross GCC, the name you can select anyone, but lets call "template"

3 - After select, click on next and now click on Advanced Settings... 

4 - Now select C/C++ tab, Build>Settings. Change the Configuration: box to [All Configurations], after write in the Prefix box arm-none-eabi-

Remember to select [All Configurations], in the next configurations boxes. 
5 - Click on Cross GCC Compiler>Symbols, and add the symbols PART_TM4C123GH6PM, TARGET_IS_BLIZZARD_RB1, ARM_MATH_CM4, the apply: 

6 - Go to Cross GCC Compiler>Include, and add the way of tivaware (/home/your_user/tools/tivaware)

7 - Select the Cross GCC Compiler>Miscellaneous, and add in the Other flags tab this flags "-c -fmessage-length=0 -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections": 

8 - Next, click on Cross GCC Linker>Libraries and add this path "/home/your_user/tools/tivaware/driverlib/gcc", in the Libraries add "driver"

9 - Select the Cross GCC Linker>Miscellaneous and add the flags "-Wl,--static,--gc-sections,-T../ldStart.ld -mthumb -mcpu=cortex-m4"

10 - Go to Build Steps, and add the command "arm-none-eabi-objcopy -O binary ${ProjName}.elf ${ProjName}.bin" and if you want, change the description "Generate binary file from elf file"

11 - Go to Build Artifact tab and add the ".elf" to the Artifact Name box, this instance the output from the compiler: 

12 - After this step, click on "Apply","ok" and "Finish"

13 - In the "Cross compiler prefix:" box, type "arm-none-eabi-" and "Finish" again:

Now we need to add some files to conclude our workspace, like the loader script to the target and the vector of interrupts. Just get this files from:

cd ~/workspace/template
wget --no-check-certificate && wget --no-check-certificate && wget --no-check-certificate

These files are copied into your workspace/template, if you create a new template, remember to copy them into the new. Before we continue, click in Refresh in the template project: 

LM4FLASH on eclipse
1 - Now we need to configure the flasher for your ambiance, lets use lm4tools instead OpenOCD, this can be a little easier for a new template. Alright, in eclipse, just click on "Run>External Tools>External Tools Configuration". Now right click on Program tab and "New"

2 - Now, change the Name to lm4flash, location to "/home/your_user/tools/lm4tools/lm4flash/lm4flash" and Working Directory: to "${workspace_loc:/template/Debug}", in the Arguments: add the binary file, "template.bin"

3 - Now click on "Apply" and then in "Close", if you did Al right now we can program the Tiva Launchpad. First, let's compile our code, click on "Build" to compile the blink green example, and after go to the external tools symbol(see picture below), then click on lm4flash, now you need to connect your board to computer. 

If all it's right, your board will flash the green led. 

OpenOCD on eclipse
Okay, maybe you are sweating at this time, i know that's is very extensive tutorial, but i guarantee that when you finish you will be happy to develop to this target platform. One of the basic tools when you work with microcontrollers is the debug tool, the [OpenOCD] is the right tool when you need to this for our target. Let's configure this tool on eclipse to debug our programs.
1 - Go to Run>External tools and right click on Program>New, as you did for lm4flash. Create with name "openocd". In Location paste "/home/your_user/tools/openocd/src/openocd", Working Directory paste "${workspace_loc:/template/Debug}" and in the Arguments, just paste the script that you will use to debug "-f /home/your_user/tools/openocd/tcl/board/ek-tm4c123gxl.cfg" and then apply: 

2 - Go to Help>Install New Software on the Work With tab, add "CDT -" and search for C/C++ GDB Hardware Debugging and install the plugin: 

3 - After go to Run>Debug Configurations, right click on GDB Hardware Debugging and select New, then change the name to gdb, then go to C/C++ Application: and paste "Debug/template_tiva.elf". Modify the Project box to "template" then apply the settings: 

4 - Now go to Debugger tab and uncheck the "Use remote target", paste as GDB command "arm-none-eabi-gdb", and remember to select "Standard GDB Hardware Debugging Launcher" then apply>close

5 - Now go to Startup tab and, uncheck "Reset and Delay(seconds)" and "Halt", paste the gdb commands to initialize "target extended-remote :3333 monitor reset halt" on Run Commands box, just paste "monitor reset init" and then apply: 

6 - Then select Launch Group menu, and create a launch with name Debug, after add in this sequence,Program::Openocd and GDB Hardware Debugging::gdb with Add... then apply: 

7 - Now close and go to debug button, then click on "1 Debug" and if no errors appeared, you probably finished configuring all.

If you reached this step without any problems, then congratulations, you have a perfect environment to develop firmware for the ARM platform. Thanks mainly to the blogger Doragasu. We meet in the next tutorial.

Mar 1, 2014

Git tutorial, a little bit of a powerful tool

Hi, in this post i will show a interesting tool called GIT. If you're a new programmer it's normal to understand that you never heard about git repository, after all, it's a little confuse to understand in the beginning. But, if this is not the first time that you program something, you may had already heard about git and the advantages to use it. A lot of software developers knows the git protocol and for my surprise, i found that there are a lot of hardware developers that never heard about Git. Well, i learned about this protocol by a teacher that helped me to create a organize code and safe version controller for my projects, he always spoke that in bigger projects and companies, this tool is fundamental. Then let's learn what's this protocol and how to use it:

Wikipedia resume: In software development, Git is a distributed revision control and source code management (SCM) system with an emphasis on speed.Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005. Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server. Git is free software distributed under the terms of the GNU General Public License version 2.

This is a good resume about git and i think there're a lot of information about history of this protocol in the internet, but i think that's more interesting learn about how to use it. I will show some commands and give an example to explain them. First, git is a protocol for a repository, in other words, in some place you will have your source files from your project stored(data local server, cloud servers...) and using GIT, you will be able to upload more files or edit them and for each modification you will have the date and comments. Initially you think, "I don't care about control version, i'm organized enough!", in the beginning i thought the same thing, but with the time you will have three, four...twenty files named "main_v1_0.c" and your single information will be the windows/linux data of creation file and the devil will embrace your shoulders for a time. For who wants to learn about how to create a repo and how to use it with git, follow me in the next steps:

Step 1. Choose a repo:

Well, there're a lot of web repos, but the most famous are Git Hub and Bitbucket, the basic difference is that in git hub your codes will be able for anyone to see and in the bitbucket you have a private repository where you can control who can see or work in the project. Talking about space, both do not have code size limitation, but both recommend that each repo has less than 1GB and about suppoort git hub has a much larger community than BitBucket. I prefer bitbucket because of the privacy, but both are good repositories. 

Let's use to explain the bitbucket, i don't know well but i think that's almost the same thing on github to create a repository on website. 

-First access the website of bitbucket (

-Then create your free account and log in.
-Create your first repository.

Ok, you create a account and you already have a repository for a project, now you need to create a copy to your computer where you will develop your project and after modified the files, upload them to the repository. If you pay some attention, you will see that in one step, the site gives you a code like below:

git clone

This code is important to you use to copy the repository structure to your computer. If you skipped when it was shown, do not be afraid, you can see this code again in the "clone/https" icon:

Step 2. Configure the client:

If you're a windows/mac user, you can download the tools for git client in this link. After install just open the program and select the directory to add your repository files. Then paste the code "git clone htt..." with "shit+Insert" keys on the terminal emulator. Before you press ENTER and copy the files from repository, add your password after the name of your directory on the command, like "git clone https://name of your repo:password repo(same the website)" and press enter:

The git protocol will copy all files of your repo to your local computer. After you can enter in your directory and see the files created, you will see threes files that's the same if you click on tab "source" of bitbucket repository. This files comes with the tutorial repo that you created before, in other words, you're sync with the repository and if you type:

git status

You will see that you're up-to-date with the repo and there's nothing to do. Ok, now let's add a file and upload for the repo. First open any text editor and create a simple file, after save it in the repo directory. The git protocol works this way:

First add the files that are in the version that you will send to the repo with "git add", then lock this version with the "git commit" and then send the files to the repo with "git push". I will show an example with the file that i created named "test.txt":

If you note in the bitbucket, you will see that the file was copied to the repository with the commentary that a i put in the terminal. I will put the three commands that i used to demonstrate this sample version: 

git add . #add all files to the version that i will send, you can also send one by one typing git add test.txt ....
git commit -m "Commentary" #Lock the version that will be send to the repo
git push origin master #Send your locked version to the repo
If you use the git in other computer with the same repository, just type "git pull" to update your local repository before work. Still there are a lot of information about git to study, i recommend you to see about "branches on git" after do this tutorial. For while let's finish here and see you next time. Any doubts just comment below and i will be greatful to answer you. Tks All.